mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
use metamask/etherscan-link (#10580)
This commit is contained in:
parent
91ffb80606
commit
3840a58e82
@ -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…
Reference in New Issue
Block a user