1import Maybe from 'folktale/maybe'
2import React from 'react'
3import * as azimuth from 'azimuth-js'
4import { Row, Col, H1, H3, P, InnerLabel, ShowBlockie, Anchor } from '../components/Base'
5import { AddressInput, Warning } from '../components/Base'
6import * as ob from 'urbit-ob'
8import { PROXY_TYPE, renderProxyType } from '../lib/proxy'
9import { BRIDGE_ERROR } from '../lib/error'
11import { NETWORK_NAMES } from '../lib/network'
13import StatelessTransaction from '../components/StatelessTransaction'
15import { ROUTE_NAMES } from '../lib/router'
18 sendSignedTransaction,
24 addressFromSecp256k1Public,
27const SetManagementProxy = (props) =>
30 proxyType={ PROXY_TYPE.MANAGEMENT_PROXY }
33const SetSpawnProxy = (props) =>
36 proxyType={ PROXY_TYPE.SPAWN_PROXY }
39const SetTransferProxy = (props) =>
42 proxyType={ PROXY_TYPE.TRANSFER_PROXY }
45class SetProxy extends React.Component {
49 const issuingPoint = props.pointCursor.matchWith({
50 Just: (shp) => shp.value,
52 throw BRIDGE_ERROR.MISSING_POINT
59 txError: Maybe.Nothing(),
60 issuingPoint: issuingPoint,
61 showGasDetails: false,
70 this.handleAddressInput = this.handleAddressInput.bind(this)
72 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
73 this.handleSubmit = this.handleSubmit.bind(this)
74 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
75 this.handleSetTxn = this.handleSetTxn.bind(this)
76 this.handleSetStx = this.handleSetStx.bind(this)
77 this.handleSetNonce = this.handleSetNonce.bind(this)
78 this.handleSetChainId = this.handleSetChainId.bind(this)
79 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
80 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
81 this.toggleGasDetails = this.toggleGasDetails.bind(this)
86 showGasDetails: !this.state.showGasDetails
91 const { props } = this
93 const addr = props.wallet.matchWith({
94 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
96 throw BRIDGE_ERROR.MISSING_WALLET
100 props.web3.matchWith({
103 const validWeb3 = w3.value
105 const getTxMetadata = [
106 validWeb3.eth.getTransactionCount(addr),
107 validWeb3.eth.net.getId(),
108 validWeb3.eth.getGasPrice()
111 Promise.all(getTxMetadata).then(r => {
115 gasPrice: fromWei(r[2], 'gwei'),
118 this.setState({...txMetadata})
128 handleAddressInput(proxyAddress) {
129 this.setState({ proxyAddress })
130 this.handleClearTxn()
134 handleCreateUnsignedTxn() {
135 const txn = this.createUnsignedTxn()
136 this.setState({ txn })
140 handleSetUserApproval(){
142 this.setState({ userApproval: !state.userApproval })
148 this.setState({ txn })
162 handleSetNonce(nonce){
163 this.setState({ nonce })
164 this.handleClearStx()
169 handleSetChainId(chainId){
170 this.setState({ chainId })
171 this.handleClearStx()
176 handleSetGasPrice(gasPrice){
177 this.setState({ gasPrice })
178 this.handleClearStx()
183 handleSetGasLimit(gasLimit){
184 this.setState({ gasLimit })
185 this.handleClearStx()
193 stx: Maybe.Nothing(),
202 txn: Maybe.Nothing(),
203 stx: Maybe.Nothing(),
209 handleClearTransaction() {
212 txn: Maybe.Nothing(),
213 stx: Maybe.Nothing(),
220 const { props, state } = this
221 sendSignedTransaction(props.web3.value, state.stx)
223 props.setTxnHashCursor(sent)
225 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
228 this.setState({ txError: err.map(val => val.merge()) })
233 createUnsignedTxn(proxyAddress) {
234 const { state, props } = this
236 const validContracts = props.contracts.matchWith({
237 Just: (cs) => cs.value,
239 throw BRIDGE_ERROR.MISSING_CONTRACTS
243 const validPoint = props.pointCursor.matchWith({
244 Just: (shp) => shp.value,
246 throw BRIDGE_ERROR.MISSING_POINT
256 if (props.proxyType === PROXY_TYPE.TRANSFER_PROXY) {
257 return Maybe.Just(azimuth.ecliptic.setTransferProxy(...txArgs))
260 if (props.proxyType === PROXY_TYPE.SPAWN_PROXY) {
261 return Maybe.Just(azimuth.ecliptic.setSpawnProxy(...txArgs))
264 if (props.proxyType === PROXY_TYPE.MANAGEMENT_PROXY) {
265 return Maybe.Just(azimuth.ecliptic.setManagementProxy(...txArgs))
268 return Maybe.Nothing()
274 const { props, state } = this
276 const renderedProxyType = renderProxyType(props.proxyType)
278 const validAddress = isValidAddress(state.proxyAddress)
280 const canGenerate = validAddress === true
282 const canSign = Maybe.Just.hasInstance(state.txn)
283 const canApprove = Maybe.Just.hasInstance(state.stx)
284 const canSend = Maybe.Just.hasInstance(state.stx) && state.userApproval === true
287 props.networkType === NETWORK_NAMES.ROPSTEN ||
288 props.networkType === NETWORK_NAMES.MAINNET
291 props.networkType === NETWORK_NAMES.ROPSTEN
292 ? "ropsten.etherscan.io"
295 const ucFirst = w => w.charAt(0).toUpperCase() + w.slice(1);
302 { `Set ${ucFirst(renderedProxyType)} Proxy For ` }
303 <code>{ `${ob.patp(state.issuingPoint)}` }</code>
308 'Please provide an Ethereum address to act as the ' +
309 `${renderedProxyType} proxy. You can also use Wallet ` +
310 'Generator to generate a keypair.'
315 className='mono mt-8'
317 prop-format='innerLabel'
318 placeholder={ `e.g. 0x84295d5e054d8cff5a22428b195f5a1615bd644f` }
319 value={ state.proxyAddress }
320 onChange={ v => this.handleAddressInput(v) }>
321 <InnerLabel>{ 'Proxy Address' }</InnerLabel>
322 <ShowBlockie className={'mt-1'} address={state.proxyAddress} />
328 prop-disabled={!isValidAddress(state.proxyAddress) || !esvisible}
330 href={`https://${esdomain}/address/${state.proxyAddress}`}>
331 {'View on Etherscan ↗'}
334 <StatelessTransaction
337 contracts={props.contracts}
338 wallet={props.wallet}
339 walletType={props.walletType}
340 walletHdPath={props.walletHdPath}
341 networkType={props.networkType}
347 gasPrice={state.gasPrice}
348 chainId={state.chainId}
349 gasLimit={state.gasLimit}
350 showGasDetails={state.showGasDetails}
351 toggleGasDetails={this.toggleGasDetails}
353 userApproval={state.userApproval}
354 canGenerate={ canGenerate }
356 canApprove={ canApprove }
359 createUnsignedTxn={this.handleCreateUnsignedTxn}
360 setUserApproval={this.handleSetUserApproval}
361 setTxn={this.handleSetTxn}
362 setStx={this.handleSetStx}
363 setNonce={this.handleSetNonce}
364 setChainId={this.handleSetChainId}
365 setGasPrice={this.handleSetGasPrice}
366 setGasLimit={this.handleSetGasLimit}
367 handleSubmit={this.handleSubmit} />
370 Maybe.Nothing.hasInstance(state.txError)
372 : <Warning className={'mt-8'}>
373 <H3 style={{marginTop: 0, paddingTop: 0}}>
375 'There was an error sending your transaction.'
378 { state.txError.value }
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list