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,22 @@ 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
+ settingsStack .startLoading ()
110
+ }
83
111
}
84
112
}
85
113
}
@@ -102,17 +130,49 @@ ColumnLayout {
102
130
Layout .leftMargin : 20
103
131
Layout .rightMargin : 20
104
132
header: qsTr (" Loading Snapshot" )
133
+ description: qsTr (" This might take a while..." )
105
134
}
106
135
136
+ // TODO: uncomment this once snapshot verification progress is available
137
+ /*
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
+
152
+ Connections {
153
+ target: nodeModel
154
+ // TODO: uncomment this once the verification progress is available
155
+ // function onVerificationProgressChanged() {
156
+ // progressIndicator.progress = nodeModel.verificationProgress
157
+ // }
158
+ // function onSnapshotProgressChanged() {
159
+ // progressIndicator.progress = nodeModel.snapshotProgress
160
+ // }
161
+
162
+ function onSnapshotLoaded (success ) {
163
+ if (success) {
164
+ chainModel .isSnapshotActiveChanged ()
165
+ snapshotVerified = chainModel .isSnapshotActive
166
+ snapshotInfo = chainModel .getSnapshotInfo ()
167
+ settingsStack .stopLoading ()
168
+ // progressIndicator.progress = 1
169
+ settingsStack .currentIndex = 2 // Move to the "Snapshot Loaded" page
170
+ } else {
171
+ // Handle snapshot loading failure
172
+ console .error (" Snapshot loading failed" )
173
+ }
174
+ }
175
+ }
116
176
}
117
177
118
178
ColumnLayout {
@@ -137,8 +197,11 @@ ColumnLayout {
137
197
descriptionColor: Theme .color .neutral6
138
198
descriptionSize: 17
139
199
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." )
200
+ description: snapshotInfo && snapshotInfo[" date" ] ?
201
+ qsTr (" It contains transactions up to %1. Newer transactions still need to be downloaded." +
202
+ " The data will be verified in the background." ).arg (snapshotInfo[" date" ]) :
203
+ qsTr (" It contains transactions up to DEBUG. Newer transactions still need to be downloaded." +
204
+ " The data will be verified in the background." )
142
205
}
143
206
144
207
ContinueButton {
@@ -188,16 +251,25 @@ ColumnLayout {
188
251
font .pixelSize : 14
189
252
}
190
253
CoreText {
191
- text: qsTr (" 200,000" )
254
+ text: snapshotInfo && snapshotInfo[" height" ] ?
255
+ snapshotInfo[" height" ] : qsTr (" DEBUG" )
192
256
Layout .alignment : Qt .AlignRight
193
257
font .pixelSize : 14
194
258
}
195
259
}
196
260
Separator { Layout .fillWidth : true }
197
261
CoreText {
198
- text: qsTr (" Hash: 0x1234567890abcdef..." )
262
+ text: snapshotInfo && snapshotInfo[" hashSerialized" ] ?
263
+ qsTr (" Hash: %1" ).arg (snapshotInfo[" hashSerialized" ].substring (0 , 13 ) + " ..." ) :
264
+ qsTr (" Hash: DEBUG" )
199
265
font .pixelSize : 14
200
266
}
267
+
268
+ Component .onCompleted : {
269
+ if (snapshotVerified) {
270
+ snapshotInfo = chainModel .getSnapshotInfo ()
271
+ }
272
+ }
201
273
}
202
274
}
203
275
}
0 commit comments