Skip to content

Commit

Permalink
Merge pull request #1232 from KomodoPlatform/wallet_enabling_rework
Browse files Browse the repository at this point in the history
Wallet enabling rework
  • Loading branch information
tonymorony authored Sep 2, 2021
2 parents ed32995 + 9bcff45 commit 4295810
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 59 deletions.
2 changes: 2 additions & 0 deletions atomic_defi_design/qml/Portfolio/Portfolio.qml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ Item {
text: qsTr("Show only coins with balance") + " <b>%1</b>".arg(qsTr("(%1/%2)").arg(coinsList.innerList.count).arg(portfolio_mdl.length))
checked: portfolio_coins.with_balance
onCheckedChanged: portfolio_coins.with_balance = checked

Component.onDestruction: portfolio_coins.with_balance = false
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion atomic_defi_design/qml/Screens/Dashboard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Item {

anchors.fill: parent
transformOrigin: Item.Center
asynchronous: true

sourceComponent: {
switch (current_page) {
Expand Down Expand Up @@ -399,4 +400,4 @@ Item {
return qsTr(event_name)
}
}
}
}
4 changes: 2 additions & 2 deletions atomic_defi_design/qml/Screens/InitialLoading.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SetupPage {
readonly property string current_status: API.app.wallet_mgr.initial_loading_status

onCurrent_statusChanged: {
if (current_status === "complete")
if (current_status === "enabling_coins")
onLoaded()
}

Expand Down Expand Up @@ -47,4 +47,4 @@ SetupPage {
current_status === "enabling_coins" ? qsTr("Enabling assets") : qsTr("Getting ready")) + "..."
}
}
}
}
2 changes: 1 addition & 1 deletion src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace atomic_dex
if (coin_info.has_parent_fees_ticker && coin_info.ticker != coin_info.fees_ticker)
{
auto coin_parent_info = mm2.get_coin_info(coin_info.fees_ticker);
if (extra_coins.insert(coin_parent_info.ticker).second)
if (!coin_parent_info.currently_enabled && !coin_parent_info.active && extra_coins.insert(coin_parent_info.ticker).second)
{
SPDLOG_INFO("Adding extra coin: {} to enable", coin_parent_info.ticker);
}
Expand Down
1 change: 1 addition & 0 deletions src/core/atomicdex/managers/qt.wallet.manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ namespace atomic_dex
{
this->m_current_status = std::move(status);
emit onStatusChanged();
SPDLOG_INFO("Set status: {}", m_current_status.toStdString());
}

bool
Expand Down
25 changes: 16 additions & 9 deletions src/core/atomicdex/models/qt.portfolio.model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "atomicdex/utilities/global.utilities.hpp"
#include "atomicdex/utilities/qt.utilities.hpp"
#include "qt.portfolio.model.hpp"
#include "atomicdex/managers/qt.wallet.manager.hpp"

namespace atomic_dex
{
Expand Down Expand Up @@ -135,10 +136,11 @@ namespace atomic_dex
auto&& [prev_balance, new_balance, is_change_b] = update_value(BalanceRole, balance, idx, *this);
const QString display = QString::fromStdString(coin.ticker) + " (" + balance + ")";
update_value(Display, display, idx, *this);
if (is_change_b)
{
balance_update_handler(prev_balance.toString(), new_balance.toString(), QString::fromStdString(ticker));
}
// Not a good way to trigger notification, use websocket instead in the future. New was of enabling coins is not compatible.
// if (is_change_b && m_system_manager.has_system<qt_wallet_manager>() && m_system_manager.get_system<qt_wallet_manager>().get_status() == "complete")
// {
// balance_update_handler(prev_balance.toString(), new_balance.toString(), QString::fromStdString(ticker));
// }
QJsonArray trend = nlohmann_json_array_to_qt_json_array(coingecko.get_ticker_historical(ticker));
update_value(Trend7D, trend, idx, *this);
// SPDLOG_DEBUG("updated currency values of: {}", ticker);
Expand All @@ -153,9 +155,13 @@ namespace atomic_dex
bool
portfolio_model::update_balance_values(const std::vector<std::string>& tickers)
{
//SPDLOG_INFO("update_balance_values");
SPDLOG_INFO("update_balance_values");
for (auto&& ticker: tickers)
{
if (ticker.empty())
{
return false;
}
if (m_ticker_registry.find(ticker) == m_ticker_registry.end())
{
SPDLOG_WARN("ticker: {} not inserted yet in the model, skipping", ticker);
Expand Down Expand Up @@ -185,10 +191,11 @@ namespace atomic_dex
update_value(Display, display, idx, *this);
QString change24_h = retrieve_change_24h(coingecko, coin, *m_config, m_system_manager);
update_value(Change24H, change24_h, idx, *this);
if (is_change_b)
{
balance_update_handler(prev_balance.toString(), new_balance.toString(), QString::fromStdString(ticker));
}
// Not a good way to trigger notification, use websocket instead in the future. New was of enabling coins is not compatible.
// if (is_change_b && m_system_manager.has_system<qt_wallet_manager>() && m_system_manager.get_system<qt_wallet_manager>().get_status() == "complete")
// {
// balance_update_handler(prev_balance.toString(), new_balance.toString(), QString::fromStdString(ticker));
// }
QJsonArray trend = nlohmann_json_array_to_qt_json_array(coingecko.get_ticker_historical(ticker));
update_value(Trend7D, trend, idx, *this);
if (ticker == mm2_system.get_current_ticker() && (is_change_b || is_change_mc || is_change_mcpfo))
Expand Down
1 change: 1 addition & 0 deletions src/core/atomicdex/pages/qt.portfolio.page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ namespace atomic_dex
void
portfolio_page::initialize_portfolio(const std::vector<std::string>& tickers)
{
SPDLOG_INFO("initialize_portfolio with tickers: {}", fmt::join(tickers, ", "));
m_portfolio_mdl->initialize_portfolio(tickers);
m_global_cfg_mdl->update_status(tickers, true);
}
Expand Down
31 changes: 29 additions & 2 deletions src/core/atomicdex/pages/qt.wallet.page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,22 @@ namespace atomic_dex
this->set_send_busy(false);
};

auto error_functor = [this](pplx::task<void> previous_task) {
try
{
previous_task.wait();
}
catch (const std::exception& e)
{
SPDLOG_ERROR("error caught in send: {}", e.what());
auto error_json = QJsonObject({{"error_code", 500}, {"error_message", QString::fromStdString(e.what())}});
this->set_rpc_send_data(error_json);
this->set_send_busy(false);
}
};

//! Process
mm2_system.get_mm2_client().async_rpc_batch_standalone(batch).then(answer_functor).then(&handle_exception_pplx_task);
mm2_system.get_mm2_client().async_rpc_batch_standalone(batch).then(answer_functor).then(error_functor);
}

void
Expand Down Expand Up @@ -645,7 +659,20 @@ namespace atomic_dex
this->set_broadcast_busy(false);
};

mm2_system.get_mm2_client().async_rpc_batch_standalone(batch).then(answer_functor).then(&handle_exception_pplx_task);
auto error_functor = [this](pplx::task<void> previous_task) {
try
{
previous_task.wait();
}
catch (const std::exception& e)
{
SPDLOG_ERROR("error caught in broadcast finished: {}", e.what());
this->set_rpc_broadcast_data(QString::fromStdString(e.what()));
this->set_broadcast_busy(false);
}
};

mm2_system.get_mm2_client().async_rpc_batch_standalone(batch).then(answer_functor).then(error_functor);
}

void
Expand Down
Loading

0 comments on commit 4295810

Please sign in to comment.