forked from monero-project/monero-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
2414 lines (2123 loc) · 91.4 KB
/
main.qml
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) 2014-2019, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import QtQml.Models 2.2
import QtQuick 2.9
import QtQuick.Window 2.0
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import FontAwesome 1.0
import moneroComponents.Network 1.0
import moneroComponents.Wallet 1.0
import moneroComponents.WalletManager 1.0
import moneroComponents.PendingTransaction 1.0
import moneroComponents.NetworkType 1.0
import moneroComponents.Settings 1.0
import moneroComponents.P2PoolManager 1.0
import "components"
import "components" as MoneroComponents
import "components/effects" as MoneroEffects
import "pages/merchant" as MoneroMerchant
import "wizard"
import "js/Utils.js" as Utils
import "js/Windows.js" as Windows
import "version.js" as Version
ApplicationWindow {
id: appWindow
title: "Monero" +
(persistentSettings.displayWalletNameInTitleBar && walletName
? " - " + walletName
: "")
minimumWidth: 750
minimumHeight: 450
property var currentItem
property var previousActiveFocusItem
property bool hideBalanceForced: false
property bool ctrlPressed: false
property alias persistentSettings : persistentSettings
property string accountsDir: !persistentSettings.portable ? moneroAccountsDir : persistentSettings.portableFolderName + "/wallets"
property var currentWallet;
property bool disconnected: currentWallet ? currentWallet.disconnected : false
property var transaction;
property var walletPassword
property int restoreHeight:0
property bool daemonSynced: false
property bool walletSynced: false
property int maxWindowHeight: (isAndroid || isIOS)? screenAvailableHeight : (screenAvailableHeight < 900)? 720 : 800;
property bool daemonRunning: !persistentSettings.useRemoteNode && !disconnected
property int daemonStartStopInProgress: 0
property alias toolTip: toolTip
property string walletName
property bool viewOnly: false
property bool foundNewBlock: false
property bool qrScannerEnabled: (typeof builtWithScanner != "undefined") && builtWithScanner
property int blocksToSync: 1
property int firstBlockSeen
property bool isMining: false
property int walletMode: persistentSettings.walletMode
property var cameraUi
property bool androidCloseTapped: false;
property int userLastActive; // epoch
// Default daemon addresses
readonly property string localDaemonAddress : "localhost:" + getDefaultDaemonRpcPort(persistentSettings.nettype)
property string currentDaemonAddress;
property int disconnectedEpoch: 0
property int estimatedBlockchainSize: persistentSettings.pruneBlockchain ? 55 : 150 // GB
property alias viewState: rootItem.state
property string prevSplashText;
property bool splashDisplayedBeforeButtonRequest;
property bool themeTransition: false
// fiat price conversion
property real fiatPrice: 0
property var fiatPriceAPIs: {
return {
"kraken": {
"xmrusd": "https://api.kraken.com/0/public/Ticker?pair=XMRUSD",
"xmreur": "https://api.kraken.com/0/public/Ticker?pair=XMREUR"
},
"coingecko": {
"xmrusd": "https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=usd",
"xmreur": "https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=eur"
},
"cryptocompare": {
"xmrusd": "https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=USD",
"xmreur": "https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=EUR",
}
}
}
// true if wallet ever synchronized
property bool walletInitialized : false
// Current selected address / subaddress / (Receive/Account page)
property var current_address
property var current_address_label: "Primary"
property int current_subaddress_table_index: 0
function showPageRequest(page) {
middlePanel.state = page
leftPanel.selectItem(page)
}
function lock() {
passwordDialog.onRejectedCallback = function() { appWindow.showWizard(); }
passwordDialog.onAcceptedCallback = function() {
if(walletPassword === passwordDialog.password)
passwordDialog.close();
else
passwordDialog.showError(qsTr("Wrong password") + translationManager.emptyString);
}
passwordDialog.open(usefulName(persistentSettings.wallet_path));
}
function sequencePressed(obj, seq) {
if(seq === undefined || !leftPanel.enabled)
return
if(seq === "Ctrl") {
ctrlPressed = true
return
}
// lock wallet on demand
if(seq === "Ctrl+L" && !passwordDialog.visible) lock()
if(seq === "Ctrl+S") middlePanel.state = "Transfer"
else if(seq === "Ctrl+R") middlePanel.state = "Receive"
else if(seq === "Ctrl+H") middlePanel.state = "History"
else if(seq === "Ctrl+B") middlePanel.state = "AddressBook"
else if(seq === "Ctrl+E") middlePanel.state = "Settings"
else if(seq === "Ctrl+D") middlePanel.state = "Advanced"
else if(seq === "Ctrl+T") middlePanel.state = "Account"
else if(seq === "Ctrl+Tab" || seq === "Alt+Tab") {
/*
if(middlePanel.state === "Transfer") middlePanel.state = "Receive"
else if(middlePanel.state === "Receive") middlePanel.state = "TxKey"
else if(middlePanel.state === "TxKey") middlePanel.state = "SharedRingDB"
else if(middlePanel.state === "SharedRingDB") middlePanel.state = "History"
else if(middlePanel.state === "History") middlePanel.state = "AddressBook"
else if(middlePanel.state === "AddressBook") middlePanel.state = "Mining"
else if(middlePanel.state === "Mining") middlePanel.state = "Sign"
else if(middlePanel.state === "Sign") middlePanel.state = "Settings"
*/
if(middlePanel.state === "Settings") middlePanel.state = "Account"
else if(middlePanel.state === "Account") middlePanel.state = "Transfer"
else if(middlePanel.state === "Transfer") middlePanel.state = "AddressBook"
else if(middlePanel.state === "AddressBook") middlePanel.state = "Receive"
else if(middlePanel.state === "Receive") middlePanel.state = "History"
else if(middlePanel.state === "History") middlePanel.state = "Advanced"
else if(middlePanel.state === "Advanced") middlePanel.state = "Settings"
} else if(seq === "Ctrl+Shift+Backtab" || seq === "Alt+Shift+Backtab") {
/*
if(middlePanel.state === "Settings") middlePanel.state = "Sign"
else if(middlePanel.state === "Sign") middlePanel.state = "Mining"
else if(middlePanel.state === "Mining") middlePanel.state = "AddressBook"
else if(middlePanel.state === "AddressBook") middlePanel.state = "History"
else if(middlePanel.state === "History") middlePanel.state = "SharedRingDB"
else if(middlePanel.state === "SharedRingDB") middlePanel.state = "TxKey"
else if(middlePanel.state === "TxKey") middlePanel.state = "Receive"
else if(middlePanel.state === "Receive") middlePanel.state = "Transfer"
*/
if(middlePanel.state === "Settings") middlePanel.state = "Advanced"
else if(middlePanel.state === "Advanced") middlePanel.state = "History"
else if(middlePanel.state === "History") middlePanel.state = "Receive"
else if(middlePanel.state === "Receive") middlePanel.state = "AddressBook"
else if(middlePanel.state === "AddressBook") middlePanel.state = "Transfer"
else if(middlePanel.state === "Transfer") middlePanel.state = "Account"
else if(middlePanel.state === "Account") middlePanel.state = "Settings"
}
if (middlePanel.state !== "Advanced") updateBalance();
leftPanel.selectItem(middlePanel.state)
}
function sequenceReleased(obj, seq) {
if(seq === "Ctrl")
ctrlPressed = false
}
function mousePressed(obj, mouseX, mouseY) {}
function mouseReleased(obj, mouseX, mouseY) {}
function loadPage(page) {
middlePanel.state = page;
leftPanel.selectItem(page);
}
function openWallet(prevState) {
passwordDialog.onAcceptedCallback = function() {
walletPassword = passwordDialog.password;
initialize();
}
passwordDialog.onRejectedCallback = function() {
if (prevState) {
appWindow.viewState = prevState;
}
if (wizard.wizardState == "wizardOpenWallet1") {
wizard.wizardStateView.wizardOpenWallet1View.pageRoot.forceActiveFocus();
}
};
passwordDialog.open(usefulName(persistentSettings.wallet_path));
}
function initialize() {
console.log("initializing..")
// Use stored log level
if (persistentSettings.logLevel == 5)
walletManager.setLogCategories(persistentSettings.logCategories)
else
walletManager.setLogLevel(persistentSettings.logLevel)
// Reload transfer page with translations enabled
middlePanel.transferView.onPageCompleted();
// If currentWallet exists, we're just switching daemon - close/reopen wallet
if (typeof currentWallet !== "undefined" && currentWallet !== null) {
console.log("Daemon change - closing " + currentWallet)
closeWallet();
} else if (!walletInitialized) {
// set page to transfer if not changing daemon
middlePanel.state = "Transfer";
leftPanel.selectItem(middlePanel.state)
}
// Local daemon settings
walletManager.setDaemonAddressAsync(localDaemonAddress);
// enable timers
userInActivityTimer.running = true;
// wallet already opened with wizard, we just need to initialize it
var wallet_path = persistentSettings.wallet_path;
if(isIOS)
wallet_path = appWindow.accountsDir + wallet_path;
// console.log("opening wallet at: ", wallet_path, "with password: ", appWindow.walletPassword);
console.log("opening wallet at: ", wallet_path, ", network type: ", persistentSettings.nettype == NetworkType.MAINNET ? "mainnet" : persistentSettings.nettype == NetworkType.TESTNET ? "testnet" : "stagenet");
this.onWalletOpening();
walletManager.openWalletAsync(
wallet_path,
walletPassword,
persistentSettings.nettype,
persistentSettings.kdfRounds);
}
function closeWallet(callback) {
// Disconnect all listeners
if (typeof currentWallet === "undefined" || currentWallet === null) {
if (callback) {
callback();
}
return;
}
currentWallet.heightRefreshed.disconnect(onHeightRefreshed);
currentWallet.refreshed.disconnect(onWalletRefresh)
currentWallet.updated.disconnect(onWalletUpdate)
currentWallet.newBlock.disconnect(onWalletNewBlock)
currentWallet.moneySpent.disconnect(onWalletMoneySent)
currentWallet.moneyReceived.disconnect(onWalletMoneyReceived)
currentWallet.unconfirmedMoneyReceived.disconnect(onWalletUnconfirmedMoneyReceived)
currentWallet.transactionCreated.disconnect(onTransactionCreated)
currentWallet.connectionStatusChanged.disconnect(onWalletConnectionStatusChanged)
currentWallet.deviceButtonRequest.disconnect(onDeviceButtonRequest);
currentWallet.deviceButtonPressed.disconnect(onDeviceButtonPressed);
currentWallet.walletPassphraseNeeded.disconnect(onWalletPassphraseNeededWallet);
currentWallet.transactionCommitted.disconnect(onTransactionCommitted);
middlePanel.paymentClicked.disconnect(handlePayment);
middlePanel.sweepUnmixableClicked.disconnect(handleSweepUnmixable);
middlePanel.getProofClicked.disconnect(handleGetProof);
middlePanel.checkProofClicked.disconnect(handleCheckProof);
appWindow.walletName = "";
currentWallet = undefined;
appWindow.showProcessingSplash(qsTr("Closing wallet..."));
if (callback) {
walletManager.closeWalletAsync(function() {
hideProcessingSplash();
callback();
});
} else {
walletManager.closeWallet();
hideProcessingSplash();
}
}
function connectWallet(wallet) {
currentWallet = wallet
walletName = usefulName(wallet.path)
viewOnly = currentWallet.viewOnly;
// New wallets saves the testnet flag in keys file.
if(persistentSettings.nettype != currentWallet.nettype) {
console.log("Using network type from keys file")
persistentSettings.nettype = currentWallet.nettype;
}
// connect handlers
currentWallet.heightRefreshed.connect(onHeightRefreshed);
currentWallet.refreshed.connect(onWalletRefresh)
currentWallet.updated.connect(onWalletUpdate)
currentWallet.newBlock.connect(onWalletNewBlock)
currentWallet.moneySpent.connect(onWalletMoneySent)
currentWallet.moneyReceived.connect(onWalletMoneyReceived)
currentWallet.unconfirmedMoneyReceived.connect(onWalletUnconfirmedMoneyReceived)
currentWallet.transactionCreated.connect(onTransactionCreated)
currentWallet.connectionStatusChanged.connect(onWalletConnectionStatusChanged)
currentWallet.deviceButtonRequest.connect(onDeviceButtonRequest);
currentWallet.deviceButtonPressed.connect(onDeviceButtonPressed);
currentWallet.walletPassphraseNeeded.connect(onWalletPassphraseNeededWallet);
currentWallet.transactionCommitted.connect(onTransactionCommitted);
currentWallet.proxyAddress = Qt.binding(persistentSettings.getWalletProxyAddress);
middlePanel.paymentClicked.connect(handlePayment);
middlePanel.sweepUnmixableClicked.connect(handleSweepUnmixable);
middlePanel.getProofClicked.connect(handleGetProof);
middlePanel.checkProofClicked.connect(handleCheckProof);
persistentSettings.restore_height = currentWallet.walletCreationHeight;
console.log("Recovering from seed: ", persistentSettings.is_recovering)
console.log("restore Height", persistentSettings.restore_height)
if (persistentSettings.useRemoteNode) {
const remoteNode = remoteNodesModel.currentRemoteNode();
currentDaemonAddress = remoteNode.address;
currentWallet.setDaemonLogin(remoteNode.username, remoteNode.password);
} else {
currentDaemonAddress = localDaemonAddress;
}
console.log("initializing with daemon address: ", currentDaemonAddress)
currentWallet.initAsync(
currentDaemonAddress,
isTrustedDaemon(),
0,
persistentSettings.is_recovering,
persistentSettings.is_recovering_from_device,
persistentSettings.restore_height,
persistentSettings.getWalletProxyAddress());
// save wallet keys in case wallet settings have been changed in the init
currentWallet.setPassword(walletPassword);
}
function isTrustedDaemon() {
return appWindow.walletMode >= 2 && (!persistentSettings.useRemoteNode || remoteNodesModel.currentRemoteNode().trusted);
}
function usefulName(path) {
// arbitrary "short enough" limit
if (path.length < 32)
return path
return path.replace(/.*[\/\\]/, '').replace(/\.keys$/, '')
}
function getUnlockedBalance() {
if(!currentWallet){
return 0
}
return currentWallet.unlockedBalance()
}
function updateBalance() {
if (!currentWallet)
return;
var balance = "?.??";
var balanceU = "?.??";
if(!hideBalanceForced && !persistentSettings.hideBalance){
balance = walletManager.displayAmount(currentWallet.balance());
balanceU = walletManager.displayAmount(currentWallet.unlockedBalance());
}
if (persistentSettings.fiatPriceEnabled) {
appWindow.fiatApiUpdateBalance(balance);
}
leftPanel.minutesToUnlock = (balance !== balanceU) ? currentWallet.history.minutesToUnlock : "";
leftPanel.balanceString = balance
leftPanel.balanceUnlockedString = balanceU
if (middlePanel.state === "Account") {
middlePanel.accountView.balanceAllText = walletManager.displayAmount(appWindow.currentWallet.balanceAll()) + " XMR";
middlePanel.accountView.unlockedBalanceAllText = walletManager.displayAmount(appWindow.currentWallet.unlockedBalanceAll()) + " XMR";
}
}
function onUriHandler(uri){
if(uri.startsWith("monero://")){
var address = uri.substring("monero://".length);
var params = {}
if(address.length === 0) return;
var spl = address.split("?");
if(spl.length > 2) return;
if(spl.length >= 1) {
// parse additional params
address = spl[0];
if(spl.length === 2){
spl.shift();
var item = spl[0];
var _spl = item.split("&");
for (var param in _spl){
var _item = _spl[param];
if(!_item.indexOf("=") > 0) continue;
var __spl = _item.split("=");
if(__spl.length !== 2) continue;
params[__spl[0]] = __spl[1];
}
}
}
// Fill fields
middlePanel.transferView.sendTo(address, params["tx_payment_id"], params["tx_description"], params["tx_amount"]);
// Raise window
appWindow.raise();
appWindow.show();
}
}
function onWalletConnectionStatusChanged(status){
console.log("Wallet connection status changed " + status)
middlePanel.updateStatus();
leftPanel.networkStatus.connected = status
if (status == Wallet.ConnectionStatus_Disconnected) {
firstBlockSeen = 0;
}
// If wallet isnt connected, advanced wallet mode and no daemon is running - Ask
if (appWindow.walletMode >= 2 && !persistentSettings.useRemoteNode && !walletInitialized && disconnected) {
daemonManager.runningAsync(persistentSettings.nettype, persistentSettings.blockchainDataDir, function(running) {
if (!running) {
daemonManagerDialog.open();
}
});
}
// initialize transaction history once wallet is initialized first time;
if (!walletInitialized) {
currentWallet.history.refresh(currentWallet.currentSubaddressAccount)
walletInitialized = true
// check if daemon was already mining and add mining logo if true
if (!persistentSettings.useRemoteNode || persistentSettings.allowRemoteNodeMining) {
middlePanel.advancedView.miningView.update();
}
}
}
function onDeviceButtonRequest(code){
if (txConfirmationPopup.visible) {
txConfirmationPopup.bottomTextAnimation.running = true
if (!txConfirmationPopup.errorText.visible) {
txConfirmationPopup.bottomText.text = qsTr("Please confirm transaction on the device...") + translationManager.emptyString;
} else {
txConfirmationPopup.bottomText.text = qsTr("Please proceed to the device...") + translationManager.emptyString;
}
} else {
prevSplashText = splash.messageText;
splashDisplayedBeforeButtonRequest = splash.visible;
appWindow.showProcessingSplash(qsTr("Please proceed to the device..."));
}
}
function onDeviceButtonPressed(){
if (txConfirmationPopup.visible) {
txConfirmationPopup.bottomTextAnimation.running = false;
txConfirmationPopup.bottomText.text = qsTr("Signing transaction in the device...") + translationManager.emptyString;
} else {
if (splashDisplayedBeforeButtonRequest){
appWindow.showProcessingSplash(prevSplashText);
} else {
hideProcessingSplash();
}
}
}
function onWalletOpening(){
appWindow.showProcessingSplash(qsTr("Opening wallet ..."));
}
function onWalletOpened(wallet) {
hideProcessingSplash();
walletName = usefulName(wallet.path)
console.log(">>> wallet opened: " + wallet)
if (wallet.status !== Wallet.Status_Ok) {
// try to resolve common wallet cache errors automatically
switch (wallet.errorString) {
case "basic_string::_M_replace_aux":
case "std::bad_alloc":
walletManager.clearWalletCache(wallet.path);
walletPassword = passwordDialog.password;
appWindow.initialize();
console.error("Repairing wallet cache with error: ", wallet.errorString);
appWindow.showStatusMessage(qsTr("Repairing incompatible wallet cache. Resyncing wallet."),6);
return;
default:
// opening with password but password doesn't match
console.error("Error opening wallet with password: ", wallet.errorString);
passwordDialog.showError(qsTr("Couldn't open wallet: ") + wallet.errorString);
console.log("closing wallet async : " + wallet.address)
closeWallet();
return;
}
}
// wallet opened successfully, subscribing for wallet updates
connectWallet(wallet)
// Force switch normal view
rootItem.state = "normal";
// Process queued IPC command
if(typeof IPC !== "undefined" && IPC.queuedCmd().length > 0){
var queuedCmd = IPC.queuedCmd();
if(/^\w+:\/\/(.*)$/.test(queuedCmd)) appWindow.onUriHandler(queuedCmd); // uri
}
}
function onWalletPassphraseNeededManager(on_device){
onWalletPassphraseNeeded(walletManager, on_device)
}
function onWalletPassphraseNeededWallet(on_device){
onWalletPassphraseNeeded(currentWallet, on_device)
}
function onWalletPassphraseNeeded(handler, on_device){
hideProcessingSplash();
console.log(">>> wallet passphrase needed: ")
devicePassphraseDialog.onAcceptedCallback = function(passphrase) {
handler.onPassphraseEntered(passphrase, false, false);
appWindow.onWalletOpening();
}
devicePassphraseDialog.onWalletEntryCallback = function() {
handler.onPassphraseEntered("", true, false);
appWindow.onWalletOpening();
}
devicePassphraseDialog.onRejectedCallback = function() {
handler.onPassphraseEntered("", false, true);
appWindow.onWalletOpening();
}
devicePassphraseDialog.open(on_device)
}
function onWalletUpdate() {
if (!currentWallet)
return;
console.log(">>> wallet updated")
updateBalance();
// Update history if new block found since last update
if(foundNewBlock) {
foundNewBlock = false;
console.log("New block found - updating history")
currentWallet.history.refresh(currentWallet.currentSubaddressAccount)
if(middlePanel.state == "History")
middlePanel.historyView.update();
}
}
function connectRemoteNode() {
console.log("connecting remote node");
p2poolManager.exit();
p2poolManager.getStatus();
const callback = function() {
persistentSettings.useRemoteNode = true;
const remoteNode = remoteNodesModel.currentRemoteNode();
currentDaemonAddress = remoteNode.address;
currentWallet.setDaemonLogin(remoteNode.username, remoteNode.password);
currentWallet.initAsync(
currentDaemonAddress,
isTrustedDaemon(),
0,
false,
false,
0,
persistentSettings.getWalletProxyAddress());
walletManager.setDaemonAddressAsync(currentDaemonAddress);
};
if (typeof daemonManager != "undefined" && daemonRunning) {
showDaemonIsRunningDialog(callback);
} else {
callback();
}
}
function disconnectRemoteNode() {
if (typeof currentWallet === "undefined" || currentWallet === null)
return;
console.log("disconnecting remote node");
p2poolManager.exit();
p2poolManager.getStatus();
persistentSettings.useRemoteNode = false;
currentDaemonAddress = localDaemonAddress
currentWallet.setDaemonLogin("", "");
currentWallet.initAsync(
currentDaemonAddress,
isTrustedDaemon(),
0,
false,
false,
0,
persistentSettings.getWalletProxyAddress());
walletManager.setDaemonAddressAsync(currentDaemonAddress);
firstBlockSeen = 0;
}
function onHeightRefreshed(bcHeight, dCurrentBlock, dTargetBlock) {
// Daemon fully synced
// TODO: implement onDaemonSynced or similar in wallet API and don't start refresh thread before daemon is synced
// targetBlock = currentBlock = 1 before network connection is established.
if (firstBlockSeen == 0 && dTargetBlock != 1) {
firstBlockSeen = dCurrentBlock;
}
daemonSynced = dCurrentBlock >= dTargetBlock && dTargetBlock != 1
walletSynced = bcHeight >= dTargetBlock
// Update progress bars
if(!daemonSynced) {
leftPanel.daemonProgressBar.updateProgress(dCurrentBlock,dTargetBlock, dTargetBlock-firstBlockSeen);
leftPanel.progressBar.updateProgress(0,dTargetBlock, dTargetBlock, qsTr("Waiting for daemon to sync"));
} else {
leftPanel.daemonProgressBar.updateProgress(dCurrentBlock,dTargetBlock, 0, qsTr("Daemon is synchronized (%1)").arg(dCurrentBlock.toFixed(0)));
if(walletSynced)
leftPanel.progressBar.updateProgress(bcHeight,dTargetBlock,dTargetBlock-bcHeight, qsTr("Wallet is synchronized"))
}
// Update wallet sync progress
leftPanel.isSyncing = !disconnected && !daemonSynced;
// Update transfer page status
middlePanel.updateStatus();
// Refresh is succesfull if blockchain height > 1
if (bcHeight > 1){
// recovering from seed is finished after first refresh
if(persistentSettings.is_recovering) {
persistentSettings.is_recovering = false
}
if (persistentSettings.is_recovering_from_device) {
persistentSettings.is_recovering_from_device = false;
}
}
// Update history on every refresh if it's empty
if(currentWallet.history.count == 0)
currentWallet.history.refresh(currentWallet.currentSubaddressAccount)
onWalletUpdate();
}
function onWalletRefresh() {
console.log(">>> wallet refreshed")
// Daemon connected
leftPanel.networkStatus.connected = currentWallet ? currentWallet.connected() : Wallet.ConnectionStatus_Disconnected
if (currentWallet)
currentWallet.refreshHeightAsync();
}
function startDaemon(flags){
daemonStartStopInProgress = 1;
// Pause refresh while starting daemon
currentWallet.pauseRefresh();
const noSync = appWindow.walletMode === 0;
const bootstrapNodeAddress = persistentSettings.walletMode < 2 ? "auto" : persistentSettings.bootstrapNodeAddress
daemonManager.start(flags, persistentSettings.nettype, persistentSettings.blockchainDataDir, bootstrapNodeAddress, noSync, persistentSettings.pruneBlockchain);
}
function stopDaemon(callback, splash){
daemonStartStopInProgress = 2;
if (splash) {
appWindow.showProcessingSplash(qsTr("Waiting for daemon to stop..."));
}
p2poolManager.exit()
daemonManager.stopAsync(persistentSettings.nettype, persistentSettings.blockchainDataDir, function(result) {
daemonStartStopInProgress = 0;
if (splash) {
hideProcessingSplash();
}
callback(result);
});
}
function onDaemonStarted(){
console.log("daemon started");
daemonStartStopInProgress = 0;
if (currentWallet) {
currentWallet.connected(true);
// resume refresh
currentWallet.startRefresh();
}
// resume simplemode connection timer
appWindow.disconnectedEpoch = Utils.epoch();
}
function onDaemonStopped(){
if (currentWallet) {
currentWallet.connected(true);
}
}
function onDaemonStartFailure(error) {
console.log("daemon start failed");
daemonStartStopInProgress = 0;
// resume refresh
currentWallet.startRefresh();
informationPopup.title = qsTr("Daemon failed to start") + translationManager.emptyString;
informationPopup.text = error + ".\n\n" + qsTr("Please check your wallet and daemon log for errors. You can also try to start %1 manually.").arg((isWindows)? "monerod.exe" : "monerod")
if (middlePanel.advancedView.miningView.stopMiningEnabled == true) {
walletManager.stopMining()
p2poolManager.exit()
middlePanel.advancedView.miningView.update()
informationPopup.text += qsTr("\n\nExiting p2pool. Please check that port 18083 is available.") + translationManager.emptyString;
}
informationPopup.icon = StandardIcon.Critical
informationPopup.onCloseCallback = null
informationPopup.open();
}
function onWalletNewBlock(blockHeight, targetHeight) {
// Update progress bar
var remaining = targetHeight - blockHeight;
if(blocksToSync < remaining) {
blocksToSync = remaining;
}
leftPanel.progressBar.updateProgress(blockHeight,targetHeight, blocksToSync);
// If wallet is syncing, daemon is already synced
leftPanel.daemonProgressBar.updateProgress(1,1,0,qsTr("Daemon is synchronized"));
foundNewBlock = true;
}
function onWalletMoneyReceived(txId, amount) {
// refresh transaction history here
console.log("Confirmed money found")
// history refresh is handled by walletUpdated
currentWallet.history.refresh(currentWallet.currentSubaddressAccount) // this will refresh model
currentWallet.subaddress.refresh(currentWallet.currentSubaddressAccount)
if(middlePanel.state == "History")
middlePanel.historyView.update();
}
function onWalletUnconfirmedMoneyReceived(txId, amount) {
// refresh history
console.log("unconfirmed money found")
currentWallet.history.refresh(currentWallet.currentSubaddressAccount);
if(middlePanel.state == "History")
middlePanel.historyView.update();
}
function onWalletMoneySent(txId, amount) {
// refresh transaction history here
console.log("monero sent found")
currentWallet.history.refresh(currentWallet.currentSubaddressAccount); // this will refresh model
if(middlePanel.state == "History")
middlePanel.historyView.update();
}
function walletsFound() {
if (persistentSettings.wallet_path.length > 0) {
if(isIOS)
return walletManager.walletExists(appWindow.accountsDir + persistentSettings.wallet_path);
else
return walletManager.walletExists(persistentSettings.wallet_path);
}
return false;
}
function onTransactionCreated(pendingTransaction, addresses, paymentId, mixinCount) {
console.log("Transaction created");
txConfirmationPopup.bottomText.text = "";
transaction = pendingTransaction;
// validate address;
if (transaction.status !== PendingTransaction.Status_Ok) {
console.error("Can't create transaction: ", transaction.errorString);
if (currentWallet.connected() == Wallet.ConnectionStatus_WrongVersion) {
txConfirmationPopup.errorText.text = qsTr("Can't create transaction: Wrong daemon version: ") + transaction.errorString
} else {
txConfirmationPopup.errorText.text = qsTr("Can't create transaction: ") + transaction.errorString
}
// deleting transaction object, we don't want memleaks
currentWallet.disposeTransaction(transaction);
} else if (transaction.txCount == 0) {
console.error("Can't create transaction: ", transaction.errorString);
txConfirmationPopup.errorText.text = qsTr("No unmixable outputs to sweep") + translationManager.emptyString
// deleting transaction object, we don't want memleaks
currentWallet.disposeTransaction(transaction);
} else {
console.log("Transaction created, amount: " + walletManager.displayAmount(transaction.amount)
+ ", fee: " + walletManager.displayAmount(transaction.fee));
// here we update txConfirmationPopup
txConfirmationPopup.transactionAmount = Utils.removeTrailingZeros(walletManager.displayAmount(transaction.amount));
txConfirmationPopup.transactionFee = Utils.removeTrailingZeros(walletManager.displayAmount(transaction.fee));
txConfirmationPopup.confirmButton.text = viewOnly ? qsTr("Save as file") : qsTr("Confirm") + translationManager.emptyString;
txConfirmationPopup.confirmButton.rightIcon = viewOnly ? "" : "qrc:///images/rightArrow.png"
}
}
function getDisplayAmountTotal(recipients) {
const amounts = recipients.map(function (recipient) {
return recipient.amount;
});
const total = walletManager.amountsSumFromStrings(amounts);
return Utils.removeTrailingZeros(walletManager.displayAmount(total));
}
// called on "transfer"
function handlePayment(recipients, paymentId, mixinCount, priority, description, createFile) {
console.log("Creating transaction: ")
console.log("\trecipients: ", recipients,
", payment_id: ", paymentId,
", mixins: ", mixinCount,
", priority: ", priority,
", description: ", description);
const recipientAll = recipients.find(function (recipient) {
return recipient.amount == "(all)";
});
if (recipientAll && recipients.length > 1) {
throw "Sending all requires one destination address";
}
txConfirmationPopup.bottomTextAnimation.running = false;
txConfirmationPopup.bottomText.text = qsTr("Creating transaction...") + translationManager.emptyString;
txConfirmationPopup.recipients = recipients;
txConfirmationPopup.transactionAmount = recipientAll ? "(all)" : getDisplayAmountTotal(recipients);
txConfirmationPopup.transactionPriority = priority;
txConfirmationPopup.transactionDescription = description;
txConfirmationPopup.open();
if (recipientAll) {
currentWallet.createTransactionAllAsync(recipientAll.address, paymentId, mixinCount, priority);
} else {
const addresses = recipients.map(function (recipient) {
return recipient.address;
});
const amountsxmr = recipients.map(function (recipient) {
return recipient.amount;
});
currentWallet.createTransactionAsync(addresses, paymentId, amountsxmr, mixinCount, priority);
}
}
//Choose where to save transaction
FileDialog {
id: saveTxDialog
title: "Please choose a location"
folder: "file://" + appWindow.accountsDir
selectExisting: false;
onAccepted: {
handleTransactionConfirmed()
}
onRejected: {
// do nothing
}
}
function handleSweepUnmixable() {
console.log("Creating transaction: ")
txConfirmationPopup.sweepUnmixable = true;
transaction = currentWallet.createSweepUnmixableTransaction();
if (transaction.status !== PendingTransaction.Status_Ok) {
console.error("Can't create transaction: ", transaction.errorString);
txConfirmationPopup.errorText.text = qsTr("Can't create transaction: ") + transaction.errorString + translationManager.emptyString
// deleting transaction object, we don't want memleaks
currentWallet.disposeTransaction(transaction);
} else if (transaction.txCount == 0) {
console.error("No unmixable outputs to sweep");
txConfirmationPopup.errorText.text = qsTr("No unmixable outputs to sweep") + translationManager.emptyString
// deleting transaction object, we don't want memleaks
currentWallet.disposeTransaction(transaction);
} else {
console.log("Transaction created, amount: " + walletManager.displayAmount(transaction.amount)
+ ", fee: " + walletManager.displayAmount(transaction.fee));
txConfirmationPopup.transactionAmount = Utils.removeTrailingZeros(walletManager.displayAmount(transaction.amount));
txConfirmationPopup.transactionFee = Utils.removeTrailingZeros(walletManager.displayAmount(transaction.fee));
// committing transaction
}
txConfirmationPopup.open();
}
// called after user confirms transaction
function handleTransactionConfirmed(fileName) {
// View only wallet - we save the tx
if(viewOnly){
// No file specified - abort
if(!saveTxDialog.fileUrl) {
currentWallet.disposeTransaction(transaction)
return;
}
var path = walletManager.urlToLocalPath(saveTxDialog.fileUrl)
// Store to file
transaction.setFilename(path);
}
appWindow.showProcessingSplash(qsTr("Sending transaction ..."));
currentWallet.commitTransactionAsync(transaction);
}
function onTransactionCommitted(success, transaction, txid) {
hideProcessingSplash();
if (!success) {
console.log("Error committing transaction: " + transaction.errorString);
informationPopup.title = qsTr("Error") + translationManager.emptyString
informationPopup.text = qsTr("Couldn't send the money: ") + transaction.errorString
informationPopup.icon = StandardIcon.Critical
informationPopup.onCloseCallback = null;
informationPopup.open();
} else {
if (txConfirmationPopup.transactionDescription.length > 0) {
for (var i = 0; i < txid.length; ++i)
currentWallet.setUserNote(txid[i], txConfirmationPopup.transactionDescription);
}
// Clear tx fields
middlePanel.transferView.clearFields()
txConfirmationPopup.clearFields()
successfulTxPopup.open(txid)
}
currentWallet.refresh()
currentWallet.disposeTransaction(transaction)
currentWallet.storeAsync(function(success) {
if (!success) {
appWindow.showStatusMessage(qsTr("Failed to store the wallet"), 3);
}
});
}
function doSearchInHistory(searchTerm) {
middlePanel.searchInHistory(searchTerm);
leftPanel.selectItem(middlePanel.state)
}
// called on "getProof"