Skip to content

Commit

Permalink
feat(): replaced etherscanBaseUrl with blockExplorerUrl (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkGeeRomano authored and sohkai committed Feb 26, 2019
1 parent 93af822 commit 5e093fa
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 68 deletions.
2 changes: 0 additions & 2 deletions apps/finance/app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import AppLayout from './components/AppLayout'
import NewTransferIcon from './components/NewTransferIcon'
import { networkContextType } from './lib/provideNetwork'
import { ETHER_TOKEN_FAKE_ADDRESS } from './lib/token-utils'
import { makeEtherscanBaseUrl } from './lib/utils'

import addFundsIcon from './components/assets/add-funds-icon.svg'

Expand All @@ -37,7 +36,6 @@ class App extends React.Component {
const { network } = this.props
return {
network: {
etherscanBaseUrl: makeEtherscanBaseUrl(network.type),
type: network.type,
},
}
Expand Down
16 changes: 13 additions & 3 deletions apps/finance/app/src/components/TransferRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ContextMenu,
ContextMenuItem,
IdentityBadge,
blockExplorerUrl,
theme,
} from '@aragon/ui'
import provideNetwork from '../lib/provideNetwork'
Expand All @@ -16,10 +17,15 @@ import IconTokens from './icons/IconTokens'
class TransferRow extends React.PureComponent {
handleViewTransaction = () => {
const {
network: { etherscanBaseUrl },
network,
transaction: { transactionHash },
} = this.props
window.open(`${etherscanBaseUrl}/tx/${transactionHash}`, '_blank')
window.open(
blockExplorerUrl('transaction', transactionHash, {
networkType: network.type,
}),
'_blank'
)
}

render() {
Expand All @@ -33,9 +39,13 @@ class TransferRow extends React.PureComponent {
isIncoming,
numData: { amount },
reference,
transactionHash,
},
} = this.props

const txUrl = blockExplorerUrl('transaction', transactionHash, {
networkType: network.type,
})
const formattedAmount = formatTokenAmount(
amount,
isIncoming,
Expand Down Expand Up @@ -96,7 +106,7 @@ class TransferRow extends React.PureComponent {
</NoWrapCell>
<NoWrapCell>
<div css="position: relative">
{network.etherscanBaseUrl && (
{txUrl && (
<ContextMenu>
<ContextMenuItem onClick={this.handleViewTransaction}>
<IconTokens />
Expand Down
1 change: 0 additions & 1 deletion apps/finance/app/src/lib/provideNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'
import getDisplayName from 'react-display-name'

export const networkContextType = PropTypes.shape({
etherscanBaseUrl: PropTypes.string,
type: PropTypes.string,
})

Expand Down
12 changes: 0 additions & 12 deletions apps/finance/app/src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,3 @@ export const formatTokenAmount = (
maximumFractionDigits: 18,
}
)

export function makeEtherscanBaseUrl(network) {
// Don't make etherscan urls if the network isn't one that etherscan supports
if (
network === 'main' ||
network === 'kovan' ||
network === 'rinkeby' ||
network === 'ropsten'
) {
return `https://${network === 'main' ? '' : `${network}.`}etherscan.io`
}
}
6 changes: 1 addition & 5 deletions apps/token-manager/app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import BN from 'bn.js'
import { Badge, Main, SidePanel, font, observe } from '@aragon/ui'
import { Badge, Main, SidePanel, observe } from '@aragon/ui'
import EmptyState from './screens/EmptyState'
import Holders from './screens/Holders'
import AssignVotePanelContent from './components/Panels/AssignVotePanelContent'
import MenuButton from './components/MenuButton/MenuButton'
import AssignTokensIcon from './components/AssignTokensIcon'
import AppLayout from './components/AppLayout'
import { networkContextType } from './provide-network'
import { hasLoadedTokenSettings } from './token-settings'
import { makeEtherscanBaseUrl } from './utils'
import { addressesEqual } from './web3-utils'

const initialAssignTokensConfig = {
Expand Down Expand Up @@ -43,7 +40,6 @@ class App extends React.Component {

return {
network: {
etherscanBaseUrl: makeEtherscanBaseUrl(network.type),
type: network.type,
},
}
Expand Down
4 changes: 2 additions & 2 deletions apps/token-manager/app/src/components/TokenBadge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import styled from 'styled-components'
import { SafeLink } from '@aragon/ui'
import { SafeLink, blockExplorerUrl } from '@aragon/ui'
import provideNetwork from '../provide-network'

import { ETHER_TOKEN_VERIFIED_ADDRESSES } from '../verified-tokens'
Expand All @@ -12,7 +12,7 @@ class TokenBadge extends React.PureComponent {
return (
<Main
title={`${name} (${address})`}
href={`${network.etherscanBaseUrl}/token/${address}`}
href={blockExplorerUrl('token', address, { networkType: network.type })}
>
<Label>
{verified && (
Expand Down
1 change: 0 additions & 1 deletion apps/token-manager/app/src/provide-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'
import getDisplayName from 'react-display-name'

export const networkContextType = PropTypes.shape({
etherscanBaseUrl: PropTypes.string,
type: PropTypes.string,
})

Expand Down
1 change: 0 additions & 1 deletion apps/token-manager/app/src/screens/Holders.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
TableRow,
Viewport,
breakpoint,
springs,
} from '@aragon/ui'
import HolderRow from '../components/HolderRow'
import SideBar from '../components/SideBar'
Expand Down
12 changes: 0 additions & 12 deletions apps/token-manager/app/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,3 @@ export function stakesPercentages(
adjustedStakes[firstZeroIndex - 1].percentage
)
}

export function makeEtherscanBaseUrl(network) {
// Don't make etherscan urls if the network isn't one that etherscan supports
if (
network === 'main' ||
network === 'kovan' ||
network === 'rinkeby' ||
network === 'ropsten'
) {
return `https://${network === 'main' ? '' : `${network}.`}etherscan.io`
}
}
4 changes: 0 additions & 4 deletions apps/voting/app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { Main, SidePanel, observe } from '@aragon/ui'
import BN from 'bn.js'
import EmptyState from './screens/EmptyState'
Expand All @@ -9,15 +8,13 @@ import tokenAbi from './abi/token-balanceOfAt.json'
import VotePanelContent from './components/VotePanelContent'
import NewVotePanelContent from './components/NewVotePanelContent'
import AutoLink from './components/AutoLink'
import MenuButton from './components/MenuButton/MenuButton'
import AppLayout from './components/AppLayout'
import NewVoteIcon from './components/NewVoteIcon'
import { networkContextType } from './utils/provideNetwork'
import { settingsContextType } from './utils/provideSettings'
import { hasLoadedVoteSettings } from './vote-settings'
import { VOTE_YEA } from './vote-types'
import { EMPTY_CALLSCRIPT } from './evmscript-utils'
import { makeEtherscanBaseUrl } from './utils'
import { isVoteOpen, voteTypeFromContractEnum } from './vote-utils'
import { shortenAddress, transformAddresses } from './web3-utils'

Expand All @@ -42,7 +39,6 @@ class App extends React.Component {

return {
network: {
etherscanBaseUrl: makeEtherscanBaseUrl(network.type),
type: network.type,
},
settings: {
Expand Down
17 changes: 6 additions & 11 deletions apps/voting/app/src/components/VotePanelContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SidePanelSeparator,
Countdown,
Text,
blockExplorerUrl,
theme,
} from '@aragon/ui'
import provideNetwork from '../utils/provideNetwork'
Expand Down Expand Up @@ -123,15 +124,12 @@ class VotePanelContent extends React.Component {
}
renderBlockLink = snapshotBlock => {
const {
network: { etherscanBaseUrl },
network: { type },
} = this.props
const text = `(block ${snapshotBlock})`

return etherscanBaseUrl ? (
<SafeLink
href={`${etherscanBaseUrl}/block/${snapshotBlock}`}
target="_blank"
>
const url = blockExplorerUrl('block', snapshotBlock, { networkType: type })
return url ? (
<SafeLink href={url} target="_blank">
{text}
</SafeLink>
) : (
Expand Down Expand Up @@ -229,10 +227,7 @@ class VotePanelContent extends React.Component {
<Label>Created By</Label>
</h2>
<Creator>
<IdentityBadge
entity={creator}
networkType={network.type}
/>
<IdentityBadge entity={creator} networkType={network.type} />
</Creator>
</Part>
<SidePanelSeparator />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Grid = styled.div`
'medium',
`
grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
`,
`
)};
`

Expand Down
12 changes: 0 additions & 12 deletions apps/voting/app/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,3 @@ export function pluralize(count, singular, plural, re = PLURALIZE_RE) {
}
return plural.replace(re, count)
}

export function makeEtherscanBaseUrl(network) {
// Don't make etherscan urls if the network isn't one that etherscan supports
if (
network === 'main' ||
network === 'kovan' ||
network === 'rinkeby' ||
network === 'ropsten'
) {
return `https://${network === 'main' ? '' : `${network}.`}etherscan.io`
}
}
1 change: 0 additions & 1 deletion apps/voting/app/src/utils/provideNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'
import getDisplayName from 'react-display-name'

export const networkContextType = PropTypes.shape({
etherscanBaseUrl: PropTypes.string,
type: PropTypes.string,
})

Expand Down

0 comments on commit 5e093fa

Please sign in to comment.