55import QtQuick 2.15
66import QtQuick.Controls 2.15
77import QtQuick.Layouts 1.15
8+ import QtQuick.Dialogs 1.3
89
910import "../controls"
1011
1112ColumnLayout {
13+ property bool snapshotLoading: nodeModel .snapshotLoading
1214 signal snapshotImportCompleted ()
1315 property int snapshotVerificationCycles: 0
1416 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: ({})
1621
1722 id: columnLayout
1823 width: Math .min (parent .width , 450 )
1924 anchors .horizontalCenter : parent .horizontalCenter
2025
21-
26+ // TODO: remove this before release
2227 Timer {
2328 id: snapshotSimulationTimer
2429 interval: 50 // Update every 50ms
@@ -29,7 +34,7 @@ ColumnLayout {
2934 snapshotVerificationProgress += 0.01
3035 } else {
3136 snapshotVerificationCycles++
32- if (snapshotVerificationCycles < 1 ) {
37+ if (snapshotVerificationCycles < 3 ) {
3338 snapshotVerificationProgress = 0
3439 } else {
3540 running = false
@@ -42,7 +47,7 @@ ColumnLayout {
4247
4348 StackLayout {
4449 id: settingsStack
45- currentIndex: 0
50+ currentIndex: onboarding ? 0 : snapshotVerified ? 2 : snapshotLoading ? 1 : 0
4651
4752 ColumnLayout {
4853 Layout .alignment : Qt .AlignHCenter
@@ -78,8 +83,25 @@ ColumnLayout {
7883 Layout .alignment : Qt .AlignCenter
7984 text: qsTr (" Choose snapshot file" )
8085 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+ }
83105 }
84106 }
85107 }
@@ -102,17 +124,37 @@ ColumnLayout {
102124 Layout .leftMargin : 20
103125 Layout .rightMargin : 20
104126 header: qsTr (" Loading Snapshot" )
127+ description: qsTr (" This might take a while..." )
105128 }
106129
107130 ProgressIndicator {
108131 id: progressIndicator
109132 Layout .topMargin : 20
110133 width: 200
111134 height: 20
112- progress: snapshotVerificationProgress
135+ progress: nodeModel . snapshotProgress
113136 Layout .alignment : Qt .AlignCenter
114137 progressColor: Theme .color .blue
115138 }
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+ }
116158 }
117159
118160 ColumnLayout {
@@ -137,8 +179,11 @@ ColumnLayout {
137179 descriptionColor: Theme .color .neutral6
138180 descriptionSize: 17
139181 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." )
142187 }
143188
144189 ContinueButton {
@@ -188,16 +233,26 @@ ColumnLayout {
188233 font .pixelSize : 14
189234 }
190235 CoreText {
191- text: qsTr (" 200,000" )
236+ text: snapshotInfo && snapshotInfo[" height" ] ?
237+ snapshotInfo[" height" ] : qsTr (" DEBUG" )
192238 Layout .alignment : Qt .AlignRight
193239 font .pixelSize : 14
194240 }
195241 }
196242 Separator { Layout .fillWidth : true }
197243 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" )
199248 font .pixelSize : 14
200249 }
250+
251+ Component .onCompleted : {
252+ if (snapshotVerified) {
253+ snapshotInfo = chainModel .getSnapshotInfo ()
254+ }
255+ }
201256 }
202257 }
203258 }
0 commit comments