improvement(token warning card): link to the token page on etherscan instead of the address page (#914)
This commit is contained in:
parent
0698e0f82a
commit
e7d3289754
@ -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}`
|
||||
|
Loading…
Reference in New Issue
Block a user