-
Notifications
You must be signed in to change notification settings - Fork 919
Expand file tree
/
Copy pathAddressBook.qml
More file actions
582 lines (526 loc) · 25.5 KB
/
Copy pathAddressBook.qml
File metadata and controls
582 lines (526 loc) · 25.5 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
// Copyright (c) 2014-2024, 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 QtQuick 2.9
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2
import "../components" as MoneroComponents
import "../components/effects/" as MoneroEffects
import "../js/TxUtils.js" as TxUtils
import moneroComponents.AddressBook 1.0
import moneroComponents.AddressBookModel 1.0
import moneroComponents.Clipboard 1.0
import moneroComponents.NetworkType 1.0
import FontAwesome 1.0
Rectangle {
id: root
color: "transparent"
property alias addressbookHeight: mainLayout.height
property bool selectAndSend: false
property bool editEntry: false
Clipboard { id: clipboard }
ColumnLayout {
id: mainLayout
anchors.margins: 20
anchors.topMargin: 40
anchors.left: parent.left
anchors.top: parent.top
anchors.right: parent.right
spacing: 20
ColumnLayout {
id: addressBookEmptyLayout
visible: addressBookListView.count == 0
spacing: 0
Layout.fillWidth: true
Text {
id: titleLabel
Layout.fillWidth: true
color: MoneroComponents.Style.defaultFontColor
font.family: MoneroComponents.Style.fontRegular.name
font.pixelSize: 32
horizontalAlignment: TextInput.AlignLeft
wrapMode: Text.WordWrap;
leftPadding: 0
topPadding: 0
text: qsTr("Save your most used addresses here") + translationManager.emptyString
width: parent.width
}
Text {
Layout.fillWidth: true
color: MoneroComponents.Style.dimmedFontColor
font.family: MoneroComponents.Style.fontRegular.name
font.pixelSize: 16
horizontalAlignment: TextInput.AlignLeft
wrapMode: Text.WordWrap;
leftPadding: 0
topPadding: 0
text: qsTr("This makes it easier to send or receive Monero and reduces errors when typing in addresses manually.") + translationManager.emptyString
width: parent.width
}
MoneroComponents.StandardButton {
id: addFirstEntryButton
Layout.topMargin: 20
Layout.alignment: Qt.AlignHCenter
small: true
text: qsTr("Add an address") + translationManager.emptyString
onClicked: {
root.showAddAddress();
}
}
}
ColumnLayout {
id: addressBookLayout
visible: addressBookListView.count >= 1
spacing: 0
MoneroComponents.Label {
Layout.bottomMargin: 20
fontSize: 32
text: qsTr("Address book") + translationManager.emptyString
}
MoneroComponents.StandardButton {
id: addAddressButton
Layout.bottomMargin: 8
Layout.alignment: Qt.AlignRight
small: true
text: qsTr("Add address") + translationManager.emptyString
fontSize: 13
onClicked: {
root.showAddAddress();
}
}
ColumnLayout {
id: addressBookListRow
property int addressBookListItemHeight: 50
Layout.fillWidth: true
Layout.minimumWidth: 240
Layout.preferredHeight: addressBookListItemHeight * addressBookListView.count
ListView {
id: addressBookListView
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
boundsBehavior: ListView.StopAtBounds
interactive: false
delegate: Rectangle {
id: tableItem2
height: addressBookListRow.addressBookListItemHeight
width: parent ? parent.width : undefined
Layout.fillWidth: true
color: itemMouseArea.containsMouse ? MoneroComponents.Style.titleBarButtonHoverColor : "transparent"
function doSend() {
middlePanel.sendTo(address, paymentId);
leftPanel.selectItem(middlePanel.state)
}
Rectangle {
color: MoneroComponents.Style.appWindowBorderColor
anchors.right: parent.right
anchors.left: parent.left
anchors.top: parent.top
height: 1
MoneroEffects.ColorTransition {
targetObj: parent
blackColor: MoneroComponents.Style._b_appWindowBorderColor
whiteColor: MoneroComponents.Style._w_appWindowBorderColor
}
}
Rectangle {
anchors.fill: parent
anchors.topMargin: 5
anchors.rightMargin: 125
color: "transparent"
MoneroComponents.Label {
id: descriptionLabel
color: MoneroComponents.Style.defaultFontColor
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 6
fontSize: 16
text: description
elide: Text.ElideRight
textWidth: addressLabel.x - descriptionLabel.x - 1
}
MoneroComponents.Label {
id: addressLabel
color: MoneroComponents.Style.defaultFontColor
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.right
anchors.leftMargin: -addressLabel.width - 5
fontSize: 16
fontFamily: MoneroComponents.Style.fontMonoRegular.name;
text: TxUtils.addressTruncatePretty(address, mainLayout.width < 540 ? 1 : (mainLayout.width < 700 ? 2 : 3));
}
MouseArea {
id: itemMouseArea
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
visible: root.selectAndSend
onClicked: {
doSend();
}
}
}
RowLayout {
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 6
height: 21
spacing: 10
MoneroComponents.IconButton {
id: sendToButton
image: "qrc:///images/arrow-right-in-circle-outline-medium-white.svg"
color: MoneroComponents.Style.defaultFontColor
opacity: isOpenGL ? 0.5 : 1
fontAwesomeFallbackIcon: FontAwesome.arrowRight
fontAwesomeFallbackSize: 22
fontAwesomeFallbackOpacity: 0.5
Layout.preferredWidth: 20
Layout.preferredHeight: 20
tooltip: qsTr("Send to this address") + translationManager.emptyString
onClicked: {
doSend();
}
}
MoneroComponents.IconButton {
fontAwesomeFallbackIcon: FontAwesome.searchPlus
fontAwesomeFallbackSize: 22
color: MoneroComponents.Style.defaultFontColor
fontAwesomeFallbackOpacity: 0.5
Layout.preferredWidth: 23
Layout.preferredHeight: 21
tooltip: qsTr("See transactions") + translationManager.emptyString
onClicked: doSearchInHistory(address)
}
MoneroComponents.IconButton {
id: editEntryButton
image: "qrc:///images/edit.svg"
color: MoneroComponents.Style.defaultFontColor
opacity: isOpenGL ? 0.5 : 1
fontAwesomeFallbackIcon: FontAwesome.edit
fontAwesomeFallbackSize: 22
fontAwesomeFallbackOpacity: 0.5
Layout.preferredWidth: 23
Layout.preferredHeight: 21
tooltip: qsTr("Edit entry") + translationManager.emptyString
onClicked: {
addressBookListView.currentIndex = index;
root.showEditAddress(address, description);
}
}
MoneroComponents.IconButton {
id: copyButton
image: "qrc:///images/copy.svg"
color: MoneroComponents.Style.defaultFontColor
opacity: isOpenGL ? 0.5 : 1
fontAwesomeFallbackIcon: FontAwesome.clipboard
fontAwesomeFallbackSize: 22
fontAwesomeFallbackOpacity: 0.5
Layout.preferredWidth: 16
Layout.preferredHeight: 21
tooltip: qsTr("Copy address to clipboard") + translationManager.emptyString
onClicked: {
console.log("Address copied to clipboard");
clipboard.setText(address);
appWindow.showStatusMessage(qsTr("Address copied to clipboard"), 3);
}
}
}
}
}
}
Rectangle {
id: border2
color: MoneroComponents.Style.appWindowBorderColor
Layout.fillWidth: true
height: 1
MoneroEffects.ColorTransition {
targetObj: border2
blackColor: MoneroComponents.Style._b_appWindowBorderColor
whiteColor: MoneroComponents.Style._w_appWindowBorderColor
}
}
}
ColumnLayout {
id: addContactLayout
visible: false
spacing: 0
MoneroComponents.Label {
fontSize: 32
wrapMode: Text.WordWrap
text: (root.editEntry ? qsTr("Edit entry") : qsTr("Add an address")) + translationManager.emptyString
}
MoneroComponents.LineEditMulti {
id: addressLine
visible: !root.editEntry
Layout.topMargin: 20
KeyNavigation.backtab: deleteButton.visible ? deleteButton: cancelButton
KeyNavigation.tab: resolveButton.visible ? resolveButton : descriptionLine
labelText: "<style type='text/css'>a {text-decoration: none; color: #858585; font-size: 14px;}</style> %1"
.arg(qsTr("Address")) + translationManager.emptyString
placeholderText: {
if(persistentSettings.nettype == NetworkType.MAINNET){
return "4.. / 8.. / monero:.. / OpenAlias";
} else if (persistentSettings.nettype == NetworkType.STAGENET){
return "5.. / 7.. / monero:..";
} else if(persistentSettings.nettype == NetworkType.TESTNET){
return "9.. / B.. / monero:..";
}
}
wrapMode: Text.WrapAnywhere
addressValidation: true
pasteButton: false
onTextChanged: {
const parsed = walletManager.parse_uri_to_object(addressLine.text);
if (!parsed.error) {
addressLine.text = parsed.address;
descriptionLine.text = parsed.tx_description;
}
}
onEnterPressed: addButton.enabled ? addButton.clicked() : ""
onReturnPressed: addButton.enabled ? addButton.clicked() : ""
MoneroComponents.InlineButton {
fontFamily: FontAwesome.fontFamilySolid
fontStyleName: "Solid"
fontPixelSize: 18
text: FontAwesome.desktop
tooltip: qsTr("Grab QR code from screen") + translationManager.emptyString
onClicked: {
clearFields();
const codes = oshelper.grabQrCodesFromScreen();
for (var index = 0; index < codes.length; ++index) {
const parsed = walletManager.parse_uri_to_object(codes[index]);
if (!parsed.error) {
addressLine.text = parsed.address
descriptionLine.text = parsed.recipient_name
break;
} else if (walletManager.addressValid(codes[index], appWindow.persistentSettings.nettype)) {
addressLine.text = codes[index];
break;
}
}
}
}
MoneroComponents.InlineButton {
buttonColor: MoneroComponents.Style.orange
fontFamily: FontAwesome.fontFamily
text: FontAwesome.qrcode
visible : appWindow.qrScannerEnabled && !addressLine.text
onClicked: {
cameraUi.state = "Capture"
cameraUi.qrcode_decoded.connect(root.updateFromQrCode)
}
}
}
MoneroComponents.StandardButton {
id: resolveButton
KeyNavigation.backtab: addressLine
KeyNavigation.tab: descriptionLine
Layout.topMargin: 10
text: qsTr("Resolve") + translationManager.emptyString
visible: TxUtils.isValidOpenAliasAddress(addressLine.text)
enabled : visible
onClicked: {
const openAlias = addressLine.text;
const response = TxUtils.handleOpenAliasResolution(addressLine.text, descriptionLine.text);
if (response) {
if (response.confirm && response.address) {
const resolvedAddress = response.address;
const resolvedDescription = response.description;
oa_confirm(openAlias, resolvedAddress, function() {
addressLine.text = resolvedAddress;
if (resolvedDescription) {
descriptionLine.text = resolvedDescription;
}
});
return;
}
if (response.message) {
oa_message(response.message);
}
if (response.address) {
addressLine.text = response.address;
}
if (response.description) {
descriptionLine.text = response.description;
}
}
}
}
MoneroComponents.LineEdit {
id: descriptionLine
KeyNavigation.backtab: resolveButton.visible ? resolveButton : addressLine
KeyNavigation.tab: addButton.enabled ? addButton : cancelButton
Layout.topMargin: 20
Layout.fillWidth: true
fontSize: 16
placeholderFontSize: 16
labelText: "<style type='text/css'>a {text-decoration: none; color: #858585; font-size: 14px;}</style> %1"
.arg(qsTr("Description")) + translationManager.emptyString
placeholderText: qsTr("Add a name...") + translationManager.emptyString
onAccepted: addButton.enabled ? addButton.clicked() : ""
}
RowLayout {
Layout.topMargin: 20
Layout.alignment: Qt.AlignRight
MoneroComponents.StandardButton {
id: cancelButton
KeyNavigation.backtab: addButton
KeyNavigation.tab: deleteButton.visible ? deleteButton : addressLine
small: true
text: qsTr("Cancel") + translationManager.emptyString
primary: false
onClicked: root.showAddressBook();
}
MoneroComponents.StandardButton {
id: deleteButton
KeyNavigation.backtab: cancelButton
KeyNavigation.tab: addressLine
small: true
visible: root.editEntry
text: qsTr("Delete") + translationManager.emptyString
primary: false
onClicked: {
currentWallet.addressBook.deleteRow(addressBookListView.currentIndex);
root.showAddressBook();
}
}
MoneroComponents.StandardButton {
id: addButton
KeyNavigation.backtab: descriptionLine
KeyNavigation.tab: cancelButton
small: true
text: (root.editEntry ? qsTr("Save") : qsTr("Add")) + translationManager.emptyString
enabled: root.checkInformation(addressLine.text, appWindow.persistentSettings.nettype)
onClicked: {
if (!root.editEntry) {
if (currentWallet.addressBook.addRow(addressLine.text.trim(),"", descriptionLine.text)) {
console.log("Entry added")
} else {
informationPopup.title = qsTr("Error") + translationManager.emptyString;
// TODO: check currentWallet.addressBook.errorString() instead.
if (currentWallet.addressBook.errorCode() === AddressBook.Invalid_Address)
informationPopup.text = qsTr("Invalid address") + translationManager.emptyString
else if (currentWallet.addressBook.errorCode() === AddressBook.Invalid_Payment_Id)
informationPopup.text = currentWallet.addressBook.errorString()
else
informationPopup.text = qsTr("Can't create entry") + translationManager.emptyString
informationPopup.onCloseCallback = null
informationPopup.open();
}
} else {
currentWallet.addressBook.setDescription(addressBookListView.currentIndex, descriptionLine.text);
console.log("Description edited")
}
root.showAddressBook()
}
}
}
}
}
function checkInformation(address, nettype) {
address = address.trim()
var address_ok = walletManager.addressValid(address, nettype)
addressLine.error = !address_ok
return address_ok
}
function clearFields() {
addressLine.text = "";
descriptionLine.text = "";
}
function showAddressBook() {
addressBookEmptyLayout.visible = addressBookListView.count == 0
addressBookLayout.visible = addressBookListView.count >= 1;
addContactLayout.visible = false;
clearFields();
}
function showAddAddress() {
root.editEntry = false;
addressBookEmptyLayout.visible = false
addressBookLayout.visible = false;
addContactLayout.visible = true;
addressLine.forceActiveFocus();
}
function showEditAddress(address, description) {
//TODO: real contact editing, requires API change
root.editEntry = true;
addressBookEmptyLayout.visible = false
addressBookLayout.visible = false;
addContactLayout.visible = true;
addressLine.text = address;
descriptionLine.text = description;
addressLine.forceActiveFocus();
addressLine.cursorPosition = addressLine.text.length;
}
function updateFromQrCode(address, payment_id, amount, tx_description, recipient_name) {
console.log("updateFromQrCode")
addressLine.text = address
descriptionLine.text = recipient_name
cameraUi.qrcode_decoded.disconnect(updateFromQrCode)
}
function oa_message(text) {
oaPopup.title = qsTr("OpenAlias error") + translationManager.emptyString
oaPopup.text = text
oaPopup.icon = StandardIcon.Information
oaPopup.onCloseCallback = null
oaPopup.open()
}
function oa_confirm(openAlias, resolvedAddress, onAccepted) {
confirmationDialog.title = qsTr("OpenAlias warning") + translationManager.emptyString
confirmationDialog.text = qsTr("Address found, but the DNSSEC signatures could not be verified, so this address may be spoofed.") + "\n\n" +
qsTr("OpenAlias: ") + openAlias + "\n\n" +
qsTr("Resolved address: ") + resolvedAddress + "\n\n" +
qsTr("Only use this address if you trust this OpenAlias result.") + translationManager.emptyString
confirmationDialog.icon = StandardIcon.Question
confirmationDialog.cancelText = qsTr("Cancel") + translationManager.emptyString
confirmationDialog.okText = qsTr("Use address") + translationManager.emptyString
confirmationDialog.onAcceptedCallback = onAccepted
confirmationDialog.onRejectedCallback = null
confirmationDialog.open()
}
MoneroComponents.StandardDialog {
// dynamically change onclose handler
property var onCloseCallback
id: oaPopup
cancelVisible: false
onAccepted: {
if (onCloseCallback) {
onCloseCallback()
}
}
}
function onPageCompleted() {
console.log("adress book");
addressBookListView.model = currentWallet.addressBookModel;
showAddressBook();
}
function onPageClosed() {
root.selectAndSend = false;
root.editEntry = false;
clearFields();
}
}