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