Commit e7d32897 authored by Jonathan Diep's avatar Jonathan Diep Committed by GitHub

improvement(token warning card): link to the token page on etherscan instead...

improvement(token warning card): link to the token page on etherscan instead of the address page (#914)
parent 0698e0f8
......@@ -109,7 +109,7 @@ export default function TokenWarningCard({ token, ...rest }: TokenWarningCardPro
? `${token.name} (${token.symbol})`
: token.name || token.symbol}
</div>
<ExternalLink style={{ fontWeight: 400 }} href={getEtherscanLink(chainId, token.address, 'address')}>
<ExternalLink style={{ fontWeight: 400 }} href={getEtherscanLink(chainId, token.address, 'token')}>
(View on Etherscan)
</ExternalLink>
</Row>
......
......@@ -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')
})
......
......@@ -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}`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment