diff --git a/src/assets/filters.ts b/src/assets/filters.ts new file mode 100644 index 00000000..5c9d6f41 --- /dev/null +++ b/src/assets/filters.ts @@ -0,0 +1,8 @@ +import { AssetWithMetadata } from "@/context/assets"; + +export function filterSifAssets(asset: AssetWithMetadata) { + if (asset.originChainID === "sifchain-1" && asset.originDenom !== "rowan") { + return false; + } + return true; +} diff --git a/src/components/AssetSelect/AssetSelectContent.tsx b/src/components/AssetSelect/AssetSelectContent.tsx index e6f3f07f..3dc46be5 100644 --- a/src/components/AssetSelect/AssetSelectContent.tsx +++ b/src/components/AssetSelect/AssetSelectContent.tsx @@ -4,6 +4,7 @@ import { ethers, toBigInt } from "ethers"; import { FC, useEffect, useRef, useState } from "react"; import { useWindowSize } from "usehooks-ts"; +import { filterSifAssets } from "@/assets/filters"; import { AssetWithMetadata } from "@/context/assets"; interface Props { @@ -45,6 +46,7 @@ const AssetSelectContent: FC = ({ return 0; }) + .filter(filterSifAssets) .sort((a, b) => { const balanceA = balances[a.denom] ? toBigInt(balances[a.denom]) : 0n; const balanceB = balances[b.denom] ? toBigInt(balances[b.denom]) : 0n; diff --git a/src/context/assets.tsx b/src/context/assets.tsx index 11895ff2..3122a730 100644 --- a/src/context/assets.tsx +++ b/src/context/assets.tsx @@ -31,11 +31,81 @@ export const AssetsContext = createContext({ getNativeAssets: () => [], }); +function getAssetSymbolSuffix(originDenom: string, originChainName: string) { + switch (originChainName) { + case "Axelar": + if (originDenom.includes("polygon-")) { + return ".axl (Polygon)"; + } + + if (originDenom.includes("avalanche-")) { + return ".axl (Avalanche)"; + } + + return ".axl"; + case "Sifchain": + return ".sif"; + case "Gravity Bridge": + return ".grv"; + case "Noble": + return ""; + default: + return ` ${originChainName}`; + } +} + function getAssetSymbol( asset: AssetWithMetadata, assets: Asset[], chains: Chain[], ) { + if (asset.originChainID === "axelar-dojo-1") { + if (asset.originDenom === "uaxl") { + return asset.symbol ?? asset.denom; + } + + const originChain = chains.find((c) => c.chainID === asset.originChainID); + const originChainName = originChain?.prettyName ?? asset.originChainID; + + return `${asset.symbol?.replace("axl", "")}${getAssetSymbolSuffix( + asset.originDenom, + originChainName, + )}`; + } + + if (asset.originChainID === "gravity-bridge-3") { + if (asset.originDenom === "ugraviton") { + return asset.symbol ?? asset.denom; + } + + const originChain = chains.find((c) => c.chainID === asset.originChainID); + const originChainName = originChain?.prettyName ?? asset.originChainID; + + return `${asset.symbol}${getAssetSymbolSuffix( + asset.originDenom, + originChainName, + )}`; + } + + if (asset.originChainID === "sifchain-1") { + const originChain = chains.find((c) => c.chainID === asset.originChainID); + const originChainName = originChain?.prettyName ?? asset.originChainID; + + if (asset.originDenom === "rowan") { + return asset.symbol ?? asset.denom; + } + + return `${asset.symbol}${getAssetSymbolSuffix( + asset.originDenom, + originChainName, + )}`; + } + + // this just handles a weird EVM token edge case + if (asset.symbol?.startsWith("axl")) { + return `${asset.symbol.replace("axl", "")}.axl`; + } + const hasDuplicates = (assets?.filter((a) => a.symbol === asset.symbol).length ?? 0) > 1; @@ -43,10 +113,13 @@ function getAssetSymbol( const originChain = chains.find((c) => c.chainID === asset.originChainID); const originChainName = originChain?.prettyName ?? asset.originChainID; - return `${originChainName} ${asset.symbol}`; + return `${asset.symbol}${getAssetSymbolSuffix( + asset.originDenom, + originChainName, + )}`; } - return asset.symbol; + return asset.symbol ?? asset.denom; } export const AssetsProvider: FC = ({ children }) => {