-
Notifications
You must be signed in to change notification settings - Fork 504
/
template.success.js
198 lines (191 loc) · 8.19 KB
/
template.success.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { FormattedMessage } from 'react-intl'
import { Field, reduxForm } from 'redux-form'
import { required, validBitcoinAddress, validBitcoinPrivateKey } from 'services/FormHelper'
import { Button, Icon, Link, Text, Tooltip } from 'blockchain-info-components'
import { FiatConvertor, Form, FormGroup, FormItem, FormLabel, NumberBox, SelectBoxBitcoinAddresses, SelectBoxCoin, SelectBox, TextBox, TextArea } from 'components/Form'
import { shouldValidate, isAddressDerivedFromPriv, emptyAccount, minimumAmount, maximumAmount, minimumFeePerByte, maximumFeePerByte } from './validation'
import QRCodeCapture from 'components/QRCodeCapture'
import RegularFeeLink from './RegularFeeLink'
import PriorityFeeLink from './PriorityFeeLink'
import ComboDisplay from 'components/Display/ComboDisplay'
const Row = styled.div`
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 100%;
`
const ColLeft = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
width: 50%;
`
const ColRight = ColLeft.extend`
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-end;
width: 50%;
`
const AddressButton = styled.div`
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 40px;
height: 40px;
box-sizing: border-box;
border: 1px solid ${props => props.theme['gray-2']};
&:hover { background-color: ${props => props.theme['gray-1']}; }
`
const FeeFormContainer = styled.div`
display: flex;
flex-direction: ${props => props.toggled ? 'column' : 'row'};
align-items: center;
justify-content: space-between;
width: 100%;
`
const FeeFormLabel = styled(FormLabel)`
width: 100%;
display: flex;
white-space: nowrap;
> div {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
}
`
const FeeOptionsContainer = styled.div`
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
`
const FeePerByteContainer = styled.div`
margin-top: 10px;
width: 100%;
`
const FirstStep = props => {
const { invalid, submitting, ...rest } = props
const { watchOnly, addressMatchesPriv, destination, toToggled, feePerByteToggled, feePerByteElements, regularFeePerByte, priorityFeePerByte, isPriorityFeePerByte, totalFee, ...rest2 } = rest
const { handleFeePerByteToggle, handleToToggle, handleSubmit } = rest2
return (
<Form onSubmit={handleSubmit}>
<FormGroup inline margin={'15px'}>
<FormItem width={'40%'}>
<FormLabel for='coin'>
<FormattedMessage id='modals.sendbtc.firststep.coin' defaultMessage='Currency:' />
</FormLabel>
<Field name='coin' component={SelectBoxCoin} validate={[required]} />
</FormItem>
<FormItem width={'60%'}>
<FormLabel for='from'>
<FormattedMessage id='modals.sendbtc.firststep.from' defaultMessage='From:' />
</FormLabel>
<Field name='from' component={SelectBoxBitcoinAddresses} validate={[required]} includeAll={false} />
{watchOnly &&
<Row>
<Field name='priv' placeholder='Please enter your private key...' component={TextBox} validate={[required, validBitcoinPrivateKey, isAddressDerivedFromPriv]} autoFocus />
<QRCodeCapture scanType='btcPriv' border={['top', 'bottom']} />
</Row>
}
</FormItem>
</FormGroup>
<FormGroup margin={'15px'}>
<FormItem>
<FormLabel for='to'>
<FormattedMessage id='modals.sendbtc.firststep.to' defaultMessage='To:' />
</FormLabel>
<Row>
{toToggled && !destination && <Field name='to' component={SelectBoxBitcoinAddresses} opened includeAll={false} />}
{toToggled && destination && <Field name='to' component={SelectBoxBitcoinAddresses} onFocus={() => handleToToggle()} includeAll={false} validate={[required]} hideArrow />}
{!toToggled && <Field name='to' placeholder='Paste or scan an address, or select a destination' component={TextBox} validate={[required, validBitcoinAddress]} autoFocus />}
{(!toToggled || destination) && <QRCodeCapture scanType='btcAddress' border={['top', 'bottom']} />}
{(!toToggled || destination) && <AddressButton onClick={() => handleToToggle(true)}><Icon name='down-arrow' size='10px' cursor /></AddressButton>}
</Row>
</FormItem>
</FormGroup>
<FormGroup margin={'15px'}>
<FormItem>
<FormLabel for='amount'>
<FormattedMessage id='modals.sendbtc.firststep.amount' defaultMessage='Enter Amount:' />
</FormLabel>
<Field name='amount' component={FiatConvertor} validate={[required, emptyAccount, minimumAmount, maximumAmount]} coin='BTC' />
</FormItem>
</FormGroup>
<FormGroup margin={'15px'}>
<FormItem>
<FormLabel>
<FormattedMessage id='modals.sendbtc.firststep.description' defaultMessage='Description: ' />
<Tooltip>
<FormattedMessage id='modals.sendbtc.firststep.share_tooltip' defaultMessage='Add a note to remind yourself what this transaction relates to. This note will be private and only seen by you.' />
</Tooltip>
</FormLabel>
<Field name='description' component={TextArea} placeholder="What's this transaction for?" fullwidth />
</FormItem>
</FormGroup>
<FormGroup inline margin={'15px'}>
<ColLeft>
<FeeFormContainer toggled={feePerByteToggled}>
<FeeFormLabel>
<FormattedMessage id='modals.sendbtc.firststep.fee' defaultMessage='Transaction fee:' />
{!feePerByteToggled && <Field name='feePerByte' component={SelectBox} elements={feePerByteElements} />}
{feePerByteToggled &&
<FeeOptionsContainer>
<RegularFeeLink fee={regularFeePerByte} />
<PriorityFeeLink fee={priorityFeePerByte} />
</FeeOptionsContainer>
}
</FeeFormLabel>
{feePerByteToggled &&
<FeePerByteContainer>
<Field name='feePerByte' component={NumberBox} validate={[required, minimumFeePerByte, maximumFeePerByte]} />
</FeePerByteContainer>
}
</FeeFormContainer>
</ColLeft>
<ColRight>
<ComboDisplay size='14px' coin='BTC'>{totalFee}</ComboDisplay>
<Link size='13px' weight={300} capitalize onClick={handleFeePerByteToggle} >
{feePerByteToggled
? <FormattedMessage id='modals.sendbtc.firststep.cancel' defaultMessage='Cancel' />
: <FormattedMessage id='modals.sendbtc.firststep.edit' defaultMessage='Customize fee' />
}
</Link>
</ColRight>
</FormGroup>
<FormGroup>
<Text size='13px' weight={300}>
{!isPriorityFeePerByte && <FormattedMessage id='modals.sendbtc.firststep.estimated' defaultMessage='Estimated confirmation time 1+ hour' />}
{isPriorityFeePerByte && <FormattedMessage id='modals.sendbtc.firststep.estimated2' defaultMessage='Estimated confirmation time 0-60 minutes' />}
</Text>
</FormGroup>
<FormGroup>
<Button type='submit' nature='primary' uppercase disabled={submitting || invalid}>
<FormattedMessage id='modals.sendbtc.firststep.continue' defaultMessage='Continue' />
</Button>
</FormGroup>
</Form>
)
}
FirstStep.propTypes = {
invalid: PropTypes.bool.isRequired,
submitting: PropTypes.bool.isRequired,
toToggled: PropTypes.bool.isRequired,
feePerByteToggled: PropTypes.bool.isRequired,
feePerByteElements: PropTypes.array.isRequired,
regularFeePerByte: PropTypes.number.isRequired,
priorityFeePerByte: PropTypes.number.isRequired,
isPriorityFeePerByte: PropTypes.bool.isRequired,
handleFeePerByteToggle: PropTypes.func.isRequired,
handleToToggle: PropTypes.func.isRequired,
handleSubmit: PropTypes.func.isRequired,
totalFee: PropTypes.number
}
export default reduxForm({ form: 'sendBtc', destroyOnUnmount: false, shouldValidate })(FirstStep)