2022-10-28 17:17:16 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
|
2023-01-12 22:39:46 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
2022-10-28 17:17:16 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
ChartStoreBase {
|
|
|
|
id: root
|
|
|
|
|
2022-11-15 21:48:59 +00:00
|
|
|
readonly property alias address: d.address
|
|
|
|
readonly property alias tokenSymbol: d.tokenSymbol
|
|
|
|
readonly property alias currencySymbol: d.currencySymbol
|
2023-11-29 11:19:59 +00:00
|
|
|
readonly property alias allAddresses: d.allAddresses
|
2022-11-15 21:48:59 +00:00
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
// Data identity received from backend
|
|
|
|
property var chainIds: []
|
|
|
|
property string address
|
2023-11-29 11:19:59 +00:00
|
|
|
property bool allAddresses: false
|
2022-11-15 21:48:59 +00:00
|
|
|
property string tokenSymbol
|
|
|
|
property string currencySymbol
|
|
|
|
}
|
|
|
|
|
2023-11-29 11:19:59 +00:00
|
|
|
function hasData(address, allAddresses, tokenSymbol, currencySymbol, timeRangeEnum) {
|
|
|
|
return address === d.address && allAddresses === d.allAddresses && tokenSymbol === d.tokenSymbol && currencySymbol === d.currencySymbol
|
2022-11-15 21:48:59 +00:00
|
|
|
&& root.dataRange[root.timeRangeEnumToTimeIndex(timeRangeEnum)][root.timeRangeEnumToStr(timeRangeEnum)].length > 0
|
|
|
|
}
|
2022-10-28 17:17:16 +00:00
|
|
|
|
|
|
|
/// \arg timeRange: of type ChartStoreBase.TimeRange
|
2023-11-29 11:19:59 +00:00
|
|
|
function setData(address, allAddresses, tokenSymbol, currencySymbol, timeRange, timeRangeData, balanceData) {
|
2022-10-28 17:17:16 +00:00
|
|
|
switch(timeRange) {
|
|
|
|
case ChartStoreBase.TimeRange.Weekly:
|
|
|
|
root.weeklyData = balanceData
|
|
|
|
root.weeklyMaxTicks = 0
|
|
|
|
break;
|
|
|
|
case ChartStoreBase.TimeRange.Monthly:
|
|
|
|
root.monthlyData = balanceData
|
|
|
|
root.monthlyMaxTicks = 0
|
|
|
|
break;
|
|
|
|
case ChartStoreBase.TimeRange.HalfYearly:
|
|
|
|
root.halfYearlyData = balanceData
|
|
|
|
root.halfYearlyMaxTicks = 0
|
|
|
|
break;
|
|
|
|
case ChartStoreBase.TimeRange.Yearly:
|
|
|
|
root.yearlyData = balanceData
|
|
|
|
root.yearlyMaxTicks = 0
|
|
|
|
break;
|
|
|
|
case ChartStoreBase.TimeRange.All:
|
|
|
|
root.allData = balanceData
|
|
|
|
root.allTimeRangeTicks = 0
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.warn("Invalid or unsupported time range")
|
2022-11-15 21:48:59 +00:00
|
|
|
return
|
2022-10-28 17:17:16 +00:00
|
|
|
}
|
2022-11-15 21:48:59 +00:00
|
|
|
|
|
|
|
d.address = address
|
2023-11-29 11:19:59 +00:00
|
|
|
d.allAddresses = allAddresses
|
2022-11-15 21:48:59 +00:00
|
|
|
d.tokenSymbol = tokenSymbol
|
|
|
|
d.currencySymbol = currencySymbol
|
|
|
|
|
|
|
|
root.newDataReady(address, tokenSymbol, currencySymbol, timeRange)
|
2022-10-28 17:17:16 +00:00
|
|
|
}
|
|
|
|
|
2023-11-29 11:19:59 +00:00
|
|
|
function resetAllData(address, allAddresses, tokenSymbol, currencySymbol) {
|
2022-11-15 21:48:59 +00:00
|
|
|
for (let tR = ChartStoreBase.TimeRange.Weekly; tR <= ChartStoreBase.TimeRange.All; tR++) {
|
2023-11-29 11:19:59 +00:00
|
|
|
root.setData(address, allAddresses, tokenSymbol, currencySymbol, tR, [], [])
|
2022-11-15 21:48:59 +00:00
|
|
|
}
|
2022-10-28 17:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: walletSectionAllTokens
|
2022-11-15 21:48:59 +00:00
|
|
|
|
|
|
|
function onTokenBalanceHistoryDataReady(balanceHistoryJson: string) {
|
|
|
|
// chainIds, address, tokenSymbol, currencySymbol, timeInterval
|
|
|
|
let response = JSON.parse(balanceHistoryJson)
|
|
|
|
if(typeof response.error !== "undefined") {
|
|
|
|
console.warn("error in balance history: " + response.error)
|
2022-10-28 17:17:16 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-29 11:19:59 +00:00
|
|
|
if (!response.allAddresses && response.addresses.length > 0) {
|
|
|
|
response.address = response.addresses[0]
|
|
|
|
} else {
|
|
|
|
response.address = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d.allAddresses != response.allAddresses || d.address != response.address || d.tokenSymbol != response.tokenSymbol || d.currencySymbol != response.currencySymbol) {
|
|
|
|
root.resetAllData(response.address, response.allAddresses, response.tokenSymbol, response.currencySymbol)
|
2022-11-15 21:48:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-28 17:17:16 +00:00
|
|
|
if(typeof response.historicalData === "undefined" || response.historicalData === null || response.historicalData.length == 0) {
|
2022-11-15 21:48:59 +00:00
|
|
|
console.info("no data in balance history")
|
2022-10-28 17:17:16 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var tmpDataValues = []
|
|
|
|
for(let i = 0; i < response.historicalData.length; i++) {
|
|
|
|
let dataEntry = response.historicalData[i]
|
2023-09-15 17:27:00 +00:00
|
|
|
tmpDataValues.push({ x: new Date(dataEntry.time * 1000), y: dataEntry.value })
|
2022-10-28 17:17:16 +00:00
|
|
|
}
|
|
|
|
|
2023-11-29 11:19:59 +00:00
|
|
|
root.setData(response.address, response.allAddresses, response.tokenSymbol, response.currencySymbol, response.timeInterval, [], tmpDataValues)
|
2022-10-28 17:17:16 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-12 22:39:46 +00:00
|
|
|
}
|