UNPKG

@reservoir0x/relay-kit-ui

Version:

Relay is the Fastest and Cheapest Way to Bridge and Transact Across Chains.

50 lines 1.75 kB
import { ASSETS_RELAY_API } from '@reservoir0x/relay-sdk'; export const convertApiCurrencyToToken = (currency, chainId) => { return { chainId: Number(chainId), address: currency?.address ?? '', name: currency?.name ?? '', symbol: currency?.symbol ?? '', decimals: currency?.decimals ?? 0, logoURI: `${ASSETS_RELAY_API}/icons/currencies/${currency?.id ?? currency?.symbol?.toLowerCase() ?? chainId}.png`, verified: true }; }; export const findBridgableToken = (chain, token) => { if (chain && token && token.chainId === chain.id) { const toCurrencies = [ ...(chain?.erc20Currencies ?? []), chain.currency ?? undefined ]; const toCurrency = toCurrencies.find((c) => c?.address === token?.address); if (!toCurrency || !toCurrency.supportsBridging) { const supportedToCurrency = toCurrencies.find((c) => c?.supportsBridging); if (supportedToCurrency) { return convertApiCurrencyToToken(supportedToCurrency, chain.id); } } else { return token; } } return null; }; export const mergeTokenLists = (lists) => { const mergedList = []; const seenTokens = new Set(); lists.forEach((list) => { if (!list) return; list.forEach((currency) => { if (!currency) return; const tokenKey = `${currency.chainId}:${currency.address?.toLowerCase()}`; if (!seenTokens.has(tokenKey)) { seenTokens.add(tokenKey); mergedList.push(currency); } }); }); return mergedList; }; //# sourceMappingURL=tokens.js.map