5
5
import QtQuick 2.15
6
6
import QtQuick.Controls 2.15
7
7
import QtQuick.Layouts 1.15
8
+ import QtQuick.Dialogs 1.3
8
9
9
10
import "../controls"
10
11
11
12
ColumnLayout {
13
+ property bool snapshotLoading: false
12
14
signal snapshotImportCompleted ()
13
15
property int snapshotVerificationCycles: 0
14
16
property real snapshotVerificationProgress: 0
15
- property bool snapshotVerified: false
17
+ property bool onboarding: false
18
+ property bool snapshotVerified: onboarding ? false : chainModel .isSnapshotActive
19
+ property string snapshotFileName: " "
20
+ property var snapshotInfo: ({})
16
21
17
22
id: columnLayout
18
23
width: Math .min (parent .width , 450 )
19
24
anchors .horizontalCenter : parent .horizontalCenter
20
25
21
-
26
+ // TODO: Remove this once the verification progress is available
22
27
Timer {
23
28
id: snapshotSimulationTimer
24
29
interval: 50 // Update every 50ms
@@ -29,7 +34,7 @@ ColumnLayout {
29
34
snapshotVerificationProgress += 0.01
30
35
} else {
31
36
snapshotVerificationCycles++
32
- if (snapshotVerificationCycles < 1 ) {
37
+ if (snapshotVerificationCycles < 3 ) {
33
38
snapshotVerificationProgress = 0
34
39
} else {
35
40
running = false
@@ -42,7 +47,16 @@ ColumnLayout {
42
47
43
48
StackLayout {
44
49
id: settingsStack
45
- currentIndex: 0
50
+ currentIndex: onboarding ? 0 : snapshotVerified ? 2 : 0
51
+
52
+ function startLoading () {
53
+ snapshotLoading = true ;
54
+ settingsStack .currentIndex = 1 ; // Navigate to loading page
55
+ }
56
+
57
+ function stopLoading () {
58
+ snapshotLoading = false ;
59
+ }
46
60
47
61
ColumnLayout {
48
62
Layout .alignment : Qt .AlignHCenter
@@ -78,8 +92,23 @@ ColumnLayout {
78
92
Layout .alignment : Qt .AlignCenter
79
93
text: qsTr (" Choose snapshot file" )
80
94
onClicked: {
81
- settingsStack .currentIndex = 1
82
- snapshotSimulationTimer .start ()
95
+ fileDialog .open ()
96
+ }
97
+ }
98
+
99
+ FileDialog {
100
+ id: fileDialog
101
+ folder: shortcuts .home
102
+ selectMultiple: false
103
+ onAccepted: {
104
+ console .log (" File chosen:" , fileDialog .fileUrls )
105
+ snapshotFileName = fileDialog .fileUrl .toString ()
106
+ console .log (" Snapshot file name:" , snapshotFileName)
107
+ if (snapshotFileName .endsWith (" .dat" )) {
108
+ nodeModel .initializeSnapshot (true , snapshotFileName)
109
+ nodeModel .presyncProgress
110
+ settingsStack .startLoading ()
111
+ }
83
112
}
84
113
}
85
114
}
@@ -102,17 +131,50 @@ ColumnLayout {
102
131
Layout .leftMargin : 20
103
132
Layout .rightMargin : 20
104
133
header: qsTr (" Loading Snapshot" )
134
+ description: qsTr (" This might take a while..." )
105
135
}
106
136
137
+ // TODO: uncomment this once snapshot verification progress is available
107
138
ProgressIndicator {
108
139
id: progressIndicator
109
140
Layout .topMargin : 20
110
141
width: 200
111
142
height: 20
112
- progress: snapshotVerificationProgress
143
+ // TODO: uncomment this once the verification progress is available
144
+ // progress: nodeModel.verificationProgress
145
+ // progress: 0
146
+ progress: nodeModel .snapshotProgress
113
147
Layout .alignment : Qt .AlignCenter
114
148
progressColor: Theme .color .blue
115
149
}
150
+
151
+ Connections {
152
+ target: nodeModel
153
+ // TODO: uncomment this once the verification progress is available
154
+ // function onVerificationProgressChanged() {
155
+ // progressIndicator.progress = nodeModel.verificationProgress
156
+ // }
157
+ function onSnapshotProgressChanged () {
158
+ progressIndicator .progress = nodeModel .snapshotProgress
159
+ }
160
+ // function onPresyncProgressChanged() {
161
+ // progressIndicator.progress = nodeModel.presyncProgress
162
+ // }
163
+
164
+ function onSnapshotLoaded (success ) {
165
+ if (success) {
166
+ chainModel .isSnapshotActiveChanged ()
167
+ snapshotVerified = chainModel .isSnapshotActive
168
+ snapshotInfo = chainModel .getSnapshotInfo ()
169
+ settingsStack .stopLoading ()
170
+ // progressIndicator.progress = 1
171
+ settingsStack .currentIndex = 2 // Move to the "Snapshot Loaded" page
172
+ } else {
173
+ // Handle snapshot loading failure
174
+ console .error (" Snapshot loading failed" )
175
+ }
176
+ }
177
+ }
116
178
}
117
179
118
180
ColumnLayout {
@@ -137,8 +199,11 @@ ColumnLayout {
137
199
descriptionColor: Theme .color .neutral6
138
200
descriptionSize: 17
139
201
descriptionLineHeight: 1.1
140
- description: qsTr (" It contains transactions up to January 12, 2024. Newer transactions still need to be downloaded." +
141
- " The data will be verified in the background." )
202
+ description: snapshotInfo && snapshotInfo[" date" ] ?
203
+ qsTr (" It contains transactions up to %1. Newer transactions still need to be downloaded." +
204
+ " The data will be verified in the background." ).arg (snapshotInfo[" date" ]) :
205
+ qsTr (" It contains transactions up to DEBUG. Newer transactions still need to be downloaded." +
206
+ " The data will be verified in the background." )
142
207
}
143
208
144
209
ContinueButton {
@@ -188,16 +253,25 @@ ColumnLayout {
188
253
font .pixelSize : 14
189
254
}
190
255
CoreText {
191
- text: qsTr (" 200,000" )
256
+ text: snapshotInfo && snapshotInfo[" height" ] ?
257
+ snapshotInfo[" height" ] : qsTr (" DEBUG" )
192
258
Layout .alignment : Qt .AlignRight
193
259
font .pixelSize : 14
194
260
}
195
261
}
196
262
Separator { Layout .fillWidth : true }
197
263
CoreText {
198
- text: qsTr (" Hash: 0x1234567890abcdef..." )
264
+ text: snapshotInfo && snapshotInfo[" hashSerialized" ] ?
265
+ qsTr (" Hash: %1" ).arg (snapshotInfo[" hashSerialized" ].substring (0 , 13 ) + " ..." ) :
266
+ qsTr (" Hash: DEBUG" )
199
267
font .pixelSize : 14
200
268
}
269
+
270
+ Component .onCompleted : {
271
+ if (snapshotVerified) {
272
+ snapshotInfo = chainModel .getSnapshotInfo ()
273
+ }
274
+ }
201
275
}
202
276
}
203
277
}
0 commit comments