@@ -1,4 +1,4 @@
1−import Maybe from 'folktale/maybe'
1+import { Just, Nothing } from 'folktale/maybe'
2import React from 'react'
2import React from 'react'
3import { Row, Col, H1, H3, P, Warning } from '../components/Base'
3import { Row, Col, H1, H3, P, Warning } from '../components/Base'
4import { InnerLabel, AddressInput, ShowBlockie, Anchor } from '../components/Base'
4import { InnerLabel, AddressInput, ShowBlockie, Anchor } from '../components/Base'
@@ -9,17 +9,8 @@ import StatelessTransaction from '../components/StatelessTransaction'
9import { BRIDGE_ERROR } from '../lib/error'
9import { BRIDGE_ERROR } from '../lib/error'
10import { NETWORK_NAMES } from '../lib/network'
10import { NETWORK_NAMES } from '../lib/network'
11import { ROUTE_NAMES } from '../lib/router'
11import { ROUTE_NAMES } from '../lib/router'
14− sendSignedTransaction,
12+import { sendSignedTransaction, fromWei } from '../lib/txn'
20− addressFromSecp256k1Public,
13+import { isValidAddress, addressFromSecp256k1Public } from '../lib/wallet'
21−} from '../lib/wallet'
24class AcceptTransfer extends React.Component {
15class AcceptTransfer extends React.Component {
25 constructor(props) {
16 constructor(props) {
@@ -41,18 +32,18 @@ class AcceptTransfer extends React.Component {
42 this.state = {
33 this.state = {
43 receivingAddress: receivingAddress,
34 receivingAddress: receivingAddress,
44− txn: Maybe.Nothing(),
35+ txn: Nothing(),
45− txError: Maybe.Nothing(),
36+ txError: Nothing(),
46 incomingPoint: incomingPoint,
37 incomingPoint: incomingPoint,
47 userApproval: false,
38 userApproval: false,
48 nonce: '',
39 nonce: '',
49 gasPrice: '5',
40 gasPrice: '5',
50 chainId: '',
41 chainId: '',
51 gasLimit: '600000',
42 gasLimit: '600000',
52− stx: Maybe.Nothing(),
43+ stx: Nothing(),
54 this.handleAddressInput = this.handleAddressInput.bind(this)
46 this.handleAddressInput = this.handleAddressInput.bind(this)
56 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
47 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
57 this.handleSubmit = this.handleSubmit.bind(this)
48 this.handleSubmit = this.handleSubmit.bind(this)
58 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
49 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
@@ -97,57 +88,27 @@ class AcceptTransfer extends React.Component {
101− // const validPoint = props.pointCursor.matchWith({
102− // Just: (shp) => shp.value,
104− // throw BRIDGE_ERROR.MISSING_POINT
110− // We need to get the point's owner, so it's not possible to perform this
111− // transaction offline.
113− // Perhaps we could add an 'owner' input in the offline case, if necessary.
115− // const owner = props.pointCache[validPoint].owner
117− // const txn = Maybe.Just(this.createUnsignedTxn(
119− // state.receivingAddress))
121− // this.setState({ txn })
126 handleAddressInput(proxyAddress) {
93 handleAddressInput(proxyAddress) {
127 this.setState({ proxyAddress })
94 this.setState({ proxyAddress })
128 this.handleClearTxn()
95 this.handleClearTxn()
132 handleCreateUnsignedTxn() {
98 handleCreateUnsignedTxn() {
133 const txn = this.createUnsignedTxn()
99 const txn = this.createUnsignedTxn()
134 this.setState({ txn })
100 this.setState({ txn })
138 handleSetUserApproval(){
103 handleSetUserApproval(){
139 const {state} = this
104 const {state} = this
140 this.setState({ userApproval: !state.userApproval })
105 this.setState({ userApproval: !state.userApproval })
145 handleSetTxn(txn){
108 handleSetTxn(txn){
146 this.setState({ txn })
109 this.setState({ txn })
151 handleSetStx(stx){
112 handleSetStx(stx){
152 this.setState({
113 this.setState({
@@ -155,65 +116,41 @@ class AcceptTransfer extends React.Component {
160 handleSetNonce(nonce){
119 handleSetNonce(nonce){
161 this.setState({ nonce })
120 this.setState({ nonce })
162 this.handleClearStx()
121 this.handleClearStx()
167 handleSetChainId(chainId){
124 handleSetChainId(chainId){
168 this.setState({ chainId })
125 this.setState({ chainId })
169 this.handleClearStx()
126 this.handleClearStx()
174 handleSetGasPrice(gasPrice){
129 handleSetGasPrice(gasPrice){
175 this.setState({ gasPrice })
130 this.setState({ gasPrice })
176 this.handleClearStx()
131 this.handleClearStx()
181 handleSetGasLimit(gasLimit){
134 handleSetGasLimit(gasLimit){
182 this.setState({ gasLimit })
135 this.setState({ gasLimit })
183 this.handleClearStx()
136 this.handleClearStx()
188 handleClearStx() {
139 handleClearStx() {
189 this.setState({
140 this.setState({
190 userApproval: false,
141 userApproval: false,
191− stx: Maybe.Nothing(),
142+ stx: Nothing(),
197 handleClearTxn() {
146 handleClearTxn() {
198 this.setState({
147 this.setState({
199 userApproval: false,
148 userApproval: false,
200− txn: Maybe.Nothing(),
149+ txn: Nothing(),
201− stx: Maybe.Nothing(),
207− handleClearTransaction() {
209− userApproval: false,
210− txn: Maybe.Nothing(),
211− stx: Maybe.Nothing(),
150+ stx: Nothing(),
217 handleSubmit() {
154 handleSubmit() {
218 const { props, state } = this
155 const { props, state } = this
219 sendSignedTransaction(props.web3.value, state.stx)
156 sendSignedTransaction(props.web3.value, state.stx)
@@ -223,8 +160,7 @@ class AcceptTransfer extends React.Component {
223 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
160 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
225 .catch(err => {
162 .catch(err => {
226− // Note that value.value is due to wrapped Maybe.Just + Result.Error
227− this.setState({ txError: Maybe.Just(err.value.value) })
163+ this.setState({ txError: err.map(val => val.merge()) })
@@ -247,7 +183,7 @@ class AcceptTransfer extends React.Component {
248 const owner = props.pointCache[validPoint].owner
184 const owner = props.pointCache[validPoint].owner
250− return Maybe.Just(azimuth.ecliptic.transferFrom(
186+ return Just(azimuth.ecliptic.transferFrom(
251 validContracts,
187 validContracts,
253 state.receivingAddress,
189 state.receivingAddress,
@@ -260,9 +196,11 @@ class AcceptTransfer extends React.Component {
260 const { state, props } = this
196 const { state, props } = this
261 const validAddress = isValidAddress(state.receivingAddress)
197 const validAddress = isValidAddress(state.receivingAddress)
262 const canGenerate = validAddress === true
198 const canGenerate = validAddress === true
263− const canSign = !Maybe.Nothing.hasInstance(state.txn)
199+ const canSign = Just.hasInstance(state.txn)
264− const canApprove = !Maybe.Nothing.hasInstance(state.stx)
200+ const canApprove = Just.hasInstance(state.stx)
202+ Just.hasInstance(state.stx)
265− const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
203+ && state.userApproval === true
267 const esvisible =
205 const esvisible =
268 props.networkType === NETWORK_NAMES.ROPSTEN ||
206 props.networkType === NETWORK_NAMES.ROPSTEN ||
@@ -286,6 +224,7 @@ class AcceptTransfer extends React.Component {
286 "as. But you can transfer to any address you like."
224 "as. But you can transfer to any address you like."
289 <AddressInput
228 <AddressInput
290 className='mono mt-8'
229 className='mono mt-8'
291 prop-size='lg'
230 prop-size='lg'
@@ -339,7 +278,7 @@ class AcceptTransfer extends React.Component {
339 handleSubmit={this.handleSubmit} />
278 handleSubmit={this.handleSubmit} />
342− Maybe.Nothing.hasInstance(state.txError)
281+ Nothing.hasInstance(state.txError)
344 : <Warning className={'mt-8'}>
283 : <Warning className={'mt-8'}>
345 <H3 style={{marginTop: 0, paddingTop: 0}}>
284 <H3 style={{marginTop: 0, paddingTop: 0}}>
@@ -350,6 +289,7 @@ class AcceptTransfer extends React.Component {
350 { state.txError.value }
289 { state.txError.value }
351 </Warning>
290 </Warning>