Skip to content

Commit

Permalink
fix zhtlc sync percentage display
Browse files Browse the repository at this point in the history
  • Loading branch information
smk762 committed Dec 21, 2023
1 parent c7dff8d commit 33b2558
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 153 deletions.
101 changes: 49 additions & 52 deletions atomic_defi_design/Dex/Constants/General.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ QtObject {
readonly property string custom_coin_icons_path: os_file_prefix + API.app.settings_pg.get_custom_coins_icons_path() + "/"
readonly property string providerIconsPath: image_path + "providers/"

/* Timers */
property Timer prevent_coin_disabling: Timer { interval: 5000 }

function coinIcon(ticker)
{
if (ticker === "" || ticker === "All" || ticker===undefined)
Expand Down Expand Up @@ -67,19 +70,12 @@ QtObject {
}

function coinName(ticker) {
if(ticker === "" || ticker === "All" || ticker===undefined) {
return ""
} else {
const name = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker).name
return name
}
return (ticker === "" || ticker === "All" || ticker===undefined) ? "" : API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker).name
}

function canSend(ticker, progress=100)
{
if (!API.app.wallet_pg.send_available) return false
if (isZhtlc(ticker) && progress < 100) return false
return true
return !API.app.wallet_pg.send_available ? false : progress < 100 ? false : true
}

function isWalletOnly(ticker)
Expand All @@ -92,78 +88,84 @@ QtObject {
return API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker).is_faucet_coin
}

function isCoinWithMemo(ticker) {
const coin_info = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker)
return coin_info.has_memos
function isCoinWithMemo(ticker)
{
return API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker).has_memos
}

function getLanguage()
{
return API.app.settings_pg.lang
}

function isZhtlc(ticker)
function isZhtlc(coin)
{
const coin_info = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker)
return coin_info.is_zhtlc_family
return API.app.portfolio_pg.global_cfg_mdl.get_coin_info(coin).is_zhtlc_family
}

function isZhtlcReady(ticker)
function isZhtlcReady(coin)
{
if (!isZhtlc(ticker)) return true
let activation_status = API.app.get_zhtlc_status(ticker)
let progress = zhtlcActivationProgress(activation_status, ticker)
if (progress == 100) return true
return false
return !isZhtlc(coin) ? true : (zhtlcActivationProgress(coin) == 100) ? true : false
}

function zhtlcActivationProgress(activation_status, coin='ARRR')
{
let progress = 100
if (!activation_status.hasOwnProperty("result")) return progress
const coin_info = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(coin)
let block_offset = coin_info.checkpoint_height
if (!isZhtlc(coin)) return progress
if (!activation_status.hasOwnProperty("result"))
{
return progress
}
let status = activation_status.result.status
let details = activation_status.result.details
// use range from checkpoint block to present

if (!status)
{
return -1
return 0
}
else if (status == "Ok")
{
if (details.hasOwnProperty("error"))
{
console.log("["+coin+"] [zhtlcActivationProgress] Error enabling: " + JSON.stringify(details.error))
return 0
}
}
else if (status == "InProgress")
{
if (details.hasOwnProperty("UpdatingBlocksCache"))
{
block_offset = details.UpdatingBlocksCache.first_sync_block.actual
let n = details.UpdatingBlocksCache.current_scanned_block - block_offset
let d = details.UpdatingBlocksCache.latest_block - block_offset
progress = 5 + parseInt(n/d*20)
let current = details.UpdatingBlocksCache.current_scanned_block
let latest = details.UpdatingBlocksCache.latest_block
let abs_pct = parseFloat(current/latest)
progress = parseInt(15 * abs_pct)
// console.log("["+coin+"] [zhtlcActivationProgress] UpdatingBlocksCache ["+current+"/"+latest+" * "+abs_pct+" | "+progress+"%]: " + JSON.stringify(details.UpdatingBlocksCache))
}
else if (details.hasOwnProperty("BuildingWalletDb"))
{
block_offset = details.BuildingWalletDb.first_sync_block.actual
let n = details.BuildingWalletDb.current_scanned_block - block_offset
let d = details.BuildingWalletDb.latest_block - block_offset
progress = 45 + parseInt(n/d*60)
if (progress > 95) {
progress = 95
let current = details.BuildingWalletDb.current_scanned_block
let latest = details.BuildingWalletDb.latest_block
let abs_pct = parseFloat(current/latest)
progress = parseInt(98 * abs_pct)
// console.log("["+coin+"] [zhtlcActivationProgress] BuildingWalletDb ["+current+"/"+latest+" * "+abs_pct+" * 98 | "+progress+"%]: " + JSON.stringify(details.BuildingWalletDb))
if (progress < 15) {
progress = 15
}

else if (progress > 98) {
progress = 98
}
}
else if (details.hasOwnProperty("RequestingWalletBalance")) progress = 99
else if (details.hasOwnProperty("ActivatingCoin")) progress = 1
else
{
progress = 2
}
else if (details.hasOwnProperty("RequestingBalance")) progress = 95
else if (details.hasOwnProperty("ActivatingCoin")) progress = 5
else progress = 5
}
else console.log("["+coin+"] [zhtlcActivationProgress] Unexpected status: " + status)
else console.log("["+coin+"] [zhtlcActivationProgress] Unexpected status: " + JSON.stringify(status))
if (progress > 100) {
progress = 98
}

progress = 100
}
return progress
}

Expand Down Expand Up @@ -683,7 +685,6 @@ QtObject {
return false
}

property Timer prevent_coin_disabling: Timer { interval: 5000 }

