use metamask/etherscan-link (#10580)

feature/default_network_editable
Brad Decker 4 years ago committed by GitHub
parent 91ffb80606
commit 3840a58e82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      test/unit/ui/etherscan-prefix-for-network.spec.js
  2. 6
      ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js
  3. 6
      ui/app/helpers/utils/transactions.util.js
  4. 23
      ui/lib/etherscan-prefix-for-network.js

@ -1,28 +0,0 @@
import assert from 'assert';
import { getEtherscanNetworkPrefix } from '../../../ui/lib/etherscan-prefix-for-network';
describe('Etherscan Network Prefix', function () {
it('returns empty string as default value', function () {
assert.equal(getEtherscanNetworkPrefix(), '');
});
it('returns empty string as a prefix for networkId of 1', function () {
assert.equal(getEtherscanNetworkPrefix('1'), '');
});
it('returns ropsten as prefix for networkId of 3', function () {
assert.equal(getEtherscanNetworkPrefix('3'), 'ropsten.');
});
it('returns rinkeby as prefix for networkId of 4', function () {
assert.equal(getEtherscanNetworkPrefix('4'), 'rinkeby.');
});
it('returs kovan as prefix for networkId of 42', function () {
assert.equal(getEtherscanNetworkPrefix('42'), 'kovan.');
});
it('returs goerli as prefix for networkId of 5', function () {
assert.equal(getEtherscanNetworkPrefix('5'), 'goerli.');
});
});

@ -1,12 +1,13 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { createExplorerLink } from '@metamask/etherscan-link';
import {
getEthConversionFromWeiHex,
getValueFromWeiHex,
} from '../../../helpers/utils/conversions.util';
import { formatDate } from '../../../helpers/utils/util';
import { getEtherscanNetworkPrefix } from '../../../../lib/etherscan-prefix-for-network';
import TransactionActivityLogIcon from './transaction-activity-log-icon';
import { CONFIRMED_STATUS } from './transaction-activity-log.constants';
@ -33,8 +34,7 @@ export default class TransactionActivityLog extends PureComponent {
const { primaryTransaction } = this.props;
const { metamaskNetworkId } = primaryTransaction;
const prefix = getEtherscanNetworkPrefix(metamaskNetworkId);
const etherscanUrl = `https://${prefix}etherscan.io/tx/${hash}`;
const etherscanUrl = createExplorerLink(hash, metamaskNetworkId);
global.platform.openTab({ url: etherscanUrl });
};

@ -2,8 +2,9 @@ import { MethodRegistry } from 'eth-method-registry';
import abi from 'human-standard-token-abi';
import { ethers } from 'ethers';
import log from 'loglevel';
import { createExplorerLink } from '@metamask/etherscan-link';
import { addHexPrefix } from '../../../../app/scripts/lib/util';
import { getEtherscanNetworkPrefix } from '../../../lib/etherscan-prefix-for-network';
import {
TRANSACTION_CATEGORIES,
TRANSACTION_GROUP_STATUSES,
@ -202,8 +203,7 @@ export function getBlockExplorerUrlForTx(networkId, hash, rpcPrefs = {}) {
if (rpcPrefs.blockExplorerUrl) {
return `${rpcPrefs.blockExplorerUrl.replace(/\/+$/u, '')}/tx/${hash}`;
}
const prefix = getEtherscanNetworkPrefix(networkId);
return `https://${prefix}etherscan.io/tx/${hash}`;
return createExplorerLink(hash, networkId);
}
/**

@ -1,23 +0,0 @@
import * as networkEnums from '../../shared/constants/network';
/**
* Gets the etherscan.io URL prefix for a given network ID.
*
* @param {string} networkId - The network ID to get the prefix for.
* @returns {string} The etherscan.io URL prefix for the given network ID.
*/
export function getEtherscanNetworkPrefix(networkId) {
switch (networkId) {
case networkEnums.ROPSTEN_NETWORK_ID:
return 'ropsten.';
case networkEnums.RINKEBY_NETWORK_ID:
return 'rinkeby.';
case networkEnums.KOVAN_NETWORK_ID:
return 'kovan.';
case networkEnums.GOERLI_NETWORK_ID:
return 'goerli.';
default:
// also covers mainnet
return '';
}
}
Loading…
Cancel
Save