mirror of
https://github.com/feather-wallet/feather.git
synced 2025-01-24 03:25:51 +00:00
Merge pull request 'MorphToken: get rates' (#171) from tobtoht/feather:morphtoken_rates into master
Reviewed-on: https://git.wownero.com/feather/feather/pulls/171
This commit is contained in:
commit
5ce6c8933d
3 changed files with 45 additions and 0 deletions
|
@ -19,13 +19,16 @@ MorphTokenWidget::MorphTokenWidget(QWidget *parent) :
|
||||||
|
|
||||||
connect(ui->btnCreateTrade, &QPushButton::clicked, this, &MorphTokenWidget::createTrade);
|
connect(ui->btnCreateTrade, &QPushButton::clicked, this, &MorphTokenWidget::createTrade);
|
||||||
connect(ui->btn_lookupTrade, &QPushButton::clicked, this, &MorphTokenWidget::lookupTrade);
|
connect(ui->btn_lookupTrade, &QPushButton::clicked, this, &MorphTokenWidget::lookupTrade);
|
||||||
|
connect(ui->btn_getRates, &QPushButton::clicked, this, &MorphTokenWidget::getRates);
|
||||||
|
|
||||||
connect(m_api, &MorphTokenApi::ApiResponse, this, &MorphTokenWidget::onApiResponse);
|
connect(m_api, &MorphTokenApi::ApiResponse, this, &MorphTokenWidget::onApiResponse);
|
||||||
|
|
||||||
connect(ui->combo_From, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index){
|
connect(ui->combo_From, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index){
|
||||||
|
this->displayRate();
|
||||||
ui->label_refundAddress->setText(QString("Refund address (%1):").arg(ui->combo_From->currentText()));
|
ui->label_refundAddress->setText(QString("Refund address (%1):").arg(ui->combo_From->currentText()));
|
||||||
});
|
});
|
||||||
connect(ui->combo_To, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index){
|
connect(ui->combo_To, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index){
|
||||||
|
this->displayRate();
|
||||||
ui->label_destinationAddress->setText(QString("Destination address (%1):").arg(ui->combo_To->currentText()));
|
ui->label_destinationAddress->setText(QString("Destination address (%1):").arg(ui->combo_To->currentText()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -45,6 +48,12 @@ MorphTokenWidget::MorphTokenWidget(QWidget *parent) :
|
||||||
ui->combo_From->setCurrentIndex(1);
|
ui->combo_From->setCurrentIndex(1);
|
||||||
ui->combo_To->setCurrentIndex(0);
|
ui->combo_To->setCurrentIndex(0);
|
||||||
|
|
||||||
|
ui->label_rate->setVisible(false);
|
||||||
|
m_ratesTimer.setSingleShot(true);
|
||||||
|
connect(&m_ratesTimer, &QTimer::timeout, [this]{
|
||||||
|
ui->label_rate->setVisible(false);
|
||||||
|
});
|
||||||
|
|
||||||
ui->tabWidget->setTabVisible(2, false);
|
ui->tabWidget->setTabVisible(2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +73,10 @@ void MorphTokenWidget::lookupTrade() {
|
||||||
m_api->getTrade(morphId);
|
m_api->getTrade(morphId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MorphTokenWidget::getRates() {
|
||||||
|
m_api->getRates();
|
||||||
|
}
|
||||||
|
|
||||||
void MorphTokenWidget::onApiResponse(const MorphTokenApi::MorphTokenResponse &resp) {
|
void MorphTokenWidget::onApiResponse(const MorphTokenApi::MorphTokenResponse &resp) {
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
ui->check_autorefresh->setChecked(false);
|
ui->check_autorefresh->setChecked(false);
|
||||||
|
@ -136,6 +149,11 @@ void MorphTokenWidget::onApiResponse(const MorphTokenApi::MorphTokenResponse &re
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->label_status->setText(statusText);
|
ui->label_status->setText(statusText);
|
||||||
|
} else if (resp.endpoint == MorphTokenApi::Endpoint::GET_RATES) {
|
||||||
|
m_rates = resp.obj.value("data").toObject();
|
||||||
|
this->displayRate();
|
||||||
|
ui->label_rate->setVisible(true);
|
||||||
|
m_ratesTimer.start(120 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.endpoint == MorphTokenApi::Endpoint::CREATE_TRADE) {
|
if (resp.endpoint == MorphTokenApi::Endpoint::CREATE_TRADE) {
|
||||||
|
@ -153,6 +171,15 @@ void MorphTokenWidget::onCountdown() {
|
||||||
ui->check_autorefresh->setText(QString("Autorefresh (%1)").arg(m_countdown));
|
ui->check_autorefresh->setText(QString("Autorefresh (%1)").arg(m_countdown));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MorphTokenWidget::displayRate() {
|
||||||
|
QString inputAsset = ui->combo_From->currentText();
|
||||||
|
QString outputAsset = ui->combo_To->currentText();
|
||||||
|
QString outputRate = m_rates.value(inputAsset).toObject().value(outputAsset).toString("1");
|
||||||
|
|
||||||
|
QString rateStr = QString("1 %1 -> %2 %3").arg(inputAsset, outputRate, outputAsset);
|
||||||
|
ui->label_rate->setText(rateStr);
|
||||||
|
}
|
||||||
|
|
||||||
QString MorphTokenWidget::formatAmount(const QString &asset, double amount) {
|
QString MorphTokenWidget::formatAmount(const QString &asset, double amount) {
|
||||||
double displayAmount;
|
double displayAmount;
|
||||||
double div;
|
double div;
|
||||||
|
|
|
@ -23,9 +23,11 @@ public:
|
||||||
private:
|
private:
|
||||||
void createTrade();
|
void createTrade();
|
||||||
void lookupTrade();
|
void lookupTrade();
|
||||||
|
void getRates();
|
||||||
void onApiResponse(const MorphTokenApi::MorphTokenResponse &resp);
|
void onApiResponse(const MorphTokenApi::MorphTokenResponse &resp);
|
||||||
|
|
||||||
void onCountdown();
|
void onCountdown();
|
||||||
|
void displayRate();
|
||||||
|
|
||||||
QString formatAmount(const QString &asset, double amount);
|
QString formatAmount(const QString &asset, double amount);
|
||||||
|
|
||||||
|
@ -36,6 +38,8 @@ private:
|
||||||
UtilsNetworking *m_network;
|
UtilsNetworking *m_network;
|
||||||
QTimer m_countdownTimer;
|
QTimer m_countdownTimer;
|
||||||
int m_countdown = 30;
|
int m_countdown = 30;
|
||||||
|
QJsonObject m_rates;
|
||||||
|
QTimer m_ratesTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //FEATHER_MORPHTOKENWIDGET_H
|
#endif //FEATHER_MORPHTOKENWIDGET_H
|
||||||
|
|
|
@ -145,6 +145,13 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_rate">
|
||||||
|
<property name="text">
|
||||||
|
<string>rate</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -196,6 +203,13 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_getRates">
|
||||||
|
<property name="text">
|
||||||
|
<string>Get Rates</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnCreateTrade">
|
<widget class="QPushButton" name="btnCreateTrade">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
Loading…
Reference in a new issue