Open in etherscan user address

This commit is contained in:
apanizo 2018-09-06 12:49:45 +02:00
parent befddc3b48
commit 7db8239460
2 changed files with 11 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import Spacer from '~/components/Spacer'
import { xs, sm, md, lg, background } from '~/theme/variables' import { xs, sm, md, lg, background } from '~/theme/variables'
import { upperFirst } from '~/utils/css' import { upperFirst } from '~/utils/css'
import { shortVersionOf } from '~/logic/wallets/ethAddresses' import { shortVersionOf } from '~/logic/wallets/ethAddresses'
import { openInEtherScan } from '~/logic/wallets/getWeb3'
const metamask = require('../../assets/metamask.svg') const metamask = require('../../assets/metamask.svg')
const connectedLogo = require('../../assets/connected.svg') const connectedLogo = require('../../assets/connected.svg')
@ -63,6 +64,9 @@ const styles = () => ({
open: { open: {
paddingLeft: sm, paddingLeft: sm,
width: 'auto', width: 'auto',
'&:hover': {
cursor: 'pointer',
},
}, },
disconnect: { disconnect: {
padding: `${md} ${lg}`, padding: `${md} ${lg}`,
@ -79,7 +83,7 @@ const UserDetails = ({
provider, connected, network, userAddress, classes, onDisconnect, provider, connected, network, userAddress, classes, onDisconnect,
}: Props) => { }: Props) => {
const status = connected ? 'Connected' : 'Connection error' const status = connected ? 'Connected' : 'Connection error'
const address = userAddress ? shortVersionOf(userAddress, 6) : 'Not available' const address = userAddress ? shortVersionOf(userAddress, 6) : 'Address not available'
const identiconAddress = userAddress || 'random' const identiconAddress = userAddress || 'random'
const connectionLogo = connected ? connectedLogo : connectedWarning const connectionLogo = connected ? connectedLogo : connectedWarning
const color = connected ? 'primary' : 'warning' const color = connected ? 'primary' : 'warning'
@ -92,7 +96,9 @@ const UserDetails = ({
</Row> </Row>
<Block align="center" className={classes.user}> <Block align="center" className={classes.user}>
<Paragraph className={classes.address} size="sm" noMargin>{address}</Paragraph> <Paragraph className={classes.address} size="sm" noMargin>{address}</Paragraph>
<OpenInNew className={classes.open} style={openIconStyle} /> { userAddress &&
<OpenInNew className={classes.open} style={openIconStyle} onClick={openInEtherScan(userAddress, network)} />
}
</Block> </Block>
</Block> </Block>
<Hairline margin="xs" /> <Hairline margin="xs" />

View File

@ -33,6 +33,9 @@ export const ETHEREUM_NETWORK_IDS = {
42: ETHEREUM_NETWORK.KOVAN, 42: ETHEREUM_NETWORK.KOVAN,
} }
export const openInEtherScan = (address: string, network: string) => () => {
window.open(`https://${network}.etherscan.io/address/${address}`)
}
let web3 let web3
export const getWeb3 = () => web3 || new Web3(window.web3.currentProvider) export const getWeb3 = () => web3 || new Web3(window.web3.currentProvider)