From e7d328975436356a9b466d92a58561cd758c49e9 Mon Sep 17 00:00:00 2001 From: Jonathan Diep Date: Thu, 2 Jul 2020 05:27:19 -0700 Subject: [PATCH] improvement(token warning card): link to the token page on etherscan instead of the address page (#914) --- src/components/TokenWarningCard/index.tsx | 2 +- src/utils/index.test.ts | 3 +++ src/utils/index.ts | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/TokenWarningCard/index.tsx b/src/components/TokenWarningCard/index.tsx index 84d6a4551b..9bb33f34ca 100644 --- a/src/components/TokenWarningCard/index.tsx +++ b/src/components/TokenWarningCard/index.tsx @@ -109,7 +109,7 @@ export default function TokenWarningCard({ token, ...rest }: TokenWarningCardPro ? `${token.name} (${token.symbol})` : token.name || token.symbol} - + (View on Etherscan) diff --git a/src/utils/index.test.ts b/src/utils/index.test.ts index f8a13679d6..59c7730a4e 100644 --- a/src/utils/index.test.ts +++ b/src/utils/index.test.ts @@ -16,6 +16,9 @@ describe('utils', () => { it('correct for tx', () => { expect(getEtherscanLink(1, 'abc', 'transaction')).toEqual('https://etherscan.io/tx/abc') }) + it('correct for token', () => { + expect(getEtherscanLink(1, 'abc', 'token')).toEqual('https://etherscan.io/token/abc') + }) it('correct for address', () => { expect(getEtherscanLink(1, 'abc', 'address')).toEqual('https://etherscan.io/address/abc') }) diff --git a/src/utils/index.ts b/src/utils/index.ts index 5087ab6d46..f913f1a0da 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -25,13 +25,16 @@ const ETHERSCAN_PREFIXES: { [chainId in ChainId]: string } = { 42: 'kovan.' } -export function getEtherscanLink(chainId: ChainId, data: string, type: 'transaction' | 'address'): string { +export function getEtherscanLink(chainId: ChainId, data: string, type: 'transaction' | 'token' | 'address'): string { const prefix = `https://${ETHERSCAN_PREFIXES[chainId] || ETHERSCAN_PREFIXES[1]}etherscan.io` switch (type) { case 'transaction': { return `${prefix}/tx/${data}` } + case 'token': { + return `${prefix}/token/${data}` + } case 'address': default: { return `${prefix}/address/${data}`