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,22 @@ 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:" 
107+                     if  (snapshotFileName .endsWith (" .dat" 
108+                         nodeModel .initializeSnapshot (true , snapshotFileName)
109+                         settingsStack .startLoading ()
110+                     }
83111                }
84112            }
85113        }
@@ -102,17 +130,49 @@ ColumnLayout {
102130                Layout .leftMargin :  20 
103131                Layout .rightMargin :  20 
104132                header:  qsTr (" Loading Snapshot" 
133+                 description:  qsTr (" This might take a while..." 
105134            }
106135
136+             //  TODO: uncomment this once snapshot verification progress is available
137+             /* 
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+ 
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+             }
116176        }
117177
118178        ColumnLayout {
@@ -137,8 +197,11 @@ ColumnLayout {
137197                descriptionColor:  Theme .color .neutral6 
138198                descriptionSize:  17 
139199                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." 
142205            }
143206
144207            ContinueButton {
@@ -188,16 +251,25 @@ ColumnLayout {
188251                        font .pixelSize :  14 
189252                    }
190253                    CoreText {
191-                         text:  qsTr (" 200,000" 
254+                         text:  snapshotInfo &&  snapshotInfo[" height" ? 
255+                             snapshotInfo[" height" :  qsTr (" DEBUG" 
192256                        Layout .alignment :  Qt .AlignRight 
193257                        font .pixelSize :  14 
194258                    }
195259                }
196260                Separator { Layout .fillWidth :  true  }
197261                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" 
199265                    font .pixelSize :  14 
200266                }
267+ 
268+                 Component .onCompleted :  {
269+                     if  (snapshotVerified) {
270+                         snapshotInfo =  chainModel .getSnapshotInfo ()
271+                     }
272+                 }
201273            }
202274        }
203275    }
0 commit comments