use etherscan-link customBlockExplorer methods with customNetwork usage tracking (#11017)
* use etherscan-link customBlockExplorer methods with customNetwork usage tracking * consolidate blockexplorer events, add domain to metametrics event * lint fixfeature/default_network_editable
parent
b7a1c8c302
commit
f19207ca87
@ -1,96 +0,0 @@ |
||||
import { strict as assert } from 'assert'; |
||||
import { |
||||
MAINNET_CHAIN_ID, |
||||
MAINNET_NETWORK_ID, |
||||
ROPSTEN_CHAIN_ID, |
||||
ROPSTEN_NETWORK_ID, |
||||
} from '../../constants/network'; |
||||
import { getBlockExplorerUrlForTx } from '../transaction.utils'; |
||||
|
||||
const tests = [ |
||||
{ |
||||
expected: 'https://etherscan.io/tx/0xabcd', |
||||
transaction: { |
||||
metamaskNetworkId: MAINNET_NETWORK_ID, |
||||
hash: '0xabcd', |
||||
}, |
||||
}, |
||||
{ |
||||
expected: 'https://ropsten.etherscan.io/tx/0xdef0', |
||||
transaction: { |
||||
metamaskNetworkId: ROPSTEN_NETWORK_ID, |
||||
hash: '0xdef0', |
||||
}, |
||||
rpcPrefs: {}, |
||||
}, |
||||
{ |
||||
// test handling of `blockExplorerUrl` for a custom RPC
|
||||
expected: 'https://block.explorer/tx/0xabcd', |
||||
transaction: { |
||||
metamaskNetworkId: '31', |
||||
hash: '0xabcd', |
||||
}, |
||||
rpcPrefs: { |
||||
blockExplorerUrl: 'https://block.explorer', |
||||
}, |
||||
}, |
||||
{ |
||||
// test handling of trailing `/` in `blockExplorerUrl` for a custom RPC
|
||||
expected: 'https://another.block.explorer/tx/0xdef0', |
||||
transaction: { |
||||
networkId: '33', |
||||
hash: '0xdef0', |
||||
}, |
||||
rpcPrefs: { |
||||
blockExplorerUrl: 'https://another.block.explorer/', |
||||
}, |
||||
}, |
||||
{ |
||||
expected: 'https://etherscan.io/tx/0xabcd', |
||||
transaction: { |
||||
chainId: MAINNET_CHAIN_ID, |
||||
hash: '0xabcd', |
||||
}, |
||||
}, |
||||
{ |
||||
expected: 'https://ropsten.etherscan.io/tx/0xdef0', |
||||
transaction: { |
||||
chainId: ROPSTEN_CHAIN_ID, |
||||
hash: '0xdef0', |
||||
}, |
||||
rpcPrefs: {}, |
||||
}, |
||||
{ |
||||
// test handling of `blockExplorerUrl` for a custom RPC
|
||||
expected: 'https://block.explorer/tx/0xabcd', |
||||
transaction: { |
||||
chainId: '0x1f', |
||||
hash: '0xabcd', |
||||
}, |
||||
rpcPrefs: { |
||||
blockExplorerUrl: 'https://block.explorer', |
||||
}, |
||||
}, |
||||
{ |
||||
// test handling of trailing `/` in `blockExplorerUrl` for a custom RPC
|
||||
expected: 'https://another.block.explorer/tx/0xdef0', |
||||
transaction: { |
||||
chainId: '0x21', |
||||
hash: '0xdef0', |
||||
}, |
||||
rpcPrefs: { |
||||
blockExplorerUrl: 'https://another.block.explorer/', |
||||
}, |
||||
}, |
||||
]; |
||||
|
||||
describe('getBlockExplorerUrlForTx', function () { |
||||
tests.forEach((test) => { |
||||
it(`should return '${test.expected}' for transaction with hash: '${test.transaction.hash}'`, function () { |
||||
assert.strictEqual( |
||||
getBlockExplorerUrlForTx(test.transaction, test.rpcPrefs), |
||||
test.expected, |
||||
); |
||||
}); |
||||
}); |
||||
}); |
@ -1,12 +0,0 @@ |
||||
import { createAccountLinkForChain } from '@metamask/etherscan-link'; |
||||
|
||||
export default function getAccountLink(address, chainId, rpcPrefs) { |
||||
if (rpcPrefs && rpcPrefs.blockExplorerUrl) { |
||||
return `${rpcPrefs.blockExplorerUrl.replace( |
||||
/\/+$/u, |
||||
'', |
||||
)}/address/${address}`;
|
||||
} |
||||
|
||||
return createAccountLinkForChain(address, chainId); |
||||
} |
@ -1,49 +0,0 @@ |
||||
import { |
||||
MAINNET_CHAIN_ID, |
||||
ROPSTEN_CHAIN_ID, |
||||
} from '../../../shared/constants/network'; |
||||
import getAccountLink from './account-link'; |
||||
|
||||
describe('Account link', () => { |
||||
describe('getAccountLink', () => { |
||||
it('should return the correct block explorer url for an account', () => { |
||||
const tests = [ |
||||
{ |
||||
expected: 'https://etherscan.io/address/0xabcd', |
||||
chainId: MAINNET_CHAIN_ID, |
||||
address: '0xabcd', |
||||
}, |
||||
{ |
||||
expected: 'https://ropsten.etherscan.io/address/0xdef0', |
||||
chainId: ROPSTEN_CHAIN_ID, |
||||
address: '0xdef0', |
||||
rpcPrefs: {}, |
||||
}, |
||||
{ |
||||
// test handling of `blockExplorerUrl` for a custom RPC
|
||||
expected: 'https://block.explorer/address/0xabcd', |
||||
chainId: '0x21', |
||||
address: '0xabcd', |
||||
rpcPrefs: { |
||||
blockExplorerUrl: 'https://block.explorer', |
||||
}, |
||||
}, |
||||
{ |
||||
// test handling of trailing `/` in `blockExplorerUrl` for a custom RPC
|
||||
expected: 'https://another.block.explorer/address/0xdef0', |
||||
chainId: '0x1f', |
||||
address: '0xdef0', |
||||
rpcPrefs: { |
||||
blockExplorerUrl: 'https://another.block.explorer/', |
||||
}, |
||||
}, |
||||
]; |
||||
|
||||
tests.forEach(({ expected, address, chainId, rpcPrefs }) => { |
||||
expect(getAccountLink(address, chainId, rpcPrefs)).toStrictEqual( |
||||
expected, |
||||
); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
Loading…
Reference in new issue