Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #262 from rahulsnkr/16990-view-on-etherscan
Browse files Browse the repository at this point in the history
#16990: 'View on Etherscan' now works for other networks
  • Loading branch information
onyb authored Jul 26, 2021
2 parents 08776ca + 6d8aba5 commit 0849cb2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
6 changes: 6 additions & 0 deletions ui/app/helpers/utils/transactions.util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ describe('Transactions utils', function () {
hash: '0xdef0',
rpcPrefs: {},
},
{
expected: 'https://kovan.etherscan.io/tx/0x1234',
networkId: '0x2a',
hash: '0x1234',
rpcPrefs: {},
},
{
// test handling of `blockExplorerUrl` for a custom RPC
expected: 'https://block.explorer/tx/0xabcd',
Expand Down
4 changes: 1 addition & 3 deletions ui/app/pages/swap/wait-for-transaction/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
SUBMITTED_STATUS,
} from '../../../helpers/constants/transactions'
import { getBlockExplorerUrlForTx } from '../../../helpers/utils/transactions.util'
import { getEtherScanNetworkIdentifier } from '../../../../lib/etherscan-prefix-for-network'

const FAILURE_STATUSES = [FAILED_STATUS, CANCELLED_STATUS, REJECTED_STATUS]

Expand Down Expand Up @@ -45,15 +44,14 @@ export default class WaitForTransaction extends Component {

const { txReceipt, hash } = transaction
const transactionHash = txReceipt?.transactionHash || hash
const networkId = getEtherScanNetworkIdentifier(network)

return (
transactionHash && (
<p
onClick={() =>
global.platform.openTab({
url: getBlockExplorerUrlForTx(
networkId,
network,
transactionHash,
rpcPrefs,
),
Expand Down
30 changes: 8 additions & 22 deletions ui/lib/etherscan-prefix-for-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,23 @@ import * as networkEnums from '../../app/scripts/controllers/network/enums'
*/
export function getEtherscanNetworkPrefix (networkId) {
switch (networkId) {
case networkEnums.ROPSTEN:
case networkEnums.ROPSTEN_CHAIN_ID:
case networkEnums.ROPSTEN_NETWORK_ID:
return 'ropsten.'
case networkEnums.RINKEBY:
case networkEnums.RINKEBY_CHAIN_ID:
case networkEnums.RINKEBY_NETWORK_ID:
return 'rinkeby.'
case networkEnums.KOVAN:
case networkEnums.KOVAN_CHAIN_ID:
case networkEnums.KOVAN_NETWORK_ID:
return 'kovan.'
case networkEnums.GOERLI:
case networkEnums.GOERLI_CHAIN_ID:
case networkEnums.GOERLI_NETWORK_ID:
return 'goerli.'
default: // also covers mainnet
return ''
}
}

export function getEtherScanNetworkIdentifier (networkName) {
switch (networkName) {
case networkEnums.ROPSTEN:
return networkEnums.ROPSTEN_NETWORK_ID

case networkEnums.RINKEBY:
return networkEnums.RINKEBY_NETWORK_ID

case networkEnums.KOVAN:
return networkEnums.KOVAN_NETWORK_ID

case networkEnums.GOERLI:
return networkEnums.GOERLI_NETWORK_ID

case networkEnums.MAINNET:
return networkEnums.MAINNET_NETWORK_ID

default:
return networkName
}
}

0 comments on commit 0849cb2

Please sign in to comment.