Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak trade errors #2115

Merged
merged 6 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions atomic_defi_design/Dex/Constants/General.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
48 changes: 18 additions & 30 deletions atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -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.")
return qsTr("Entered amount must be higher 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 qsTr("Select an order.")
return Constants.General.getTradingError(last_trading_error, fee_info, base_ticker, rel_ticker, left_ticker, right_ticker)
}

tooltipText: _swapAlert.getAlert()
Expand Down
10 changes: 4 additions & 6 deletions atomic_defi_design/Dex/Exchange/Trade/Trade.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Item

Component.onCompleted:
{
API.app.trading_pg.on_gui_enter_dex()
if (dashboard.current_ticker!==undefined)
{
onOpened(dashboard.current_ticker)
Expand All @@ -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

Expand Down Expand Up @@ -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)
}

Expand Down
7 changes: 7 additions & 0 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//! QT
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QProcess>
#include <QSettings>
#include <QTimer>
Expand Down Expand Up @@ -427,6 +428,12 @@ namespace atomic_dex
return this->system_manager_.get_system<mm2_service>();
}

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;
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/core/atomicdex/models/qt.orderbook.model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/core/atomicdex/pages/qt.trading.page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 2 additions & 3 deletions src/core/atomicdex/pages/qt.trading.page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nlohmann::json> m_preferred_order;
boost::synchronized_value<QVariantMap> m_fees;
bool m_skip_taker{false};
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/core/atomicdex/services/mm2/mm2.service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,13 +1448,24 @@ 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);
if (coin_info.is_zhtlc_family)
{
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")
Expand Down
12 changes: 7 additions & 5 deletions src/core/atomicdex/services/mm2/mm2.service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down