function canDisable(ticker) {
if (prevent_coin_disabling.running) return false
Expand All @@ -700,13 +701,9 @@ QtObject {
if (ticker === "BCH") return !General.isParentCoinNeeded("BCH", "SLP")
if (ticker === "UBQ") return !General.isParentCoinNeeded("UBQ", "Ubiq")
if (ticker === "MOVR") return !General.isParentCoinNeeded("MOVR", "Moonriver")
if (ticker === "GLMR") return !General.isParentCoinNeeded("GLMR", "Moonbeam")
if (General.isZhtlc(ticker))
{
let progress = General.zhtlcActivationProgress(API.app.wallet_pg.ticker_infos.activation_status, ticker)
if (progress != 100) return false
}

if (ticker === "IRIS") return !General.isParentCoinNeeded("IRIS", "COSMOS")
if (ticker === "OSMO") return !General.isParentCoinNeeded("OSMO", "COSMOS")
if (ticker === "ATOM") return !General.isParentCoinNeeded("ATOM", "COSMOS")
return true
}

Expand Down
16 changes: 11 additions & 5 deletions atomic_defi_design/Dex/Exchange/ProView/DexComboBoxLine.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ RowLayout
property color color: !details ? "white" : Style.getCoinColor(details.ticker)
property alias middle_text: middle_line.text_value
property alias bottom_text: bottom_line.text_value
property int activation_progress: Dex.General.zhtlcActivationProgress(details.activation_status, details.ticker)

property int activation_pct: General.zhtlcActivationProgress(API.app.get_zhtlc_status(details.ticker), details.ticker)
Connections
{
target: API.app.settings_pg
function onZhtlcStatusChanged() {
activation_pct = General.zhtlcActivationProgress(API.app.get_zhtlc_status(details.ticker), details.ticker)
}
}
Behavior on color { ColorAnimation { duration: Style.animationDuration } }

Dex.Image
Expand All @@ -40,7 +46,7 @@ RowLayout
anchors.centerIn: parent
anchors.fill: parent
radius: 10
enabled: Dex.General.isZhtlc(details.ticker) ? activation_progress < 100 : false
enabled: activation_pct < 100
visible: enabled
opacity: .9
color: Dex.DexTheme.backgroundColor
Expand All @@ -50,11 +56,11 @@ RowLayout
{
anchors.centerIn: parent
anchors.fill: parent
enabled: Dex.General.isZhtlc(details.ticker) ? activation_progress < 100 : false
enabled: activation_pct < 100
visible: enabled
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: activation_progress + "%"
text: activation_pct + "%"
font: Dex.DexTypo.body2
color: Dex.DexTheme.okColor
}
Expand Down
29 changes: 18 additions & 11 deletions atomic_defi_design/Dex/Portfolio/AssetsList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ Dex.DexListView
delegate: Rectangle
{
property color _idleColor: index % 2 === 1 ? Dex.CurrentTheme.listItemOddBackground : Dex.CurrentTheme.listItemEvenBackground
property int activation_progress: Dex.General.zhtlcActivationProgress(activation_status, ticker)
property int activation_pct: Dex.General.zhtlcActivationProgress(Dex.API.app.get_zhtlc_status(ticker), ticker)
Connections
{
target: Dex.API.app.settings_pg
function onZhtlcStatusChanged() {
activation_pct = Dex.General.zhtlcActivationProgress(Dex.API.app.get_zhtlc_status(ticker), ticker)
}
}

width: list.width
height: _assetRowHeight
Expand Down Expand Up @@ -126,7 +133,7 @@ Dex.DexListView
anchors.centerIn: parent
anchors.fill: parent
radius: 15
enabled: Dex.General.isZhtlc(ticker) ? activation_progress < 100 : false
enabled: activation_pct < 100
visible: enabled
opacity: .9
color: Dex.DexTheme.backgroundColor
Expand All @@ -136,11 +143,11 @@ Dex.DexListView
{
anchors.centerIn: parent
anchors.fill: parent
enabled: Dex.General.isZhtlc(ticker) ? activation_progress < 100 : false
enabled: activation_pct < 100
visible: enabled
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: activation_progress + "%"
text: activation_pct + "%"
font: Dex.DexTypo.head8
color: Dex.DexTheme.okColor
}
Expand Down Expand Up @@ -193,11 +200,13 @@ Dex.DexListView
font: Dex.DexTypo.body2
text_value:
{

if (Dex.General.isZhtlc(ticker))
{
if (activation_progress != 100)
let x = activation_pct
if (x != 100)
{
return qsTr("Activating: ") + activation_progress + "%"
return qsTr("Activating: ") + x + "%"
}
}
return parseFloat(balance).toFixed(8)
Expand Down Expand Up @@ -286,8 +295,8 @@ Dex.DexListView
}

Dex.CoinMenu { id: contextMenu }
}

}
Dex.DefaultMouseArea
{
id: mouseArea
Expand All @@ -297,8 +306,6 @@ Dex.DexListView

onClicked:
{
if (!can_change_ticker)
return
if (mouse.button === Qt.RightButton)
{
contextMenu.can_disable = Dex.General.canDisable(ticker)
Expand All @@ -313,11 +320,11 @@ Dex.DexListView

onPressAndHold:
{
if (!can_change_ticker) return

if (mouse.source === Qt.MouseEventNotSynthesized)
{
contextMenu.can_disable = Dex.General.canDisable(ticker)
contextMenu.popup()
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion atomic_defi_design/Dex/Screens/Dashboard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Item

readonly property var api_wallet_page: API.app.wallet_pg
readonly property var current_ticker_infos: api_wallet_page.ticker_infos
readonly property bool can_change_ticker: !api_wallet_page.tx_fetching_busy
readonly property bool can_disable_ticker: !api_wallet_page.tx_fetching_busy

readonly property alias loader: loader
readonly property alias current_component: loader.item
Expand Down
Loading

0 comments on commit 33b2558

Please sign in to comment.