mirror of
https://github.com/feather-wallet/feather.git
synced 2025-01-25 20:05:55 +00:00
Added AtomicFundDialog ui to make depositing btc for swap easy. Updated AtomicSwap functionality to clean swap and monero-wallet-rpc. Can run swap successfully if nothing goes wrong. Cleaned some code
TODO: 1. Connect signals to make status of swap reflected in AtomicSwap dialog 2. Add informational tabs to AtomicSwap dialog 3. Add cancel and refund functionality to AtomicSwap when things go wrong, possibly add automatic cancel functionality
This commit is contained in:
parent
513d83229f
commit
8744138b42
2 changed files with 12 additions and 14 deletions
|
@ -31,7 +31,6 @@ AtomicWidget::AtomicWidget(QWidget *parent)
|
||||||
QString amount_rx = R"(^\d{0,8}[\.]\d{0,12}$)";
|
QString amount_rx = R"(^\d{0,8}[\.]\d{0,12}$)";
|
||||||
QRegularExpression rx;
|
QRegularExpression rx;
|
||||||
rx.setPattern(amount_rx);
|
rx.setPattern(amount_rx);
|
||||||
QValidator *validator = new QRegularExpressionValidator(rx, this);
|
|
||||||
ui->offerBookTable->setModel(o_model);
|
ui->offerBookTable->setModel(o_model);
|
||||||
ui->offerBookTable->setSortingEnabled(true);
|
ui->offerBookTable->setSortingEnabled(true);
|
||||||
ui->offerBookTable->sortByColumn(0, Qt::SortOrder::AscendingOrder);
|
ui->offerBookTable->sortByColumn(0, Qt::SortOrder::AscendingOrder);
|
||||||
|
@ -53,7 +52,7 @@ AtomicWidget::AtomicWidget(QWidget *parent)
|
||||||
ui->meta_label->setText("Updating offer book this may take a bit, if no offers appear after a while try refreshing again");
|
ui->meta_label->setText("Updating offer book this may take a bit, if no offers appear after a while try refreshing again");
|
||||||
|
|
||||||
QStringList pointList = m_instance->get(Config::rendezVous).toStringList();
|
QStringList pointList = m_instance->get(Config::rendezVous).toStringList();
|
||||||
for(QString point :pointList)
|
for(const QString& point :pointList)
|
||||||
AtomicWidget::list(point);
|
AtomicWidget::list(point);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -110,7 +109,7 @@ void AtomicWidget::updateStatus() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomicWidget::runSwap(QString seller, QString btcChange, QString xmrReceive) {
|
void AtomicWidget::runSwap(const QString& seller, const QString& btcChange, const QString& xmrReceive) {
|
||||||
qDebug() << "starting swap";
|
qDebug() << "starting swap";
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << "--data-base-dir";
|
arguments << "--data-base-dir";
|
||||||
|
@ -151,7 +150,7 @@ void AtomicWidget::runSwap(QString seller, QString btcChange, QString xmrReceive
|
||||||
QJsonDocument line = QJsonDocument::fromJson(rawline, &err);
|
QJsonDocument line = QJsonDocument::fromJson(rawline, &err);
|
||||||
qDebug() << rawline;
|
qDebug() << rawline;
|
||||||
if (line["fields"]["message"].toString().contains("Connected to Alice")){
|
if (line["fields"]["message"].toString().contains("Connected to Alice")){
|
||||||
qDebug() << "Succesfully connected";
|
qDebug() << "Successfully connected";
|
||||||
swapDialog->logLine(line["fields"].toString());
|
swapDialog->logLine(line["fields"].toString());
|
||||||
} else if (!line["fields"]["deposit_address"].toString().isEmpty()){
|
} else if (!line["fields"]["deposit_address"].toString().isEmpty()){
|
||||||
qDebug() << "Deposit to btc to segwit address";
|
qDebug() << "Deposit to btc to segwit address";
|
||||||
|
@ -159,12 +158,12 @@ void AtomicWidget::runSwap(QString seller, QString btcChange, QString xmrReceive
|
||||||
QrCode qrc(address, QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::HIGH);
|
QrCode qrc(address, QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::HIGH);
|
||||||
AtomicFundDialog dialog(qobject_cast<QWidget*>(parent()), &qrc, "Deposit BTC to this address", address);
|
AtomicFundDialog dialog(qobject_cast<QWidget*>(parent()), &qrc, "Deposit BTC to this address", address);
|
||||||
connect(&dialog,&AtomicFundDialog::cleanProcs, this, [this]{clean();});
|
connect(&dialog,&AtomicFundDialog::cleanProcs, this, [this]{clean();});
|
||||||
connect(this, &AtomicWidget::receivedBTC,&dialog, [this, &dialog]{
|
connect(this, &AtomicWidget::receivedBTC,&dialog, [ &dialog]{
|
||||||
disconnect(&dialog, SIGNAL(cleanProcs()), nullptr, nullptr);
|
disconnect(&dialog, SIGNAL(cleanProcs()), nullptr, nullptr);
|
||||||
dialog.close();});
|
dialog.close();});
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
} else if (line["fields"]["message"].toString().startsWith("Received Bitcoin")){
|
} else if (line["fields"]["message"].toString().startsWith("Received Bitcoin")){
|
||||||
emit receivedBTC(line["fields"]["new_balance"].toString().split(" ")[0].toDouble());
|
emit receivedBTC(line["fields"]["new_balance"].toString().split(" ")[0].toFloat());
|
||||||
qDebug() << "Spawn atomic swap progress dialog";
|
qDebug() << "Spawn atomic swap progress dialog";
|
||||||
showAtomicSwapDialog();
|
showAtomicSwapDialog();
|
||||||
}
|
}
|
||||||
|
@ -177,9 +176,8 @@ void AtomicWidget::runSwap(QString seller, QString btcChange, QString xmrReceive
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomicWidget::list(QString rendezvous) {
|
void AtomicWidget::list(const QString& rendezvous) {
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
QList<QSharedPointer<OfferEntry>> list;
|
|
||||||
arguments << "--data-base-dir";
|
arguments << "--data-base-dir";
|
||||||
arguments << Config::defaultConfigDir().absolutePath();
|
arguments << Config::defaultConfigDir().absolutePath();
|
||||||
arguments << "-j";
|
arguments << "-j";
|
||||||
|
@ -204,7 +202,7 @@ void AtomicWidget::list(QString rendezvous) {
|
||||||
qDebug() << "parsing Output";
|
qDebug() << "parsing Output";
|
||||||
|
|
||||||
|
|
||||||
for(auto line : lines){
|
for(const auto& line : lines){
|
||||||
qDebug() << line;
|
qDebug() << line;
|
||||||
if(line.contains("status")){
|
if(line.contains("status")){
|
||||||
qDebug() << "status contained";
|
qDebug() << "status contained";
|
||||||
|
@ -212,7 +210,7 @@ void AtomicWidget::list(QString rendezvous) {
|
||||||
if (parsedLine["fields"]["status"].toString().contains("Online")){
|
if (parsedLine["fields"]["status"].toString().contains("Online")){
|
||||||
bool skip = false;
|
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());
|
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){
|
for(const auto& post : *offerList){
|
||||||
if(std::equal(entry->address.begin(), entry->address.end(),post->address.begin(),post->address.end()))
|
if(std::equal(entry->address.begin(), entry->address.end(),post->address.begin(),post->address.end()))
|
||||||
skip = true;
|
skip = true;
|
||||||
}
|
}
|
||||||
|
@ -237,7 +235,7 @@ void AtomicWidget::list(QString rendezvous) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomicWidget::~AtomicWidget() {
|
AtomicWidget::~AtomicWidget() {
|
||||||
qDebug()<< "EXiting widget!!";
|
qDebug()<< "Exiting widget!!";
|
||||||
delete o_model;
|
delete o_model;
|
||||||
delete offerList;
|
delete offerList;
|
||||||
clean();
|
clean();
|
||||||
|
@ -246,7 +244,7 @@ AtomicWidget::~AtomicWidget() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomicWidget::clean() {
|
void AtomicWidget::clean() {
|
||||||
for (auto proc : *procList){
|
for (const auto& proc : *procList){
|
||||||
if(!proc->atEnd())
|
if(!proc->atEnd())
|
||||||
proc->terminate();
|
proc->terminate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit AtomicWidget(QWidget *parent = nullptr);
|
explicit AtomicWidget(QWidget *parent = nullptr);
|
||||||
~AtomicWidget() override;
|
~AtomicWidget() override;
|
||||||
void list(QString rendezvous);
|
void list(const QString& rendezvous);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void skinChanged();
|
void skinChanged();
|
||||||
|
@ -33,7 +33,7 @@ public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showAtomicConfigureDialog();
|
void showAtomicConfigureDialog();
|
||||||
void runSwap(QString seller, QString btcChange, QString xmrReceive);
|
void runSwap(const QString& seller, const QString& btcChange, const QString& xmrReceive);
|
||||||
signals:
|
signals:
|
||||||
void receivedBTC(float new_amount);
|
void receivedBTC(float new_amount);
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue