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 {
12- signal snapshotImportCompleted ()
13- property int snapshotVerificationCycles: 0
14- property real snapshotVerificationProgress: 0
15- property bool snapshotVerified: false
16-
1713 id: columnLayout
14+ signal back
15+ property bool snapshotLoading: nodeModel .snapshotLoading
16+ property bool snapshotLoaded: nodeModel .isSnapshotLoaded
17+ property bool snapshotImportCompleted: chainModel .isSnapshotActive
18+ property bool onboarding: false
19+ property bool snapshotVerified: onboarding ? false : chainModel .isSnapshotActive
20+ property string snapshotFileName: " "
21+ property var snapshotInfo: ({})
22+ property string selectedFile: " "
23+
1824 width: Math .min (parent .width , 450 )
1925 anchors .horizontalCenter : parent .horizontalCenter
2026
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-
4327 StackLayout {
4428 id: settingsStack
45- currentIndex: 0
29+ currentIndex: onboarding ? 0 : snapshotLoaded ? 2 : snapshotVerified ? 2 : snapshotLoading ? 1 : 0
4630
4731 ColumnLayout {
4832 Layout .alignment : Qt .AlignHCenter
@@ -77,11 +61,22 @@ ColumnLayout {
7761 Layout .bottomMargin : 20
7862 Layout .alignment : Qt .AlignCenter
7963 text: qsTr (" Choose snapshot file" )
80- onClicked: {
81- settingsStack .currentIndex = 1
82- snapshotSimulationTimer .start ()
64+ onClicked: fileDialog .open ()
65+ }
66+
67+ FileDialog {
68+ id: fileDialog
69+ folder: shortcuts .home
70+ selectMultiple: false
71+ selectExisting: true
72+ nameFilters: [" Snapshot files (*.dat)" , " All files (*)" ]
73+ onAccepted: {
74+ selectedFile = fileUrl .toString ()
75+ snapshotFileName = selectedFile
76+ nodeModel .initializeSnapshot (true , snapshotFileName)
8377 }
8478 }
79+ // TODO: Handle file error signal
8580 }
8681
8782 ColumnLayout {
@@ -102,17 +97,10 @@ 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
115- }
103+ // TODO: add progress indicator once the snapshot progress is implemented
116104 }
117105
118106 ColumnLayout {
@@ -137,20 +125,19 @@ ColumnLayout {
137125 descriptionColor: Theme .color .neutral6
138126 descriptionSize: 17
139127 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." )
128+ description: snapshotInfo && snapshotInfo[" date" ] ?
129+ qsTr (" It contains transactions up to %1. Newer transactions still need to be downloaded." +
130+ " The data will be verified in the background." ).arg (snapshotInfo[" date" ]) :
131+ qsTr (" It contains transactions up to DEBUG. Newer transactions still need to be downloaded." +
132+ " The data will be verified in the background." )
142133 }
143134
144135 ContinueButton {
145136 Layout .preferredWidth : Math .min (300 , columnLayout .width - 2 * Layout .leftMargin )
146137 Layout .topMargin : 40
147138 Layout .alignment : Qt .AlignCenter
148139 text: qsTr (" Done" )
149- onClicked: {
150- snapshotImportCompleted ()
151- connectionSwipe .decrementCurrentIndex ()
152- connectionSwipe .decrementCurrentIndex ()
153- }
140+ onClicked: back ()
154141 }
155142
156143 Setting {
@@ -188,16 +175,25 @@ ColumnLayout {
188175 font .pixelSize : 14
189176 }
190177 CoreText {
191- text: qsTr (" 200,000" )
178+ text: snapshotInfo && snapshotInfo[" height" ] ?
179+ snapshotInfo[" height" ] : qsTr (" DEBUG" )
192180 Layout .alignment : Qt .AlignRight
193181 font .pixelSize : 14
194182 }
195183 }
196184 Separator { Layout .fillWidth : true }
197185 CoreText {
198- text: qsTr (" Hash: 0x1234567890abcdef..." )
186+ text: snapshotInfo && snapshotInfo[" hashSerialized" ] ?
187+ qsTr (" Hash: %1" ).arg (snapshotInfo[" hashSerialized" ].substring (0 , 13 ) + " ..." ) :
188+ qsTr (" Hash: DEBUG" )
199189 font .pixelSize : 14
200190 }
191+
192+ Component .onCompleted : {
193+ if (snapshotVerified || snapshotLoaded) {
194+ snapshotInfo = chainModel .getSnapshotInfo ()
195+ }
196+ }
201197 }
202198 }
203199 }
0 commit comments