diff --git a/src/atomic.dex.app.cpp b/src/atomic.dex.app.cpp index bdb4634892..af76e0352e 100644 --- a/src/atomic.dex.app.cpp +++ b/src/atomic.dex.app.cpp @@ -103,13 +103,13 @@ namespace atomic_dex #endif } - QObjectList + const QObjectList& atomic_dex::application::get_enabled_coins() const noexcept { return m_enabled_coins; } - QObjectList + const QObjectList& atomic_dex::application::get_enableable_coins() const noexcept { return m_enableable_coins; @@ -281,13 +281,6 @@ namespace atomic_dex this->set_current_balance_fiat_all(QString::fromStdString(fiat_balance_std)); } - // auto second_fiat_balance_std = paprika.get_price_in_fiat_all(m_second_current_fiat.toStdString(), ec); - - // if (!ec) - //{ - // this->set_second_current_balance_fiat_all(QString::fromStdString(second_fiat_balance_std)); - //} - if (not m_coin_info->get_ticker().isEmpty() && not m_enabled_coins.empty()) { refresh_fiat_balance(mm2, paprika); @@ -368,18 +361,12 @@ namespace atomic_dex return m_coin_info; } - QString + const QString& atomic_dex::application::get_balance_fiat_all() const noexcept { return m_current_balance_all; } - QString - application::get_second_balance_fiat_all() const noexcept - { - return m_second_current_balance_all; - } - void atomic_dex::application::set_current_balance_fiat_all(QString current_fiat_all_balance) noexcept { @@ -387,13 +374,6 @@ namespace atomic_dex emit on_fiat_balance_all_changed(); } - void - application::set_second_current_balance_fiat_all(QString current_fiat_all_balance) noexcept - { - this->m_second_current_balance_all = std::move(current_fiat_all_balance); - emit on_second_fiat_balance_all_changed(); - } - application::application(QObject* pParent) noexcept : QObject(pParent), m_coin_info(new current_coin_info(dispatcher_, this)) { //! MM2 system need to be created before the GUI and give the instance to the gui @@ -452,15 +432,16 @@ namespace atomic_dex m_refresh_enabled_coin_event = true; } - QString + const QString& application::get_current_fiat() const noexcept { - return QString::fromStdString(this->m_config.current_fiat); + return m_current_fiat; } void application::set_current_fiat(QString current_fiat) noexcept { + this->m_current_fiat = current_fiat; if (current_fiat.toStdString() != m_config.current_fiat) { spdlog::info("change lang {} to {}", m_config.current_fiat, current_fiat.toStdString()); @@ -480,7 +461,7 @@ namespace atomic_dex application::refresh_address(mm2& mm2) { std::error_code ec; - auto address = QString::fromStdString(mm2.address(m_coin_info->get_ticker().toStdString(), ec)); + QString address = QString::fromStdString(mm2.address(m_coin_info->get_ticker().toStdString(), ec)); this->m_coin_info->set_address(address); } @@ -505,6 +486,7 @@ namespace atomic_dex { atomic_dex::t_withdraw_request req{ .to = address.toStdString(), .coin = m_coin_info->get_ticker().toStdString(), .max = max, .amount = amount.toStdString()}; + //! If req max is set to true, amount is ignored if (req.max == true) { req.amount = "0"; @@ -660,7 +642,7 @@ namespace atomic_dex this->dispatcher_.trigger(); } - QString + const QString& application::get_status() const noexcept { return m_current_status; @@ -892,7 +874,7 @@ namespace atomic_dex return out; } - QString + const QString& application::get_current_lang() const noexcept { return m_current_lang; @@ -1138,13 +1120,14 @@ namespace atomic_dex QString application::get_mm2_version() const { - return QString::fromStdString(::mm2::api::rpc_version()); + auto res = QString::fromStdString(::mm2::api::rpc_version()); + return res; } QString application::get_export_folder() const { - return QString::fromStdString(get_atomic_dex_export_folder().string().c_str()); + return QString::fromStdString(get_atomic_dex_export_folder().string()); } QString @@ -1209,7 +1192,7 @@ namespace atomic_dex //! Wallet manager QML API namespace atomic_dex { - QString + const QString& application::get_wallet_default_name() const noexcept { return m_wallet_manager.get_wallet_default_name(); diff --git a/src/atomic.dex.app.hpp b/src/atomic.dex.app.hpp index 904f75eb4d..2756c3a2ad 100644 --- a/src/atomic.dex.app.hpp +++ b/src/atomic.dex.app.hpp @@ -49,12 +49,9 @@ namespace atomic_dex Q_PROPERTY(QList enableable_coins READ get_enableable_coins NOTIFY enableableCoinsChanged) Q_PROPERTY(QObject* current_coin_info READ get_current_coin_info NOTIFY coinInfoChanged) Q_PROPERTY(QString fiat READ get_current_fiat WRITE set_current_fiat NOTIFY on_fiat_changed) - // Q_PROPERTY(QString second_fiat READ get_second_current_fiat WRITE set_second_current_fiat NOTIFY on_second_fiat_changed) Q_PROPERTY(QString lang READ get_current_lang WRITE set_current_lang NOTIFY on_lang_changed) Q_PROPERTY(QString wallet_default_name READ get_wallet_default_name WRITE set_wallet_default_name NOTIFY on_wallet_default_name_changed) Q_PROPERTY(QString balance_fiat_all READ get_balance_fiat_all WRITE set_current_balance_fiat_all NOTIFY on_fiat_balance_all_changed) - Q_PROPERTY(QString second_balance_fiat_all READ get_second_balance_fiat_all WRITE set_second_current_balance_fiat_all NOTIFY - on_second_fiat_balance_all_changed) Q_PROPERTY(QString initial_loading_status READ get_status WRITE set_status NOTIFY on_status_changed) private: @@ -87,14 +84,13 @@ namespace atomic_dex coinpaprika_provider& get_paprika() noexcept; entt::dispatcher& get_dispatcher() noexcept; QObject* get_current_coin_info() const noexcept; - QObjectList get_enabled_coins() const noexcept; - QObjectList get_enableable_coins() const noexcept; - QString get_current_fiat() const noexcept; - QString get_current_lang() const noexcept; - QString get_balance_fiat_all() const noexcept; - QString get_second_balance_fiat_all() const noexcept; - QString get_wallet_default_name() const noexcept; - QString get_status() const noexcept; + const QObjectList& get_enabled_coins() const noexcept; + const QObjectList& get_enableable_coins() const noexcept; + const QString& get_current_fiat() const noexcept; + const QString& get_current_lang() const noexcept; + const QString& get_balance_fiat_all() const noexcept; + const QString& get_wallet_default_name() const noexcept; + const QString& get_status() const noexcept; Q_INVOKABLE QString get_version() const noexcept; //! Properties Setter @@ -102,7 +98,6 @@ namespace atomic_dex void set_current_lang(const QString& current_lang) noexcept; void set_wallet_default_name(QString wallet_default_name) noexcept; void set_current_balance_fiat_all(QString current_fiat_all_balance) noexcept; - void set_second_current_balance_fiat_all(QString current_fiat_all_balance) noexcept; void set_status(QString status) noexcept; void set_qt_app(std::shared_ptr app) noexcept; @@ -190,11 +185,9 @@ namespace atomic_dex void enableableCoinsChanged(); void coinInfoChanged(); void on_fiat_changed(); - void on_second_fiat_changed(); void on_lang_changed(); void lang_changed(); void on_fiat_balance_all_changed(); - void on_second_fiat_balance_all_changed(); void on_status_changed(); void on_wallet_default_name_changed(); void myOrdersUpdated(); @@ -211,21 +204,23 @@ namespace atomic_dex atomic_dex::qt_wallet_manager m_wallet_manager; //! Private members - std::atomic_bool m_refresh_enabled_coin_event{false}; - std::atomic_bool m_refresh_current_ticker_infos{false}; - std::atomic_bool m_refresh_orders_needed{false}; - std::atomic_bool m_refresh_ohlc_needed{false}; - std::atomic_bool m_refresh_transaction_only{false}; - bool m_need_a_full_refresh_of_mm2{false}; - QObjectList m_enabled_coins; - QObjectList m_enableable_coins; - QTranslator m_translator; - // QString m_current_fiat{"USD"}; - // QString m_second_current_fiat{"BTC"}; + std::atomic_bool m_refresh_enabled_coin_event{false}; + std::atomic_bool m_refresh_current_ticker_infos{false}; + std::atomic_bool m_refresh_orders_needed{false}; + std::atomic_bool m_refresh_ohlc_needed{false}; + std::atomic_bool m_refresh_transaction_only{false}; + bool m_need_a_full_refresh_of_mm2{false}; + QObjectList m_enabled_coins; + QObjectList m_enableable_coins; + QTranslator m_translator; + QString m_current_fiat{QString::fromStdString(m_config.current_fiat)}; QString m_current_lang{QString::fromStdString(m_config.current_lang)}; QString m_current_status{"None"}; QString m_current_balance_all{"0.00"}; QString m_second_current_balance_all{"0.00"}; current_coin_info* m_coin_info; + + //! Object reusable + QVariantList m_portfolio_informations; }; } // namespace atomic_dex diff --git a/src/atomic.dex.qt.current.coin.infos.cpp b/src/atomic.dex.qt.current.coin.infos.cpp index b05b287cfa..e99a1aeabc 100644 --- a/src/atomic.dex.qt.current.coin.infos.cpp +++ b/src/atomic.dex.qt.current.coin.infos.cpp @@ -37,29 +37,29 @@ namespace atomic_dex return this->selected_coin_fname; } - QString + const QString& atomic_dex::current_coin_info::get_balance() const noexcept { return selected_coin_balance; } void - atomic_dex::current_coin_info::set_balance(QString balance) noexcept + atomic_dex::current_coin_info::set_balance(const QString& balance) noexcept { - this->selected_coin_balance = std::move(balance); + this->selected_coin_balance = balance; emit balance_changed(); } - QString + const QString& atomic_dex::current_coin_info::get_ticker() const noexcept { return selected_coin_name; } void - atomic_dex::current_coin_info::set_ticker(QString ticker) noexcept + atomic_dex::current_coin_info::set_ticker(const QString& ticker) noexcept { - selected_coin_name = std::move(ticker); + selected_coin_name = ticker; this->m_dispatcher.trigger(); emit ticker_changed(); } @@ -70,7 +70,7 @@ namespace atomic_dex return selected_coin_url; } - QString + const QString& current_coin_info::get_fiat_amount() const noexcept { return this->selected_coin_fiat_amount; @@ -91,11 +91,12 @@ namespace atomic_dex void - current_coin_info::set_fiat_amount(QString fiat_amount) noexcept + current_coin_info::set_fiat_amount(const QString& fiat_amount) noexcept { - this->selected_coin_fiat_amount = std::move(fiat_amount); + this->selected_coin_fiat_amount = fiat_amount; emit fiat_amount_changed(); } + QObjectList current_coin_info::get_transactions() const noexcept { @@ -109,17 +110,21 @@ namespace atomic_dex this->selected_coin_transactions = std::move(transactions); emit transactionsChanged(); } - QString + + const QString& current_coin_info::get_address() const noexcept { return selected_coin_address; } void - current_coin_info::set_address(QString address) noexcept + current_coin_info::set_address(const QString& address) noexcept { - this->selected_coin_address = std::move(address); - emit address_changed(); + if (address != selected_coin_address) + { + this->selected_coin_address = address; + emit address_changed(); + } } void @@ -210,7 +215,7 @@ namespace atomic_dex QString atomic_dex::current_coin_info::get_paprika_id() const noexcept { - return this->selected_coin_paprika_id; + return this->selected_coin_paprika_id; } void diff --git a/src/atomic.dex.qt.current.coin.infos.hpp b/src/atomic.dex.qt.current.coin.infos.hpp index 1060595b79..9af99e18c9 100644 --- a/src/atomic.dex.qt.current.coin.infos.hpp +++ b/src/atomic.dex.qt.current.coin.infos.hpp @@ -48,36 +48,37 @@ namespace atomic_dex public: explicit current_coin_info(entt::dispatcher& dispatcher, QObject* pParent = nullptr) noexcept; - [[nodiscard]] bool is_claimable_ticker() const noexcept; - void set_claimable(bool claimable) noexcept; - [[nodiscard]] QString get_minimal_balance_for_asking_rewards() const noexcept; - void set_minimal_balance_for_asking_rewards(QString amount) noexcept; - [[nodiscard]] QString get_tx_state() const noexcept; - void set_tx_state(QString state) noexcept; - [[nodiscard]] unsigned int get_tx_current_block() const noexcept; - void set_tx_current_block(unsigned int block) noexcept; - [[nodiscard]] unsigned int get_txs_left() const noexcept; - void set_txs_left(unsigned int txs) noexcept; - [[nodiscard]] unsigned int get_blocks_left() const noexcept; - void set_blocks_left(unsigned int blocks) noexcept; - [[nodiscard]] QObjectList get_transactions() const noexcept; - void set_transactions(QObjectList transactions) noexcept; - [[nodiscard]] QString get_ticker() const noexcept; - void set_ticker(QString ticker) noexcept; - [[nodiscard]] QString get_name() const noexcept; - void set_name(QString ticker) noexcept; - [[nodiscard]] QString get_paprika_id() const noexcept; - void set_paprika_id(QString ticker) noexcept; - [[nodiscard]] QString get_address() const noexcept; - void set_address(QString address) noexcept; - [[nodiscard]] QString get_balance() const noexcept; - void set_balance(QString balance) noexcept; - [[nodiscard]] QString get_explorer_url() const noexcept; - void set_explorer_url(QString url) noexcept; - [[nodiscard]] QString get_fiat_amount() const noexcept; - void set_fiat_amount(QString fiat_amount) noexcept; - [[nodiscard]] QString get_type() const noexcept; - void set_type(QString type) noexcept;; + [[nodiscard]] bool is_claimable_ticker() const noexcept; + void set_claimable(bool claimable) noexcept; + [[nodiscard]] QString get_minimal_balance_for_asking_rewards() const noexcept; + void set_minimal_balance_for_asking_rewards(QString amount) noexcept; + [[nodiscard]] QString get_tx_state() const noexcept; + void set_tx_state(QString state) noexcept; + [[nodiscard]] unsigned int get_tx_current_block() const noexcept; + void set_tx_current_block(unsigned int block) noexcept; + [[nodiscard]] unsigned int get_txs_left() const noexcept; + void set_txs_left(unsigned int txs) noexcept; + [[nodiscard]] unsigned int get_blocks_left() const noexcept; + void set_blocks_left(unsigned int blocks) noexcept; + [[nodiscard]] QObjectList get_transactions() const noexcept; + void set_transactions(QObjectList transactions) noexcept; + [[nodiscard]] const QString& get_ticker() const noexcept; + void set_ticker(const QString& ticker) noexcept; + [[nodiscard]] QString get_name() const noexcept; + void set_name(QString ticker) noexcept; + [[nodiscard]] QString get_paprika_id() const noexcept; + void set_paprika_id(QString ticker) noexcept; + [[nodiscard]] const QString& get_address() const noexcept; + void set_address(const QString& address) noexcept; + [[nodiscard]] const QString& get_balance() const noexcept; + void set_balance(const QString& balance) noexcept; + [[nodiscard]] QString get_explorer_url() const noexcept; + void set_explorer_url(QString url) noexcept; + [[nodiscard]] const QString& get_fiat_amount() const noexcept; + void set_fiat_amount(const QString& fiat_amount) noexcept; + [[nodiscard]] QString get_type() const noexcept; + void set_type(QString type) noexcept; + ; signals: void ticker_changed(); diff --git a/src/atomic.dex.qt.wallet.manager.cpp b/src/atomic.dex.qt.wallet.manager.cpp index fb7ab2a118..9708af2322 100644 --- a/src/atomic.dex.qt.wallet.manager.cpp +++ b/src/atomic.dex.qt.wallet.manager.cpp @@ -18,7 +18,7 @@ namespace atomic_dex { - QString + const QString& qt_wallet_manager::get_wallet_default_name() const noexcept { return m_current_default_wallet; diff --git a/src/atomic.dex.qt.wallet.manager.hpp b/src/atomic.dex.qt.wallet.manager.hpp index ca5fd62ff5..948109683b 100644 --- a/src/atomic.dex.qt.wallet.manager.hpp +++ b/src/atomic.dex.qt.wallet.manager.hpp @@ -32,7 +32,7 @@ namespace atomic_dex class qt_wallet_manager { public: - QString get_wallet_default_name() const noexcept; + const QString& get_wallet_default_name() const noexcept; void set_wallet_default_name(QString wallet_name) noexcept;