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.setTxnHashCursor(sent)
217 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
220 this.setState({ txError: err.map(val => val.merge()) })
225 createUnsignedTxn(proxyAddress) {
226 const { state, props } = this
228 const validContracts = props.contracts.matchWith({
229 Just: (cs) => cs.value,
231 throw BRIDGE_ERROR.MISSING_CONTRACTS
235 const validPoint = props.pointCursor.matchWith({
236 Just: (shp) => shp.value,
238 throw BRIDGE_ERROR.MISSING_POINT
248 if (props.proxyType === PROXY_TYPE.TRANSFER_PROXY) {
249 return Maybe.Just(azimuth.ecliptic.setTransferProxy(...txArgs))
252 if (props.proxyType === PROXY_TYPE.SPAWN_PROXY) {
253 return Maybe.Just(azimuth.ecliptic.setSpawnProxy(...txArgs))
256 if (props.proxyType === PROXY_TYPE.MANAGEMENT_PROXY) {
257 return Maybe.Just(azimuth.ecliptic.setManagementProxy(...txArgs))
260 return Maybe.Nothing()
266 const { props, state } = this
268 const renderedProxyType = renderProxyType(props.proxyType)
270 const validAddress = isValidAddress(state.proxyAddress)
272 const canGenerate = validAddress === true
274 const canSign = !Maybe.Nothing.hasInstance(state.txn)
275 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
276 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
279 props.networkType === NETWORK_NAMES.ROPSTEN ||
280 props.networkType === NETWORK_NAMES.MAINNET
283 props.networkType === NETWORK_NAMES.ROPSTEN
284 ? "ropsten.etherscan.io"
287 const ucFirst = w => w.charAt(0).toUpperCase() + w.slice(1);
294 { `Set ${ucFirst(renderedProxyType)} Proxy For ` }
295 <code>{ `${ob.patp(state.issuingPoint)}` }</code>
300 'Please provide an Ethereum address to act as the ' +
301 `${renderedProxyType} proxy. You can also use Wallet ` +
302 'Generator to generate a keypair.'
307 className='mono mt-8'
309 prop-format='innerLabel'
310 placeholder={ `e.g. 0x84295d5e054d8cff5a22428b195f5a1615bd644f` }
311 value={ state.proxyAddress }
312 onChange={ v => this.handleAddressInput(v) }>
313 <InnerLabel>{ 'Proxy Address' }</InnerLabel>
314 <ShowBlockie className={'mt-1'} address={state.proxyAddress} />
320 prop-disabled={!isValidAddress(state.proxyAddress) || !esvisible}
322 href={`https://${esdomain}/address/${state.proxyAddress}`}>
323 {'View on Etherscan ↗'}
326 <StatelessTransaction
329 contracts={props.contracts}
330 wallet={props.wallet}
331 walletType={props.walletType}
332 walletHdPath={props.walletHdPath}
333 networkType={props.networkType}
339 gasPrice={state.gasPrice}
340 chainId={state.chainId}
341 gasLimit={state.gasLimit}
343 userApproval={state.userApproval}
344 canGenerate={ canGenerate }
346 canApprove={ canApprove }
349 createUnsignedTxn={this.handleCreateUnsignedTxn}
350 setUserApproval={this.handleSetUserApproval}
351 setTxn={this.handleSetTxn}
352 setStx={this.handleSetStx}
353 setNonce={this.handleSetNonce}
354 setChainId={this.handleSetChainId}
355 setGasPrice={this.handleSetGasPrice}
356 setGasLimit={this.handleSetGasLimit}
357 handleSubmit={this.handleSubmit} />
360 Maybe.Nothing.hasInstance(state.txError)
362 : <Warning className={'mt-8'}>
363 <H3 style={{marginTop: 0, paddingTop: 0}}>
365 'There was an error sending your transaction.'
368 { 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