/
LtcToEth.js
374 lines (348 loc) · 13.2 KB
/
LtcToEth.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import React, { Component, Fragment } from 'react'
import crypto from 'crypto'
import config from 'app-config'
import { BigNumber } from 'bignumber.js'
import actions from 'redux/actions'
import Timer from './Timer/Timer'
import InlineLoader from 'components/loaders/InlineLoader/InlineLoader'
import { TimerButton, Button } from 'components/controls'
import { FormattedMessage } from 'react-intl'
export default class LtcToEth extends Component {
constructor({ swap, currencyData }) {
super()
this.swap = swap
this.state = {
currencyAddress: currencyData.address,
flow: this.swap.flow.state,
secret: crypto.randomBytes(32).toString('hex'),
enabledButton: false,
}
}
componentWillMount() {
this.swap.on('state update', this.handleFlowStateUpdate)
}
componentWillUnmount() {
this.swap.off('state update', this.handleFlowStateUpdate)
}
handleFlowStateUpdate = (values) => {
const stepNumbers = {
1: 'sign',
2: 'submit-secret',
3: 'sync-balance',
4: 'lock-ltc',
5: 'wait-lock-eth',
6: 'withdraw-eth',
7: 'finish',
8: 'end',
}
// actions.analytics.swapEvent(stepNumbers[values.step], 'LTC2ETH')
this.setState({
flow: values,
})
}
overProgress = ({ flow, length }) => {
actions.loader.show(true, '', '', true, { flow, length, name: 'LTC2ETH' })
}
submitSecret = () => {
const { secret } = this.state
this.swap.flow.submitSecret(secret)
}
updateBalance = () => {
this.swap.flow.syncBalance()
}
tryRefund = () => {
this.swap.flow.tryRefund()
this.setState(() => ({ enabledButton: false }))
}
getRefundTxHex = () => {
const { flow } = this.state
if (flow.refundTxHex) {
return flow.refundTxHex
}
else if (flow.ltcScriptValues) {
this.swap.flow.getRefundTxHex()
}
}
render() {
const { children, disabledTimer } = this.props
const { currencyAddress, secret, flow, enabledButton } = this.state
return (
<div>
{
this.swap.id && (
<strong>{this.swap.sellAmount.toNumber()} {this.swap.sellCurrency} ⟶ {this.swap.buyAmount.toNumber()} {this.swap.buyCurrency}</strong>
)
}
{
!this.swap.id && (
this.swap.isMy ? (
<h3>
<FormattedMessage id="LtcTOeth101" defaultMessage="This order doesn't have a buyer" />
</h3>
) : (
<Fragment>
<h3>
<FormattedMessage id="LtcToEth.orderCreatorIsOffline" defaultMessage="The order creator is offline. Waiting for him.." />
</h3>
<InlineLoader />
</Fragment>
)
)
}
{
!flow.isParticipantSigned && (
<Fragment>
<h3>
<FormattedMessage
id="LtcTOeth117"
defaultMessage="Waiting for a market maker. If the market maker does not appear within 5 minutes, the swap will be canceled automatically." />
</h3>
<InlineLoader />
</Fragment>
)
}
{
flow.isParticipantSigned && (
<Fragment>
<h3>
<FormattedMessage id="LtcTOeth127" defaultMessage="2. Create a secret key" />
</h3>
{
!flow.secretHash ? (
<Fragment>
<input type="text" placeholder="Secret Key" defaultValue={secret} />
<br />
<TimerButton disabledTimer={disabledTimer} timeLeft={5} brand onClick={this.submitSecret}>
<FormattedMessage id="LtcTOeth136" defaultMessage="Confirm" />
</TimerButton>
</Fragment>
) : (
<Fragment>
<div>
<FormattedMessage id="LtcTOeth142" defaultMessage="Save the secret key! Otherwise there will be a chance you loose your money!" />
</div>
<div>
<FormattedMessage id="LtcTOeth145" defaultMessage="Secret Key: " />
<strong>{flow.secret}</strong>
</div>
<div>
<FormattedMessage id="LtcTOeth148" defaultMessage="Secret Hash: " />
<strong>{flow.secretHash}</strong>
</div>
</Fragment>
)
}
{
flow.step === 3 && !flow.isBalanceEnough && !flow.isBalanceFetching && (
<Fragment>
<h3>
<FormattedMessage id="LtcTOeth158" defaultMessage="Not enough money for this swap. Please charge the balance" />
<strong>{flow.secretHash}</strong>
</h3>
<div>
<div>
<FormattedMessage id="LtcTOeth162" defaultMessage="Your balance: " />
<strong>{flow.balance}</strong> {this.swap.sellCurrency}
</div>
<div>
<FormattedMessage id="LtcTOeth165" defaultMessage="Required balance: " />
<strong>{this.swap.sellAmount.toNumber()}</strong>
{this.swap.sellCurrency}
</div>
<div>
<FormattedMessage id="LtcTOeth168" defaultMessage="Your address: " />
<a href={`${config.link.ltc}/address/${currencyAddress}`} target="_blank" el="noopener noreferrer">
{currencyAddress}
</a>
</div>
<hr />
<span>{flow.address}</span>
</div>
<br />
<Button brand onClick={this.updateBalance}>
<FormattedMessage id="LtcTOeth175" defaultMessage="Continue" />
</Button>
</Fragment>
)
}
{
flow.step === 3 && flow.isBalanceFetching && (
<Fragment>
<div>
<FormattedMessage id="LtcTOeth184" defaultMessage="Checking balance.." />
{this.swap.flow.myLtcAddress}
</div>
<InlineLoader />
</Fragment>
)
}
{
(flow.step === 4 || flow.ltcScriptValues) && (
<Fragment>
<h3>
<FormattedMessage id="LtcTOeth195" defaultMessage="3. Creating Litecoin Script.{br}Please wait, it can take a few minutes" values={{ br: <br /> }} />
{this.swap.flow.myLtcAddress}
</h3>
{
flow.ltcScriptCreatingTransactionHash && (
<div>
<FormattedMessage id="LtcTOeth200" defaultMessage="Transaction: " />
<strong>
<a
href={`${config.link.ltc}/tx/${flow.ltcScriptCreatingTransactionHash}`}
target="_blank"
rel="noopener noreferrer"
>
{flow.ltcScriptCreatingTransactionHash}
</a>
</strong>
</div>
)
}
{
!flow.ltcScriptValues && (
<InlineLoader />
)
}
</Fragment>
)
}
{
flow.ltcScriptValues && !flow.isFinished && !flow.isEthWithdrawn && (
<Fragment>
<br />
{ !flow.refundTxHex &&
<Button brand onClick={this.getRefundTxHex}>
<FormattedMessage id="LtcTOeth227" defaultMessage="Create refund hex" />
</Button>
}
{
flow.refundTxHex && (
<div>
<a
href="https://wiki.swap.online/faq/my-swap-got-stuck-and-my-bitcoin-has-been-withdrawn-what-to-do/"
target="_blank"
rel="noopener noreferrer"
>
<FormattedMessage id="LtcTOeth234" defaultMessage="How refund your money ?" />
</a>
Refund hex transaction:
<code>
{flow.refundTxHex}
</code>
</div>
)
}
</Fragment>
)
}
{
(flow.step === 5 || flow.isEthContractFunded) && (
<Fragment>
<h3>
<FormattedMessage id="LtcTOeth254" defaultMessage="4. ETH Owner received Litecoin Script and Secret Hash. Waiting when he creates ETH Contract" />
</h3>
{
!flow.isEthContractFunded && (
<InlineLoader />
)
}
</Fragment>
)
}
{
flow.ethSwapCreationTransactionHash && (
<div>
<FormattedMessage id="LtcTOeth267" defaultMessage="Transaction: " />
<strong>
<a
href={`${config.link.etherscan}/tx/${flow.ethSwapCreationTransactionHash}`}
target="_blank"
rel="noopener noreferrer"
>
{flow.ethSwapCreationTransactionHash}
</a>
</strong>
</div>
)
}
{
(flow.step === 6 || flow.isEthWithdrawn) && (
<h3>
<FormattedMessage id="LtcTOeth283" defaultMessage="5. ETH Contract created and charged. Requesting withdrawal from ETH Contract. Please wait" />
</h3>
)
}
{
flow.ethSwapWithdrawTransactionHash && (
<div>
<FormattedMessage id="LtcTOeth290" defaultMessage="Transaction: " />
<strong>
<a
href={`${config.link.etherscan}/tx/${flow.ethSwapWithdrawTransactionHash}`}
target="_blank"
rel="noreferrer noopener"
>
{flow.ethSwapWithdrawTransactionHash}
</a>
</strong>
</div>
)
}
{
flow.step === 6 && (
<InlineLoader />
)
}
{
flow.isEthWithdrawn && (
<Fragment>
<h3>
<FormattedMessage id="LtcTOeth313" defaultMessage="6. ETH was transferred to your wallet. Check the balance." />
</h3>
<h2>
<FormattedMessage id="LtcTOeth315" defaultMessage="Thank you for using Swap.Online!" />
</h2>
</Fragment>
)
}
{
flow.step >= 5 && !flow.isFinished && (
<div style={{ display: 'flex', alignItems: 'center' }}>
{ enabledButton && !flow.isEthWithdrawn &&
<Button brand onClick={this.tryRefund}>
<FormattedMessage id="LtcTOeth326" defaultMessage="TRY REFUND" />
</Button>
}
<div>
<Timer lockTime={flow.ltcScriptValues.lockTime * 1000} enabledButton={() => this.setState({ enabledButton: true })} />
</div>
</div>
)
}
{
flow.refundTransactionHash && (
<div>
<FormattedMessage id="LtcTOeth338" defaultMessage="Transaction: " />
<strong>
<a
href={`${config.link.ltc}/tx/${flow.refundTransactionHash}`}
target="_blank"
rel="noreferrer noopener"
>
{flow.refundTransactionHash}
</a>
</strong>
</div>
)
}
</Fragment>
)
}
<br />
{/* { !flow.isFinished && <Button green onClick={this.addGasPrice}>Add gas price</Button> } */}
{ children }
</div>
)
}
}