55import  QtQuick  2.15 
66import  QtQuick.Controls  2.15 
77import  QtQuick.Layouts  1.15 
8+ import  QtQuick.Dialogs  1.3 
9+ 
810
911import  "../controls" 
1012
1113ColumnLayout  {
1214    signal snapshotImportCompleted ()
1315    property int snapshotVerificationCycles:  0 
1416    property real snapshotVerificationProgress:  0 
15-     property bool snapshotVerified:  false 
17+     property bool snapshotVerified:  optionsModel . snapshotLoadCompleted 
1618
1719    id:  columnLayout
1820    width:  Math .min (parent .width , 450 )
1921    anchors .horizontalCenter :  parent .horizontalCenter 
2022
21- 
23+      //  TODO: Remove simulation timer before release 
2224    Timer {
2325        id:  snapshotSimulationTimer
2426        interval:  50  //  Update every 50ms
@@ -42,7 +44,7 @@ ColumnLayout {
4244
4345    StackLayout {
4446        id:  settingsStack
45-         currentIndex:  0 
47+         currentIndex:  optionsModel . snapshotLoadCompleted   ?   2   :   0 
4648
4749        ColumnLayout {
4850            Layout .alignment :  Qt .AlignHCenter 
@@ -78,8 +80,26 @@ ColumnLayout {
7880                Layout .alignment :  Qt .AlignCenter 
7981                text:  qsTr (" Choose snapshot file" 
8082                onClicked:  {
81-                     settingsStack .currentIndex  =  1 
82-                     snapshotSimulationTimer .start ()
83+                     //  TODO: Connect this to snapshot loading
84+                     //  settingsStack.currentIndex = 1
85+                     fileDialog .open ()
86+                 }
87+             }
88+ 
89+             FileDialog {
90+                 id:  fileDialog
91+                 folder:  shortcuts .home 
92+                 selectMultiple:  false 
93+                 onAccepted:  {
94+                     console .log (" File chosen:" fileDialog .fileUrls )
95+                     var  snapshotFileName =  fileDialog .fileUrl .toString ()
96+                     console .log (" Snapshot file name:" 
97+                     if  (snapshotFileName .endsWith (" .dat" 
98+                         //  optionsModel.setSnapshotDirectory(snapshotFileName)
99+                         //  console.log("Snapshot directory set:", optionsModel.getSnapshotDirectory())
100+                         optionsModel .initializeSnapshot (true , snapshotFileName)
101+                         settingsStack .currentIndex  =  1 
102+                     }
83103                }
84104            }
85105        }
@@ -109,10 +129,27 @@ ColumnLayout {
109129                Layout .topMargin :  20 
110130                width:  200 
111131                height:  20 
112-                 progress:  snapshotVerificationProgress 
132+                 progress:  optionsModel . snapshotProgress 
113133                Layout .alignment :  Qt .AlignCenter 
114134                progressColor:  Theme .color .blue 
115135            }
136+ 
137+             Connections {
138+                 target:  optionsModel
139+                 function  onSnapshotProgressChanged () {
140+                     progressIndicator .progress  =  optionsModel .snapshotProgress 
141+                 }
142+                 function  onSnapshotLoadCompletedChanged (success ) {
143+                     if  (success) {
144+                         progressIndicator .progress  =  1 
145+                         settingsStack .currentIndex  =  2   //  Move to the "Snapshot Loaded" page
146+                     } else  {
147+                         //  Handle snapshot loading failure
148+                         console .error (" Snapshot loading failed" 
149+                         //  You might want to show an error message or take other actions here
150+                     }
151+                 }
152+             }
116153        }
117154
118155        ColumnLayout {
@@ -137,8 +174,8 @@ ColumnLayout {
137174                descriptionColor:  Theme .color .neutral6 
138175                descriptionSize:  17 
139176                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." 
177+                 description:  qsTr (" It contains transactions up to %1 . Newer transactions still need to be downloaded." + 
178+                 "  The data will be verified in the background." . arg ( optionsModel . snapshotDate ) 
142179            }
143180
144181            ContinueButton {
@@ -188,14 +225,17 @@ ColumnLayout {
188225                        font .pixelSize :  14 
189226                    }
190227                    CoreText {
191-                         text:  qsTr (" 200,000" 
228+                         //  text: qsTr("160,000")
229+                         text:  optionsModel .snapshotBlockHeight .toLocaleString (Qt .locale (), ' f' 0 )
192230                        Layout .alignment :  Qt .AlignRight 
193231                        font .pixelSize :  14 
194232                    }
195233                }
196234                Separator { Layout .fillWidth :  true  }
197235                CoreText {
198-                     text:  qsTr (" Hash: 0x1234567890abcdef..." 
236+                     //  text: qsTr("Hash: 0x1234567890abcdef...")
237+                     //  TODO: truncate the hash to 8 characters
238+                     text:  qsTr (" Hash: %1" arg (optionsModel .snapshotBlockHash )
199239                    font .pixelSize :  14 
200240                }
201241            }
0 commit comments