mirror of
https://git.wownero.com/wowlet/wowlet.git
synced 2024-08-15 01:03:14 +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->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(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()));
|
||||
});
|
||||
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()));
|
||||
});
|
||||
|
||||
|
@ -45,6 +48,12 @@ MorphTokenWidget::MorphTokenWidget(QWidget *parent) :
|
|||
ui->combo_From->setCurrentIndex(1);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -64,6 +73,10 @@ void MorphTokenWidget::lookupTrade() {
|
|||
m_api->getTrade(morphId);
|
||||
}
|
||||
|
||||
void MorphTokenWidget::getRates() {
|
||||
m_api->getRates();
|
||||
}
|
||||
|
||||
void MorphTokenWidget::onApiResponse(const MorphTokenApi::MorphTokenResponse &resp) {
|
||||
if (!resp.ok) {
|
||||
ui->check_autorefresh->setChecked(false);
|
||||
|
@ -136,6 +149,11 @@ void MorphTokenWidget::onApiResponse(const MorphTokenApi::MorphTokenResponse &re
|
|||
}
|
||||
|
||||
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) {
|
||||
|
@ -153,6 +171,15 @@ void MorphTokenWidget::onCountdown() {
|
|||
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) {
|
||||
double displayAmount;
|
||||
double div;
|
||||
|
|
|
@ -23,9 +23,11 @@ public:
|
|||
private:
|
||||
void createTrade();
|
||||
void lookupTrade();
|
||||
void getRates();
|
||||
void onApiResponse(const MorphTokenApi::MorphTokenResponse &resp);
|
||||
|
||||
void onCountdown();
|
||||
void displayRate();
|
||||
|
||||
QString formatAmount(const QString &asset, double amount);
|
||||
|
||||
|
@ -36,6 +38,8 @@ private:
|
|||
UtilsNetworking *m_network;
|
||||
QTimer m_countdownTimer;
|
||||
int m_countdown = 30;
|
||||
QJsonObject m_rates;
|
||||
QTimer m_ratesTimer;
|
||||
};
|
||||
|
||||
#endif //FEATHER_MORPHTOKENWIDGET_H
|
||||
|
|
|
@ -145,6 +145,13 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_rate">
|
||||
<property name="text">
|
||||
<string>rate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -196,6 +203,13 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_getRates">
|
||||
<property name="text">
|
||||
<string>Get Rates</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnCreateTrade">
|
||||
<property name="text">
|
||||
|
|
Loading…
Reference in a new issue