Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion assets/config/cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
"fr",
"tr"
],
"current_currency": "USD",
"current_fiat": "USD",
"available_fiat": [
"USD",
"EUR"
],
"possible_currencies": [
"USD",
"BTC",
"EUR",
"KMD"
]
}
5 changes: 4 additions & 1 deletion atomic_qt_design/qml/Constants/API.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ QtObject {

balance_fiat_all: "12345678.90",

fiat: "EUR",
current_currency: "EUR",
get_available_fiats: () => ["USD", "EUR"],
get_available_currencies: () => ["EUR", "BTC", "KMD"],

lang: "en",
get_available_langs: () => ["en", "fr", "tr"],

Expand Down
8 changes: 7 additions & 1 deletion atomic_qt_design/qml/Constants/General.qml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,16 @@ QtObject {
return list.find(c => c.ticker === ticker)
}

function validFiatRates(data, fiat) {
return data && data.rates && data.rates[fiat]
}

function formatFiat(received, amount, fiat) {
const symbols = {
"USD": "$",
"EUR": "€"
"EUR": "€",
"BTC": "₿",
"KMD": "KMD",
}

return diffPrefix(received) + symbols[fiat] + " " + amount
Expand Down
39 changes: 28 additions & 11 deletions atomic_qt_design/qml/Portfolio/Portfolio.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ ColumnLayout {
}

function getColor(data) {
return data.rates === null || data.rates[API.get().fiat].percent_change_24h === 0 ? Style.colorWhite4 :
data.rates[API.get().fiat].percent_change_24h > 0 ? Style.colorGreen : Style.colorRed
const fiat = API.get().current_currency

if(General.validFiatRates(data, fiat) && data.rates[fiat].percent_change_24h !== 0)
return data.rates[fiat].percent_change_24h > 0 ? Style.colorGreen : Style.colorRed

return Style.colorWhite4
}

function updateChart(chart, historical) {
Expand Down Expand Up @@ -73,6 +77,7 @@ ColumnLayout {
height: 200

ColumnLayout {
id: top_layout
anchors.centerIn: parent

// Total Title
Expand All @@ -89,11 +94,23 @@ ColumnLayout {
DefaultText {
Layout.alignment: Qt.AlignHCenter
Layout.bottomMargin: 30
text_value: API.get().empty_string + (General.formatFiat("", API.get().balance_fiat_all, API.get().fiat))
text_value: API.get().empty_string + (General.formatFiat("", API.get().balance_fiat_all, API.get().current_currency))
font.pixelSize: Style.textSize4
}
}

MouseArea {
anchors.fill: top_layout

onClicked: {
const current_fiat = API.get().current_currency
const available_fiats = API.get().get_available_currencies()
const current_index = available_fiats.indexOf(current_fiat)
const next_index = (current_index + 1) % available_fiats.length
const next_fiat = available_fiats[next_index]
API.get().current_currency = next_fiat
}
}

// Add button
PlusButton {
Expand Down Expand Up @@ -158,7 +175,7 @@ ColumnLayout {
id: balance_header
icon_at_left: true
anchors.left: parent.left
anchors.leftMargin: parent.width * 0.3
anchors.leftMargin: parent.width * 0.265
anchors.verticalCenter: parent.verticalCenter

text: API.get().empty_string + (qsTr("Balance"))
Expand All @@ -170,7 +187,7 @@ ColumnLayout {
id: change_24h_header
icon_at_left: false
anchors.right: parent.right
anchors.rightMargin: parent.width * 0.27
anchors.rightMargin: parent.width * 0.37
anchors.verticalCenter: parent.verticalCenter

text: API.get().empty_string + (qsTr("Change 24h"))
Expand All @@ -182,7 +199,7 @@ ColumnLayout {
id: trend_7d_header
icon_at_left: false
anchors.right: parent.right
anchors.rightMargin: parent.width * 0.15
anchors.rightMargin: parent.width * 0.24
anchors.verticalCenter: parent.verticalCenter

text: API.get().empty_string + (qsTr("Trend 7d"))
Expand Down Expand Up @@ -266,8 +283,8 @@ ColumnLayout {
case sort_by_balance: return (parseFloat(b.balance) - parseFloat(a.balance)) * order
case sort_by_trend: return (parseFloat(b.price) - parseFloat(a.price)) * order
case sort_by_change:
val_a = a.rates === null ? -9999999 : a.rates[API.get().fiat].percent_change_24h
val_b = b.rates === null ? -9999999 : b.rates[API.get().fiat].percent_change_24h
val_a = General.validFiatRates(a, API.get().current_currency) ? a.rates[API.get().current_currency].percent_change_24h : -9999999
val_b = General.validFiatRates(b, API.get().current_currency) ? b.rates[API.get().current_currency].percent_change_24h : -9999999

return (val_b - val_a) * order
}
Expand Down Expand Up @@ -355,7 +372,7 @@ ColumnLayout {
anchors.left: balance_ticker.right
anchors.leftMargin: 10

text_value: API.get().empty_string + ("(" + General.formatFiat('', model.modelData.balance_fiat, API.get().fiat) + ")")
text_value: API.get().empty_string + ("(" + General.formatFiat('', model.modelData.balance_fiat, API.get().current_currency) + ")")
color: Style.colorWhite5
anchors.verticalCenter: parent.verticalCenter
}
Expand All @@ -365,7 +382,7 @@ ColumnLayout {
anchors.right: parent.right
anchors.rightMargin: change_24h_header.anchors.rightMargin

text_value: API.get().empty_string + (model.modelData.rates === null ? '-' : General.formatPercent(model.modelData.rates[API.get().fiat].percent_change_24h))
text_value: API.get().empty_string + (General.validFiatRates(model.modelData, API.get().current_currency) ? General.formatPercent(model.modelData.rates[API.get().current_currency].percent_change_24h) : '-')
color: getColor(model.modelData)
anchors.verticalCenter: parent.verticalCenter
}
Expand All @@ -375,7 +392,7 @@ ColumnLayout {
anchors.right: parent.right
anchors.rightMargin: price_header.anchors.rightMargin

text_value: API.get().empty_string + (General.formatFiat('', model.modelData.price, API.get().fiat))
text_value: API.get().empty_string + (General.formatFiat('', model.modelData.price, API.get().current_currency))
color: Style.colorThemeDarkLight
anchors.verticalCenter: parent.verticalCenter
}
Expand Down
7 changes: 4 additions & 3 deletions atomic_qt_design/qml/Settings/Settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "../Components"
import "../Constants"

Item {
id: root
function disconnect() {
API.get().disconnect()
onDisconnect()
Expand All @@ -21,7 +22,7 @@ Item {
}

property string mm2_version: ''
property var fiats: (["USD", "EUR"])
property var fiats: API.get().get_available_fiats()

InnerBackground {
id: layout_background
Expand All @@ -44,10 +45,10 @@ Item {

property bool initialized: false
field.onCurrentIndexChanged: {
if(initialized) API.get().fiat = fiats[field.currentIndex]
if(initialized) API.get().current_currency = fiats[field.currentIndex]
}
Component.onCompleted: {
field.currentIndex = fiats.indexOf(API.get().fiat)
field.currentIndex = fiats.indexOf(API.get().current_currency)
initialized = true
}
}
Expand Down
14 changes: 8 additions & 6 deletions atomic_qt_design/qml/Wallet/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Item {
}

DefaultText {
text_value: API.get().empty_string + (General.formatFiat("", API.get().current_coin_info.fiat_amount, API.get().fiat))
text_value: API.get().empty_string + (General.formatFiat("", API.get().current_coin_info.current_currency_amount, API.get().current_currency))
Layout.alignment: Qt.AlignLeft
font.pixelSize: name.font.pixelSize
}
Expand Down Expand Up @@ -121,7 +121,7 @@ Item {
const c = General.getCoin(portfolio_coins, API.get().current_coin_info.ticker)
if(c === undefined) return "-"

return API.get().empty_string + (General.formatFiat('', c.price, API.get().fiat))
return API.get().empty_string + (General.formatFiat('', c.price, API.get().current_currency))
}

Layout.alignment: Qt.AlignLeft
Expand All @@ -143,19 +143,21 @@ Item {
DefaultText {
text_value: {
const c = General.getCoin(portfolio_coins, API.get().current_coin_info.ticker)
if(c === undefined || c.rates === null) return "-"
const fiat = API.get().current_currency
if(!General.validFiatRates(c, fiat)) return "-"

return API.get().empty_string + (General.formatPercent(c.rates[API.get().fiat].percent_change_24h))
return API.get().empty_string + (General.formatPercent(c.rates[fiat].percent_change_24h))
}
Layout.alignment: Qt.AlignLeft
font.pixelSize: name.font.pixelSize
color: {
const c = General.getCoin(portfolio_coins, API.get().current_coin_info.ticker)

const def_color = Style.colorWhite4
if(c === undefined || c.rates === null) return def_color
const fiat = API.get().current_currency
if(!General.validFiatRates(c, fiat)) return def_color

const v = parseFloat(c.rates[API.get().fiat].percent_change_24h)
const v = parseFloat(c.rates[fiat].percent_change_24h)
return v === 0 ? def_color : v > 0 ? Style.colorGreen : Style.colorRed
}
}
Expand Down
2 changes: 1 addition & 1 deletion atomic_qt_design/qml/Wallet/TransactionDetailsModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DefaultModal {
// Amount
TextWithTitle {
title: API.get().empty_string + (qsTr("Amount"))
text: API.get().empty_string + (General.formatCrypto(details.received, details.amount, API.get().current_coin_info.ticker, details.amount_fiat, API.get().fiat))
text: API.get().empty_string + (General.formatCrypto(details.received, details.amount, API.get().current_coin_info.ticker, details.amount_fiat, API.get().current_currency))
value_color: details.received ? Style.colorGreen : Style.colorRed
}

Expand Down
2 changes: 1 addition & 1 deletion atomic_qt_design/qml/Wallet/Transactions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ DefaultListView {

// Fiat
DefaultText {
text_value: API.get().empty_string + (General.formatFiat(model.modelData.received, model.modelData.amount_fiat, API.get().fiat))
text_value: API.get().empty_string + (General.formatFiat(model.modelData.received, model.modelData.amount_fiat, API.get().current_currency))
font.pixelSize: description.font.pixelSize
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
Expand Down
39 changes: 24 additions & 15 deletions src/atomic.dex.app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ namespace atomic_dex
}

std::error_code ec;
auto fiat_balance_std = paprika.get_price_in_fiat_all(m_config.current_fiat, ec);
auto fiat_balance_std = paprika.get_price_in_fiat_all(m_config.current_currency, ec);

if (!ec)
{
Expand Down Expand Up @@ -303,12 +303,12 @@ namespace atomic_dex
QString target_balance = QString::fromStdString(mm2.my_balance(m_coin_info->get_ticker().toStdString(), ec));
m_coin_info->set_balance(target_balance);

if (std::any_of(begin(m_config.available_fiat), end(m_config.available_fiat), [this](const std::string& cur_fiat) {
return cur_fiat == m_config.current_fiat;
if (std::any_of(begin(m_config.possible_currencies), end(m_config.possible_currencies), [this](const std::string& cur_fiat) {
return cur_fiat == m_config.current_currency;
}))
{
ec = std::error_code();
auto amount = QString::fromStdString(paprika.get_price_in_fiat(m_config.current_fiat, m_coin_info->get_ticker().toStdString(), ec));
auto amount = QString::fromStdString(paprika.get_price_in_fiat(m_config.current_currency, m_coin_info->get_ticker().toStdString(), ec));
if (!ec)
{
m_coin_info->set_fiat_amount(amount);
Expand All @@ -325,7 +325,7 @@ namespace atomic_dex
if (!ec)
{
m_coin_info->set_transactions(
to_qt_binding(std::move(txs), this, get_paprika(), QString::fromStdString(m_config.current_fiat), m_coin_info->get_ticker().toStdString()));
to_qt_binding(std::move(txs), this, get_paprika(), QString::fromStdString(m_config.current_currency), m_coin_info->get_ticker().toStdString()));
}
auto tx_state = mm2.get_tx_state(m_coin_info->get_ticker().toStdString(), ec);

Expand Down Expand Up @@ -453,19 +453,19 @@ namespace atomic_dex
}

QString
application::get_current_fiat() const noexcept
application::get_current_currency() const noexcept
{
return QString::fromStdString(this->m_config.current_fiat);
return QString::fromStdString(this->m_config.current_currency);
}

void
application::set_current_fiat(QString current_fiat) noexcept
application::set_current_currency(QString current_currency) noexcept
{
if (current_fiat.toStdString() != m_config.current_fiat)
if (current_currency.toStdString() != m_config.current_currency)
{
spdlog::info("change lang {} to {}", m_config.current_fiat, current_fiat.toStdString());
atomic_dex::change_fiat(m_config, current_fiat.toStdString());
emit on_fiat_changed();
spdlog::info("change currency {} to {}", m_config.current_currency, current_currency.toStdString());
atomic_dex::change_currency(m_config, current_currency.toStdString());
emit on_currency_changed();
}
}

Expand Down Expand Up @@ -880,9 +880,9 @@ namespace atomic_dex
nlohmann::json cur_obj{
{"ticker", coin.ticker},
{"name", coin.name},
{"price", get_paprika().get_rate_conversion(m_config.current_fiat, coin.ticker, ec, true)},
{"price", get_paprika().get_rate_conversion(m_config.current_currency, coin.ticker, ec, true)},
{"balance", get_mm2().my_balance(coin.ticker, ec)},
{"balance_fiat", get_paprika().get_price_in_fiat(m_config.current_fiat, coin.ticker, ec)},
{"balance_fiat", get_paprika().get_price_in_fiat(m_config.current_currency, coin.ticker, ec)},
{"rates", get_paprika().get_ticker_infos(coin.ticker).answer},
{"historical", get_paprika().get_ticker_historical(coin.ticker).answer}};
j.push_back(cur_obj);
Expand Down Expand Up @@ -957,6 +957,15 @@ namespace atomic_dex
return out;
}

QStringList
application::get_available_currencies() const
{
QStringList out;
out.reserve(m_config.possible_currencies.size());
for (auto&& cur_currency: m_config.possible_currencies) { out.push_back(QString::fromStdString(cur_currency)); }
return out;
}

const QString&
application::get_empty_string() const
{
Expand Down Expand Up @@ -1165,7 +1174,7 @@ namespace atomic_dex
std::error_code ec;
return QString::fromStdString(get_paprika().get_cex_rates(base.toStdString(), rel.toStdString(), ec));
}
}
} // namespace atomic_dex

//! OHLC Relative functions
namespace atomic_dex
Expand Down
9 changes: 5 additions & 4 deletions src/atomic.dex.app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace atomic_dex
Q_PROPERTY(QList<QObject*> enabled_coins READ get_enabled_coins NOTIFY enabledCoinsChanged)
Q_PROPERTY(QList<QObject*> 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 current_currency READ get_current_currency WRITE set_current_currency NOTIFY on_currency_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)
Expand Down Expand Up @@ -89,7 +89,7 @@ namespace atomic_dex
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_currency() const noexcept;
QString get_current_lang() const noexcept;
QString get_balance_fiat_all() const noexcept;
QString get_second_balance_fiat_all() const noexcept;
Expand All @@ -98,7 +98,7 @@ namespace atomic_dex
Q_INVOKABLE QString get_version() const noexcept;

//! Properties Setter
void set_current_fiat(QString current_fiat) noexcept;
void set_current_currency(QString current_currency) noexcept;
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;
Expand Down Expand Up @@ -131,6 +131,7 @@ namespace atomic_dex
Q_INVOKABLE QString get_export_folder() const;
Q_INVOKABLE QStringList get_available_langs() const;
Q_INVOKABLE QStringList get_available_fiats() const;
Q_INVOKABLE QStringList get_available_currencies() const;
Q_INVOKABLE static void change_state(int visibility);

//! Portfolio QML API Bindings
Expand Down Expand Up @@ -190,7 +191,7 @@ namespace atomic_dex
void enabledCoinsChanged();
void enableableCoinsChanged();
void coinInfoChanged();
void on_fiat_changed();
void on_currency_changed();
void on_second_fiat_changed();
void on_lang_changed();
void lang_changed();
Expand Down
Loading