Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,34 @@ const ChainItem = ({ chain, setChainId, isLast }: ChainItemProps) => {
const isSignedIn = signedInWallets.some(wallet => wallet.xChainId === chain.xChainId);
const crossChainBalances = useCrossChainWalletBalances();
const collateralType = useCollateralType();
const xToken = xTokenMap[chain.xChainId].find(xToken => xToken.symbol === collateralType);
const selectedCollateralType = useCollateralType();
const isSmall = useMedia('(max-width: 440px)');

// Find token by symbol or by identifier (for BTC/BTCB case)
const findTokenForCollateral = useMemo(() => {
const chainTokens = xTokenMap[chain.xChainId] || [];
// First try to find by symbol
let token = chainTokens.find(xToken => xToken.symbol === collateralType);

// If not found, find tokens that share the same identifier
if (!token) {
// Get identifiers from tokens with matching symbol across all chains
const allTokens = Object.values(xTokenMap).flat();
const matchingTokens = allTokens.filter(t => t.symbol === collateralType);
const matchingIdentifiers = new Set(matchingTokens.map(t => t.identifier));

// Find token on this chain that shares the identifier
token = chainTokens.find(t => matchingIdentifiers.has(t.identifier));
}

return token;
}, [chain.xChainId, collateralType]);

const xToken = findTokenForCollateral;
const depositedAmounts = useCollateralAmounts(chain.xChainId);
const existingPosition = depositedAmounts[collateralType];
const prices = useOraclePrices();
const xTokenPrice = prices?.[xToken?.symbol || ''];
const selectedCollateralType = useCollateralType();
const isSmall = useMedia('(max-width: 440px)');

const formattedWalletBalance = useMemo(() => {
if (existingPosition?.isGreaterThan(0) || !xToken) return;
Expand All @@ -66,9 +87,22 @@ const ChainItem = ({ chain, setChainId, isLast }: ChainItemProps) => {
return xTokenPrice ? formatValue(existingPosition.times(xTokenPrice).toFixed()) : '-';
}, [existingPosition, xTokenPrice]);

const spokeAssetVersion = xTokenMap[chain.xChainId].find(
xToken => xToken.symbol === selectedCollateralType,
)?.spokeVersion;
// Find spoke version using the same logic
const spokeAssetVersion = useMemo(() => {
const chainTokens = xTokenMap[chain.xChainId] || [];
// First try to find by symbol
let token = chainTokens.find(xToken => xToken.symbol === selectedCollateralType);

// If not found, find tokens that share the same identifier
if (!token) {
const allTokens = Object.values(xTokenMap).flat();
const matchingTokens = allTokens.filter(t => t.symbol === selectedCollateralType);
const matchingIdentifiers = new Set(matchingTokens.map(t => t.identifier));
token = chainTokens.find(t => matchingIdentifiers.has(t.identifier));
}

return token?.spokeVersion;
}, [chain.xChainId, selectedCollateralType]);

return (
<Grid $isSignedIn={isSignedIn} className={isLast ? '' : 'border-bottom'} onClick={e => setChainId(chain.xChainId)}>
Expand Down
1 change: 1 addition & 0 deletions packages/xwagmi/src/constants/xTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export const xTokenMap: { [key in XChainId]: XToken[] } = {
'BTCB',
'Binance-Peg BTCB Token',
'BTC1',
'BTCB',
),
new XToken('0x38.bsc', 56, '0xd94F0Aea6d6f14C012d992e8886C8C1736921e10', 18, 'sICX', 'Staked ICX'),
new XToken('0x38.bsc', 56, '0x94cf269d63c4140eD481CB0b149daE03c4620cdF', 18, 'BALN', 'Balance Token'),
Expand Down
19 changes: 15 additions & 4 deletions packages/xwagmi/src/xcall/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,21 @@ export const toICONDecimals = (currencyAmount: CurrencyAmount<Currency>): bigint
};

export const getSupportedXChainIdsForToken = (currency: Currency | XToken): XChainId[] => {
return Object.values(xTokenMap)
.flat()
.filter(t => t.symbol === currency?.symbol)
.map(t => t.xChainId);
const allTokens = Object.values(xTokenMap).flat();

// Find tokens matching by symbol
const matchingTokens = allTokens.filter(t => t.symbol === currency?.symbol);

// Get identifiers from matching tokens (for BTC-related tokens that share 'BTC1' identifier)
const matchingIdentifiers = new Set(matchingTokens.map(t => t.identifier));

// Also include tokens that share the same identifier (e.g., BTCB shares 'BTC1' with BTC)
const tokensByIdentifier = allTokens.filter(t => matchingIdentifiers.has(t.identifier));

// Combine both sets and get unique chain IDs
const chainIds = new Set(tokensByIdentifier.map(t => t.xChainId));

return Array.from(chainIds);
};

export const getSupportedXChainForToken = (currency?: Currency | XToken | null): XChain[] | undefined => {
Expand Down