Files
pay/guis/mobile/AccountSyncState.qml
T

103 lines
3.4 KiB
QML
Raw Permalink Normal View History

2022-11-24 13:11:09 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2022-2024 Tom Zander <tom@flowee.org>
2022-11-24 13:11:09 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-11-23 19:04:03 +01:00
import QtQuick
import Flowee.org.pay;
2023-03-23 20:03:39 +01:00
import "../Flowee" as Flowee
2022-11-23 19:04:03 +01:00
Item {
id: root
visible: !account.uptodate
height: {
if (account.uptodate)
return 0;
var h = indicator.height + 3;
if (!root.uptodate)
h += progressbar.height + 10;
return h;
}
2022-11-23 19:04:03 +01:00
property QtObject account: null
property bool uptodate: false
2022-11-24 13:11:09 +01:00
property int startPos: account.initialBlockHeight
onAccountChanged: checkIfDone();
function checkIfDone() {
2022-11-24 13:11:09 +01:00
let startPos = account.initialBlockHeight;
if (startPos === -2) {
// special number, the account is just created and waits for transactions.
uptodate = true;
2022-11-24 13:11:09 +01:00
return;
}
let end = Pay.expectedChainHeight;
let currentPos = account.lastBlockSynched;
// only show the progress-circle when its more than 2 days behind
// and we are not synched
uptodate = end - startPos < 300 || end - currentPos <= 6;
}
Connections {
2024-11-29 15:50:42 +01:00
target: root.account
function onLastBlockSynchedChanged() { checkIfDone(); }
2022-11-23 19:04:03 +01:00
}
Flowee.Progressbar {
2023-03-23 20:03:39 +01:00
id: progressbar
x: 10
y: 10
2023-03-23 20:03:39 +01:00
width: parent.width - 20
visible: !root.uptodate
progress: {
2023-03-23 20:03:39 +01:00
let startPos = root.startPos;
let end = Pay.expectedChainHeight
if (startPos == 0)
return 0;
let currentPos = root.account.lastBlockSynched;
let totalDistance = end - startPos;
2024-11-29 19:37:10 +01:00
let ourProgress = currentPos - startPos;
return ourProgress / totalDistance;
}
progress2: {
let startPos = root.startPos;
let end = Pay.expectedChainHeight
if (startPos == 0)
return 0;
let currentPos = root.account.lastBlockSynched2;
let totalDistance = end - startPos;
2023-03-23 20:03:39 +01:00
let ourProgress = currentPos - startPos;
return ourProgress / totalDistance;
}
2022-11-23 19:04:03 +01:00
}
Flowee.Label {
id: indicator
width: parent.width
2023-03-23 20:03:39 +01:00
y: root.uptodate ? 0 : progressbar.height + 13
2022-11-23 19:04:03 +01:00
wrapMode: Text.Wrap
text: {
2024-11-29 15:50:42 +01:00
if (mainWindow.isLoading)
return "";
2022-11-23 19:04:03 +01:00
var account = portfolio.current;
if (account === null)
return "";
2025-02-26 14:04:58 +01:00
if (Pay.deviceOffline || (account.needsPinToOpen && !account.isDecrypted))
return qsTr("Status: Offline");
return account.timeBehind;
2022-11-23 19:04:03 +01:00
}
font.italic: true
2022-11-24 13:11:09 +01:00
Behavior on y { NumberAnimation { duration: 100 } }
2022-11-23 19:04:03 +01:00
}
2022-11-24 13:11:09 +01:00
Behavior on height { NumberAnimation { duration: 100 } }
2022-11-23 19:04:03 +01:00
}