1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Tidy up getAccountLink (#9223)

This commit is contained in:
Whymarrh Whitby 2020-08-14 12:31:59 -02:30 committed by GitHub
parent 937616565d
commit 2aa4b6bbee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 25 deletions

View File

@ -6,7 +6,7 @@ import { useDispatch, useSelector } from 'react-redux'
import { showModal } from '../../../store/actions' import { showModal } from '../../../store/actions'
import { CONNECTED_ROUTE } from '../../../helpers/constants/routes' import { CONNECTED_ROUTE } from '../../../helpers/constants/routes'
import { Menu, MenuItem } from '../../ui/menu' import { Menu, MenuItem } from '../../ui/menu'
import genAccountLink from '../../../../lib/account-link' import getAccountLink from '../../../../lib/account-link'
import { getCurrentKeyring, getCurrentNetwork, getRpcPrefsForCurrentProvider, getSelectedIdentity } from '../../../selectors' import { getCurrentKeyring, getCurrentNetwork, getRpcPrefsForCurrentProvider, getSelectedIdentity } from '../../../selectors'
import { useI18nContext } from '../../../hooks/useI18nContext' import { useI18nContext } from '../../../hooks/useI18nContext'
import { useMetricEvent } from '../../../hooks/useMetricEvent' import { useMetricEvent } from '../../../hooks/useMetricEvent'
@ -90,7 +90,7 @@ export default function AccountOptionsMenu ({ anchorElement, onClose }) {
<MenuItem <MenuItem
onClick={() => { onClick={() => {
viewOnEtherscanEvent() viewOnEtherscanEvent()
global.platform.openTab({ url: genAccountLink(address, network, rpcPrefs) }) global.platform.openTab({ url: getAccountLink(address, network, rpcPrefs) })
onClose() onClose()
}} }}
subtitle={ subtitle={

View File

@ -1,7 +1,7 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import AccountModalContainer from '../account-modal-container' import AccountModalContainer from '../account-modal-container'
import genAccountLink from '../../../../../lib/account-link' import getAccountLink from '../../../../../lib/account-link'
import QrView from '../../../ui/qr-code' import QrView from '../../../ui/qr-code'
import EditableLabel from '../../../ui/editable-label' import EditableLabel from '../../../ui/editable-label'
import Button from '../../../ui/button' import Button from '../../../ui/button'
@ -62,7 +62,7 @@ export default class AccountDetailsModal extends Component {
type="secondary" type="secondary"
className="account-details-modal__button" className="account-details-modal__button"
onClick={() => { onClick={() => {
global.platform.openTab({ url: genAccountLink(address, network, rpcPrefs) }) global.platform.openTab({ url: getAccountLink(address, network, rpcPrefs) })
}} }}
> >
{rpcPrefs.blockExplorerUrl {rpcPrefs.blockExplorerUrl

View File

@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import Modal from '../../modal' import Modal from '../../modal'
import { addressSummary } from '../../../../helpers/utils/util' import { addressSummary } from '../../../../helpers/utils/util'
import Identicon from '../../../ui/identicon' import Identicon from '../../../ui/identicon'
import genAccountLink from '../../../../../lib/account-link' import getAccountLink from '../../../../../lib/account-link'
export default class ConfirmRemoveAccount extends Component { export default class ConfirmRemoveAccount extends Component {
static propTypes = { static propTypes = {
@ -47,7 +47,7 @@ export default class ConfirmRemoveAccount extends Component {
<div className="confirm-remove-account__account__link"> <div className="confirm-remove-account__account__link">
<a <a
className="" className=""
href={genAccountLink(identity.address, this.props.network)} href={getAccountLink(identity.address, this.props.network)}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
title={this.context.t('etherscanView')} title={this.context.t('etherscanView')}

View File

@ -1,7 +1,7 @@
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import React, { Component } from 'react' import React, { Component } from 'react'
import Select from 'react-select' import Select from 'react-select'
import genAccountLink from '../../../../lib/account-link' import getAccountLink from '../../../../lib/account-link'
import Button from '../../../components/ui/button' import Button from '../../../components/ui/button'
class AccountList extends Component { class AccountList extends Component {
@ -101,7 +101,7 @@ class AccountList extends Component {
</div> </div>
<a <a
className="hw-account-list__item__link" className="hw-account-list__item__link"
href={genAccountLink(account.address, this.props.network)} href={getAccountLink(account.address, this.props.network)}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
title={this.context.t('etherscanView')} title={this.context.t('etherscanView')}

View File

@ -4,30 +4,20 @@ export default function getAccountLink (address, network, rpcPrefs) {
} }
const net = parseInt(network) const net = parseInt(network)
let link
switch (net) { switch (net) {
case 1: // main net case 1: // main net
link = `https://etherscan.io/address/${address}` return `https://etherscan.io/address/${address}`
break
case 2: // morden test net case 2: // morden test net
link = `https://morden.etherscan.io/address/${address}` return `https://morden.etherscan.io/address/${address}`
break
case 3: // ropsten test net case 3: // ropsten test net
link = `https://ropsten.etherscan.io/address/${address}` return `https://ropsten.etherscan.io/address/${address}`
break
case 4: // rinkeby test net case 4: // rinkeby test net
link = `https://rinkeby.etherscan.io/address/${address}` return `https://rinkeby.etherscan.io/address/${address}`
break
case 42: // kovan test net case 42: // kovan test net
link = `https://kovan.etherscan.io/address/${address}` return `https://kovan.etherscan.io/address/${address}`
break
case 5: // goerli test net case 5: // goerli test net
link = `https://goerli.etherscan.io/address/${address}` return `https://goerli.etherscan.io/address/${address}`
break
default: default:
link = '' return ''
break
} }
return link
} }