Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix to token display issue #272

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .release/.changeset/gold-zebras-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

fix: Fix to token display issue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Flex, Link, useBreakpointValue, useColorMode, useIntl, useTheme } from '@bnb-chain/space';
import { useMemo } from 'react';
import { BridgeType } from '@bnb-chain/canonical-bridge-sdk';

import { useAppSelector } from '@/modules/store/StoreProvider';
import { useGetReceiveAmount } from '@/modules/transfer/hooks/useGetReceiveAmount';
Expand All @@ -22,21 +23,28 @@ export const TransferSummary = () => {
const selectedToken = useAppSelector((state) => state.transfer.selectedToken);
const sendValue = useAppSelector((state) => state.transfer.sendValue);
const transferActionInfo = useAppSelector((state) => state.transfer.transferActionInfo);
const { toTokenInfo } = useToTokenInfo();
const { getToTokenAddress, toTokenInfo, getToTokenSymbol } = useToTokenInfo();

const bridgeType = useMemo(
() => transferActionInfo?.bridgeType,
[transferActionInfo],
) as BridgeType;
const receiveAmt = useMemo(() => {
if (!Number(sendValue)) return null;
if (transferActionInfo && transferActionInfo.bridgeType) {
const bridgeType = transferActionInfo.bridgeType;
if (bridgeType) {
const receiveValue = getSortedReceiveAmount();
return Number(receiveValue[bridgeType].value);
}
return null;
}, [getSortedReceiveAmount, transferActionInfo, sendValue]);
}, [getSortedReceiveAmount, bridgeType, sendValue]);

const toTokenAddress = useMemo(() => {
return bridgeType ? getToTokenAddress()[bridgeType] : '';
}, [bridgeType, getToTokenAddress]);

const isNative = useMemo(
() => isNativeToken(toTokenInfo?.address, toChain?.chainType),
[toTokenInfo?.address, toChain?.chainType],
() => isNativeToken(toTokenAddress, toChain?.chainType),
[toTokenAddress, toChain?.chainType],
);

return (
Expand Down Expand Up @@ -77,25 +85,27 @@ export const TransferSummary = () => {
<span style={{ marginRight: '2px' }}>
{formatMessage({ id: 'transfer.warning.confirm.to.address' })}
</span>
<Link
isExternal
href={formatTokenUrl(toChain?.tokenUrlPattern, toTokenInfo?.address)}
display="inline-block"
overflowWrap={'break-word'}
pointerEvents={'all'}
color="currentColor"
>
{isBase
? formatAppAddress({ address: toTokenInfo?.address, isTruncated: true })
: toTokenInfo?.address}
</Link>
{toTokenAddress ? (
<Link
isExternal
href={formatTokenUrl(toChain?.tokenUrlPattern, toTokenAddress)}
display="inline-block"
overflowWrap={'break-word'}
pointerEvents={'all'}
color="currentColor"
>
{isBase
? formatAppAddress({ address: toTokenAddress, isTruncated: true })
: toTokenAddress}
</Link>
) : null}
</>
) : (
<>
<span style={{ marginRight: '2px' }}>
{formatMessage({ id: 'transfer.warning.confirm.to.native.token.address' })}
</span>
<span>{toTokenInfo?.symbol?.toUpperCase()}</span>
<span>{getToTokenSymbol()?.[bridgeType]?.toUpperCase() ?? ''}</span>
</>
)}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const useToTokenInfo = () => {
deBridge: toTokenInfo?.deBridge?.raw?.address || '',
stargate: toTokenInfo?.stargate?.raw?.token?.address || '',
layerZero: toTokenInfo?.layerZero?.raw?.address || '',
meson: toTokenInfo?.meson?.raw?.addr || 0,
meson: toTokenInfo?.meson?.raw?.addr || '',
};
}, [toTokenInfo]);

Expand Down
Loading