@reservoir0x/relay-kit-ui
Version:
Relay is the Fastest and Cheapest Way to Bridge and Transact Across Chains.
56 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeTokenLists = exports.findBridgableToken = exports.convertApiCurrencyToToken = void 0;
const relay_sdk_1 = require("@reservoir0x/relay-sdk");
const convertApiCurrencyToToken = (currency, chainId) => {
return {
chainId: Number(chainId),
address: currency?.address ?? '',
name: currency?.name ?? '',
symbol: currency?.symbol ?? '',
decimals: currency?.decimals ?? 0,
logoURI: `${relay_sdk_1.ASSETS_RELAY_API}/icons/currencies/${currency?.id ?? currency?.symbol?.toLowerCase() ?? chainId}.png`,
verified: true
};
};
exports.convertApiCurrencyToToken = convertApiCurrencyToToken;
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 (0, exports.convertApiCurrencyToToken)(supportedToCurrency, chain.id);
}
}
else {
return token;
}
}
return null;
};
exports.findBridgableToken = findBridgableToken;
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;
};
exports.mergeTokenLists = mergeTokenLists;
//# sourceMappingURL=tokens.js.map