From 91e6b539b145ff4ce8133c2e0ec50edfab700722 Mon Sep 17 00:00:00 2001 From: smk762 Date: Thu, 1 Dec 2022 23:25:55 +0800 Subject: [PATCH] fix busyindicator on sell coin when balance is zero --- atomic_defi_design/Dex/Constants/General.qml | 31 ++++++-------- .../Dex/Exchange/Trade/SimpleView/Trade.qml | 40 +++++++++---------- atomic_defi_design/Dex/Wallet/Main.qml | 4 +- 3 files changed, 33 insertions(+), 42 deletions(-) diff --git a/atomic_defi_design/Dex/Constants/General.qml b/atomic_defi_design/Dex/Constants/General.qml index a2059d24dc..6167959ca3 100644 --- a/atomic_defi_design/Dex/Constants/General.qml +++ b/atomic_defi_design/Dex/Constants/General.qml @@ -64,11 +64,12 @@ QtObject { return coin_info.is_zhtlc_family } - function isZhtlcReady(ticker, progress=100) + function isZhtlcReady(ticker) { + 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 - const coin_info = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker) - if (!coin_info.is_zhtlc_family) return true return false } @@ -385,30 +386,24 @@ QtObject { ) } - function getSimpleFromPlaceholder(selectedTicker, selectedOrder) { - if (isZhtlc(selectedTicker)) + function getSimpleFromPlaceholder(selectedTicker, selectedOrder, sell_ticker_balance) { + if (sell_ticker_balance == 0) { - let activation_status = API.app.get_zhtlc_status(selectedTicker) - let progress = zhtlcActivationProgress(activation_status, selectedTicker) - - if (!isZhtlcReady(selectedTicker, progress)) - { - return qsTr("Activating %1 (%2%)").arg(atomic_qt_utilities.retrieve_main_ticker(selectedTicker)).arg(progress) - } + return qsTr("%1 balance is zero").arg(selectedTicker) + } + if (!isZhtlcReady(selectedTicker)) + { + return qsTr("Activating %1 (%2%)").arg(atomic_qt_utilities.retrieve_main_ticker(selectedTicker)).arg(progress) } - if (API.app.trading_pg.max_volume == 0) { return qsTr("Loading wallet...") } - else if (typeof selectedOrder !== 'undefined') + if (typeof selectedOrder !== 'undefined') { return qsTr("Min: %1").arg(API.app.trading_pg.min_trade_vol) } - else - { - return qsTr("Enter an amount") - } + return qsTr("Enter an amount") } function arrayExclude(arr, excl) { diff --git a/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml b/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml index d0fde890cd..3e72049c65 100644 --- a/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml +++ b/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml @@ -19,8 +19,14 @@ ClipRRect // Trade Card { id: _tradeCard - readonly property var fees: API.app.trading_pg.fees - property string selectedTicker: API.app.get_balance(left_ticker) > 0 ? left_ticker : "" + readonly property var fees: Constants.API.app.trading_pg.fees + readonly property var max_trade_volume: Constants.API.app.trading_pg.max_volume + readonly property var min_trade_volume: Constants.API.app.trading_pg.min_trade_vol + readonly property var sell_ticker_balance: parseFloat(API.app.get_balance(left_ticker)) + readonly property bool coin_tradable: selectedTicker !== "" && sell_ticker_balance > 0 + readonly property bool waiting_for_sell_coin_info: (API.app.trading_pg.max_volume == 0 || !Constants.General.isZhtlcReady(left_ticker)) && sell_ticker_balance != 0 + + property string selectedTicker: sell_ticker_balance > 0 ? left_ticker : "" property var selectedOrder: undefined property bool best: false property bool coinSelection: false @@ -63,8 +69,8 @@ ClipRRect // Trade Card { if (typeof selectedOrder === 'undefined') return - if (parseFloat(_fromValue.text) > Constants.API.app.trading_pg.max_volume) - _fromValue.text = Constants.API.app.trading_pg.max_volume + if (parseFloat(_fromValue.text) > max_trade_volume) + _fromValue.text = max_trade_volume Constants.API.app.trading_pg.determine_fees() } @@ -246,7 +252,7 @@ ClipRRect // Trade Card anchors.verticalCenter: _fromTitle.verticalCenter anchors.right: parent.right anchors.rightMargin: 17 - text: qsTr("%1").arg(Constants.API.app.trading_pg.max_volume) // This is slow to appear + text: qsTr("%1").arg(max_trade_volume) // This is slow to appear font.pixelSize: Constants.Style.textSizeSmall2 elide: Text.ElideRight color: DexTheme.foregroundColorLightColor1 @@ -289,13 +295,12 @@ ClipRRect // Trade Card AmountField // Amount { id: _fromValue - enabled: selectedTicker !== "" - visible: enabled + enabled: !waiting_for_sell_coin_info anchors.bottom: parent.bottom anchors.bottomMargin: 19 anchors.left: parent.left anchors.leftMargin: 2 - placeholderText: Constants.General.getSimpleFromPlaceholder(selectedTicker, selectedOrder) + placeholderText: Constants.General.getSimpleFromPlaceholder(selectedTicker, selectedOrder, sell_ticker_balance) font.pixelSize: Constants.Style.textSizeSmall3 background: Rectangle { color: swap_from_card.color} @@ -311,9 +316,9 @@ ClipRRect // Trade Card onFocusChanged: { - if (!focus && parseFloat(text) < parseFloat(Constants.API.app.trading_pg.min_trade_vol)) + if (!focus && parseFloat(text) < parseFloat(min_trade_volume)) { - text = Constants.API.app.trading_pg.min_trade_vol + text = min_trade_volume } } Component.onCompleted: text = "" @@ -432,20 +437,13 @@ ClipRRect // Trade Card text: qsTr("MAX") color: Dex.CurrentTheme.foregroundColor2 - onClicked: _fromValue.text = Constants.API.app.trading_pg.max_volume + onClicked: _fromValue.text = max_trade_volume } DefaultBusyIndicator { anchors.centerIn: parent - visible: - { - console.log("selectedTicker: " + selectedTicker) - console.log("Constants.API.app.trading_pg.max_volume: " + Constants.API.app.trading_pg.max_volume) - console.log("_fromValue.placeholderText: " + _fromValue.placeholderText) - console.log("_fromValue.placeholderText.search(Activating): " + _fromValue.placeholderText.search("Activating")) - selectedTicker !== "" && Constants.API.app.trading_pg.max_volume == 0 && _fromValue.placeholderText.search("Activating") == -1 - } + visible: waiting_for_sell_coin_info } } @@ -712,17 +710,15 @@ ClipRRect // Trade Card function getAlert() { console.log("_fromValue.text: " + _fromValue.text) - var left_ticker = Constants.API.app.trading_pg.market_pairs_mdl.left_selected_coin var right_ticker = Constants.API.app.trading_pg.market_pairs_mdl.right_selected_coin var base_ticker = Constants.API.app.trading_pg.market_pairs_mdl.base_selected_coin var rel_ticker = Constants.API.app.trading_pg.market_pairs_mdl.rel_selected_coin - var fee_info = Constants.API.app.trading_pg.fees if (_fromValue.text === "" || parseFloat(_fromValue.text) === 0) return qsTr("Entered amount must be higher than 0.") if (typeof selectedOrder === 'undefined') return qsTr("Select an order.") - return Constants.General.getTradingError(last_trading_error, fee_info, base_ticker, rel_ticker, left_ticker, right_ticker) + return Constants.General.getTradingError(last_trading_error, fees, base_ticker, rel_ticker, left_ticker, right_ticker) } tooltipText: _swapAlert.getAlert() diff --git a/atomic_defi_design/Dex/Wallet/Main.qml b/atomic_defi_design/Dex/Wallet/Main.qml index eb6bba59cd..f046780849 100644 --- a/atomic_defi_design/Dex/Wallet/Main.qml +++ b/atomic_defi_design/Dex/Wallet/Main.qml @@ -533,7 +533,7 @@ Item DefaultButton { // Address wont display until activated - enabled: General.isZhtlcReady(api_wallet_page.ticker, activation_progress) + enabled: General.isZhtlcReady(api_wallet_page.ticker) anchors.fill: parent radius: 18 @@ -556,7 +556,7 @@ Item // Receive button error icon DefaultAlertIcon { - visible: !General.isZhtlcReady(api_wallet_page.ticker, activation_progress) + visible: !General.isZhtlcReady(api_wallet_page.ticker) tooltipText: api_wallet_page.ticker + qsTr(" Activation: " + activation_progress + "%") } }