Skip to content

Commit

Permalink
update wallet, change here for meteor
Browse files Browse the repository at this point in the history
  • Loading branch information
PiVortex committed Aug 21, 2024
1 parent 174c64e commit c8c99a7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@near-wallet-selector/core": "^8.9.11",
"@near-wallet-selector/here-wallet": "^8.9.11",
"@near-wallet-selector/meteor-wallet": "^8.9.11",
"@near-wallet-selector/modal-ui": "^8.9.11",
"@near-wallet-selector/my-near-wallet": "^8.9.11",
"bootstrap": "^5",
Expand Down
51 changes: 49 additions & 2 deletions frontend/src/wallets/near.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { distinctUntilChanged, map } from 'rxjs';
import '@near-wallet-selector/modal-ui/styles.css';
import { setupModal } from '@near-wallet-selector/modal-ui';
import { setupWalletSelector } from '@near-wallet-selector/core';
import { setupHereWallet } from '@near-wallet-selector/here-wallet';
import { setupMeteorWallet } from '@near-wallet-selector/meteor-wallet';
import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet';

const THIRTY_TGAS = '30000000000000';
Expand Down Expand Up @@ -35,7 +35,7 @@ export class Wallet {
startUp = async (accountChangeHook) => {
this.selector = setupWalletSelector({
network: this.networkId,
modules: [setupMyNearWallet(), setupHereWallet()]
modules: [setupMyNearWallet(), setupMeteorWallet()]
});

const walletSelector = await this.selector;
Expand Down Expand Up @@ -138,4 +138,51 @@ export class Wallet {
const transaction = await provider.txStatus(txhash, 'unnused');
return providers.getTransactionLastResult(transaction);
};

/**
* Retrieves the balance of an account
* @param {string} accountId - the account id
* @returns {Promise<number>} - the account balance
*/
getBalance = async (accountId) => {
const walletSelector = await this.selector;
const { network } = walletSelector.options;
const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });

// Retrieve account state from the network
const account = await provider.query({
request_type: 'view_account',
account_id: accountId,
finality: 'final',
});

// Return amount in NEAR
return account.amount ? account.amount / (10**24) : 0;
};

/**
* Send multiple transactions simultaneously
* @param {Array<Object>} transactions - the array of transaction objects to be signed and sent
* @returns {Promise<Object>} - the resulting transactions
* @example
* await wallet.signAndSendTransactions({
transactions: [
{
receiverId: "receiver.testnet",
actions: [
{
type: "Transfer",
params: {
amount: "10000000000000000000000",
},
},
],
}
],
});
*/
signAndSendTransactions = async (transactions) => {
const selectedWallet = await (await this.selector).wallet();
return selectedWallet.signAndSendTransactions(transactions);
};
}

0 comments on commit c8c99a7

Please sign in to comment.