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,
69 this.handleAddressInput = this.handleAddressInput.bind(this)
71 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
72 this.handleSubmit = this.handleSubmit.bind(this)
73 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
74 this.handleSetTxn = this.handleSetTxn.bind(this)
75 this.handleSetStx = this.handleSetStx.bind(this)
76 this.handleSetNonce = this.handleSetNonce.bind(this)
77 this.handleSetChainId = this.handleSetChainId.bind(this)
78 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
79 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
83 const { props } = this
85 const addr = props.wallet.matchWith({
86 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
88 throw BRIDGE_ERROR.MISSING_WALLET
92 props.web3.matchWith({
95 const validWeb3 = w3.value
97 const getTxMetadata = [
98 validWeb3.eth.getTransactionCount(addr),
99 validWeb3.eth.net.getId(),
100 validWeb3.eth.getGasPrice()
103 Promise.all(getTxMetadata).then(r => {
107 gasPrice: fromWei(r[2], 'gwei'),
110 this.setState({...txMetadata})
120 handleAddressInput(proxyAddress) {
121 this.setState({ proxyAddress })
122 this.handleClearTxn()
126 handleCreateUnsignedTxn() {
127 const txn = this.createUnsignedTxn()
128 this.setState({ txn })
132 handleSetUserApproval(){
134 this.setState({ userApproval: !state.userApproval })
140 this.setState({ txn })
154 handleSetNonce(nonce){
155 this.setState({ nonce })
156 this.handleClearStx()
161 handleSetChainId(chainId){
162 this.setState({ chainId })
163 this.handleClearStx()
168 handleSetGasPrice(gasPrice){
169 this.setState({ gasPrice })
170 this.handleClearStx()
175 handleSetGasLimit(gasLimit){
176 this.setState({ gasLimit })
177 this.handleClearStx()
185 stx: Maybe.Nothing(),
194 txn: Maybe.Nothing(),
195 stx: Maybe.Nothing(),
201 handleClearTransaction() {
204 txn: Maybe.Nothing(),
205 stx: Maybe.Nothing(),
212 const { props, state } = this
213 sendSignedTransaction(props.web3.value, state.stx)
215 props.setTxnCursor(sent)
217 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
220 // Note that value.value is due to wrapped Maybe.Just + Result.Error
221 this.setState({ txError: Maybe.Just(err.value.value) })
226 createUnsignedTxn(proxyAddress) {
227 const { state, props } = this
229 const validContracts = props.contracts.matchWith({
230 Just: (cs) => cs.value,
232 throw BRIDGE_ERROR.MISSING_CONTRACTS
236 const validPoint = props.pointCursor.matchWith({
237 Just: (shp) => shp.value,
239 throw BRIDGE_ERROR.MISSING_POINT
249 if (props.proxyType === PROXY_TYPE.TRANSFER_PROXY) {
250 return Maybe.Just(azimuth.ecliptic.setTransferProxy(...txArgs))
253 if (props.proxyType === PROXY_TYPE.SPAWN_PROXY) {
254 return Maybe.Just(azimuth.ecliptic.setSpawnProxy(...txArgs))
257 if (props.proxyType === PROXY_TYPE.MANAGEMENT_PROXY) {
258 return Maybe.Just(azimuth.ecliptic.setManagementProxy(...txArgs))
261 return Maybe.Nothing()
267 const { props, state } = this
269 const renderedProxyType = renderProxyType(props.proxyType)
271 const validAddress = isValidAddress(state.proxyAddress)
273 const canGenerate = validAddress === true
275 const canSign = !Maybe.Nothing.hasInstance(state.txn)
276 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
277 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
280 props.networkType === NETWORK_NAMES.ROPSTEN ||
281 props.networkType === NETWORK_NAMES.MAINNET
284 props.networkType === NETWORK_NAMES.ROPSTEN
285 ? "ropsten.etherscan.io"
288 const ucFirst = w => w.charAt(0).toUpperCase() + w.slice(1);
295 { `Set ${ucFirst(renderedProxyType)} Proxy For ` }
296 <code>{ `${ob.patp(state.issuingPoint)}` }</code>
301 'Please provide an Ethereum address to act as the ' +
302 `${renderedProxyType} proxy. You can also use Wallet ` +
303 'Generator to generate a keypair.'
308 className='mono mt-8'
310 prop-format='innerLabel'
311 placeholder={ `e.g. 0x84295d5e054d8cff5a22428b195f5a1615bd644f` }
312 value={ state.proxyAddress }
313 onChange={ v => this.handleAddressInput(v) }>
314 <InnerLabel>{ 'Proxy Address' }</InnerLabel>
315 <ShowBlockie className={'mt-1'} address={state.proxyAddress} />
321 prop-disabled={!isValidAddress(state.proxyAddress) || !esvisible}
323 href={`https://${esdomain}/address/${state.proxyAddress}`}>
324 {'View on Etherscan ↗'}
327 <StatelessTransaction
330 contracts={props.contracts}
331 wallet={props.wallet}
332 walletType={props.walletType}
333 walletHdPath={props.walletHdPath}
334 networkType={props.networkType}
340 gasPrice={state.gasPrice}
341 chainId={state.chainId}
342 gasLimit={state.gasLimit}
344 userApproval={state.userApproval}
345 canGenerate={ canGenerate }
347 canApprove={ canApprove }
350 createUnsignedTxn={this.handleCreateUnsignedTxn}
351 setUserApproval={this.handleSetUserApproval}
352 setTxn={this.handleSetTxn}
353 setStx={this.handleSetStx}
354 setNonce={this.handleSetNonce}
355 setChainId={this.handleSetChainId}
356 setGasPrice={this.handleSetGasPrice}
357 setGasLimit={this.handleSetGasLimit}
358 handleSubmit={this.handleSubmit} />
361 Maybe.Nothing.hasInstance(state.txError)
363 : <Warning className={'mt-8'}>
364 <H3 style={{marginTop: 0, paddingTop: 0}}>
366 'There was an error sending your transaction.'
369 { 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