diff --git a/src/plugins/atomic/AtomicWidget.cpp b/src/plugins/atomic/AtomicWidget.cpp index 5605d30..908ce95 100644 --- a/src/plugins/atomic/AtomicWidget.cpp +++ b/src/plugins/atomic/AtomicWidget.cpp @@ -6,6 +6,7 @@ #include <QList> #include <QProcess> +#include <QInputDialog> #include "AtomicConfigDialog.h" #include "OfferModel.h" @@ -22,18 +23,12 @@ AtomicWidget::AtomicWidget(QWidget *parent) { ui->setupUi(this); - ui->imageExchange->setBackgroundRole(QPalette::Base); - ui->imageExchange->setAssets(":/assets/images/exchange.png", ":/assets/images/exchange_white.png"); - ui->imageExchange->setScaledContents(true); - ui->imageExchange->setFixedSize(26, 26); // validator/locale for input QString amount_rx = R"(^\d{0,8}[\.]\d{0,12}$)"; QRegularExpression rx; rx.setPattern(amount_rx); QValidator *validator = new QRegularExpressionValidator(rx, this); - ui->lineFrom->setValidator(validator); - ui->lineTo->setValidator(validator); ui->offerBookTable->setModel(o_model); ui->offerBookTable->setSortingEnabled(true); ui->offerBookTable->sortByColumn(0, Qt::SortOrder::AscendingOrder); @@ -42,21 +37,18 @@ AtomicWidget::AtomicWidget(QWidget *parent) ui->offerBookTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->offerBookTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch); - //ui->offerBookTable-> - connect(&appData()->prices, &Prices::fiatPricesUpdated, this, &AtomicWidget::onPricesReceived); - connect(&appData()->prices, &Prices::cryptoPricesUpdated, this, &AtomicWidget::onPricesReceived); + ui->btn_configure->setEnabled(true); - connect(ui->lineFrom, &QLineEdit::textEdited, this, [this]{this->convert(false);}); - connect(ui->lineTo, &QLineEdit::textEdited, this, [this]{this->convert(true);}); - - connect(ui->comboAtomicFrom, QOverload<int>::of(&QComboBox::currentIndexChanged), [this]{this->convert(false);}); - connect(ui->comboAtomicTo, QOverload<int>::of(&QComboBox::currentIndexChanged), [this]{this->convert(false);}); + if (!Config::instance()->get(Config::swapPath).toString().isEmpty()) + ui->meta_label->setText("Refresh offer book before swapping to prevent errors"); connect(ui->btn_configure, &QPushButton::clicked, this, &AtomicWidget::showAtomicConfigureDialog); connect(ui->btn_refreshOffer, &QPushButton::clicked, this, [this]{ offerList->clear(); + ui->meta_label->setText("Updating offer book this may take a bit, if no offers appear after a while try refreshing again"); + auto m_instance = Config::instance(); QStringList pointList = m_instance->get(Config::rendezVous).toStringList(); for(QString point :pointList) @@ -88,129 +80,40 @@ AtomicWidget::AtomicWidget(QWidget *parent) */ }); - QTimer::singleShot(1, [this]{ - this->skinChanged(); + connect(ui->btn_addRendezvous, &QPushButton::clicked, this, [this]{ + //offerList = new QList<QSharedPointer<OfferEntry>>; + bool ok; + QString text = QInputDialog::getText(this, tr("Add new rendezvous point"), + tr("p2p multi address of rendezvous point"), QLineEdit::Normal, + "", &ok); + if (ok && !text.isEmpty()) { + QStringList copy = Config::instance()->get(Config::rendezVous).toStringList(); + copy.append(text); + Config::instance()->set(Config::rendezVous,copy); + } }); - m_statusTimer.start(5000); - connect(&m_statusTimer, &QTimer::timeout, this, &AtomicWidget::updateStatus); - QPixmap warningIcon = QPixmap(":/assets/images/warning.png"); - ui->icon_warning->setPixmap(warningIcon.scaledToWidth(32, Qt::SmoothTransformation)); this->updateStatus(); } -void AtomicWidget::convert(bool reverse) { - if (!m_comboBoxInit) - return; - auto lineFrom = reverse ? ui->lineTo : ui->lineFrom; - auto lineTo = reverse ? ui->lineFrom : ui->lineTo; - - auto comboFrom = reverse ? ui->comboAtomicTo : ui->comboAtomicFrom; - auto comboTo = reverse ? ui->comboAtomicFrom : ui->comboAtomicTo; - - QString symbolFrom = comboFrom->itemText(comboFrom->currentIndex()); - QString symbolTo = comboTo->itemText(comboTo->currentIndex()); - - if (symbolFrom == symbolTo) { - lineTo->setText(lineFrom->text()); - } - - QString amountStr = lineFrom->text(); - double amount = amountStr.toDouble(); - double result = appData()->prices.convert(symbolFrom, symbolTo, amount); - - int precision = 10; - if (appData()->prices.rates.contains(symbolTo)) - precision = 2; - - lineTo->setText(QString::number(result, 'f', precision)); -} - -void AtomicWidget::onPricesReceived() { - if (m_comboBoxInit) - return; - - QList<QString> cryptoKeys = appData()->prices.markets.keys(); - QList<QString> fiatKeys = appData()->prices.rates.keys(); - if (cryptoKeys.empty() || fiatKeys.empty()) - return; - - ui->btn_configure->setEnabled(true); - this->initComboBox(); - m_comboBoxInit = true; - this->updateStatus(); -} - -void AtomicWidget::initComboBox() { - QList<QString> cryptoKeys = appData()->prices.markets.keys(); - QList<QString> fiatKeys = appData()->prices.rates.keys(); - - QStringList enabledCrypto = conf()->get(Config::cryptoSymbols).toStringList(); - QStringList filteredCryptoKeys; - for (const auto& symbol : cryptoKeys) { - if (enabledCrypto.contains(symbol)) { - filteredCryptoKeys.append(symbol); - } - } - - QStringList enabledFiat = conf()->get(Config::fiatSymbols).toStringList(); - auto preferredFiat = conf()->get(Config::preferredFiatCurrency).toString(); - if (!enabledFiat.contains(preferredFiat) && fiatKeys.contains(preferredFiat)) { - enabledFiat.append(preferredFiat); - conf()->set(Config::fiatSymbols, enabledFiat); - } - QStringList filteredFiatKeys; - for (const auto &symbol : fiatKeys) { - if (enabledFiat.contains(symbol)) { - filteredFiatKeys.append(symbol); - } - } - - this->setupComboBox(ui->comboAtomicFrom, filteredCryptoKeys, filteredFiatKeys); - this->setupComboBox(ui->comboAtomicTo, filteredCryptoKeys, filteredFiatKeys); - - ui->comboAtomicFrom->setCurrentIndex(ui->comboAtomicFrom->findText("XMR")); - - if (!preferredFiat.isEmpty()) { - ui->comboAtomicTo->setCurrentIndex(ui->comboAtomicTo->findText(preferredFiat)); - } else { - ui->comboAtomicTo->setCurrentIndex(ui->comboAtomicTo->findText("USD")); - } -} void AtomicWidget::skinChanged() { - ui->imageExchange->setMode(ColorScheme::hasDarkBackground(this)); } void AtomicWidget::showAtomicConfigureDialog() { AtomicConfigDialog dialog{this}; if (dialog.exec() == QDialog::Accepted) { - this->initComboBox(); + } } -void AtomicWidget::setupComboBox(QComboBox *comboBox, const QStringList &crypto, const QStringList &fiat) { - comboBox->clear(); - comboBox->addItems(crypto); - comboBox->insertSeparator(comboBox->count()); - comboBox->addItems(fiat); -} + void AtomicWidget::updateStatus() { - if (!m_comboBoxInit) { - ui->label_warning->setText("Waiting on exchange data."); - ui->frame_warning->show(); - } - else if (websocketNotifier()->stale(10)) { - ui->label_warning->setText("No new exchange rates received for over 10 minutes."); - ui->frame_warning->show(); - } - else { - ui->frame_warning->hide(); - } + } void AtomicWidget::list(QString rendezvous) { @@ -248,18 +151,27 @@ void AtomicWidget::list(QString rendezvous) { qDebug() << "status contained"; parsedLine = QJsonDocument::fromJson(line.toLocal8Bit(), &parseError ); if (parsedLine["fields"]["status"].toString().contains("Online")){ - OfferEntry entry = {parsedLine["fields"]["price"].toDouble(),parsedLine["fields"]["min_quantity"].toDouble(),parsedLine["fields"]["max_quantity"].toDouble(), parsedLine["fields"]["address"].toString()}; - offerList->append(QSharedPointer<OfferEntry>(&entry)); - qDebug() << &entry; + bool skip = false; + auto entry = new OfferEntry(parsedLine["fields"]["price"].toString().split( ' ')[0].toDouble(),parsedLine["fields"]["min_quantity"].toString().split(' ')[0].toDouble(),parsedLine["fields"]["max_quantity"].toString().split(' ')[0].toDouble(), parsedLine["fields"]["address"].toString()); + for(auto post : *offerList){ + if(std::equal(entry->address.begin(), entry->address.end(),post->address.begin(),post->address.end())) + skip = true; + } + if (!skip) { + ui->meta_label->setText("Updated offer book"); + offerList->append(QSharedPointer<OfferEntry>(entry)); + } + qDebug() << entry; } } qDebug() << "next line"; } qDebug() << "exits fine"; swap->close(); + o_model->updateOffers(*offerList); return list; }); - swap->start("/home/dev/.config/feather/swap", arguments); + swap->start(m_instance->get(Config::swapPath).toString(), arguments); //swap->waitForFinished(120000); diff --git a/src/plugins/atomic/AtomicWidget.h b/src/plugins/atomic/AtomicWidget.h index aaf1b9b..8cf353d 100644 --- a/src/plugins/atomic/AtomicWidget.h +++ b/src/plugins/atomic/AtomicWidget.h @@ -29,13 +29,9 @@ public slots: void skinChanged(); private slots: - void initComboBox(); void showAtomicConfigureDialog(); - void onPricesReceived(); private: - void convert(bool reverse); - void setupComboBox(QComboBox *comboBox, const QStringList &crypto, const QStringList &fiat); void updateStatus(); QScopedPointer<Ui::AtomicWidget> ui; diff --git a/src/plugins/atomic/AtomicWidget.ui b/src/plugins/atomic/AtomicWidget.ui index aa5a21e..3bfd080 100644 --- a/src/plugins/atomic/AtomicWidget.ui +++ b/src/plugins/atomic/AtomicWidget.ui @@ -15,124 +15,76 @@ </property> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> - <widget class="QFrame" name="frame_warning"> - <property name="frameShape"> - <enum>QFrame::Shape::StyledPanel</enum> - </property> - <property name="frameShadow"> - <enum>QFrame::Shadow::Raised</enum> - </property> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QLabel" name="icon_warning"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>icon</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Orientation::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Policy::Maximum</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>10</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QLabel" name="label_warning"> - <property name="text"> - <string>Warning text</string> - </property> - </widget> - </item> - </layout> - </widget> + <widget class="QTableView" name="offerBookTable"/> </item> <item> - <layout class="QGridLayout" name="gridLayout_2"> - <property name="horizontalSpacing"> - <number>18</number> - </property> - <item row="0" column="0"> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <property name="spacing"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QLineEdit" name="lineFrom"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="frame"> - <bool>true</bool> - </property> - <property name="placeholderText"> - <string>From...</string> + <widget class="QLabel" name="label"> + <property name="text"> + <string>BTC change address</string> </property> </widget> </item> <item> - <widget class="QComboBox" name="comboAtomicFrom"/> + <widget class="QLineEdit" name="change_address"/> </item> </layout> </item> - <item row="0" column="1"> - <widget class="DoublePixmapLabel" name="imageExchange"> - <property name="text"> - <string>exchange image</string> - </property> - </widget> - </item> - <item row="0" column="2"> - <layout class="QHBoxLayout" name="horizontalLayout_4"> - <property name="spacing"> - <number>0</number> - </property> + <item> + <layout class="QVBoxLayout" name="verticalLayout_4"> <item> - <widget class="QLineEdit" name="lineTo"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="readOnly"> - <bool>false</bool> - </property> - <property name="placeholderText"> - <string>To...</string> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>XMR receive address</string> </property> </widget> </item> <item> - <widget class="QComboBox" name="comboAtomicTo"/> + <widget class="QLineEdit" name="xmr_address"/> </item> </layout> </item> </layout> </item> <item> - <widget class="QTableView" name="offerBookTable"/> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Orientation::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="btn_swap"> + <property name="text"> + <string>Swap</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Orientation::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout"> @@ -150,6 +102,13 @@ </property> </widget> </item> + <item> + <widget class="QLabel" name="meta_label"> + <property name="text"> + <string>No swap tool configured, click configure to set up</string> + </property> + </widget> + </item> <item> <spacer name="horizontalSpacer"> <property name="orientation"> @@ -174,13 +133,6 @@ </item> </layout> </widget> - <customwidgets> - <customwidget> - <class>DoublePixmapLabel</class> - <extends>QLabel</extends> - <header>components.h</header> - </customwidget> - </customwidgets> <resources/> <connections/> <slots>