Skip to content

Commit

Permalink
Merge pull request #71 from skip-mev/asset-naming-conventions
Browse files Browse the repository at this point in the history
Asset naming conventions
  • Loading branch information
thal0x authored Oct 31, 2023
2 parents af30d84 + ce1802f commit bd98ceb
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/assets/filters.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions src/components/AssetSelect/AssetSelectContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -45,6 +46,7 @@ const AssetSelectContent: FC<Props> = ({

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;
Expand Down
77 changes: 75 additions & 2 deletions src/context/assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,95 @@ export const AssetsContext = createContext<AssetsContext>({
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;

if (hasDuplicates) {
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<PropsWithChildren> = ({ children }) => {
Expand Down

1 comment on commit bd98ceb

@vercel
Copy link

@vercel vercel bot commented on bd98ceb Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.