From 9a9324371f3db966cf06b58afc03ef452d62c4ed Mon Sep 17 00:00:00 2001 From: smk762 Date: Sat, 26 Nov 2022 06:57:50 +0800 Subject: [PATCH 1/5] add simple mode placeholder for partially activated zhtlc --- atomic_defi_design/Dex/Constants/General.qml | 35 +++++++++++++--- .../Dex/Exchange/Trade/SimpleView/Trade.qml | 42 +++++++------------ src/app/app.cpp | 7 ++++ src/app/app.hpp | 2 + .../atomicdex/services/mm2/mm2.service.cpp | 11 +++++ .../atomicdex/services/mm2/mm2.service.hpp | 12 +++--- 6 files changed, 72 insertions(+), 37 deletions(-) diff --git a/atomic_defi_design/Dex/Constants/General.qml b/atomic_defi_design/Dex/Constants/General.qml index feabbc00bb..a2059d24dc 100644 --- a/atomic_defi_design/Dex/Constants/General.qml +++ b/atomic_defi_design/Dex/Constants/General.qml @@ -69,7 +69,6 @@ QtObject { 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 - console.log("Progress: " + progress) return false } @@ -386,6 +385,32 @@ QtObject { ) } + function getSimpleFromPlaceholder(selectedTicker, selectedOrder) { + if (isZhtlc(selectedTicker)) + { + 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) + } + } + + if (API.app.trading_pg.max_volume == 0) + { + return qsTr("Loading wallet...") + } + else if (typeof selectedOrder !== 'undefined') + { + return qsTr("Min: %1").arg(API.app.trading_pg.min_trade_vol) + } + else + { + return qsTr("Enter an amount") + } + } + function arrayExclude(arr, excl) { let i = arr.indexOf(excl) if (i > -1) arr.splice(i, 1); @@ -786,6 +811,10 @@ QtObject { switch(error) { case TradingError.None: return "" + case TradingError.LeftZhtlcChainNotEnabled: + return qsTr("Please wait for %1 to fully activate").arg(left_ticker) + case TradingError.RightZhtlcChainNotEnabled: + return qsTr("Please wait for %1 to fully activate").arg(right_ticker) case TradingError.TotalFeesNotEnoughFunds: return qsTr("%1 balance is lower than the fees amount: %2 %3").arg(fee_info.error_fees.coin).arg(fee_info.error_fees.required_balance).arg(fee_info.error_fees.coin) case TradingError.BalanceIsLessThanTheMinimalTradingAmount: @@ -794,10 +823,6 @@ QtObject { return qsTr("Please fill the price field") case TradingError.VolumeFieldNotFilled: return qsTr("Please fill the volume field") - case TradingError.LeftZhtlcChainNotEnabled: - return qsTr("Please wait for %1 to fully activate").arg(left_ticker) - case TradingError.RightZhtlcChainNotEnabled: - return qsTr("Please wait for %1 to fully activate").arg(right_ticker) case TradingError.VolumeIsLowerThanTheMinimum: return qsTr("%1 volume is lower than minimum trade amount").arg(API.app.trading_pg.market_pairs_mdl.left_selected_coin) + " : " + General.getMinTradeAmount() case TradingError.ReceiveVolumeIsLowerThanTheMinimum: diff --git a/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml b/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml index 31bd8e7915..90aa353905 100644 --- a/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml +++ b/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml @@ -293,10 +293,8 @@ ClipRRect // Trade Card anchors.bottomMargin: 19 anchors.left: parent.left anchors.leftMargin: 2 - placeholderText: Constants.API.app.trading_pg.max_volume == 0 ? - "Loading wallet..." : typeof selectedOrder !== 'undefined' ? - qsTr("Min: %1").arg(Constants.API.app.trading_pg.min_trade_vol) : qsTr("Enter an amount") - font.pixelSize: Constants.Style.textSizeSmall5 + placeholderText: Constants.General.getSimpleFromPlaceholder(selectedTicker, selectedOrder) + font.pixelSize: Constants.Style.textSizeSmall3 background: Rectangle { color: swap_from_card.color} onTextChanged: @@ -438,7 +436,14 @@ ClipRRect // Trade Card DefaultBusyIndicator { anchors.centerIn: parent - visible: selectedTicker !== "" && Constants.API.app.trading_pg.max_volume == 0 + 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 + } } } @@ -703,35 +708,18 @@ 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 right_parent = Constants.API.app.portfolio_pg.global_cfg_mdl.get_parent_coin(right_ticker) - var left_parent = Constants.API.app.portfolio_pg.global_cfg_mdl.get_parent_coin(left_ticker) - var last_trading_error = Constants.API.app.trading_pg.last_trading_error - var fees_error = Constants.API.app.trading_pg.fees.error + 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 superior than 0.") if (typeof selectedOrder === 'undefined') return qsTr("You must select an order.") - if (last_trading_error == TradingError.VolumeIsLowerThanTheMinimum) - return qsTr("Entered amount is below the minimum required by this order: %1").arg(selectedOrder.base_min_volume) - if (last_trading_error == TradingError.LeftParentChainNotEnabled) - return qsTr("%1 needs to be enabled in order to use %2").arg(Constants.API.app.portfolio_pg.global_cfg_mdl.get_parent_coin(left_ticker)).arg(left_ticker) - if (last_trading_error == TradingError.LeftParentChainNotEnoughBalance) - return qsTr("%1 balance needs to be funded, a non-zero balance is required to pay the gas of %2 transactions").arg(left_parent).arg(left_ticker) - if (last_trading_error == TradingError.RightParentChainNotEnabled) - return qsTr("%1 needs to be enabled in order to use %2").arg(Constants.API.app.portfolio_pg.global_cfg_mdl.get_parent_coin(right_ticker)).arg(right_ticker) - if (last_trading_error == TradingError.RightParentChainNotEnoughBalance) - return qsTr("%1 balance needs to be funded, a non-zero balance is required to pay the gas of %2 transactions").arg(right_parent).arg(right_ticker) - if (fees_error) { - let coin = right_ticker - if (fees_error.search(Constants.API.app.portfolio_pg.global_cfg_mdl.get_parent_coin(left_ticker)) > -1) { - coin = left_ticker - } - return qsTr("%1 balance does not have enough funds to pay the gas of %2 transactions").arg(Constants.API.app.portfolio_pg.global_cfg_mdl.get_parent_coin(coin)).arg(coin) - } - return "" + return Constants.General.getTradingError(last_trading_error, fee_info, base_ticker, rel_ticker, left_ticker, right_ticker) } tooltipText: _swapAlert.getAlert() diff --git a/src/app/app.cpp b/src/app/app.cpp index cc0e164b4f..34809cf8c9 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -22,6 +22,7 @@ //! QT #include #include +#include #include #include #include @@ -427,6 +428,12 @@ namespace atomic_dex return this->system_manager_.get_system(); } + QJsonObject application::get_zhtlc_status(const QString& coin) + { + QJsonObject res = nlohmann_json_object_to_qt_json_object(get_mm2().get_zhtlc_status(coin.toStdString())); + return res; + } + QString application::get_balance(const QString& coin) { std::error_code ec; diff --git a/src/app/app.hpp b/src/app/app.hpp index dd18115804..a2d91d0a57 100644 --- a/src/app/app.hpp +++ b/src/app/app.hpp @@ -50,6 +50,7 @@ #include "atomicdex/services/price/global.provider.hpp" #include "atomicdex/services/update/update.checker.service.hpp" #include "atomicdex/services/update/zcash.params.service.hpp" +#include "atomicdex/utilities/qt.utilities.hpp" namespace ag = antara::gaming; @@ -161,6 +162,7 @@ namespace atomic_dex Q_INVOKABLE bool enable_coins(const QStringList& coins); Q_INVOKABLE bool enable_coin(const QString& coin); Q_INVOKABLE QString get_balance(const QString& coin); + Q_INVOKABLE QJsonObject get_zhtlc_status(const QString& coin); Q_INVOKABLE [[nodiscard]] bool do_i_have_enough_funds(const QString& ticker, const QString& amount) const; Q_INVOKABLE bool disable_coins(const QStringList& coins); Q_INVOKABLE bool disable_no_balance_coins(); diff --git a/src/core/atomicdex/services/mm2/mm2.service.cpp b/src/core/atomicdex/services/mm2/mm2.service.cpp index 087c206c1f..afa5553694 100644 --- a/src/core/atomicdex/services/mm2/mm2.service.cpp +++ b/src/core/atomicdex/services/mm2/mm2.service.cpp @@ -1448,6 +1448,16 @@ namespace atomic_dex } } + nlohmann::json mm2_service::get_zhtlc_status(const std::string coin) const + { + const auto coin_info = get_coin_info(coin); + if (coin_info.is_zhtlc_family) + { + return coin_info.activation_status; + } + return {}; + } + bool mm2_service::is_zhtlc_coin_ready(const std::string coin) const { const auto coin_info = get_coin_info(coin); @@ -1455,6 +1465,7 @@ namespace atomic_dex { if (coin_info.activation_status.contains("result")) { + SPDLOG_DEBUG("coin_info.activation_status {} {} :", coin, coin_info.activation_status.dump(4)); if (coin_info.activation_status.at("result").contains("status")) { if (coin_info.activation_status.at("result").at("status") == "Ready") diff --git a/src/core/atomicdex/services/mm2/mm2.service.hpp b/src/core/atomicdex/services/mm2/mm2.service.hpp index e991955d45..0ac768b43a 100644 --- a/src/core/atomicdex/services/mm2/mm2.service.hpp +++ b/src/core/atomicdex/services/mm2/mm2.service.hpp @@ -188,11 +188,13 @@ namespace atomic_dex public: //! Add a new coin in the coin_info cfg add_new_coin(normal_cfg, mm2_cfg) - void add_new_coin(const nlohmann::json& coin_cfg_json, const nlohmann::json& raw_coin_cfg_json); - void remove_custom_coin(const std::string& ticker); - [[nodiscard]] bool is_this_ticker_present_in_raw_cfg(const std::string& ticker) const; - [[nodiscard]] bool is_this_ticker_present_in_normal_cfg(const std::string& ticker) const; - [[nodiscard]] bool is_zhtlc_coin_ready(const std::string coin) const; + void add_new_coin(const nlohmann::json& coin_cfg_json, const nlohmann::json& raw_coin_cfg_json); + void remove_custom_coin(const std::string& ticker); + [[nodiscard]] bool is_this_ticker_present_in_raw_cfg(const std::string& ticker) const; + [[nodiscard]] bool is_this_ticker_present_in_normal_cfg(const std::string& ticker) const; + [[nodiscard]] bool is_zhtlc_coin_ready(const std::string coin) const; + [[nodiscard]] nlohmann::json get_zhtlc_status(const std::string coin) const; + //! Disable a single coin bool disable_coin(const std::string& ticker, std::error_code& ec); From cbe2f98ba46ff1beb68a285f661f810357b6f823 Mon Sep 17 00:00:00 2001 From: smk762 Date: Sun, 27 Nov 2022 20:48:25 +0800 Subject: [PATCH 2/5] rm duplicated signal trigger --- atomic_defi_design/Dex/Exchange/Trade/Trade.qml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/atomic_defi_design/Dex/Exchange/Trade/Trade.qml b/atomic_defi_design/Dex/Exchange/Trade/Trade.qml index 46c40aa965..71314c3bfc 100644 --- a/atomic_defi_design/Dex/Exchange/Trade/Trade.qml +++ b/atomic_defi_design/Dex/Exchange/Trade/Trade.qml @@ -24,7 +24,6 @@ Item Component.onCompleted: { - API.app.trading_pg.on_gui_enter_dex() if (dashboard.current_ticker!==undefined) { onOpened(dashboard.current_ticker) @@ -36,8 +35,6 @@ Item dashboard.current_ticker = undefined } - Component.onDestruction: API.app.trading_pg.on_gui_leave_dex() - readonly property bool block_everything: swap_cooldown.running || fetching_multi_ticker_fees_busy @@ -101,13 +98,14 @@ Item General.default_rel) } setPair(true, ticker) + // triggers chart reload app.pairChanged(base_ticker, rel_ticker) } - function setPair(is_left_side, changed_ticker) { + function setPair(is_left_side, changed_ticker, is_swap=false) { swap_cooldown.restart() - - if (API.app.trading_pg.set_pair(is_left_side, changed_ticker)) + if (API.app.trading_pg.set_pair(is_left_side, changed_ticker, is_swap)) + // triggers chart reload app.pairChanged(base_ticker, rel_ticker) } From d6c52d2aec73ab461cb7c48f1772c15b12c4ed54 Mon Sep 17 00:00:00 2001 From: smk762 Date: Wed, 30 Nov 2022 03:22:16 +0800 Subject: [PATCH 3/5] implement ReceiveVolumeIsLowerThanTheMinimum error --- .../Dex/Exchange/Trade/SimpleView/Trade.qml | 6 +++--- src/core/atomicdex/models/qt.orderbook.model.cpp | 1 - src/core/atomicdex/pages/qt.trading.page.cpp | 11 ++++++++++- src/core/atomicdex/pages/qt.trading.page.hpp | 5 ++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml b/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml index 90aa353905..ff89c0f877 100644 --- a/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml +++ b/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml @@ -244,7 +244,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) + text: qsTr("%1").arg(Constants.API.app.trading_pg.max_volume) // This is slow to appear font.pixelSize: Constants.Style.textSizeSmall2 elide: Text.ElideRight color: DexTheme.foregroundColorLightColor1 @@ -716,9 +716,9 @@ ClipRRect // Trade Card var fee_info = Constants.API.app.trading_pg.fees if (_fromValue.text === "" || parseFloat(_fromValue.text) === 0) - return qsTr("Entered amount must be superior than 0.") + return qsTr("Entered amount must be higher than 0.") if (typeof selectedOrder === 'undefined') - return qsTr("You must select an order.") + return qsTr("Select an order.") return Constants.General.getTradingError(last_trading_error, fee_info, base_ticker, rel_ticker, left_ticker, right_ticker) } diff --git a/src/core/atomicdex/models/qt.orderbook.model.cpp b/src/core/atomicdex/models/qt.orderbook.model.cpp index 9f6b9344c5..69ac5492b7 100644 --- a/src/core/atomicdex/models/qt.orderbook.model.cpp +++ b/src/core/atomicdex/models/qt.orderbook.model.cpp @@ -163,7 +163,6 @@ namespace atomic_dex { taker_vol_std = "0"; } - // t_float_50 mm2_min_trade_vol = safe_float(trading_pg.get_mm2_min_trade_vol().toStdString()); t_float_50 taker_vol = safe_float(taker_vol_std); i_have_enough_funds = min_volume_f > 0 && taker_vol > min_volume_f; return i_have_enough_funds; diff --git a/src/core/atomicdex/pages/qt.trading.page.cpp b/src/core/atomicdex/pages/qt.trading.page.cpp index 22bfe71ccc..fee796aa19 100644 --- a/src/core/atomicdex/pages/qt.trading.page.cpp +++ b/src/core/atomicdex/pages/qt.trading.page.cpp @@ -677,7 +677,7 @@ namespace atomic_dex { this->set_price("0"); this->set_max_volume("0"); - m_minimal_trading_amount = "0"; + m_minimal_trading_amount = "0.00777"; emit minTradeVolChanged(); this->set_volume("0"); } @@ -1312,6 +1312,10 @@ namespace atomic_dex { current_trading_error = TradingError::VolumeIsLowerThanTheMinimum; } + else if (safe_float(m_total_amount.toStdString()) < 0.00777) + { + current_trading_error = TradingError::ReceiveVolumeIsLowerThanTheMinimum; + } else { if (!get_fees().empty()) @@ -1472,6 +1476,11 @@ namespace atomic_dex // If not associated bugs appear as a result, we can delete this. // min_trade_vol = get_orderbook_wrapper()->get_current_min_taker_vol(); } + + if (safe_float(min_taker_vol) < 0.00777) + { + min_trade_vol = "0.00777"; + } if (min_trade_vol != m_minimal_trading_amount) { diff --git a/src/core/atomicdex/pages/qt.trading.page.hpp b/src/core/atomicdex/pages/qt.trading.page.hpp index 0e8af4be11..af42422273 100644 --- a/src/core/atomicdex/pages/qt.trading.page.hpp +++ b/src/core/atomicdex/pages/qt.trading.page.hpp @@ -110,9 +110,9 @@ namespace atomic_dex QString m_price{"0"}; QString m_volume{"0"}; QString m_max_volume{"0"}; - QString m_total_amount{"0"}; + QString m_total_amount{"0.00777"}; QString m_cex_price{"0"}; - QString m_minimal_trading_amount{"0"}; + QString m_minimal_trading_amount{"0.00777"}; std::optional m_preferred_order; boost::synchronized_value m_fees; bool m_skip_taker{false}; @@ -183,7 +183,6 @@ namespace atomic_dex [[nodiscard]] QString get_price_reversed() const; [[nodiscard]] QString get_price() const; void set_price(QString price); - //[[nodiscard]] QString get_mm2_min_trade_vol() const; [[nodiscard]] QString get_min_trade_vol() const; void set_min_trade_vol(QString min_trade_vol); [[nodiscard]] QString get_volume() const; From 91e6b539b145ff4ce8133c2e0ec50edfab700722 Mon Sep 17 00:00:00 2001 From: smk762 Date: Thu, 1 Dec 2022 23:25:55 +0800 Subject: [PATCH 4/5] 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 + "%") } } From b841c10a9a13eec76af451c6c62d3310fb99eefb Mon Sep 17 00:00:00 2001 From: smk762 Date: Thu, 1 Dec 2022 23:43:14 +0800 Subject: [PATCH 5/5] disable input if no balance or info not ready --- atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml b/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml index 3e72049c65..480c041971 100644 --- a/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml +++ b/atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml @@ -24,7 +24,7 @@ ClipRRect // Trade Card 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 + readonly property bool waiting_for_sell_coin_info: (max_trade_volume == 0 || !Constants.General.isZhtlcReady(left_ticker)) && sell_ticker_balance != 0 property string selectedTicker: sell_ticker_balance > 0 ? left_ticker : "" property var selectedOrder: undefined @@ -295,7 +295,7 @@ ClipRRect // Trade Card AmountField // Amount { id: _fromValue - enabled: !waiting_for_sell_coin_info + enabled: sell_ticker_balance == 0 ? false : waiting_for_sell_coin_info ? false : true anchors.bottom: parent.bottom anchors.bottomMargin: 19 anchors.left: parent.left