Skip to content

Commit

Permalink
fix: Merge code
Browse files Browse the repository at this point in the history
  • Loading branch information
wenty22 committed Dec 5, 2024
2 parents 5af8f7e + 034cc4f commit 5c0c7b7
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 30 deletions.
6 changes: 2 additions & 4 deletions .release/.changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"tag": "alpha",
"initialVersions": {
"@bnb-chain/canonical-bridge-sdk": "0.4.2",
"@bnb-chain/canonical-bridge-widget": "0.5.5"
"@bnb-chain/canonical-bridge-widget": "0.5.6"
},
"changesets": [
"poor-news-hear"
]
"changesets": ["rare-poets-rhyme", "silent-mirrors-drop"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@bnb-chain/canonical-bridge-widget": patch
---

Show input error message when wallet is connected
Fix token balance issue
5 changes: 5 additions & 0 deletions .release/.changeset/silent-mirrors-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

Add token address to token element
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function useTransferConfig() {
137: ['cUSDCv3'],
42161: ['cUSDCv3'],
43114: ['BNB'],
7565164: ['So11111111111111111111111111111111111111112'],
},
},
bridgedTokenGroups: [
Expand Down
16 changes: 14 additions & 2 deletions packages/canonical-bridge-widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# @bnb-chain/canonical-bridge-widget

## 0.5.6-alpha.0
## 0.5.7-alpha.1

### Patch Changes

- Add address info to token list element
- Add token address to token element

## 0.5.7-alpha.0

### Patch Changes

- Fix token balance issue

## 0.5.6

### Patch Changes

- 601fb21: Show input error message when wallet is connected

## 0.5.5

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.6-alpha.0",
"version": "0.5.7-alpha.1",
"description": "canonical bridge widget",
"author": "bnb-chain",
"private": false,
Expand Down
4 changes: 4 additions & 0 deletions packages/canonical-bridge-widget/src/core/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,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';
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})}
Expand All @@ -116,7 +117,6 @@ export function ChooseTokenModal(props: ChooseTokenModalProps) {
transform: 'translateY(-100%)',
},
}}
data-address={item.address?.toLowerCase()}
onClick={() => {
reportEvent({
id: 'select_bridge_tokenDropdown',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -162,15 +165,15 @@ async function getTronTokenBalances({
);

if (token) {
balances[token.displaySymbol.toUpperCase()] = formatUnits(
balances[token.address?.toLowerCase()] = formatUnits(
BigInt(tokenInfo.balance),
token.decimals,
);
}
});

tokens.forEach((t) => {
const key = t.displaySymbol.toUpperCase();
const key = t.address.toLowerCase();
balances[key] = balances[key] ?? '0';
});

Expand Down Expand Up @@ -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';
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const InputValidationMessage = () => {

useEffect(() => {
const balance = getTokenBalance({
symbol: selectedToken?.displaySymbol,
address: selectedToken?.address?.toLowerCase(),
});

const balanceResult = validateInput({
Expand All @@ -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;
Expand Down

0 comments on commit 5c0c7b7

Please sign in to comment.