forked from digibyte/digibyte
-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathdigidollarsendwidget.cpp
More file actions
1445 lines (1234 loc) · 50.9 KB
/
Copy pathdigidollarsendwidget.cpp
File metadata and controls
1445 lines (1234 loc) · 50.9 KB
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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2025 The DigiByte Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <qt/digidollarsendwidget.h>
#include <qt/ddaddressbookpage.h>
#include <qt/walletmodel.h>
#include <qt/clientmodel.h>
#include <qt/guiutil.h>
#include <qt/digibyteunits.h>
#include <qt/digidollarcoincontroldialog.h>
#include <qt/platformstyle.h>
#include <wallet/ddcoincontrol.h>
#include <wallet/digidollarwallet.h>
#include <consensus/amount.h>
#include <base58.h>
#include <logging.h>
#include <kernel/chainparams.h>
#include <oracle/mock_oracle.h>
#include <interfaces/node.h>
#include <univalue.h>
#include <chrono>
#include <cmath>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QFrame>
#include <QValidator>
#include <QFont>
#include <QRegularExpression>
#include <QMessageBox>
#include <QToolButton>
#include <QApplication>
#include <QClipboard>
#include <QScrollArea>
#include <QSpacerItem>
#include <QSizePolicy>
#include <QPalette>
#include <QProgressDialog>
#include <QAbstractButton>
using namespace std::chrono_literals;
DigiDollarSendWidget::DigiDollarSendWidget(const PlatformStyle *platformStyle, QWidget *parent) :
QWidget(parent),
m_mainLayout(nullptr),
m_addressFrame(nullptr),
m_addressLayout(nullptr),
m_addressLabel(nullptr),
m_addressEdit(nullptr),
m_pasteAddressButton(nullptr),
m_addressBookButton(nullptr),
m_addressValidationLabel(nullptr),
m_amountFrame(nullptr),
m_amountLayout(nullptr),
m_amountLabel(nullptr),
m_amountEdit(nullptr),
m_amountSuffix(nullptr),
m_useAvailableBalanceButton(nullptr),
m_usdEquivalentLabel(nullptr),
m_usdEquivalentValue(nullptr),
m_availableBalanceLabel(nullptr),
m_availableBalanceValue(nullptr),
m_noteFrame(nullptr),
m_noteLayout(nullptr),
m_noteLabel(nullptr),
m_noteEdit(nullptr),
m_feeFrame(nullptr),
m_feeLayout(nullptr),
m_feeLabel(nullptr),
m_feeValue(nullptr),
m_totalLabel(nullptr),
m_totalValue(nullptr),
m_buttonFrame(nullptr),
m_buttonLayout(nullptr),
m_sendButton(nullptr),
m_clearButton(nullptr),
m_coinControlFrame(nullptr),
m_coinControlLayout(nullptr),
m_coinControlButton(nullptr),
m_coinControlQuantityLabel(nullptr),
m_coinControlAmountLabel(nullptr),
m_addressValidator(nullptr),
m_amountValidator(nullptr),
m_walletModel(nullptr),
m_clientModel(nullptr),
m_platformStyle(platformStyle),
m_availableBalance(0.0),
m_oraclePrice(1.0),
m_estimatedFee(0.001) // TODO: Implement dynamic fee estimation based on transaction size and network conditions
{
setupUI();
connectSignals();
// REMOVED: applyTheme() - Let CSS handle all theming
}
DigiDollarSendWidget::~DigiDollarSendWidget()
{
// Qt will handle cleanup of child widgets
}
void DigiDollarSendWidget::setupUI()
{
// Create main layout - compact like DGB tabs
m_mainLayout = new QVBoxLayout(this);
m_mainLayout->setSpacing(0);
m_mainLayout->setContentsMargins(0, 0, 0, 0);
// Create validators
m_addressValidator = new DigiDollarAddressValidator(this);
// DD amounts are in dollars with max 2 decimal places (cents precision)
// Send limits: $1 minimum (dust threshold), $100,000 maximum
m_amountValidator = new AmountValidator(1.00, 100000.00, 2, this);
// Setup sections
setupCoinControlSection();
setupAddressSection();
setupAmountSection();
setupNoteSection();
setupFeeSection();
setupButtonSection();
// Add stretch to push content to top
m_mainLayout->addStretch();
setLayout(m_mainLayout);
}
void DigiDollarSendWidget::setupCoinControlSection()
{
// Create coin control frame
m_coinControlFrame = new QFrame(this);
m_coinControlFrame->setObjectName("coinControlFrame");
m_coinControlFrame->setFrameStyle(QFrame::StyledPanel);
m_coinControlFrame->setFrameShadow(QFrame::Sunken);
m_coinControlLayout = new QHBoxLayout(m_coinControlFrame);
m_coinControlLayout->setSpacing(10);
m_coinControlLayout->setContentsMargins(10, 8, 10, 8);
// "Inputs..." button to open coin control dialog
m_coinControlButton = new QPushButton(tr("Inputs..."), this);
m_coinControlButton->setObjectName("coinControlButton");
m_coinControlButton->setToolTip(tr("Manually select $DD inputs to spend"));
m_coinControlButton->setMinimumWidth(80);
m_coinControlLayout->addWidget(m_coinControlButton);
// Quantity label (number of selected inputs)
m_coinControlQuantityLabel = new QLabel(this);
m_coinControlQuantityLabel->setObjectName("coinControlQuantityLabel");
m_coinControlQuantityLabel->setText(tr("automatically selected"));
m_coinControlLayout->addWidget(m_coinControlQuantityLabel);
// Amount label (total selected DD amount)
m_coinControlAmountLabel = new QLabel(this);
m_coinControlAmountLabel->setObjectName("coinControlAmountLabel");
m_coinControlAmountLabel->setText(QString());
m_coinControlLayout->addWidget(m_coinControlAmountLabel);
m_coinControlLayout->addStretch();
m_mainLayout->addWidget(m_coinControlFrame);
// Initially visible - will be hidden if coin control is disabled in settings
m_coinControlFrame->setVisible(true);
}
void DigiDollarSendWidget::setupAddressSection()
{
// Create address frame
m_addressFrame = new QFrame(this);
m_addressFrame->setFrameStyle(QFrame::StyledPanel);
m_addressFrame->setFrameShadow(QFrame::Sunken);
m_addressFrame->setObjectName("addressFrame");
m_addressLayout = new QGridLayout(m_addressFrame);
m_addressLayout->setSpacing(8);
m_addressLayout->setContentsMargins(10, 10, 10, 10);
m_addressLayout->setHorizontalSpacing(12);
m_addressLayout->setVerticalSpacing(8);
// Address label and input with paste button
m_addressLabel = new QLabel(tr("Pay To:"), this);
m_addressLabel->setToolTip(tr("Enter the DigiDollar address of the recipient"));
m_addressLabel->setBuddy(m_addressEdit);
// Create horizontal layout for address input and paste button
QHBoxLayout* addressInputLayout = new QHBoxLayout();
addressInputLayout->setSpacing(0);
m_addressEdit = new QLineEdit(this);
m_addressEdit->setObjectName("addressEdit");
m_addressEdit->setValidator(m_addressValidator);
m_addressEdit->setPlaceholderText("DD1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4");
m_addressEdit->setToolTip(tr("The DigiDollar address to send the payment to.\n\nValid formats:\n• DD... (Mainnet)\n• TD... (Testnet)\n• RD... (Regtest)"));
m_addressEdit->setFocusPolicy(Qt::StrongFocus);
m_addressEdit->setAttribute(Qt::WA_InputMethodEnabled, true);
QFont monospaceFont = GUIUtil::fixedPitchFont();
m_addressEdit->setFont(monospaceFont);
m_pasteAddressButton = new QToolButton(this);
m_pasteAddressButton->setToolTip(tr("Paste address from clipboard (Alt+P)"));
m_pasteAddressButton->setIconSize(QSize(22, 22));
m_pasteAddressButton->setShortcut(QKeySequence("Alt+P"));
m_pasteAddressButton->setIcon(m_platformStyle->SingleColorIcon(":/icons/editpaste"));
m_addressBookButton = new QToolButton(this);
m_addressBookButton->setToolTip(tr("Choose from address book (Alt+A)"));
m_addressBookButton->setIconSize(QSize(22, 22));
m_addressBookButton->setShortcut(QKeySequence("Alt+A"));
m_addressBookButton->setIcon(m_platformStyle->SingleColorIcon(":/icons/address-book"));
addressInputLayout->addWidget(m_addressEdit);
addressInputLayout->addWidget(m_addressBookButton);
addressInputLayout->addWidget(m_pasteAddressButton);
m_addressLayout->addWidget(m_addressLabel, 0, 0);
m_addressLayout->addLayout(addressInputLayout, 0, 1);
// Address validation label
m_addressValidationLabel = new QLabel(this);
m_addressValidationLabel->setObjectName("addressValidationLabel");
m_addressValidationLabel->setText(tr("Enter a valid DigiDollar address (DD, TD, or RD prefix)"));
m_addressValidationLabel->setWordWrap(true);
m_addressLayout->addWidget(m_addressValidationLabel, 1, 1);
m_mainLayout->addWidget(m_addressFrame);
}
void DigiDollarSendWidget::setupAmountSection()
{
// Create amount frame
m_amountFrame = new QFrame(this);
m_amountFrame->setFrameStyle(QFrame::StyledPanel);
m_amountFrame->setFrameShadow(QFrame::Sunken);
m_amountFrame->setObjectName("amountFrame");
m_amountLayout = new QGridLayout(m_amountFrame);
m_amountLayout->setSpacing(8);
m_amountLayout->setContentsMargins(10, 10, 10, 10);
m_amountLayout->setHorizontalSpacing(12);
m_amountLayout->setVerticalSpacing(8);
// Amount input with use available balance button
m_amountLabel = new QLabel(tr("Amount:"), this);
m_amountLabel->setToolTip(tr("Enter the amount of DigiDollar to send"));
m_amountLabel->setBuddy(m_amountEdit);
// Create horizontal layout for amount input and buttons
QHBoxLayout* amountInputLayout = new QHBoxLayout();
amountInputLayout->setSpacing(8);
m_amountEdit = new QLineEdit(this);
m_amountEdit->setObjectName("amountEdit");
m_amountEdit->setValidator(m_amountValidator);
m_amountEdit->setPlaceholderText("0.00");
m_amountEdit->setToolTip(tr("The amount of DigiDollar to send.\n\n• Minimum: 1.00 $DD\n• Maximum: 100,000.00 $DD\n• Up to 2 decimal places (cents)"));
m_amountEdit->setFocusPolicy(Qt::StrongFocus);
m_amountEdit->setAttribute(Qt::WA_InputMethodEnabled, true);
QFont monospaceFont = GUIUtil::fixedPitchFont();
m_amountEdit->setFont(monospaceFont);
// Add stretch to push the button to the right
m_useAvailableBalanceButton = new QPushButton(tr("Use available balance"), this);
m_useAvailableBalanceButton->setObjectName("useAvailableBalanceButton");
m_useAvailableBalanceButton->setToolTip(tr("Use the full available DigiDollar balance (fees are paid in DGB)"));
amountInputLayout->addWidget(m_amountEdit, 0);
amountInputLayout->addWidget(m_useAvailableBalanceButton, 1);
m_amountLayout->addWidget(m_amountLabel, 0, 0);
m_amountLayout->addLayout(amountInputLayout, 0, 1);
// USD equivalent display
m_usdEquivalentLabel = new QLabel(tr("$USD Equivalent:"), this);
m_usdEquivalentLabel->setObjectName("usdEquivalentLabel");
m_usdEquivalentLabel->setToolTip(tr("Equivalent value in US Dollars (DigiDollar is pegged to $1 USD)"));
m_usdEquivalentValue = new QLabel("0.00 $USD", this);
m_usdEquivalentValue->setObjectName("usdEquivalentValue");
m_usdEquivalentValue->setFont(monospaceFont);
m_usdEquivalentValue->setToolTip(tr("USD value updates in real-time as you type"));
m_amountLayout->addWidget(m_usdEquivalentLabel, 1, 0);
m_amountLayout->addWidget(m_usdEquivalentValue, 1, 1);
// Available balance display
m_availableBalanceLabel = new QLabel(tr("Available:"), this);
m_availableBalanceLabel->setObjectName("availableBalanceLabel");
m_availableBalanceLabel->setToolTip(tr("Your current available DigiDollar balance"));
m_availableBalanceValue = new QLabel("0.00 $DD", this);
m_availableBalanceValue->setObjectName("availableBalanceValue");
m_availableBalanceValue->setFont(monospaceFont);
m_availableBalanceValue->setToolTip(tr("Your current spendable DigiDollar balance"));
m_amountLayout->addWidget(m_availableBalanceLabel, 2, 0);
m_amountLayout->addWidget(m_availableBalanceValue, 2, 1);
// Set column widths to prevent layout distortion on initial display
m_amountLayout->setColumnMinimumWidth(0, 110); // Label column
m_amountLayout->setColumnStretch(0, 0);
m_amountLayout->setColumnStretch(1, 1);
m_mainLayout->addWidget(m_amountFrame);
}
void DigiDollarSendWidget::setupNoteSection()
{
m_noteFrame = new QFrame(this);
m_noteFrame->setFrameStyle(QFrame::StyledPanel);
m_noteFrame->setFrameShadow(QFrame::Sunken);
m_noteFrame->setObjectName("noteFrame");
m_noteLayout = new QGridLayout(m_noteFrame);
m_noteLayout->setSpacing(8);
m_noteLayout->setContentsMargins(10, 10, 10, 10);
m_noteLayout->setHorizontalSpacing(12);
m_noteLayout->setVerticalSpacing(8);
m_noteLabel = new QLabel(tr("Note:"), this);
m_noteLabel->setToolTip(tr("Enter a local note for this DigiDollar transaction"));
m_noteEdit = new QLineEdit(this);
m_noteEdit->setObjectName("noteEdit");
m_noteEdit->setPlaceholderText(tr("Enter a local note for this transaction"));
m_noteEdit->setMaxLength(256);
m_noteEdit->setToolTip(tr("Saved locally with this DigiDollar transaction"));
m_noteLayout->addWidget(m_noteLabel, 0, 0);
m_noteLayout->addWidget(m_noteEdit, 0, 1);
m_noteLayout->setColumnMinimumWidth(0, 110);
m_noteLayout->setColumnStretch(0, 0);
m_noteLayout->setColumnStretch(1, 1);
m_mainLayout->addWidget(m_noteFrame);
}
void DigiDollarSendWidget::setupFeeSection()
{
// Create fee frame
m_feeFrame = new QFrame(this);
m_feeFrame->setFrameStyle(QFrame::StyledPanel);
m_feeFrame->setFrameShadow(QFrame::Sunken);
m_feeFrame->setObjectName("feeFrame");
m_feeLayout = new QGridLayout(m_feeFrame);
m_feeLayout->setSpacing(8);
m_feeLayout->setContentsMargins(10, 10, 10, 10);
m_feeLayout->setHorizontalSpacing(12);
m_feeLayout->setVerticalSpacing(8);
// Fee display
m_feeLabel = new QLabel(tr("Transaction fee:"), this);
m_feeLabel->setObjectName("feeLabel");
m_feeLabel->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
m_feeLabel->setToolTip(tr("Network fee paid in DGB (not deducted from $DD amount)"));
m_feeValue = new QLabel("~0.1 DGB", this);
m_feeValue->setObjectName("feeValue");
QFont monospaceFont = GUIUtil::fixedPitchFont();
m_feeValue->setFont(monospaceFont);
m_feeValue->setToolTip(tr("Estimated network fee paid in DGB from your DGB balance"));
m_feeLayout->addWidget(m_feeLabel, 0, 0);
m_feeLayout->addWidget(m_feeValue, 0, 1);
// Total amount display
m_totalLabel = new QLabel(tr("Total $DD:"), this);
m_totalLabel->setObjectName("totalLabel");
m_totalLabel->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
m_totalLabel->setToolTip(tr("Total DigiDollar amount to send (fee is paid separately in DGB)"));
QFont boldFont = m_totalLabel->font();
boldFont.setBold(true);
m_totalLabel->setFont(boldFont);
m_totalValue = new QLabel("0.00 $DD", this);
m_totalValue->setObjectName("totalValue");
m_totalValue->setFont(monospaceFont);
m_totalValue->setToolTip(tr("Total $DD to send (DGB fee is paid from your DGB balance)"));
m_feeLayout->addWidget(m_totalLabel, 1, 0);
m_feeLayout->addWidget(m_totalValue, 1, 1);
m_mainLayout->addWidget(m_feeFrame);
}
void DigiDollarSendWidget::setupButtonSection()
{
// Create button frame
m_buttonFrame = new QFrame(this);
m_buttonFrame->setObjectName("buttonFrame");
m_buttonFrame->setFrameStyle(QFrame::NoFrame);
m_buttonLayout = new QHBoxLayout(m_buttonFrame);
m_buttonLayout->setSpacing(10);
m_buttonLayout->setContentsMargins(10, 10, 10, 10);
// Clear button
m_clearButton = new QPushButton(tr("&Clear"), this);
m_clearButton->setObjectName("clearButton");
m_clearButton->setToolTip(tr("Clear all fields"));
m_clearButton->setAutoDefault(false);
// Removed minimum height - CSS handles button sizing
m_buttonLayout->addWidget(m_clearButton);
// Add stretch to push send button to the right
m_buttonLayout->addStretch();
// Send button - styled to match main wallet
m_sendButton = new QPushButton(tr("S&end DigiDollar"), this);
m_sendButton->setObjectName("sendButton");
m_sendButton->setEnabled(false);
m_sendButton->setDefault(true);
m_sendButton->setAutoDefault(true);
// Removed minimum height - CSS handles button sizing
m_sendButton->setToolTip(tr("Confirm and send this DigiDollar transaction"));
m_buttonLayout->addWidget(m_sendButton);
m_mainLayout->addWidget(m_buttonFrame);
}
void DigiDollarSendWidget::connectSignals()
{
// Connect address validation
connect(m_addressEdit, &QLineEdit::textChanged,
this, &DigiDollarSendWidget::onAddressChanged);
// Connect amount validation
connect(m_amountEdit, &QLineEdit::textChanged,
this, &DigiDollarSendWidget::onAmountChanged);
// Connect buttons
connect(m_sendButton, &QPushButton::clicked,
this, &DigiDollarSendWidget::onSendClicked);
connect(m_clearButton, &QPushButton::clicked,
this, &DigiDollarSendWidget::onClearClicked);
connect(m_useAvailableBalanceButton, &QPushButton::clicked,
this, &DigiDollarSendWidget::onUseAvailableBalanceClicked);
connect(m_pasteAddressButton, &QToolButton::clicked,
this, &DigiDollarSendWidget::onPasteAddressClicked);
connect(m_addressBookButton, &QToolButton::clicked,
this, &DigiDollarSendWidget::onAddressBookClicked);
// Connect coin control button
connect(m_coinControlButton, &QPushButton::clicked,
this, &DigiDollarSendWidget::onCoinControlButtonClicked);
}
void DigiDollarSendWidget::setWalletModel(WalletModel* model)
{
m_walletModel = model;
if (m_walletModel) {
// Connect wallet model signals
updateBalance();
// REMOVED: applyTheme() - Let CSS handle all theming
}
}
void DigiDollarSendWidget::setClientModel(ClientModel* model)
{
m_clientModel = model;
if (m_clientModel) {
// Connect client model signals
updateOraclePrice();
// REMOVED: applyTheme() - Let CSS handle all theming
}
}
void DigiDollarSendWidget::updateView()
{
updateBalance();
updateOraclePrice();
updateFeeDisplay();
}
void DigiDollarSendWidget::updateBalance()
{
if (m_walletModel) {
// Only confirmed DD is spendable. Pending DD, including wallet-created
// transfer change, must confirm before another DD spend can use it.
CAmount balanceCents = m_walletModel->getDigiDollarBalance();
m_availableBalance = balanceCents / 100.0; // Convert cents to DD
} else {
m_availableBalance = 0.0;
}
if (m_privacy) {
m_availableBalanceValue->setText(maskValue(formatDDAmount(0)));
} else {
m_availableBalanceValue->setText(formatDDAmount(m_availableBalance));
}
// Update button state - enable if user has any DD balance
// Fees are paid in DGB, not DD, so no need to check for fee deduction
m_useAvailableBalanceButton->setEnabled(m_availableBalance > 0);
// Re-validate amount against updated balance so the border color
// refreshes when pending DD confirms (fixes stale yellow warning).
updateAmountValidation();
updateSendButton();
}
void DigiDollarSendWidget::updateOraclePrice()
{
if (!isVisible()) return;
// Get oracle price from RPC for testnet/mainnet, MockOracleManager for regtest
if (Params().GetChainType() == ChainType::REGTEST && MockOracleManager::GetInstance().IsEnabled()) {
// BUG #6 FIX: GetCurrentPrice() returns micro-USD, not cents
CAmount priceMicroUsd = MockOracleManager::GetInstance().GetCurrentPrice();
m_oraclePrice = priceMicroUsd / 1000000.0;
} else if (m_clientModel) {
// Get actual oracle price from RPC
try {
UniValue params(UniValue::VARR);
UniValue result = m_clientModel->node().executeRpc("getoracleprice", params, "");
// Price is returned in micro-USD (1,000,000 = $1.00)
int64_t priceMicroUsd = result.find_value("price_micro_usd").getInt<int64_t>();
m_oraclePrice = priceMicroUsd / 1000000.0; // Convert micro-USD to dollars
} catch (const UniValue& e) {
LogPrintf("DigiDollar Send: updateOraclePrice RPC error - %s\n", e.write());
m_oraclePrice = 0.0;
} catch (const std::exception& e) {
LogPrintf("DigiDollar Send: updateOraclePrice error - %s\n", e.what());
m_oraclePrice = 0.0;
} catch (...) {
LogPrintf("DigiDollar Send: updateOraclePrice unknown error\n");
m_oraclePrice = 0.0;
}
} else {
m_oraclePrice = 0.0;
}
updateUSDEquivalent();
}
void DigiDollarSendWidget::onAddressChanged()
{
QString address = m_addressEdit->text();
updateAddressValidation();
updateSendButton();
}
void DigiDollarSendWidget::onAmountChanged()
{
QString amountText = m_amountEdit->text();
// Validate amount format
updateAmountValidation();
updateUSDEquivalent();
updateFeeDisplay();
updateSendButton();
}
void DigiDollarSendWidget::onSendClicked()
{
// PHASE 7.3: Comprehensive input validation with user-friendly messages
QString address = m_addressEdit->text().trimmed();
QString amountText = m_amountEdit->text().trimmed();
// Error: Empty fields
if (address.isEmpty()) {
showError(tr("Missing Address"),
tr("Please enter a DigiDollar address.\n\nThe recipient's DD address is required to send DigiDollar."));
m_addressEdit->setFocus();
return;
}
if (amountText.isEmpty()) {
showError(tr("Missing Amount"),
tr("Please enter an amount to send.\n\nSpecify how much DigiDollar you want to send (e.g., 100.00)."));
m_amountEdit->setFocus();
return;
}
// Error: Invalid address format
if (!validateAddress()) {
showError(tr("Invalid DigiDollar Address"),
tr("The address format is invalid.\n\n"
"Enter a valid DigiDollar address for the active network.\n\n"
"Please check the address and try again."));
m_addressEdit->setFocus();
return;
}
// Error: Invalid amount format
if (!validateAmount()) {
showError(tr("Invalid Amount"),
tr("The amount is invalid.\n\n"
"Valid amount format:\n"
"• Positive number\n"
"• Maximum 2 decimal places\n"
"• Between 1.00 $DD and 100,000.00 $DD\n\n"
"Please enter a valid amount."));
m_amountEdit->setFocus();
return;
}
double amount = amountText.toDouble();
// Error: Insufficient balance
if (!validateBalance()) {
showError(tr("Insufficient DigiDollar Balance"),
tr("You don't have enough DigiDollar for this transfer.\n\n"
"Available balance: %1\n"
"Amount to send: %2\n\n"
"Note: Transaction fees are paid in DGB (not $DD).\n\n"
"Please enter a smaller amount or add more $DD to your wallet.")
.arg(formatDDAmount(m_availableBalance))
.arg(formatDDAmount(amount)));
m_amountEdit->setFocus();
return;
}
if (m_coinControl && m_coinControl->HasSelected()) {
const CAmount amount_cents = static_cast<CAmount>(std::llround(amount * 100));
const CAmount selected_amount = selectedDigiDollarAmount();
if (selected_amount < amount_cents) {
showError(tr("Insufficient Selected DigiDollar Inputs"),
tr("The selected DigiDollar inputs total %1, but this send requires %2.\n\n"
"Select more inputs or clear manual input selection.")
.arg(formatDDAmount(selected_amount / 100.0))
.arg(formatDDAmount(amount)));
return;
}
}
// PHASE 7.3: Wallet state validation
if (!checkWalletState()) {
return; // Error already displayed by checkWalletState()
}
// PHASE 7.2: Enhanced confirmation dialog with fee display
if (!showConfirmationDialog(address, amount)) {
return; // User cancelled
}
// Unlock wallet if encrypted — UnlockContext MUST stay in scope through executeTransfer()
WalletModel::UnlockContext ctx(m_walletModel->requestUnlock());
if (!ctx.isValid()) {
// User cancelled the unlock dialog
return;
}
// PHASE 7.3: Execute transfer with progress indicator
executeTransfer(address, amount);
}
void DigiDollarSendWidget::onClearClicked()
{
m_addressEdit->clear();
m_amountEdit->clear();
if (m_noteEdit) m_noteEdit->clear();
onAddressChanged();
onAmountChanged();
}
void DigiDollarSendWidget::onUseAvailableBalanceClicked()
{
// FIXED: Fees are paid in DGB, not DD!
// Users can send their ENTIRE DD balance without any deduction
if (m_availableBalance > 0) {
// Set amount to full available balance (fees are paid separately in DGB)
m_amountEdit->setText(QString::number(m_availableBalance, 'f', 2));
onAmountChanged();
}
}
void DigiDollarSendWidget::onPasteAddressClicked()
{
m_addressEdit->setText(QApplication::clipboard()->text());
onAddressChanged();
}
void DigiDollarSendWidget::onAddressBookClicked()
{
if (!m_walletModel) return;
DDAddressBookPage dlg(m_platformStyle, DDAddressBookPage::ForSelection, this);
dlg.setWalletModel(m_walletModel);
if (dlg.exec() == QDialog::Accepted) {
QString address = dlg.getReturnValue();
if (!address.isEmpty()) {
m_addressEdit->setText(address);
onAddressChanged();
}
}
}
// REMOVED: applyTheme() method
// All theming is now handled by light.css and dark.css files
// This allows the DigiByte blue theme to work properly
void DigiDollarSendWidget::updateSendButton()
{
bool addressValid = validateAddress();
bool amountValid = validateAmount();
bool balanceValid = validateBalance();
m_sendButton->setEnabled(addressValid && amountValid && balanceValid);
}
void DigiDollarSendWidget::updateUSDEquivalent()
{
QString amountText = m_amountEdit->text();
if (!amountText.isEmpty()) {
double amount = amountText.toDouble();
double usdValue = amount * 1.0; // DD should be pegged to $1
m_usdEquivalentValue->setText(formatUSDAmount(usdValue));
} else {
m_usdEquivalentValue->setText("0.00 $USD");
}
// REMOVED: All programmatic styling - Let CSS handle theming
}
void DigiDollarSendWidget::updateFeeDisplay()
{
// FIXED: Display fee in DGB, not DD
// Fee is paid from DGB balance, not deducted from DD amount
m_feeValue->setText(QString("~0.1 DGB"));
QString amountText = m_amountEdit->text();
if (!amountText.isEmpty()) {
double amount = amountText.toDouble();
// Total DD sent equals the amount entered (fees don't reduce DD amount)
m_totalValue->setText(formatDDAmount(amount));
} else {
m_totalValue->setText(formatDDAmount(0));
}
}
bool DigiDollarSendWidget::validateAddress() const
{
QString address = m_addressEdit->text();
int pos = 0;
QString addressCopy = address;
return m_addressValidator->validate(addressCopy, pos) == QValidator::Acceptable;
}
bool DigiDollarSendWidget::validateAmount() const
{
QString amountText = m_amountEdit->text();
if (amountText.isEmpty()) return false;
int pos = 0;
QString amountCopy = amountText;
return m_amountValidator->validate(amountCopy, pos) == QValidator::Acceptable;
}
bool DigiDollarSendWidget::validateBalance() const
{
QString amountText = m_amountEdit->text();
if (amountText.isEmpty()) return true; // Empty is valid for enabling/disabling
double amount = amountText.toDouble();
// FIXED: Fees are paid in DGB, not DD!
// Only check if the DD amount is available, don't add fee to the check
bool valid = amount <= m_availableBalance && amount > 0;
// Note: Cannot call updateAmountValidation() from const method
return valid;
}
QString DigiDollarSendWidget::formatDDAmount(double amount) const
{
return QString::number(amount, 'f', 2) + " $DD";
}
QString DigiDollarSendWidget::formatUSDAmount(double amount) const
{
return QString::number(amount, 'f', 2) + " $USD";
}
// PHASE 7.3: Error display helper
void DigiDollarSendWidget::showError(const QString& title, const QString& message)
{
QMessageBox msgBox(this);
msgBox.setIcon(QMessageBox::Critical);
msgBox.setWindowTitle(title);
msgBox.setText(message);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
// Log for debugging
LogPrintf("DigiDollar GUI Error: %s - %s\n",
title.toStdString(), message.toStdString());
}
// PHASE 7.3: Warning display helper
void DigiDollarSendWidget::showWarning(const QString& title, const QString& message)
{
QMessageBox msgBox(this);
msgBox.setIcon(QMessageBox::Warning);
msgBox.setWindowTitle(title);
msgBox.setText(message);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
// Log for debugging
LogPrintf("DigiDollar GUI Warning: %s - %s\n",
title.toStdString(), message.toStdString());
}
// PHASE 7.3: Wallet state validation
bool DigiDollarSendWidget::checkWalletState()
{
if (!m_walletModel) {
showError(tr("Wallet Error"),
tr("Wallet is not available.\n\nPlease ensure your wallet is properly loaded."));
return false;
}
// NOTE: Wallet unlock is handled in onSendClicked() where the UnlockContext
// stays in scope through executeTransfer(). Do NOT unlock here — the context
// would die when checkWalletState() returns, re-locking before the transaction.
// Check if DigiDollar wallet initialized (balance check serves as proxy)
if (m_availableBalance < 0) {
showError(tr("DigiDollar Not Available"),
tr("DigiDollar wallet is not initialized.\n\n"
"This may indicate a wallet initialization error."));
return false;
}
return true;
}
// PHASE 7.2: Enhanced confirmation dialog with 3-second countdown
// This matches the DGB send confirmation flow exactly
bool DigiDollarSendWidget::showConfirmationDialog(const QString& address, double amount)
{
double usdEquivalent = amount * 1.0; // DD should be pegged to $1
// Create confirmation title - matches DGB "Confirm send coins"
QString title = tr("Confirm send DigiDollar");
// Build confirmation message following DGB format exactly
QString question_string;
// Main question - matches DGB
question_string.append(tr("Do you want to send this DigiDollar transaction?"));
question_string.append("<br /><span style='font-size:10pt;'>");
question_string.append(tr("Please, review your transaction."));
question_string.append("</span>%1");
if (m_coinControl && m_coinControl->HasSelected()) {
const int selected_count = static_cast<int>(m_coinControl->ListSelected().size());
const CAmount selected_amount = selectedDigiDollarAmount();
question_string.append("<hr /><b>");
question_string.append(tr("Selected $DD inputs"));
question_string.append("</b>: ");
question_string.append(tr("%1 input(s), %2 selected")
.arg(selected_count)
.arg(formatDDAmount(selected_amount / 100.0)));
}
// Transaction fee section - matches DGB format exactly
question_string.append("<hr /><b>");
question_string.append(tr("Transaction fee"));
question_string.append("</b>");
// Append fee estimate - note: DD transactions are similar size to DGB, ~0.1 DGB fee
question_string.append(" (~250 vB): ");
// Fee value in red bold - matches DGB styling exactly
question_string.append("<span style='color:#aa0000; font-weight:bold;'>");
question_string.append("~0.1 DGB");
question_string.append("</span><br />");
// Total amount section - matches DGB format
question_string.append("<hr />");
question_string.append(QString("<b>%1</b>: <b>%2</b>").arg(tr("Total Amount"))
.arg(formatDDAmount(amount)));
// USD equivalent as alternative unit - matches DGB's "or" format
question_string.append(QString("<br /><span style='font-size:10pt; font-weight:normal;'>(=%1)</span>")
.arg(formatUSDAmount(usdEquivalent)));
// Recipient details - formatted to match DGB's recipient format
QString recipientElement;
recipientElement.append(tr("%1 to %2").arg(formatDDAmount(amount), address));
// Insert recipient details into placeholder
question_string = question_string.arg("<br /><br />" + recipientElement);
// Informative text - empty for single recipient like DGB
QString informative_text = "";
// Create confirmation dialog with 3-second countdown - matches DGB exactly
auto confirmationDialog = new DDSendConfirmationDialog(
title,
question_string,
informative_text,
DD_SEND_CONFIRM_DELAY,
this
);
confirmationDialog->setAttribute(Qt::WA_DeleteOnClose);
int result = confirmationDialog->exec();
if (result == QMessageBox::Yes) {
LogPrintf("DigiDollar: User confirmed transfer of %f DD to %s after 3-second review\n",
amount, address.toStdString());
return true;
} else {
LogPrintf("DigiDollar: User cancelled transfer\n");
return false;
}
}
// PHASE 7.3: Execute transfer with progress indicator and error handling
void DigiDollarSendWidget::executeTransfer(const QString& address, double amount)
{
// Show progress dialog
QProgressDialog progress(tr("Sending DigiDollar..."),
tr("Cancel"), 0, 0, this);
progress.setWindowModality(Qt::WindowModal);
progress.setMinimumDuration(0); // Show immediately
progress.setCancelButton(nullptr); // No cancel during transfer
progress.show();
QApplication::processEvents(); // Force update
// Disable UI during transfer
m_sendButton->setEnabled(false);
m_addressEdit->setEnabled(false);
m_amountEdit->setEnabled(false);
m_clearButton->setEnabled(false);
m_useAvailableBalanceButton->setEnabled(false);
CAmount amountCents = static_cast<CAmount>(std::llround(amount * 100));
QString note = m_noteEdit ? m_noteEdit->text().trimmed() : QString();
std::vector<COutPoint> selectedInputs;
const std::vector<COutPoint>* presetInputs = nullptr;
if (m_coinControl && m_coinControl->HasSelected()) {
selectedInputs = m_coinControl->ListSelected();
presetInputs = &selectedInputs;
}
WalletModel::DigiDollarSendResult result = m_walletModel->sendDigiDollar(address, amountCents, note, presetInputs);
// Close progress dialog
progress.close();
// Re-enable UI
m_sendButton->setEnabled(true);
m_addressEdit->setEnabled(true);
m_amountEdit->setEnabled(true);
m_clearButton->setEnabled(true);
m_useAvailableBalanceButton->setEnabled(true);
// Handle result
if (result.status == WalletModel::OK) {
// Success!
showSuccess(result.txid, amount);
onClearClicked();
updateBalance(); // Refresh balance display
} else {
// Error occurred - map to user-friendly message
showBackendError(static_cast<int>(result.status), result.reasonFailed);
}
}
// PHASE 7.3: Success notification
QString DigiDollarSendWidget::buildSuccessMessage(const QString& txid, double amount) const
{
return tr(
"<b style='font-size: 14px; color: green;'>✓ DigiDollar Transfer Broadcast</b><br/><br/>"
"<table cellpadding='4' style='font-size: 12px;'>"
"<tr><td><b>Amount Sent:</b></td><td align='right'>%1</td></tr>"
"<tr><td><b>Transaction ID:</b></td><td style='font-family: monospace; font-size: 10px;'>%2</td></tr>"
"</table><br/>"
"<span style='color: #666; font-size: 11px;'>"
"Your transaction has been broadcast to the network.<br/>"
"It is pending until miners include it in a block and the block confirms."
"</span>"
).arg(formatDDAmount(amount))
.arg(txid);
}
void DigiDollarSendWidget::showSuccess(const QString& txid, double amount)
{
QString successMsg = buildSuccessMessage(txid, amount);
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Transfer Broadcast"));
msgBox.setText(successMsg);
msgBox.setIcon(QMessageBox::Information);
msgBox.setStandardButtons(QMessageBox::Ok);