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: false
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 once the verification progress is available
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,16 @@ ColumnLayout {
4247
4348 StackLayout {
4449 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+ }
4660
4761 ColumnLayout {
4862 Layout .alignment : Qt .AlignHCenter
@@ -78,8 +92,23 @@ ColumnLayout {
7892 Layout .alignment : Qt .AlignCenter
7993 text: qsTr (" Choose snapshot file" )
8094 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+ }
83112 }
84113 }
85114 }
@@ -102,17 +131,50 @@ ColumnLayout {
102131 Layout .leftMargin : 20
103132 Layout .rightMargin : 20
104133 header: qsTr (" Loading Snapshot" )
134+ description: qsTr (" This might take a while..." )
105135 }
106136
137+ // TODO: uncomment this once snapshot verification progress is available
107138 ProgressIndicator {
108139 id: progressIndicator
109140 Layout .topMargin : 20
110141 width: 200
111142 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
113147 Layout .alignment : Qt .AlignCenter
114148 progressColor: Theme .color .blue
115149 }
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+ }
116178 }
117179
118180 ColumnLayout {
@@ -137,8 +199,11 @@ ColumnLayout {
137199 descriptionColor: Theme .color .neutral6
138200 descriptionSize: 17
139201 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." )
142207 }
143208
144209 ContinueButton {
@@ -188,16 +253,25 @@ ColumnLayout {
188253 font .pixelSize : 14
189254 }
190255 CoreText {
191- text: qsTr (" 200,000" )
256+ text: snapshotInfo && snapshotInfo[" height" ] ?
257+ snapshotInfo[" height" ] : qsTr (" DEBUG" )
192258 Layout .alignment : Qt .AlignRight
193259 font .pixelSize : 14
194260 }
195261 }
196262 Separator { Layout .fillWidth : true }
197263 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" )
199267 font .pixelSize : 14
200268 }
269+
270+ Component .onCompleted : {
271+ if (snapshotVerified) {
272+ snapshotInfo = chainModel .getSnapshotInfo ()
273+ }
274+ }
201275 }
202276 }
203277 }
0 commit comments