Skip to content

Commit

Permalink
feat: add trust as a fallback to logo urls
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 committed Oct 16, 2023
1 parent 45feae5 commit 5552b69
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion libs/common-const/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export * from './networks'
export * from './routing'
export * from './ipfs'
export * from './gnosis_chain/hack'
export * from './cowprotocolTokenLists'
export * from './cowprotocolTokenUrl'
export * from './nativeAndWrappedTokens'
2 changes: 1 addition & 1 deletion libs/common-const/src/nativeAndWrappedTokens.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SupportedChainId, SupportedChainId as ChainId } from '@cowprotocol/cow-sdk'
import { TokenWithLogo } from './types'
import { WETH9 } from '@uniswap/sdk-core'
import { cowprotocolTokenUrl } from './cowprotocolTokenLists'
import { cowprotocolTokenUrl } from './cowprotocolTokenUrl'

import wxDaiLogo from '@cowprotocol/assets/cow-swap/wxdai.png'

Expand Down
2 changes: 1 addition & 1 deletion libs/common-const/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import vCowLogo from '@cowprotocol/assets/cow-swap/vCOW.png'

import { COW_CONTRACT_ADDRESS, V_COW_CONTRACT_ADDRESS } from './common'
import { TokenWithLogo } from './types'
import { cowprotocolTokenUrl } from './cowprotocolTokenLists'
import { cowprotocolTokenUrl } from './cowprotocolTokenUrl'
import { WETH_MAINNET } from './nativeAndWrappedTokens'

// Mainnet
Expand Down
18 changes: 11 additions & 7 deletions libs/tokens/src/utils/getTokenLogoUrls.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { cowprotocolTokenUrl, TokenWithLogo } from '@cowprotocol/common-const'
import { uriToHttp } from '@cowprotocol/common-utils'
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { trustTokenLogoUrl } from './trustTokenLogoUrl'

export function getTokenLogoUrls(token: TokenWithLogo | undefined): string[] {
const fallbackUrls = token?.address
? [
cowprotocolTokenUrl(token.address, token.chainId as SupportedChainId),
cowprotocolTokenUrl(token.address.toLowerCase(), token.chainId as SupportedChainId),
cowprotocolTokenUrl(token.address.toLowerCase(), SupportedChainId.MAINNET),
]
: []
const fallbackUrls = token?.address ? getTokenLogoFallbacks(token.address, token.chainId as SupportedChainId) : []

if (!token?.logoURI) {
return fallbackUrls
Expand All @@ -23,3 +18,12 @@ export function getTokenLogoUrls(token: TokenWithLogo | undefined): string[] {

return urls
}

function getTokenLogoFallbacks(address: string, chainId: SupportedChainId): string[] {
return [
cowprotocolTokenUrl(address, chainId),
cowprotocolTokenUrl(address.toLowerCase(), chainId),
cowprotocolTokenUrl(address.toLowerCase(), SupportedChainId.MAINNET),
trustTokenLogoUrl(address, chainId),
]
}
11 changes: 11 additions & 0 deletions libs/tokens/src/utils/trustTokenLogoUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SupportedChainId } from '@cowprotocol/cow-sdk'

const chainIdToName: Record<SupportedChainId, string> = {
[SupportedChainId.MAINNET]: 'ethereum',
[SupportedChainId.GNOSIS_CHAIN]: 'xdai',
[SupportedChainId.GOERLI]: 'ethereum',
}

export function trustTokenLogoUrl(address: string, chainId: SupportedChainId): string {
return `https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/${chainIdToName[chainId]}/assets/${address}/logo.png`
}

0 comments on commit 5552b69

Please sign in to comment.