Skip to content

Commit

Permalink
fix: substrate native token logos
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKheops committed Oct 11, 2023
1 parent 6b1795f commit 4f786cd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
9 changes: 6 additions & 3 deletions chaindata.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"balancesConfig": {
"substrate-native": {
"coingeckoId": "polkadot",
"dcentName": "POLKADOT"
"dcentName": "POLKADOT",
"logo": "./assets/tokens/dot.svg"
}
}
},
Expand All @@ -48,7 +49,8 @@
],
"balancesConfig": {
"substrate-native": {
"coingeckoId": "kusama"
"coingeckoId": "kusama",
"logo": "./assets/tokens/ksm.svg"
}
}
},
Expand Down Expand Up @@ -89,7 +91,8 @@
},
"balancesConfig": {
"substrate-native": {
"coingeckoId": "acala"
"coingeckoId": "acala",
"logo": "./assets/tokens/aca.svg"
},
"substrate-tokens": {
"tokens": [
Expand Down
58 changes: 33 additions & 25 deletions scripts/build/steps/setTokenLogos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,40 @@ type EvmNetworkWithBalancesConfig = EvmNetwork & {
}

export const setTokenLogos = async () => {
const allBalanceConfigs = [
...sharedData.chains.flatMap((chain) => (chain as ChainWithBalancesConfig).balancesConfig),
...sharedData.evmNetworks.flatMap((network) => (network as EvmNetworkWithBalancesConfig).balancesConfig),
const networks = [
...(sharedData.chains as ChainWithBalancesConfig[]),
...(sharedData.evmNetworks as EvmNetworkWithBalancesConfig[]),
]

const tokens = [] as TokenDef[]

for (const mod of allBalanceConfigs) {
if ('tokens' in mod.moduleConfig) tokens.push(...mod.moduleConfig.tokens)
else tokens.push(mod.moduleConfig)
}

for (const token of tokens) {
if (token.logo && !token.logo.startsWith('http') && existsSync(token.logo))
token.logo = getAssetUrlFromPath(token.logo)

if (!token.logo && token.symbol) {
const logoPath = `./assets/tokens/${token.symbol}.svg`
if (existsSync(logoPath)) token.logo = getAssetUrlFromPath(logoPath)
}

if (!token.logo && token.coingeckoId) {
const logoPath = `./assets/tokens/coingecko/${token.coingeckoId}.webp`
if (existsSync(logoPath)) token.logo = getAssetUrlFromPath(logoPath)
for (const network of networks) {
for (const mod of network.balancesConfig) {
const tokens = [] as TokenDef[]
if ('tokens' in mod.moduleConfig) tokens.push(...mod.moduleConfig.tokens)
else tokens.push(mod.moduleConfig)

for (const token of tokens) {
// resolve hardcoded logo path
if (token.logo && !token.logo.startsWith('https://') && existsSync(token.logo))
token.logo = getAssetUrlFromPath(token.logo)

// for substrate native, ignore symbol, prefer chain's logo or coingecko id
if (mod.moduleType === 'substrate-native') {
const logoPath = `./assets/chains/${network.id}.svg`
if (existsSync(logoPath)) token.logo = getAssetUrlFromPath(logoPath)
}
// for others resolve by symbol (unsafe - ex. should ETH on testnets use the official ETH icon?)
else if (!token.logo?.startsWith('https://') && token.symbol) {
const logoPath = `./assets/tokens/${token.symbol.toLocaleLowerCase()}.svg`
if (existsSync(logoPath)) token.logo = getAssetUrlFromPath(logoPath)
}

// resolve by coingecko id
if (!token.logo?.startsWith('https://') && token.coingeckoId) {
const logoPath = `./assets/tokens/coingecko/${token.coingeckoId}.webp`
if (existsSync(logoPath)) token.logo = getAssetUrlFromPath(logoPath)
}

if (!token.logo?.startsWith('https://')) token.logo = UNKNOWN_TOKEN_LOGO_URL
}
}

if (!token.logo) token.logo = UNKNOWN_TOKEN_LOGO_URL
}
}

0 comments on commit 4f786cd

Please sign in to comment.