Skip to content

Commit

Permalink
feat: Use rpc in chainsConfig to get balance
Browse files Browse the repository at this point in the history
  • Loading branch information
wenty22 committed Dec 17, 2024
1 parent 3f69a66 commit 0a61381
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .release/.changeset/gorgeous-lies-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Use rpc in chainsConfig to get balance
1 change: 1 addition & 0 deletions .release/.changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"changesets": [
"cold-baboons-serve",
"gorgeous-lies-dance",
"happy-insects-give",
"hip-news-reflect",
"honest-adults-mate",
Expand Down
2 changes: 1 addition & 1 deletion apps/canonical-bridge-ui/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
6 changes: 6 additions & 0 deletions packages/canonical-bridge-widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @bnb-chain/canonical-bridge-widget

## 0.5.14-alpha.5

### Patch Changes

- Use rpc in chainsConfig to get balance

## 0.5.14-alpha.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/canonical-bridge-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bnb-chain/canonical-bridge-widget",
"version": "0.5.14-alpha.4",
"version": "0.5.14-alpha.5",
"description": "canonical bridge widget",
"author": "bnb-chain",
"private": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { setIsLoadingTokenBalances, setTokenBalances } from '@/modules/aggregato
import { useTronWeb } from '@/core/hooks/useTronWeb';
import { useSolanaAccount } from '@/modules/wallet/hooks/useSolanaAccount';
import { useTronAccount } from '@/modules/wallet/hooks/useTronAccount';
import { useAggregator } from '@/modules/aggregator/components/AggregatorProvider';

export function TokenBalancesProvider() {
const { chainConfigs } = useAggregator();
const { address } = useAccount();
const { address: solanaAddress } = useSolanaAccount();
const { address: tronAddress } = useTronAccount();
Expand Down Expand Up @@ -41,6 +43,7 @@ export function TokenBalancesProvider() {
evmParams: {
account: address,
chain: chains?.find((item) => item.id === fromChain?.id),
chainConfig: chainConfigs?.find((item) => item.id === fromChain?.id),
},
solanaParams: {
account: solanaAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function useSelection() {
}

function useSortedTokens() {
const { transferConfig } = useAggregator();
const { transferConfig, chainConfigs } = useAggregator();
const { getTokenPrice } = useTokenPrice();

const { address } = useAccount();
Expand All @@ -243,6 +243,7 @@ function useSortedTokens() {
evmParams: {
account: address,
chain: chains?.find((item) => item.id === fromChainId),
chainConfig: chainConfigs?.find((item) => item.id === fromChainId),
},
solanaParams: {
account: solanaAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Connection, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
import axios from 'axios';

import { ChainType, IBridgeToken } from '@/modules/aggregator/types';
import { ChainType, IBridgeToken, IChainConfig } from '@/modules/aggregator/types';
import { ERC20_TOKEN } from '@/core/contract/abi';
import { isChainOrTokenCompatible } from '@/modules/aggregator/shared/isChainOrTokenCompatible';
import { isSameAddress } from '@/core/utils/address';
Expand All @@ -23,6 +23,7 @@ export async function getTokenBalances({
evmParams: {
account?: string;
chain?: Chain;
chainConfig?: IChainConfig;
};
solanaParams: {
account?: string;
Expand Down Expand Up @@ -54,26 +55,30 @@ export async function getTokenBalances({
account: evmParams.account,
chain: evmParams.chain,
tokens: compatibleTokens,
chainConfig: evmParams.chainConfig,
});
}

async function getEvmTokenBalances({
account,
chain,
tokens,
chainConfig,
}: {
account?: string;
chain?: Chain;
tokens?: IBridgeToken[];
chainConfig?: IChainConfig;
}) {
try {
if (!chain || !account || !tokens?.length) {
return {};
}

const rpcUrl = chainConfig?.rpcUrl;
const client = createPublicClient({
chain,
transport: http(),
transport: http(rpcUrl),
});

const contracts = tokens.map((item) => ({
Expand Down

0 comments on commit 0a61381

Please sign in to comment.