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+ id: columnLayout
14+ property bool snapshotLoading: nodeModel .snapshotLoading
1215 signal snapshotImportCompleted ()
13- property int snapshotVerificationCycles: 0
14- property real snapshotVerificationProgress: 0
15- property bool snapshotVerified: false
16+ property bool onboarding: false
17+ property bool snapshotVerified: onboarding ? false : chainModel .isSnapshotActive
18+ property string snapshotFileName: " "
19+ property var snapshotInfo: ({})
20+ property string selectedFile: " "
1621
17- id: columnLayout
1822 width: Math .min (parent .width , 450 )
1923 anchors .horizontalCenter : parent .horizontalCenter
2024
21-
22- Timer {
23- id: snapshotSimulationTimer
24- interval: 50 // Update every 50ms
25- running: false
26- repeat: true
27- onTriggered: {
28- if (snapshotVerificationProgress < 1 ) {
29- snapshotVerificationProgress += 0.01
30- } else {
31- snapshotVerificationCycles++
32- if (snapshotVerificationCycles < 1 ) {
33- snapshotVerificationProgress = 0
34- } else {
35- running = false
36- snapshotVerified = true
37- settingsStack .currentIndex = 2
38- }
39- }
40- }
41- }
42-
4325 StackLayout {
4426 id: settingsStack
45- currentIndex: 0
27+ currentIndex: onboarding ? 0 : snapshotVerified ? 2 : snapshotLoading ? 1 : 0
4628
4729 ColumnLayout {
4830 Layout .alignment : Qt .AlignHCenter
@@ -77,11 +59,24 @@ ColumnLayout {
7759 Layout .bottomMargin : 20
7860 Layout .alignment : Qt .AlignCenter
7961 text: qsTr (" Choose snapshot file" )
80- onClicked: {
81- settingsStack .currentIndex = 1
82- snapshotSimulationTimer .start ()
62+ onClicked: fileDialog .open ()
63+ }
64+
65+ FileDialog {
66+ id: fileDialog
67+ folder: shortcuts .home
68+ selectMultiple: false
69+ selectExisting: true
70+ nameFilters: [" Snapshot files (*.dat)" , " All files (*)" ]
71+ onAccepted: {
72+ selectedFile = String (fileUrl)
73+ snapshotFileName = selectedFile
74+ if (selectedFile .indexOf (" .dat" ) === selectedFile .length - 4 ) {
75+ nodeModel .initializeSnapshot (true , snapshotFileName)
76+ }
8377 }
8478 }
79+ // TODO: Handle file error signal
8580 }
8681
8782 ColumnLayout {
@@ -102,16 +97,22 @@ ColumnLayout {
10297 Layout .leftMargin : 20
10398 Layout .rightMargin : 20
10499 header: qsTr (" Loading Snapshot" )
100+ description: qsTr (" This might take a while..." )
105101 }
106102
107- ProgressIndicator {
108- id: progressIndicator
109- Layout .topMargin : 20
110- width: 200
111- height: 20
112- progress: snapshotVerificationProgress
113- Layout .alignment : Qt .AlignCenter
114- progressColor: Theme .color .blue
103+ // TODO: add progress indicator once the snapshot progress is implemented
104+
105+ Connections {
106+ target: nodeModel
107+ function onSnapshotLoaded (success ) {
108+ if (success) {
109+ chainModel .isSnapshotActiveChanged ()
110+ snapshotVerified = chainModel .isSnapshotActive
111+ snapshotInfo = chainModel .getSnapshotInfo ()
112+ settingsStack .currentIndex = 2
113+ }
114+ }
115+ // TODO: connect to snapshotProgressChanged once implemented
115116 }
116117 }
117118
@@ -137,8 +138,11 @@ ColumnLayout {
137138 descriptionColor: Theme .color .neutral6
138139 descriptionSize: 17
139140 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." )
141+ description: snapshotInfo && snapshotInfo[" date" ] ?
142+ qsTr (" It contains transactions up to %1. Newer transactions still need to be downloaded." +
143+ " The data will be verified in the background." ).arg (snapshotInfo[" date" ]) :
144+ qsTr (" It contains transactions up to DEBUG. Newer transactions still need to be downloaded." +
145+ " The data will be verified in the background." )
142146 }
143147
144148 ContinueButton {
@@ -188,16 +192,25 @@ ColumnLayout {
188192 font .pixelSize : 14
189193 }
190194 CoreText {
191- text: qsTr (" 200,000" )
195+ text: snapshotInfo && snapshotInfo[" height" ] ?
196+ snapshotInfo[" height" ] : qsTr (" DEBUG" )
192197 Layout .alignment : Qt .AlignRight
193198 font .pixelSize : 14
194199 }
195200 }
196201 Separator { Layout .fillWidth : true }
197202 CoreText {
198- text: qsTr (" Hash: 0x1234567890abcdef..." )
203+ text: snapshotInfo && snapshotInfo[" hashSerialized" ] ?
204+ qsTr (" Hash: %1" ).arg (snapshotInfo[" hashSerialized" ].substring (0 , 13 ) + " ..." ) :
205+ qsTr (" Hash: DEBUG" )
199206 font .pixelSize : 14
200207 }
208+
209+ Component .onCompleted : {
210+ if (snapshotVerified) {
211+ snapshotInfo = chainModel .getSnapshotInfo ()
212+ }
213+ }
201214 }
202215 }
203216 }
0 commit comments