From 005fa8d73fdcd7a16c3a088471296c15642c1b88 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 3 Dec 2024 10:43:46 +0000 Subject: [PATCH 1/2] chore: Update versions --- .release/.changeset/metal-forks-train.md | 5 ----- packages/canonical-bridge-widget/CHANGELOG.md | 6 ++++++ packages/canonical-bridge-widget/package.json | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 .release/.changeset/metal-forks-train.md diff --git a/.release/.changeset/metal-forks-train.md b/.release/.changeset/metal-forks-train.md deleted file mode 100644 index 517f5c51..00000000 --- a/.release/.changeset/metal-forks-train.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@bnb-chain/canonical-bridge-widget": patch ---- - -Show input error message when wallet is connected diff --git a/packages/canonical-bridge-widget/CHANGELOG.md b/packages/canonical-bridge-widget/CHANGELOG.md index 0915dd58..8d9af986 100644 --- a/packages/canonical-bridge-widget/CHANGELOG.md +++ b/packages/canonical-bridge-widget/CHANGELOG.md @@ -1,5 +1,11 @@ # @bnb-chain/canonical-bridge-widget +## 0.5.6 + +### Patch Changes + +- 601fb21: Show input error message when wallet is connected + ## 0.5.5 ### Patch Changes diff --git a/packages/canonical-bridge-widget/package.json b/packages/canonical-bridge-widget/package.json index 83a29389..579fc656 100644 --- a/packages/canonical-bridge-widget/package.json +++ b/packages/canonical-bridge-widget/package.json @@ -1,6 +1,6 @@ { "name": "@bnb-chain/canonical-bridge-widget", - "version": "0.5.5", + "version": "0.5.6", "description": "canonical bridge widget", "author": "bnb-chain", "private": false, From 034cc4fb7bd4517d85a4a38fab319e8896212f62 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Thu, 5 Dec 2024 15:17:54 +0800 Subject: [PATCH 2/2] feat: Fix balance issue --- .release/.changeset/pre.json | 12 ++++++++++ .release/.changeset/rare-poets-rhyme.md | 5 ++++ .release/.changeset/silent-mirrors-drop.md | 5 ++++ .../token-config/mainnet/useTransferConfig.ts | 1 + packages/canonical-bridge-widget/CHANGELOG.md | 12 ++++++++++ packages/canonical-bridge-widget/package.json | 2 +- .../src/core/constants/index.ts | 4 ++++ .../SelectModal/ChooseTokenModal.tsx | 1 + .../modules/aggregator/hooks/useSelection.ts | 2 +- .../aggregator/hooks/useTokenBalance.ts | 8 +++---- .../aggregator/shared/getTokenBalances.ts | 24 +++++++++---------- .../SendInput/InputValidationMessage.tsx | 8 +++---- 12 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 .release/.changeset/pre.json create mode 100644 .release/.changeset/rare-poets-rhyme.md create mode 100644 .release/.changeset/silent-mirrors-drop.md diff --git a/.release/.changeset/pre.json b/.release/.changeset/pre.json new file mode 100644 index 00000000..701d383e --- /dev/null +++ b/.release/.changeset/pre.json @@ -0,0 +1,12 @@ +{ + "mode": "pre", + "tag": "alpha", + "initialVersions": { + "@bnb-chain/canonical-bridge-sdk": "0.4.2", + "@bnb-chain/canonical-bridge-widget": "0.5.6" + }, + "changesets": [ + "rare-poets-rhyme", + "silent-mirrors-drop" + ] +} diff --git a/.release/.changeset/rare-poets-rhyme.md b/.release/.changeset/rare-poets-rhyme.md new file mode 100644 index 00000000..d7e60a13 --- /dev/null +++ b/.release/.changeset/rare-poets-rhyme.md @@ -0,0 +1,5 @@ +--- +"@bnb-chain/canonical-bridge-widget": patch +--- + +Fix token balance issue diff --git a/.release/.changeset/silent-mirrors-drop.md b/.release/.changeset/silent-mirrors-drop.md new file mode 100644 index 00000000..af5ea070 --- /dev/null +++ b/.release/.changeset/silent-mirrors-drop.md @@ -0,0 +1,5 @@ +--- +"@bnb-chain/canonical-bridge-widget": patch +--- + +Add token address to token element diff --git a/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts b/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts index 06db7b06..a68d93bb 100644 --- a/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts +++ b/apps/canonical-bridge-ui/token-config/mainnet/useTransferConfig.ts @@ -133,6 +133,7 @@ export function useTransferConfig() { 137: ['cUSDCv3'], 42161: ['cUSDCv3'], 43114: ['BNB'], + 7565164: ['So11111111111111111111111111111111111111112'], }, }, bridgedTokenGroups: [ diff --git a/packages/canonical-bridge-widget/CHANGELOG.md b/packages/canonical-bridge-widget/CHANGELOG.md index 8d9af986..627d4cca 100644 --- a/packages/canonical-bridge-widget/CHANGELOG.md +++ b/packages/canonical-bridge-widget/CHANGELOG.md @@ -1,5 +1,17 @@ # @bnb-chain/canonical-bridge-widget +## 0.5.7-alpha.1 + +### Patch Changes + +- Add token address to token element + +## 0.5.7-alpha.0 + +### Patch Changes + +- Fix token balance issue + ## 0.5.6 ### Patch Changes diff --git a/packages/canonical-bridge-widget/package.json b/packages/canonical-bridge-widget/package.json index 579fc656..0f118c7a 100644 --- a/packages/canonical-bridge-widget/package.json +++ b/packages/canonical-bridge-widget/package.json @@ -1,6 +1,6 @@ { "name": "@bnb-chain/canonical-bridge-widget", - "version": "0.5.6", + "version": "0.5.7-alpha.1", "description": "canonical bridge widget", "author": "bnb-chain", "private": false, diff --git a/packages/canonical-bridge-widget/src/core/constants/index.ts b/packages/canonical-bridge-widget/src/core/constants/index.ts index e5189218..f1e3254c 100644 --- a/packages/canonical-bridge-widget/src/core/constants/index.ts +++ b/packages/canonical-bridge-widget/src/core/constants/index.ts @@ -42,3 +42,7 @@ export const MIN_FEE = 0.0001; export const REFETCH_INTERVAL = 8 * 1000; export const MIN_SOL_TO_ENABLED_TX = 0.05; + +export const EVM_NATIVE_TOKEN_ADDRESS = '0x0000000000000000000000000000000000000000'; + +export const SOLANA_NATIVE_TOKEN_ADDRESS = '11111111111111111111111111111111'; diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/components/SelectModal/ChooseTokenModal.tsx b/packages/canonical-bridge-widget/src/modules/aggregator/components/SelectModal/ChooseTokenModal.tsx index 883b9229..2b9e162e 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/components/SelectModal/ChooseTokenModal.tsx +++ b/packages/canonical-bridge-widget/src/modules/aggregator/components/SelectModal/ChooseTokenModal.tsx @@ -108,6 +108,7 @@ export function ChooseTokenModal(props: ChooseTokenModalProps) { iconUrl={item.icon} isActive={isActive} isDisabled={isDisabled} + data-address={item.address?.toLowerCase()} incompatibleTooltip={formatMessage({ id: 'select-modal.token.incompatible.tooltip', })} diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/hooks/useSelection.ts b/packages/canonical-bridge-widget/src/modules/aggregator/hooks/useSelection.ts index 4ccd602c..0041eb30 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/hooks/useSelection.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/hooks/useSelection.ts @@ -242,7 +242,7 @@ function useSortedTokens() { }); const tmpTokens = tokens.map((item) => { - const balance = balances[item.displaySymbol]; + const balance = balances[item.address?.toLowerCase()]; const price = getTokenPrice(item); let value: number | undefined; diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/hooks/useTokenBalance.ts b/packages/canonical-bridge-widget/src/modules/aggregator/hooks/useTokenBalance.ts index fb240384..8958d57b 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/hooks/useTokenBalance.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/hooks/useTokenBalance.ts @@ -7,11 +7,11 @@ export function useTokenBalance() { const tokenBalances = useAppSelector((state) => state.aggregator.tokenBalances); const getTokenBalance = useCallback( - (params: IBridgeToken | { symbol?: string } = {}) => { - const tokenSymbol = (params as IBridgeToken).displaySymbol ?? params.symbol; + (params: IBridgeToken | { address?: string } = {}) => { + const tokenAddress = (params as IBridgeToken).address ?? params.address; - if (tokenSymbol) { - return tokenBalances[tokenSymbol.toUpperCase()]; + if (tokenAddress) { + return tokenBalances[tokenAddress.toLowerCase()]; } }, [tokenBalances], diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/shared/getTokenBalances.ts b/packages/canonical-bridge-widget/src/modules/aggregator/shared/getTokenBalances.ts index ab304c75..56e698ff 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/shared/getTokenBalances.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/shared/getTokenBalances.ts @@ -9,6 +9,7 @@ import { ChainType, IBridgeToken } from '@/modules/aggregator/types'; import { ERC20_TOKEN } from '@/core/contract/abi'; import { isChainOrTokenCompatible } from '@/modules/aggregator/shared/isChainOrTokenCompatible'; import { isSameAddress } from '@/core/utils/address'; +import { EVM_NATIVE_TOKEN_ADDRESS, SOLANA_NATIVE_TOKEN_ADDRESS } from '@/core/constants'; export async function getTokenBalances({ chainType, @@ -99,15 +100,17 @@ async function getEvmTokenBalances({ values.map((value, index) => { const token = tokens[index]; - const symbol = token.displaySymbol?.toUpperCase(); - balances[symbol] = + const address = token.address?.toLowerCase(); + balances[address] = typeof value === 'undefined' ? undefined : formatUnits(BigInt(value), token.decimals); }); } if (nativeTokenRes.status === 'fulfilled') { - const symbol = chain.nativeCurrency.symbol?.toUpperCase(); - balances[symbol] = formatUnits(BigInt(nativeTokenRes.value), chain.nativeCurrency.decimals); + balances[EVM_NATIVE_TOKEN_ADDRESS] = formatUnits( + BigInt(nativeTokenRes.value), + chain.nativeCurrency.decimals, + ); } return balances; @@ -162,7 +165,7 @@ async function getTronTokenBalances({ ); if (token) { - balances[token.displaySymbol.toUpperCase()] = formatUnits( + balances[token.address?.toLowerCase()] = formatUnits( BigInt(tokenInfo.balance), token.decimals, ); @@ -170,7 +173,7 @@ async function getTronTokenBalances({ }); tokens.forEach((t) => { - const key = t.displaySymbol.toUpperCase(); + const key = t.address.toLowerCase(); balances[key] = balances[key] ?? '0'; }); @@ -211,20 +214,17 @@ async function getSolanaTokenBalances({ const token = tokens.find((t) => isSameAddress(t.address, accountInfo.mint.toBase58())); if (token) { - balances[token.displaySymbol.toUpperCase()] = formatUnits( - accountInfo.amount, - token.decimals, - ); + balances[token.address?.toLowerCase()] = formatUnits(accountInfo.amount, token.decimals); } }); } if (nativeTokenRes.status === 'fulfilled') { - balances['SOL'] = String(nativeTokenRes.value / LAMPORTS_PER_SOL); + balances[SOLANA_NATIVE_TOKEN_ADDRESS] = String(nativeTokenRes.value / LAMPORTS_PER_SOL); } tokens.forEach((t) => { - const key = t.displaySymbol.toUpperCase(); + const key = t.address?.toLowerCase(); balances[key] = balances[key] ?? '0'; }); diff --git a/packages/canonical-bridge-widget/src/modules/transfer/components/SendInput/InputValidationMessage.tsx b/packages/canonical-bridge-widget/src/modules/transfer/components/SendInput/InputValidationMessage.tsx index e56c0aae..600d449a 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/components/SendInput/InputValidationMessage.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/components/SendInput/InputValidationMessage.tsx @@ -27,7 +27,7 @@ export const InputValidationMessage = () => { useEffect(() => { const balance = getTokenBalance({ - symbol: selectedToken?.displaySymbol, + address: selectedToken?.address?.toLowerCase(), }); const balanceResult = validateInput({ @@ -52,14 +52,14 @@ export const InputValidationMessage = () => { sendValue, dispatch, estimatedAmount, - minMaxSendAmt?.min, - minMaxSendAmt?.max, + minMaxSendAmt.min, + minMaxSendAmt.max, selectedToken?.decimals, selectedToken?.isPegged, transferActionInfo, validateInput, getTokenBalance, - selectedToken?.displaySymbol, + selectedToken?.address, ]); const errorMsg = balanceInputError ?? error?.text;