forked from bisq-network/bisq
/
BuyerStep2View.java
637 lines (591 loc) · 32.3 KB
/
BuyerStep2View.java
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.desktop.main.portfolio.pendingtrades.steps.buyer;
import bisq.desktop.components.BusyAnimation;
import bisq.desktop.components.TextFieldWithCopyIcon;
import bisq.desktop.components.TitledGroupBg;
import bisq.desktop.components.paymentmethods.AdvancedCashForm;
import bisq.desktop.components.paymentmethods.AliPayForm;
import bisq.desktop.components.paymentmethods.AssetsForm;
import bisq.desktop.components.paymentmethods.CashDepositForm;
import bisq.desktop.components.paymentmethods.ChaseQuickPayForm;
import bisq.desktop.components.paymentmethods.ClearXchangeForm;
import bisq.desktop.components.paymentmethods.F2FForm;
import bisq.desktop.components.paymentmethods.FasterPaymentsForm;
import bisq.desktop.components.paymentmethods.HalCashForm;
import bisq.desktop.components.paymentmethods.InteracETransferForm;
import bisq.desktop.components.paymentmethods.JapanBankTransferForm;
import bisq.desktop.components.paymentmethods.MoneyBeamForm;
import bisq.desktop.components.paymentmethods.MoneyGramForm;
import bisq.desktop.components.paymentmethods.NationalBankForm;
import bisq.desktop.components.paymentmethods.PerfectMoneyForm;
import bisq.desktop.components.paymentmethods.PopmoneyForm;
import bisq.desktop.components.paymentmethods.PromptPayForm;
import bisq.desktop.components.paymentmethods.RevolutForm;
import bisq.desktop.components.paymentmethods.SameBankForm;
import bisq.desktop.components.paymentmethods.SepaForm;
import bisq.desktop.components.paymentmethods.SepaInstantForm;
import bisq.desktop.components.paymentmethods.SpecificBankForm;
import bisq.desktop.components.paymentmethods.SwishForm;
import bisq.desktop.components.paymentmethods.USPostalMoneyOrderForm;
import bisq.desktop.components.paymentmethods.UpholdForm;
import bisq.desktop.components.paymentmethods.WeChatPayForm;
import bisq.desktop.components.paymentmethods.WesternUnionForm;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.overlays.windows.SetXmrTxKeyWindow;
import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel;
import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.Layout;
import bisq.desktop.util.Transitions;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.network.MessageState;
import bisq.core.offer.Offer;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.PaymentAccountUtil;
import bisq.core.payment.payload.AssetsAccountPayload;
import bisq.core.payment.payload.CashDepositAccountPayload;
import bisq.core.payment.payload.F2FAccountPayload;
import bisq.core.payment.payload.FasterPaymentsAccountPayload;
import bisq.core.payment.payload.HalCashAccountPayload;
import bisq.core.payment.payload.MoneyGramAccountPayload;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.payment.payload.USPostalMoneyOrderAccountPayload;
import bisq.core.payment.payload.WesternUnionAccountPayload;
import bisq.core.trade.DelayedPayoutTxValidation;
import bisq.core.trade.Trade;
import bisq.core.user.DontShowAgainLookup;
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.DevEnv;
import bisq.common.util.Tuple4;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static bisq.desktop.util.FormBuilder.addButtonBusyAnimationLabel;
import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextFieldWithCopyIcon;
import static bisq.desktop.util.FormBuilder.addTitledGroupBg;
import static bisq.desktop.util.FormBuilder.addTopLabelTextFieldWithCopyIcon;
import static com.google.common.base.Preconditions.checkNotNull;
public class BuyerStep2View extends TradeStepView {
private Button confirmButton;
private Label statusLabel;
private BusyAnimation busyAnimation;
private Subscription tradeStatePropertySubscription;
private Timer timeoutTimer;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, Initialisation
///////////////////////////////////////////////////////////////////////////////////////////
public BuyerStep2View(PendingTradesViewModel model) {
super(model);
}
@Override
public void activate() {
super.activate();
try {
DelayedPayoutTxValidation.validatePayoutTx(trade,
trade.getDelayedPayoutTx(),
model.dataModel.daoFacade,
model.dataModel.btcWalletService);
} catch (DelayedPayoutTxValidation.DonationAddressException |
DelayedPayoutTxValidation.InvalidTxException |
DelayedPayoutTxValidation.AmountMismatchException |
DelayedPayoutTxValidation.InvalidLockTimeException e) {
if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) {
new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show();
}
} catch (DelayedPayoutTxValidation.MissingDelayedPayoutTxException ignore) {
// We don't react on those errors as a failed trade might get listed initially but getting removed from the
// trade manager after initPendingTrades which happens after activate might be called.
}
if (timeoutTimer != null)
timeoutTimer.stop();
//TODO we get called twice, check why
if (tradeStatePropertySubscription == null) {
tradeStatePropertySubscription = EasyBind.subscribe(trade.stateProperty(), state -> {
if (timeoutTimer != null)
timeoutTimer.stop();
if (trade.isDepositConfirmed() && !trade.isFiatSent()) {
showPopup();
} else if (state.ordinal() <= Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG.ordinal()) {
if (!trade.hasFailed()) {
switch (state) {
case BUYER_CONFIRMED_IN_UI_FIAT_PAYMENT_INITIATED:
case BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG:
busyAnimation.play();
// confirmButton.setDisable(true);
statusLabel.setText(Res.get("shared.sendingConfirmation"));
model.setMessageStateProperty(MessageState.SENT);
timeoutTimer = UserThread.runAfter(() -> {
busyAnimation.stop();
// confirmButton.setDisable(false);
statusLabel.setText(Res.get("shared.sendingConfirmationAgain"));
}, 10);
break;
case BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG:
busyAnimation.stop();
statusLabel.setText(Res.get("shared.messageArrived"));
model.setMessageStateProperty(MessageState.ARRIVED);
break;
case BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG:
busyAnimation.stop();
statusLabel.setText(Res.get("shared.messageStoredInMailbox"));
model.setMessageStateProperty(MessageState.STORED_IN_MAILBOX);
break;
case BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG:
// We get a popup and the trade closed, so we dont need to show anything here
busyAnimation.stop();
// confirmButton.setDisable(false);
statusLabel.setText("");
model.setMessageStateProperty(MessageState.FAILED);
break;
default:
log.warn("Unexpected case: State={}, tradeId={} " + state.name(), trade.getId());
busyAnimation.stop();
// confirmButton.setDisable(false);
statusLabel.setText(Res.get("shared.sendingConfirmationAgain"));
break;
}
} else {
log.warn("confirmButton gets disabled because trade contains error message {}", trade.getErrorMessage());
// confirmButton.setDisable(true);
statusLabel.setText("");
}
}
});
}
}
@Override
public void deactivate() {
super.deactivate();
busyAnimation.stop();
if (timeoutTimer != null)
timeoutTimer.stop();
if (tradeStatePropertySubscription != null) {
tradeStatePropertySubscription.unsubscribe();
tradeStatePropertySubscription = null;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Content
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected void addContent() {
gridPane.getColumnConstraints().get(1).setHgrow(Priority.ALWAYS);
addTradeInfoBlock();
PaymentAccountPayload paymentAccountPayload = model.dataModel.getSellersPaymentAccountPayload();
String paymentMethodId = paymentAccountPayload != null ? paymentAccountPayload.getPaymentMethodId() : "";
TitledGroupBg accountTitledGroupBg = addTitledGroupBg(gridPane, ++gridRow, 4,
Res.get("portfolio.pending.step2_buyer.startPaymentUsing", Res.get(paymentMethodId)),
Layout.COMPACT_GROUP_DISTANCE);
TextFieldWithCopyIcon field = addTopLabelTextFieldWithCopyIcon(gridPane, gridRow, 0,
Res.get("portfolio.pending.step2_buyer.amountToTransfer"),
model.getFiatVolume(),
Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE).second;
field.setCopyWithoutCurrencyPostFix(true);
if (!(paymentAccountPayload instanceof AssetsAccountPayload) &&
!(paymentAccountPayload instanceof F2FAccountPayload))
addTopLabelTextFieldWithCopyIcon(gridPane, gridRow, 1,
Res.get("shared.reasonForPayment"), model.dataModel.getReference(),
Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE);
switch (paymentMethodId) {
case PaymentMethod.UPHOLD_ID:
gridRow = UpholdForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.MONEY_BEAM_ID:
gridRow = MoneyBeamForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.POPMONEY_ID:
gridRow = PopmoneyForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.REVOLUT_ID:
gridRow = RevolutForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.PERFECT_MONEY_ID:
gridRow = PerfectMoneyForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.SEPA_ID:
gridRow = SepaForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.SEPA_INSTANT_ID:
gridRow = SepaInstantForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.FASTER_PAYMENTS_ID:
gridRow = FasterPaymentsForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.NATIONAL_BANK_ID:
gridRow = NationalBankForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.SAME_BANK_ID:
gridRow = SameBankForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.SPECIFIC_BANKS_ID:
gridRow = SpecificBankForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.SWISH_ID:
gridRow = SwishForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.ALI_PAY_ID:
gridRow = AliPayForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.WECHAT_PAY_ID:
gridRow = WeChatPayForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.CLEAR_X_CHANGE_ID:
gridRow = ClearXchangeForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.CHASE_QUICK_PAY_ID:
gridRow = ChaseQuickPayForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.INTERAC_E_TRANSFER_ID:
gridRow = InteracETransferForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.JAPAN_BANK_ID:
gridRow = JapanBankTransferForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.US_POSTAL_MONEY_ORDER_ID:
gridRow = USPostalMoneyOrderForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.CASH_DEPOSIT_ID:
gridRow = CashDepositForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.MONEY_GRAM_ID:
gridRow = MoneyGramForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.WESTERN_UNION_ID:
gridRow = WesternUnionForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.HAL_CASH_ID:
gridRow = HalCashForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.F2F_ID:
checkNotNull(model.dataModel.getTrade().getOffer(), "model.dataModel.getTrade().getOffer() must not be null");
gridRow = F2FForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload, model.dataModel.getTrade().getOffer(), 0);
break;
case PaymentMethod.BLOCK_CHAINS_ID:
case PaymentMethod.BLOCK_CHAINS_INSTANT_ID:
String labelTitle = Res.get("portfolio.pending.step2_buyer.sellersAddress",
CurrencyUtil.getNameByCode(trade.getOffer().getCurrencyCode()));
gridRow = AssetsForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload, labelTitle);
break;
case PaymentMethod.PROMPT_PAY_ID:
gridRow = PromptPayForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
case PaymentMethod.ADVANCED_CASH_ID:
gridRow = AdvancedCashForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload);
break;
default:
log.error("Not supported PaymentMethod: " + paymentMethodId);
}
Trade trade = model.getTrade();
if (trade != null && model.getUser().getPaymentAccounts() != null) {
Offer offer = trade.getOffer();
List<PaymentAccount> possiblePaymentAccounts = PaymentAccountUtil.getPossiblePaymentAccounts(offer,
model.getUser().getPaymentAccounts(), model.dataModel.getAccountAgeWitnessService());
PaymentAccountPayload buyersPaymentAccountPayload = model.dataModel.getBuyersPaymentAccountPayload();
if (buyersPaymentAccountPayload != null && possiblePaymentAccounts.size() > 1) {
String id = buyersPaymentAccountPayload.getId();
possiblePaymentAccounts.stream()
.filter(paymentAccount -> paymentAccount.getId().equals(id))
.findFirst()
.ifPresent(paymentAccount -> {
String accountName = paymentAccount.getAccountName();
addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, 0,
Res.get("portfolio.pending.step2_buyer.buyerAccount"), accountName);
});
}
}
GridPane.setRowSpan(accountTitledGroupBg, gridRow - 1);
Tuple4<Button, BusyAnimation, Label, HBox> tuple3 = addButtonBusyAnimationLabel(gridPane, ++gridRow, 0,
Res.get("portfolio.pending.step2_buyer.paymentStarted"), 10);
GridPane.setColumnSpan(tuple3.fourth, 2);
confirmButton = tuple3.first;
confirmButton.setOnAction(e -> onPaymentStarted());
busyAnimation = tuple3.second;
statusLabel = tuple3.third;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Warning
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected String getFirstHalfOverWarnText() {
return Res.get("portfolio.pending.step2_buyer.warn",
model.dataModel.getCurrencyCode(),
model.getDateForOpenDispute());
}
///////////////////////////////////////////////////////////////////////////////////////////
// Dispute
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected String getPeriodOverWarnText() {
return Res.get("portfolio.pending.step2_buyer.openForDispute");
}
@Override
protected void applyOnDisputeOpened() {
}
///////////////////////////////////////////////////////////////////////////////////////////
// UI Handlers
///////////////////////////////////////////////////////////////////////////////////////////
private void onPaymentStarted() {
if (!model.dataModel.isBootstrappedOrShowPopup()) {
return;
}
PaymentAccountPayload sellersPaymentAccountPayload = model.dataModel.getSellersPaymentAccountPayload();
Trade trade = checkNotNull(model.dataModel.getTrade(), "trade must not be null");
if (sellersPaymentAccountPayload instanceof CashDepositAccountPayload) {
String key = "confirmPaperReceiptSent";
if (!DevEnv.isDevMode() && DontShowAgainLookup.showAgain(key)) {
Popup popup = new Popup();
popup.headLine(Res.get("portfolio.pending.step2_buyer.paperReceipt.headline"))
.feedback(Res.get("portfolio.pending.step2_buyer.paperReceipt.msg"))
.onAction(this::showConfirmPaymentStartedPopup)
.closeButtonText(Res.get("shared.no"))
.onClose(popup::hide)
.dontShowAgainId(key)
.show();
} else {
showConfirmPaymentStartedPopup();
}
} else if (sellersPaymentAccountPayload instanceof WesternUnionAccountPayload) {
String key = "westernUnionMTCNSent";
if (!DevEnv.isDevMode() && DontShowAgainLookup.showAgain(key)) {
String email = ((WesternUnionAccountPayload) sellersPaymentAccountPayload).getEmail();
Popup popup = new Popup();
popup.headLine(Res.get("portfolio.pending.step2_buyer.westernUnionMTCNInfo.headline"))
.feedback(Res.get("portfolio.pending.step2_buyer.westernUnionMTCNInfo.msg", email))
.onAction(this::showConfirmPaymentStartedPopup)
.actionButtonText(Res.get("shared.yes"))
.closeButtonText(Res.get("shared.no"))
.onClose(popup::hide)
.dontShowAgainId(key)
.show();
} else {
showConfirmPaymentStartedPopup();
}
} else if (sellersPaymentAccountPayload instanceof MoneyGramAccountPayload) {
String key = "moneyGramMTCNSent";
if (!DevEnv.isDevMode() && DontShowAgainLookup.showAgain(key)) {
String email = ((MoneyGramAccountPayload) sellersPaymentAccountPayload).getEmail();
Popup popup = new Popup();
popup.headLine(Res.get("portfolio.pending.step2_buyer.moneyGramMTCNInfo.headline"))
.feedback(Res.get("portfolio.pending.step2_buyer.moneyGramMTCNInfo.msg", email))
.onAction(this::showConfirmPaymentStartedPopup)
.actionButtonText(Res.get("shared.yes"))
.closeButtonText(Res.get("shared.no"))
.onClose(popup::hide)
.dontShowAgainId(key)
.show();
} else {
showConfirmPaymentStartedPopup();
}
} else if (sellersPaymentAccountPayload instanceof HalCashAccountPayload) {
String key = "halCashCodeInfo";
if (!DevEnv.isDevMode() && DontShowAgainLookup.showAgain(key)) {
String mobileNr = ((HalCashAccountPayload) sellersPaymentAccountPayload).getMobileNr();
Popup popup = new Popup();
popup.headLine(Res.get("portfolio.pending.step2_buyer.halCashInfo.headline"))
.feedback(Res.get("portfolio.pending.step2_buyer.halCashInfo.msg",
trade.getShortId(), mobileNr))
.onAction(this::showConfirmPaymentStartedPopup)
.actionButtonText(Res.get("shared.yes"))
.closeButtonText(Res.get("shared.no"))
.onClose(popup::hide)
.dontShowAgainId(key)
.show();
} else {
showConfirmPaymentStartedPopup();
}
} else if (sellersPaymentAccountPayload instanceof AssetsAccountPayload &&
checkNotNull(trade.getOffer()).getCurrencyCode().equals("XMR")) {
SetXmrTxKeyWindow setXmrTxKeyWindow = new SetXmrTxKeyWindow();
setXmrTxKeyWindow
.actionButtonText(Res.get("portfolio.pending.step2_buyer.confirmStart.headline"))
.onAction(() -> {
String txKey = setXmrTxKeyWindow.getTxKey();
String txHash = setXmrTxKeyWindow.getTxHash();
if (txKey == null || txHash == null || txKey.isEmpty() || txHash.isEmpty()) {
UserThread.runAfter(this::showProofWarningPopup, Transitions.DEFAULT_DURATION, TimeUnit.MILLISECONDS);
return;
}
trade.setCounterCurrencyExtraData(txKey);
trade.setCounterCurrencyTxId(txHash);
showConfirmPaymentStartedPopup();
})
.closeButtonText(Res.get("shared.cancel"))
.onClose(setXmrTxKeyWindow::hide)
.show();
} else {
showConfirmPaymentStartedPopup();
}
}
private void showProofWarningPopup() {
Popup popup = new Popup();
popup.headLine(Res.get("portfolio.pending.step2_buyer.confirmStart.proof.warningTitle"))
.confirmation(Res.get("portfolio.pending.step2_buyer.confirmStart.proof.noneProvided"))
.width(700)
.actionButtonText(Res.get("portfolio.pending.step2_buyer.confirmStart.warningButton"))
.onAction(this::showConfirmPaymentStartedPopup)
.closeButtonText(Res.get("shared.cancel"))
.onClose(popup::hide)
.show();
}
private void showConfirmPaymentStartedPopup() {
String key = "confirmPaymentStarted";
if (!DevEnv.isDevMode() && DontShowAgainLookup.showAgain(key)) {
Popup popup = new Popup();
popup.headLine(Res.get("portfolio.pending.step2_buyer.confirmStart.headline"))
.confirmation(Res.get("portfolio.pending.step2_buyer.confirmStart.msg",
CurrencyUtil.getNameByCode(trade.getOffer().getCurrencyCode())))
.width(700)
.actionButtonText(Res.get("portfolio.pending.step2_buyer.confirmStart.yes"))
.onAction(this::confirmPaymentStarted)
.closeButtonText(Res.get("shared.no"))
.onClose(popup::hide)
.dontShowAgainId(key)
.show();
} else {
confirmPaymentStarted();
}
}
private void confirmPaymentStarted() {
// confirmButton.setDisable(true);
busyAnimation.play();
statusLabel.setText(Res.get("shared.sendingConfirmation"));
if (trade.isFiatSent())
trade.setState(Trade.State.DEPOSIT_CONFIRMED_IN_BLOCK_CHAIN);
model.dataModel.onPaymentStarted(() -> {
// In case the first send failed we got the support button displayed.
// If it succeeds at a second try we remove the support button again.
//TODO check for support. in case of a dispute we dont want to hide the button
//if (notificationGroup != null)
// notificationGroup.setButtonVisible(false);
}, errorMessage -> {
// confirmButton.setDisable(false);
busyAnimation.stop();
new Popup().warning(Res.get("popup.warning.sendMsgFailed")).show();
});
}
private void showPopup() {
PaymentAccountPayload paymentAccountPayload = model.dataModel.getSellersPaymentAccountPayload();
if (paymentAccountPayload != null) {
String paymentDetailsForTradePopup = paymentAccountPayload.getPaymentDetailsForTradePopup();
String message = Res.get("portfolio.pending.step2.confReached");
String copyPaste = Res.get("portfolio.pending.step2_buyer.copyPaste");
String refTextWarn = Res.get("portfolio.pending.step2_buyer.refTextWarn");
String accountDetails = Res.get("portfolio.pending.step2_buyer.accountDetails");
String tradeId = Res.get("portfolio.pending.step2_buyer.tradeId");
String assign = Res.get("portfolio.pending.step2_buyer.assign");
String fees = Res.get("portfolio.pending.step2_buyer.fees");
String id = trade.getShortId();
String paddedId = " " + id + " ";
String amount = DisplayUtils.formatVolumeWithCode(trade.getTradeVolume());
if (paymentAccountPayload instanceof AssetsAccountPayload) {
message += Res.get("portfolio.pending.step2_buyer.altcoin",
CurrencyUtil.getNameByCode(trade.getOffer().getCurrencyCode()),
amount) +
accountDetails +
paymentDetailsForTradePopup + "\n\n" +
copyPaste;
} else if (paymentAccountPayload instanceof CashDepositAccountPayload) {
message += Res.get("portfolio.pending.step2_buyer.cash",
amount) +
accountDetails +
paymentDetailsForTradePopup + ".\n\n" +
copyPaste + "\n\n" +
tradeId + paddedId +
assign +
refTextWarn + "\n\n" +
fees + "\n\n" +
Res.get("portfolio.pending.step2_buyer.cash.extra");
} else if (paymentAccountPayload instanceof WesternUnionAccountPayload) {
final String email = ((WesternUnionAccountPayload) paymentAccountPayload).getEmail();
final String extra = Res.get("portfolio.pending.step2_buyer.westernUnion.extra", email);
message += Res.get("portfolio.pending.step2_buyer.westernUnion",
amount) +
accountDetails +
paymentDetailsForTradePopup + ".\n\n" +
copyPaste + "\n\n" +
extra;
} else if (paymentAccountPayload instanceof MoneyGramAccountPayload) {
final String email = ((MoneyGramAccountPayload) paymentAccountPayload).getEmail();
final String extra = Res.get("portfolio.pending.step2_buyer.moneyGram.extra", email);
message += Res.get("portfolio.pending.step2_buyer.moneyGram",
amount) +
accountDetails +
paymentDetailsForTradePopup + ".\n\n" +
copyPaste + "\n\n" +
extra;
} else if (paymentAccountPayload instanceof USPostalMoneyOrderAccountPayload) {
message += Res.get("portfolio.pending.step2_buyer.postal", amount) +
accountDetails +
paymentDetailsForTradePopup + ".\n\n" +
copyPaste + "\n\n" +
tradeId + paddedId +
assign +
refTextWarn;
} else if (paymentAccountPayload instanceof F2FAccountPayload) {
message += Res.get("portfolio.pending.step2_buyer.f2f", amount) +
accountDetails +
paymentDetailsForTradePopup + "\n\n" +
copyPaste;
} else if (paymentAccountPayload instanceof HalCashAccountPayload) {
message += Res.get("portfolio.pending.step2_buyer.bank", amount) +
accountDetails +
paymentDetailsForTradePopup + ".\n\n" +
copyPaste;
} else if (paymentAccountPayload instanceof FasterPaymentsAccountPayload) {
message += Res.get("portfolio.pending.step2_buyer.bank", amount) +
accountDetails +
paymentDetailsForTradePopup + ".\n\n" +
Res.get("portfolio.pending.step2_buyer.fasterPaymentsHolderNameInfo") + "\n\n" +
copyPaste + "\n\n" +
tradeId + paddedId +
assign +
refTextWarn + "\n\n" +
fees;
} else {
message += Res.get("portfolio.pending.step2_buyer.bank", amount) +
accountDetails +
paymentDetailsForTradePopup + ".\n\n" +
copyPaste + "\n\n" +
tradeId + paddedId +
assign +
refTextWarn + "\n\n" +
fees;
}
String key = "startPayment" + trade.getId();
if (!DevEnv.isDevMode() && DontShowAgainLookup.showAgain(key)) {
DontShowAgainLookup.dontShowAgain(key, true);
new Popup().headLine(Res.get("popup.attention.forTradeWithId", id))
.attention(message)
.show();
}
}
}
@Override
protected void deactivatePaymentButtons(boolean isDisabled) {
confirmButton.setDisable(isDisabled);
}
}