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: nodeModel .snapshotLoading
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 before release
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,7 @@ ColumnLayout {
42
47
43
48
StackLayout {
44
49
id: settingsStack
45
- currentIndex: 0
50
+ currentIndex: onboarding ? 0 : snapshotVerified ? 2 : snapshotLoading ? 1 : 0
46
51
47
52
ColumnLayout {
48
53
Layout .alignment : Qt .AlignHCenter
@@ -78,8 +83,24 @@ ColumnLayout {
78
83
Layout .alignment : Qt .AlignCenter
79
84
text: qsTr (" Choose snapshot file" )
80
85
onClicked: {
81
- settingsStack .currentIndex = 1
82
- snapshotSimulationTimer .start ()
86
+ fileDialog .open ()
87
+ }
88
+ }
89
+
90
+ FileDialog {
91
+ id: fileDialog
92
+ folder: shortcuts .home
93
+ selectMultiple: false
94
+ onAccepted: {
95
+ console .log (" File chosen:" , fileDialog .fileUrls )
96
+ snapshotFileName = fileDialog .fileUrl .toString ()
97
+ console .log (" Snapshot file name:" , snapshotFileName)
98
+ if (snapshotFileName .endsWith (" .dat" )) {
99
+ nodeModel .initializeSnapshot (true , snapshotFileName)
100
+ // nodeModel.presyncProgress
101
+ } else {
102
+ console .error (" Snapshot loading failed" )
103
+ }
83
104
}
84
105
}
85
106
}
@@ -102,17 +123,37 @@ ColumnLayout {
102
123
Layout .leftMargin : 20
103
124
Layout .rightMargin : 20
104
125
header: qsTr (" Loading Snapshot" )
126
+ description: qsTr (" This might take a while..." )
105
127
}
106
128
107
129
ProgressIndicator {
108
130
id: progressIndicator
109
131
Layout .topMargin : 20
110
132
width: 200
111
133
height: 20
112
- progress: snapshotVerificationProgress
134
+ progress: nodeModel . snapshotProgress
113
135
Layout .alignment : Qt .AlignCenter
114
136
progressColor: Theme .color .blue
115
137
}
138
+
139
+ Connections {
140
+ target: nodeModel
141
+ function onSnapshotProgressChanged () {
142
+ progressIndicator .progress = nodeModel .snapshotProgress
143
+ }
144
+
145
+ function onSnapshotLoaded (success ) {
146
+ if (success) {
147
+ chainModel .isSnapshotActiveChanged ()
148
+ snapshotVerified = chainModel .isSnapshotActive
149
+ snapshotInfo = chainModel .getSnapshotInfo ()
150
+ settingsStack .currentIndex = 2 // Move to the "Snapshot Loaded" page
151
+ } else {
152
+ // Handle snapshot loading failure
153
+ console .error (" Snapshot loading failed" )
154
+ }
155
+ }
156
+ }
116
157
}
117
158
118
159
ColumnLayout {
@@ -137,8 +178,11 @@ ColumnLayout {
137
178
descriptionColor: Theme .color .neutral6
138
179
descriptionSize: 17
139
180
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." )
181
+ description: snapshotInfo && snapshotInfo[" date" ] ?
182
+ qsTr (" It contains transactions up to %1. Newer transactions still need to be downloaded." +
183
+ " The data will be verified in the background." ).arg (snapshotInfo[" date" ]) :
184
+ qsTr (" It contains transactions up to DEBUG. Newer transactions still need to be downloaded." +
185
+ " The data will be verified in the background." )
142
186
}
143
187
144
188
ContinueButton {
@@ -188,16 +232,26 @@ ColumnLayout {
188
232
font .pixelSize : 14
189
233
}
190
234
CoreText {
191
- text: qsTr (" 200,000" )
235
+ text: snapshotInfo && snapshotInfo[" height" ] ?
236
+ snapshotInfo[" height" ] : qsTr (" DEBUG" )
192
237
Layout .alignment : Qt .AlignRight
193
238
font .pixelSize : 14
194
239
}
195
240
}
196
241
Separator { Layout .fillWidth : true }
197
242
CoreText {
198
- text: qsTr (" Hash: 0x1234567890abcdef..." )
243
+ // The CoreText component displays the hash of the loaded snapshot.
244
+ text: snapshotInfo && snapshotInfo[" hashSerialized" ] ?
245
+ qsTr (" Hash: %1" ).arg (snapshotInfo[" hashSerialized" ].substring (0 , 13 ) + " ..." ) :
246
+ qsTr (" Hash: DEBUG" )
199
247
font .pixelSize : 14
200
248
}
249
+
250
+ Component .onCompleted : {
251
+ if (snapshotVerified) {
252
+ snapshotInfo = chainModel .getSnapshotInfo ()
253
+ }
254
+ }
201
255
}
202
256
}
203
257
}
0 commit comments