Skip to content

Commit

Permalink
change get token url (#2265)
Browse files Browse the repository at this point in the history
  • Loading branch information
aelmanaa authored Jan 17, 2025
1 parent 6b86519 commit d109a71
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/features/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,27 @@ export const getTitle = (supportedChain: SupportedChain) => {
return chains[technology]?.chains[supportedChain]?.title
}

/**
* Transforms a token name according to the following rules:
* 1. Convert to lowercase
* 2. Remove all dots (.)
* 3. Replace plus signs (+) with %2B
* @example
* BTC.b → btcb
* COMP+USDC → comp%2Busdc
* TOKEN.A+B → tokena%2Bb
*/
const transformTokenName = (token: string): string => {
if (!token) return ""
return token
.toLowerCase() // Step 1: Convert to lowercase
.replace(/\./g, "") // Step 2: Remove all dots
.replace(/\+/g, "%2B") // Step 3: Replace plus signs with %2B
}

export const getTokenIconUrl = (token: string) => {
if (!token) return
return `https://d2f70xi62kby8n.cloudfront.net/tokens/${token.toLowerCase()}.webp?auto=compress%2Cformat`
return `https://d2f70xi62kby8n.cloudfront.net/tokens/${transformTokenName(token)}.webp?auto=compress%2Cformat`
}

export const fallbackTokenIconUrl = "/assets/icons/generic-token.svg"
Expand Down

0 comments on commit d109a71

Please sign in to comment.