/
main.qml
486 lines (413 loc) · 14.7 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
import QtQuick 2.11
import QtQuick.Controls 1.4
import QtQuick.Controls 2.4
import QtQuick.Controls.Styles 1.2
import QtGraphicalEffects 1.0
import QtQuick.Window 2.2
import "controls"
import Beam.Wallet 1.0
import "utils.js" as Utils
Rectangle {
id: main
property var openedNotifications: 0
property var notificationOffset: 0
property alias hasNewerVersion : updateInfoProvider.hasNewerVersion
function increaseNotificationOffset(popup) {
popup.verticalOffset = main.notificationOffset
main.notificationOffset += popup.height + 2
popup.nextVerticalOffset = main.notificationOffset
}
function decreaseNotificationOffset(popup) {
main.notificationOffset -= (popup.nextVerticalOffset - popup.verticalOffset)
if (main.notificationOffset < 0)
main.notificationOffset = 0
}
function showSimplePopup(message) {
var popup = Qt.createComponent("controls/SimpleNotificationPopup.qml").createObject(main);
popup.message = message
increaseNotificationOffset(popup)
popup.closed.connect(function() {
decreaseNotificationOffset(popup)
})
popup.open();
}
anchors.fill: parent
MainViewModel {
id: viewModel
onClipboardChanged: function(message) {
showSimplePopup(message)
}
}
PushNotificationManager {
id: updateInfoProvider
onShowUpdateNotification: function(newVersion, currentVersion, id) {
var popup = Qt.createComponent("controls/NotificationPopup.qml").createObject(main);
popup.title = "New version v " + newVersion + " is avalable";
popup.message = "Your current version is v " + currentVersion + ". Please update to get the most of your Beam wallet.";
popup.acceptButtonText = "update now";
popup.onCancel = function () {
updateInfoProvider.onCancelPopup(id);
popup.close();
}
popup.onAccept = function () {
Utils.navigateToDownloads();
}
increaseNotificationOffset(popup)
popup.closed.connect(function() {
decreaseNotificationOffset(popup);
})
popup.open();
}
}
ConfirmationDialog {
id: closeDialog
//% "Beam wallet close"
title: qsTrId("app-close-title")
//% "There are %1 active transactions that might fail if the wallet will go offline. Are you sure to close the wallet now?"
text: qsTrId("app-close-text").arg(viewModel.unsafeTxCount)
//% "yes"
okButtonText: qsTrId("atomic-swap-tx-yes-button")
okButtonIconSource: "qrc:/assets/icon-done.svg"
okButtonColor: Style.swapStateIndicator
//% "no"
cancelButtonText: qsTrId("atomic-swap-no-button")
cancelButtonIconSource: "qrc:/assets/icon-cancel-16.svg"
onOpened: {
closeDialog.visible = Qt.binding(function(){return viewModel.unsafeTxCount > 0;});
}
onClosed: {
closeDialog.visible = false;
}
onAccepted: {
Qt.quit();
}
modal: true
}
function onClosing (close) {
if (viewModel.unsafeTxCount > 0) {
close.accepted = false;
closeDialog.open();
}
}
property color topColor: Style.background_main_top
property color topGradientColor: Qt.rgba(Style.background_main_top.r, Style.background_main_top.g, Style.background_main_top.b, 0)
StatusbarViewModel {
id: statusbarModel
}
property var backgroundRect: mainBackground
property var backgroundLogo: mainBackgroundLogo
Rectangle {
id: mainBackground
anchors.fill: parent
color: Style.background_main
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
height: 230
gradient: Gradient {
GradientStop { position: 0.0; color: main.topColor }
GradientStop { position: 1.0; color: main.topGradientColor }
}
}
BgLogo {
id: mainBackgroundLogo
anchors.leftMargin: sidebar.width
}
}
MouseArea {
id: mainMouseArea
anchors.fill: parent
acceptedButtons: Qt.AllButtons
hoverEnabled: true
propagateComposedEvents: true
onMouseXChanged: resetLockTimer()
onPressedChanged: resetLockTimer()
}
Keys.onReleased: {
resetLockTimer()
}
property var contentItems : [
{name: "wallet"},
{name: "atomic_swap"},
// {name: "dex"},
{name: "addresses"},
{name: "notifications"},
{name: "applications", qml: function () {
return BeamGlobals.isFork3() ? "applications" : "applications_nofork"
}
},
{name: "daocore"}
]
property int selectedItem
Item {
id: sidebar
width: 70
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.top: parent.top
Rectangle {
anchors.fill: parent
color: Style.navigation_background
opacity: 0.1
border.width: 0
}
SvgImage {
id: image
y: 50
anchors.horizontalCenter: parent.horizontalCenter
source: Style.navigation_logo
smooth: true
}
Column {
width: 0
height: 0
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
anchors.top: parent.top
anchors.topMargin: 130
Repeater{
id: controls
model: contentItems
Item {
id: control
width: parent.width
height: 66
activeFocusOnTab: true
SvgImage {
id: icon
x: 21
y: 16
width: 28
height: 28
source: "qrc:/assets/icon-" + modelData.name + (selectedItem == index ? "-active" : "") + ".svg"
}
Item {
Rectangle {
id: indicator
y: 6
width: 4
height: 48
color: selectedItem == index ? Style.active : Style.passive
}
DropShadow {
anchors.fill: indicator
radius: 5
samples: 9
color: Style.active
source: indicator
}
visible: selectedItem == index
}
Item {
visible: contentItems[index].name == 'notifications' && viewModel.unreadNotifications > 0
Rectangle {
id: counter
x: 42
y: 9
width: 16
height: 16
radius: width/2
color: Style.active
SFText {
height: 14
text: viewModel.unreadNotifications
font.pixelSize: 12
anchors.centerIn: counter
}
}
DropShadow {
anchors.fill: counter
radius: 5
samples: 9
source: counter
color: Style.active
}
}
Rectangle {
x: 10
width: parent.width - 20
height: 2
color: Style.background_button
visible: contentItems[index].name == 'applications'
}
Keys.onPressed: {
if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter || event.key == Qt.Key_Space) && selectedItem != index)
updateItem(index);
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
control.focus = true
if (selectedItem != index)
updateItem(index)
}
hoverEnabled: true
}
}
}
}
Item {
id: control
width: parent.width
height: 66
activeFocusOnTab: true
anchors.bottom: parent.bottom
SvgImage {
id: icon
x: 21
y: 16
width: 28
height: 28
source: "qrc:/assets/icon-settings" + (selectedItem == -1 ? "-active" : "") + ".svg"
}
Item {
Rectangle {
id: indicator
y: 6
width: 4
height: 48
color: selectedItem == -1 ? Style.active : Style.passive
}
DropShadow {
anchors.fill: indicator
radius: 5
samples: 9
color: Style.active
source: indicator
}
visible: selectedItem == -1
}
Keys.onPressed: {
if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter || event.key == Qt.Key_Space) && selectedItem != index)
updateItem(-1);
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
control.focus = true
if (selectedItem != -1)
updateItem(-1)
}
hoverEnabled: true
}
}
}
Loader {
id: content
anchors.topMargin: 45
anchors.bottomMargin: 0
anchors.rightMargin: 20
anchors.leftMargin: 90
anchors.fill: parent
focus: true
}
function updateItem(indexOrID, props)
{
var update = function(index) {
selectedItem = index;
var source = "";
var args = Object.assign({"openSend": false}, props);
if (index >= 0) {
controls.itemAt(index).focus = true;
function isApp(element, index, array) {
return element.qml && (contentItems[index].qml() == "applications" || contentItems[index].qml() == "applications_nofork");
}
var appIndex = contentItems.findIndex(isApp);
if (appIndex >= 0 && index > appIndex) {
source = "qrc:/applications.qml";
args = Object.assign({"appCmd": contentItems[index].name}, args);
} else {
source = ["qrc:/", contentItems[index].qml ? contentItems[index].qml() : contentItems[index].name, ".qml"].join('');
}
} else if (index == -1) {
source = "qrc:/settings.qml";
}
content.setSource(source, args)
viewModel.update(index)
}
if (typeof(indexOrID) == "string") {
if (indexOrID == "settings")
return update(-1);
for (var index = 0; index < contentItems.length; index++) {
if (contentItems[index].name == indexOrID) {
return update(index);
}
}
}
// plain index passed
update(indexOrID)
}
function openMaxPrivacyCoins (assetId, unitName, lockedAmount) {
var details = Qt.createComponent("controls/MaxPrivacyCoinsDialog.qml").createObject(main, {
"unitName": unitName,
"lockedAmount": lockedAmount,
"assetId": assetId,
});
details.open()
}
function openWallet () {
updateItem("wallet")
}
function openSendDialog(receiver) {
updateItem("wallet", {"openSend": true, "token" : receiver})
}
function openReceiveDialog(token) {
updateItem("wallet", {"openReceive": true, "token" : token})
}
function openSwapSettings(coinID) {
updateItem("settings", {swapMode: typeof(coinID) == "string" ? coinID : "ALL"})
}
function openSwapActiveTransactionsList() {
updateItem("atomic_swap", {"shouldShowActiveTransactions": true})
}
function openTransactionDetails(id) {
updateItem("wallet", {"openedTxID": id})
}
function openSwapTransactionDetails(id) {
updateItem("atomic_swap", {"openedTxID": id})
}
function openApplications () {
updateItem("applications")
}
function resetLockTimer() {
viewModel.resetLockTimer();
}
property var trezor_popups : []
Connections {
target: viewModel
function onGotoStartScreen () {
main.parent.setSource("qrc:/start.qml", {"isLockedMode": true});
}
function onShowTrezorMessage () {
var popup = Qt.createComponent("popup_message.qml").createObject(main)
//% "Please, look at your Trezor device to complete actions..."
popup.message = qsTrId("trezor-message")
popup.open()
trezor_popups.push(popup)
}
function onHideTrezorMessage () {
console.log("onHideTrezorMessage")
if (trezor_popups.length > 0) {
var popup = trezor_popups.pop()
popup.close()
}
}
function onShowTrezorError (error) {
console.log(error)
var popup = Qt.createComponent("popup_message.qml").createObject(main)
popup.message = error
popup.open()
trezor_popup.push(popup)
}
}
Component.onCompleted: {
openWallet()
}
Component.onDestruction: {
main.Window.window.closing.disconnect(onClosing)
}
}