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, Form, Warning } from '../components/Base'
6import * as ob from 'urbit-ob'
8import { PROXY_TYPE, renderProxyType } from '../lib/proxy'
9import { BRIDGE_ERROR } from '../lib/error'
11import StatelessTransaction from '../components/StatelessTransaction'
13import { ROUTE_NAMES } from '../lib/router'
16 sendSignedTransaction,
22 addressFromSecp256k1Public,
25const SetManagementProxy = (props) =>
28 proxyType={ PROXY_TYPE.MANAGEMENT_PROXY }
31const SetSpawnProxy = (props) =>
34 proxyType={ PROXY_TYPE.SPAWN_PROXY }
37const SetTransferProxy = (props) =>
40 proxyType={ PROXY_TYPE.TRANSFER_PROXY }
43class SetProxy extends React.Component {
47 const issuingPoint = props.pointCursor.matchWith({
48 Just: (shp) => shp.value,
50 throw BRIDGE_ERROR.MISSING_POINT
57 txError: Maybe.Nothing(),
58 issuingPoint: issuingPoint,
67 this.handleAddressInput = this.handleAddressInput.bind(this)
69 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
70 this.handleSubmit = this.handleSubmit.bind(this)
71 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
72 this.handleSetTxn = this.handleSetTxn.bind(this)
73 this.handleSetStx = this.handleSetStx.bind(this)
74 this.handleSetNonce = this.handleSetNonce.bind(this)
75 this.handleSetChainId = this.handleSetChainId.bind(this)
76 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
77 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
81 const { props } = this
83 const addr = props.wallet.matchWith({
84 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
86 throw BRIDGE_ERROR.MISSING_WALLET
90 props.web3.matchWith({
93 const validWeb3 = w3.value
95 const getTxMetadata = [
96 validWeb3.eth.getTransactionCount(addr),
97 validWeb3.eth.net.getId(),
98 validWeb3.eth.getGasPrice()
101 Promise.all(getTxMetadata).then(r => {
105 gasPrice: fromWei(r[2], 'gwei'),
108 this.setState({...txMetadata})
118 handleAddressInput(proxyAddress) {
119 this.setState({ proxyAddress })
120 this.handleClearTxn()
124 handleCreateUnsignedTxn() {
125 const txn = this.createUnsignedTxn()
126 this.setState({ txn })
130 handleSetUserApproval(){
132 this.setState({ userApproval: !state.userApproval })
138 this.setState({ txn })
152 handleSetNonce(nonce){
153 this.setState({ nonce })
154 this.handleClearStx()
159 handleSetChainId(chainId){
160 this.setState({ chainId })
161 this.handleClearStx()
166 handleSetGasPrice(gasPrice){
167 this.setState({ gasPrice })
168 this.handleClearStx()
173 handleSetGasLimit(gasLimit){
174 this.setState({ gasLimit })
175 this.handleClearStx()
183 stx: Maybe.Nothing(),
192 txn: Maybe.Nothing(),
193 stx: Maybe.Nothing(),
199 handleClearTransaction() {
202 txn: Maybe.Nothing(),
203 stx: Maybe.Nothing(),
210 const { props, state } = this
211 sendSignedTransaction(props.web3.value, state.stx)
213 props.setTxnCursor(sent)
215 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
218 // Note that value.value is due to wrapped Maybe.Just + Result.Error
219 this.setState({ txError: Maybe.Just(err.value.value) })
224 createUnsignedTxn(proxyAddress) {
225 const { state, props } = this
227 const validContracts = props.contracts.matchWith({
228 Just: (cs) => cs.value,
230 throw BRIDGE_ERROR.MISSING_CONTRACTS
234 const validPoint = props.pointCursor.matchWith({
235 Just: (shp) => shp.value,
237 throw BRIDGE_ERROR.MISSING_POINT
247 if (props.proxyType === PROXY_TYPE.TRANSFER_PROXY) {
248 return Maybe.Just(azimuth.ecliptic.setTransferProxy(...txArgs))
251 if (props.proxyType === PROXY_TYPE.SPAWN_PROXY) {
252 return Maybe.Just(azimuth.ecliptic.setSpawnProxy(...txArgs))
255 if (props.proxyType === PROXY_TYPE.MANAGEMENT_PROXY) {
256 return Maybe.Just(azimuth.ecliptic.setManagementProxy(...txArgs))
259 return Maybe.Nothing()
265 const { props, state } = this
267 const renderedProxyType = renderProxyType(props.proxyType)
269 const validAddress = isValidAddress(state.proxyAddress)
271 const canGenerate = validAddress === true
273 const canSign = !Maybe.Nothing.hasInstance(state.txn)
274 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
275 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
278 const ucFirst = w => w.charAt(0).toUpperCase() + w.slice(1);
285 { `Set ${ucFirst(renderedProxyType)} Proxy For ` }
286 <code>{ `${ob.patp(state.issuingPoint)}` }</code>
291 'Please provide an Ethereum address to act as the ' +
292 `${renderedProxyType} proxy. You can also use Wallet ` +
293 'Generator to generate a keypair.'
298 className='mono mt-8'
300 prop-format='innerLabel'
301 placeholder={ `e.g. 0x84295d5e054d8cff5a22428b195f5a1615bd644f` }
302 value={ state.proxyAddress }
303 onChange={ v => this.handleAddressInput(v) }>
304 <InnerLabel>{ 'Proxy Address' }</InnerLabel>
305 <ShowBlockie className={'mt-1'} address={state.proxyAddress} />
311 disabled={!isValidAddress(state.proxyAddress)}
313 href={`https://etherscan.io/address/${state.proxyAddress}`}>
314 {'View on Etherscan ↗'}
317 <StatelessTransaction
320 contracts={props.contracts}
321 wallet={props.wallet}
322 walletType={props.walletType}
323 walletHdPath={props.walletHdPath}
329 gasPrice={state.gasPrice}
330 chainId={state.chainId}
331 gasLimit={state.gasLimit}
333 userApproval={state.userApproval}
334 canGenerate={ canGenerate }
336 canApprove={ canApprove }
339 createUnsignedTxn={this.handleCreateUnsignedTxn}
340 setUserApproval={this.handleSetUserApproval}
341 setTxn={this.handleSetTxn}
342 setStx={this.handleSetStx}
343 setNonce={this.handleSetNonce}
344 setChainId={this.handleSetChainId}
345 setGasPrice={this.handleSetGasPrice}
346 setGasLimit={this.handleSetGasLimit}
347 handleSubmit={this.handleSubmit} />
350 Maybe.Nothing.hasInstance(state.txError)
352 : <Warning className={'mt-8'}>
353 <H3 style={{marginTop: 0, paddingTop: 0}}>
355 'There was an error sending your transaction.'
358 { 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