Skip to content

Commit

Permalink
Merge pull request #28 from router-protocol/fix/suitokeninfo
Browse files Browse the repository at this point in the history
update: sui rpc calls for balance & token metadata
  • Loading branch information
jayeshbhole-rp authored Nov 26, 2024
2 parents 0c6eead + f5096d7 commit 8a51534
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 50 deletions.
16 changes: 9 additions & 7 deletions packages/react/src/actions/getToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { getCosmosTokenBalanceAndAllowance, getCosmosTokenMetadata } from './cos
import { getEVMTokenBalanceAndAllowance, getEVMTokenMetadata } from './evm/getEVMToken.js';
import { viewMethodOnNear } from './near/readCalls.js';
import { getSolanaTokenBalanceAndAllowance } from './solana/getSolanaToken.js';
import { querySuiRpc } from './sui/queryRpc.js';
import { getTonTokenBalanceAndAllowance, getTonTokenMetadata } from './ton/getTonToken.js';

/**
Expand Down Expand Up @@ -141,16 +140,16 @@ export const getTokenMetadata = async ({ token, chain, config }: GetTokenMetadat

let res;
try {
res = await querySuiRpc({
chain,
method: 'suix_getCoinMetadata',
params: [token],
});
res = await config.suiClient.getCoinMetadata({ coinType: token });
} catch (error) {
console.error('Error fetching Sui token metadata:', error);
throw new Error('Failed to fetch Sui token metadata');
}

if (!res) {
throw new Error('Failed to fetch Sui token metadata');
}

return {
name: res.name,
symbol: res.symbol,
Expand Down Expand Up @@ -290,7 +289,10 @@ export const getTokenBalanceAndAllowance = (async (params) => {
let balance = 0n;

try {
const balanceResponse = await querySuiRpc({ chain, method: 'suix_getBalance', params: [account, token] });
const balanceResponse = await config.suiClient.getBalance({
owner: account,
coinType: token,
});
balance = BigInt(balanceResponse.totalBalance);
} catch (error) {
console.error('Error fetching Sui token balance:', error);
Expand Down
43 changes: 0 additions & 43 deletions packages/react/src/actions/sui/queryRpc.ts

This file was deleted.

0 comments on commit 8a51534

Please sign in to comment.