on master help sign in
Fix 'view on Etherscan' links throughout.

At present these always point to mainnet, so are invalid when using Ropsten, local nodes, etc. This commit fixes things so that the Etherscan links are disabled, or are just not visible, when using a network other than Ropsten / mainnet, and ensures that the links go to the right place when using Ropsten. Additionally, this fixes a bug where some links were using an old 'disabled' property instead of 'prop-disabled', and so were enabled when they shouldn't be (including on mainnet).

commit61a1023c8b08b5aa5ccaaa11bdea60864eaa9fdf authorJared Tobin <jared@jtobin.io> dateSat 2 Feb 2019, 06:57 (8 years ago) parent304ae10
6 files changed+101−25
src/views/AcceptTransfer.js+11−2 src/views/CreateGalaxy.js+12−2 src/views/IssueChild.js+12−5 src/views/SentTransaction.js+42−12 src/views/SetProxy.js+12−2 src/views/Transfer.js+12−2
src/views/AcceptTransfer.js+11−2
@@ -7,6 +7,7 @@ import * as ob from 'urbit-ob'
77
88import StatelessTransaction from '../components/StatelessTransaction'
99import { BRIDGE_ERROR } from '../lib/error'
10+import { NETWORK_NAMES } from '../lib/network'
1011import { ROUTE_NAMES } from '../lib/router'
1112
1213import {
@@ -263,6 +264,14 @@ class AcceptTransfer extends React.Component {
263264 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
264265 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
265266
267+ const esvisible =
268+ props.networkType === NETWORK_NAMES.ROPSTEN ||
269+ props.networkType === NETWORK_NAMES.MAINNET
270+
271+ const esdomain =
272+ props.networkType === NETWORK_NAMES.ROPSTEN
273+ ? "ropsten.etherscan.io"
274+ : "etherscan.io"
266275
267276 return (
268277 <Row>
@@ -290,9 +299,9 @@ class AcceptTransfer extends React.Component {
290299 <Anchor
291300 className={'mt-1 sm'}
292301 prop-size='sm'
293− prop-disabled={!isValidAddress(state.receivingAddress)}
302+ prop-disabled={!isValidAddress(state.receivingAddress) || !esvisible}
294303 target={'_blank'}
295− href={`https://etherscan.io/address/${state.receivingAddress}`}>
304+ href={`https://${esdomain}/address/${state.receivingAddress}`}>
296305 {'View on Etherscan ↗'}
297306 </Anchor>
298307
src/views/CreateGalaxy.js+12−2
@@ -10,6 +10,8 @@ import StatelessTransaction from '../components/StatelessTransaction'
1010
1111import { BRIDGE_ERROR } from '../lib/error'
1212
13+import { NETWORK_NAMES } from '../lib/network'
14+
1315import {
1416 sendSignedTransaction,
1517 getTxnInfo,
@@ -179,6 +181,14 @@ class CreateGalaxy extends React.Component {
179181 const validAddress = isValidAddress(state.galaxyOwner)
180182 const validGalaxy = isValidGalaxy(state.galaxyName)
181183
184+ const esvisible =
185+ props.networkType === NETWORK_NAMES.ROPSTEN ||
186+ props.networkType === NETWORK_NAMES.MAINNET
187+
188+ const esdomain =
189+ props.networkType === NETWORK_NAMES.ROPSTEN
190+ ? "ropsten.etherscan.io"
191+ : "etherscan.io"
182192
183193 return (
184194 <Row>
@@ -225,9 +235,9 @@ class CreateGalaxy extends React.Component {
225235 <Anchor
226236 className={'mt-1'}
227237 prop-size={'sm'}
228− prop-disabled={!validAddress}
238+ prop-disabled={!validAddress || !esvisible}
229239 target={'_blank'}
230− href={`https://etherscan.io/address/${state.galaxyOwner}`}>
240+ href={`https://${esdomain}/address/${state.galaxyOwner}`}>
231241 {'View on Etherscan ↗'}
232242 </Anchor>
233243
src/views/IssueChild.js+12−5
@@ -10,6 +10,7 @@ import { PointInput, AddressInput, InnerLabel } from '../components/Base'
1010import StatelessTransaction from '../components/StatelessTransaction'
1111
1212import { ROUTE_NAMES } from '../lib/router'
13+import { NETWORK_NAMES } from '../lib/network'
1314import { BRIDGE_ERROR } from '../lib/error'
1415import { getSpawnCandidate } from '../lib/child'
1516import {
@@ -337,8 +338,6 @@ class IssueChild extends React.Component {
337338 render() {
338339 const { props, state } = this
339340
340−
341−
342341 const validAddress = isValidAddress(state.receivingAddress)
343342 const validPoint = canDecodePatp(state.desiredPoint)
344343
@@ -354,11 +353,19 @@ class IssueChild extends React.Component {
354353 }
355354 })
356355
357−
358356 const canSign = !Maybe.Nothing.hasInstance(state.txn)
359357 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
360358 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
361359
360+ const esvisible =
361+ props.networkType === NETWORK_NAMES.ROPSTEN ||
362+ props.networkType === NETWORK_NAMES.MAINNET
363+
364+ const esdomain =
365+ props.networkType === NETWORK_NAMES.ROPSTEN
366+ ? "ropsten.etherscan.io"
367+ : "etherscan.io"
368+
362369 return (
363370 <Row>
364371 <Col>
@@ -433,9 +440,9 @@ class IssueChild extends React.Component {
433440 <Anchor
434441 className={'mt-1'}
435442 prop-size={'sm'}
436− prop-disabled={!isValidAddress(state.receivingAddress)}
443+ prop-disabled={!isValidAddress(state.receivingAddress) || !esvisible}
437444 target={'_blank'}
438− href={`https://etherscan.io/address/${state.receivingAddress}`}>
445+ href={`https://${esdomain}/address/${state.receivingAddress}`}>
439446 {'View on Etherscan ↗'}
440447 </Anchor>
441448
src/views/SentTransaction.js+42−12
@@ -4,7 +4,36 @@ import { Button } from '../components/Base'
44
55import { BRIDGE_ERROR, renderTxnError } from '../lib/error'
66
7−const Success = (props) =>
7+import { NETWORK_NAMES } from '../lib/network'
8+
9+const Success = (props) => {
10+
11+ const esvisible =
12+ props.networkType === NETWORK_NAMES.ROPSTEN ||
13+ props.networkType === NETWORK_NAMES.MAINNET
14+
15+ const esdomain =
16+ props.networkType === NETWORK_NAMES.ROPSTEN
17+ ? "ropsten.etherscan.io"
18+ : "etherscan.io"
19+
20+ const esmessage =
21+ esvisible === true
22+ ? "If you’d like to keep track of it, click the Etherscan link below."
23+ : ''
24+
25+ const esanchor =
26+ esvisible === false
27+ ? <div />
28+ : <Anchor
29+ className={'mb-4 mt-1'}
30+ prop-size={'sm'}
31+ target={'_blank'}
32+ href={`https://${esdomain}/tx/${props.hash}`}>
33+ {'View on Etherscan ↗'}
34+ </Anchor>
35+
36+ return (
837 <Row>
938 <Col>
1039 <H1>{ 'Your Transaction was Sent' }</H1>
@@ -12,8 +41,7 @@ const Success = (props) =>
1241 <P>
1342 {
1443 `We sent your transaction to the chain. It can take some time to
15− execute, especially if the network is busy. If you’d like to keep
16− track of it, click the Etherscan link below.`
44+ execute, especially if the network is busy. ${esmessage}`
1745 }
1846 </P>
1947
@@ -21,15 +49,13 @@ const Success = (props) =>
2149 <P>
2250 { props.hash }
2351 </P>
24− <Anchor
25− className={'mb-4 mt-1'}
26− prop-size={'sm'}
27− target={'_blank'}
28− href={`https://etherscan.io/tx/${props.hash}`}>
29− {'View on Etherscan ↗'}
30− </Anchor>
52+
53+ { esanchor }
54+
3155 </Col>
3256 </Row>
57+ )
58+}
3359
3460const Failure = (props) =>
3561
@@ -50,7 +76,7 @@ const Failure = (props) =>
5076 </Row>
5177
5278const SentTransaction = (props) => {
53− const { web3, txnCursor, popRoute } = props
79+ const { web3, txnCursor, networkType, popRoute } = props
5480 const { setPointCursor, pointCursor } = props
5581
5682 const w3 = web3.matchWith({
@@ -65,7 +91,11 @@ const SentTransaction = (props) => {
6591
6692 const body = result.matchWith({
6793 Error: message => <Failure web3={ w3 } message={ message.value } />,
68− Ok: txn => <Success hash={ txn.value.transactionHash } />
94+ Ok: txn =>
95+ <Success
96+ hash={ txn.value.transactionHash }
97+ networkType={ networkType }
98+ />
6999 })
70100
71101 const ok =
src/views/SetProxy.js+12−2
@@ -8,6 +8,8 @@ import * as ob from 'urbit-ob'
88import { PROXY_TYPE, renderProxyType } from '../lib/proxy'
99import { BRIDGE_ERROR } from '../lib/error'
1010
11+import { NETWORK_NAMES } from '../lib/network'
12+
1113import StatelessTransaction from '../components/StatelessTransaction'
1214
1315import { ROUTE_NAMES } from '../lib/router'
@@ -274,6 +276,14 @@ class SetProxy extends React.Component {
274276 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
275277 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
276278
279+ const esvisible =
280+ props.networkType === NETWORK_NAMES.ROPSTEN ||
281+ props.networkType === NETWORK_NAMES.MAINNET
282+
283+ const esdomain =
284+ props.networkType === NETWORK_NAMES.ROPSTEN
285+ ? "ropsten.etherscan.io"
286+ : "etherscan.io"
277287
278288 const ucFirst = w => w.charAt(0).toUpperCase() + w.slice(1);
279289
@@ -308,9 +318,9 @@ class SetProxy extends React.Component {
308318 <Anchor
309319 className={'mt-1'}
310320 prop-size={'sm'}
311− disabled={!isValidAddress(state.proxyAddress)}
321+ prop-disabled={!isValidAddress(state.proxyAddress) || !esvisible}
312322 target={'_blank'}
313− href={`https://etherscan.io/address/${state.proxyAddress}`}>
323+ href={`https://${esdomain}/address/${state.proxyAddress}`}>
314324 {'View on Etherscan ↗'}
315325 </Anchor>
316326
src/views/Transfer.js+12−2
@@ -8,6 +8,7 @@ import { AddressInput, Warning, H3 } from '../components/Base'
88import StatelessTransaction from '../components/StatelessTransaction'
99
1010import { BRIDGE_ERROR } from '../lib/error'
11+import { NETWORK_NAMES } from '../lib/network'
1112import { ROUTE_NAMES } from '../lib/router'
1213
1314import {
@@ -250,6 +251,15 @@ class Transfer extends React.Component {
250251 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
251252 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
252253
254+ const esvisible =
255+ props.networkType === NETWORK_NAMES.ROPSTEN ||
256+ props.networkType === NETWORK_NAMES.MAINNET
257+
258+ const esdomain =
259+ props.networkType === NETWORK_NAMES.ROPSTEN
260+ ? "ropsten.etherscan.io"
261+ : "etherscan.io"
262+
253263 return (
254264 <Row>
255265 <Col>
@@ -280,9 +290,9 @@ class Transfer extends React.Component {
280290 <Anchor
281291 className={'mt-1'}
282292 prop-size={'s'}
283− disabled={!isValidAddress(state.receivingAddress)}
293+ prop-disabled={!isValidAddress(state.receivingAddress) || !esvisible}
284294 target={'_blank'}
285− href={`https://etherscan.io/address/${state.receivingAddress}`}>
295+ href={`https://${esdomain}/address/${state.receivingAddress}`}>
286296 {'View on Etherscan ↗'}
287297 </Anchor>
288298