Merge UI elements for migration
This commit is contained in:
@@ -67,129 +67,150 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
rpc->refresh();
|
||||
}
|
||||
|
||||
void MainWindow::setupTurnstileDialog() {
|
||||
void MainWindow::turnstileProgress() {
|
||||
Ui_TurnstileProgress progress;
|
||||
QDialog d(this);
|
||||
progress.setupUi(&d);
|
||||
|
||||
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);
|
||||
progress.msgIcon->setPixmap(icon.pixmap(64, 64));
|
||||
|
||||
progress.buttonBox->button(QDialogButtonBox::Cancel)->setText("Abort");
|
||||
|
||||
auto fnUpdateProgressUI = [=] () {
|
||||
// Get the plan progress
|
||||
if (rpc->getTurnstile()->isMigrationPresent()) {
|
||||
auto curProgress = rpc->getTurnstile()->getPlanProgress();
|
||||
|
||||
progress.progressTxt->setText(QString::number(curProgress.step) % QString(" / ") % QString::number(curProgress.totalSteps));
|
||||
progress.progressBar->setValue(100 * curProgress.step / curProgress.totalSteps);
|
||||
|
||||
auto nextTxBlock = curProgress.nextBlock - Settings::getInstance()->getBlockNumber();
|
||||
|
||||
if (curProgress.step == curProgress.totalSteps) {
|
||||
auto txt = QString("Turnstile migration finished");
|
||||
if (curProgress.hasErrors) {
|
||||
txt = txt + ". There were some errors.\n\nYour funds are all in your wallet, so you should be able to finish moving them manually.";
|
||||
}
|
||||
progress.nextTx->setText(txt);
|
||||
} else {
|
||||
progress.nextTx->setText(QString("Next transaction in ")
|
||||
% QString::number(nextTxBlock < 0 ? 0 : nextTxBlock)
|
||||
% " blocks\n"
|
||||
% (nextTxBlock <= 0 ? "(waiting for confirmations)" : ""));
|
||||
}
|
||||
|
||||
} else {
|
||||
progress.progressTxt->setText("");
|
||||
progress.progressBar->setValue(0);
|
||||
progress.nextTx->setText("No turnstile migration is in progress");
|
||||
}
|
||||
};
|
||||
|
||||
QTimer progressTimer(this);
|
||||
QObject::connect(&progressTimer, &QTimer::timeout, fnUpdateProgressUI);
|
||||
progressTimer.start(Utils::updateSpeed);
|
||||
fnUpdateProgressUI();
|
||||
|
||||
auto accpeted = d.exec();
|
||||
auto curProgress = rpc->getTurnstile()->getPlanProgress();
|
||||
if (accpeted == QDialog::Accepted && curProgress.step == curProgress.totalSteps) {
|
||||
// Finished, so delete the file
|
||||
rpc->getTurnstile()->removeFile();
|
||||
}
|
||||
if (accpeted == QDialog::Rejected && curProgress.step != curProgress.totalSteps) {
|
||||
auto abort = QMessageBox::warning(this, "Are you sure you want to Abort?",
|
||||
"Are you sure you want to abort the migration?\nAll further transactions will be cancelled.\nAll your funds are still in your wallet.",
|
||||
QMessageBox::Yes, QMessageBox::No);
|
||||
if (abort) {
|
||||
rpc->getTurnstile()->removeFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::turnstileDoMigration() {
|
||||
Ui_Turnstile turnstile;
|
||||
QDialog d(this);
|
||||
turnstile.setupUi(&d);
|
||||
|
||||
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation);
|
||||
turnstile.msgIcon->setPixmap(icon.pixmap(64, 64));
|
||||
|
||||
auto fnGetAllSproutBalance = [=] () {
|
||||
double bal = 0;
|
||||
for (auto addr : *rpc->getAllZAddresses()) {
|
||||
if (Settings::getInstance()->isSproutAddress(addr)) {
|
||||
bal += rpc->getAllBalances()->value(addr);
|
||||
}
|
||||
}
|
||||
|
||||
return bal;
|
||||
};
|
||||
|
||||
//turnstile.migrateZaddList->addItem("All Sprout z-Addrs");
|
||||
turnstile.fromBalance->setText(Settings::getInstance()->getZECUSDDisplayFormat(fnGetAllSproutBalance()));
|
||||
for (auto addr : *rpc->getAllZAddresses()) {
|
||||
if (Settings::getInstance()->isSaplingAddress(addr)) {
|
||||
turnstile.migrateTo->addItem(addr);
|
||||
} else {
|
||||
if (rpc->getAllBalances()->value(addr) > 0)
|
||||
turnstile.migrateZaddList->addItem(addr);
|
||||
}
|
||||
}
|
||||
|
||||
QObject::connect(turnstile.migrateZaddList, &QComboBox::currentTextChanged, [=] (auto addr) {
|
||||
double bal = 0;
|
||||
if (addr.startsWith("All")) {
|
||||
bal = fnGetAllSproutBalance();
|
||||
} else {
|
||||
bal = rpc->getAllBalances()->value(addr);
|
||||
}
|
||||
|
||||
turnstile.fromBalance->setText(Settings::getInstance()->getZECUSDDisplayFormat(bal));
|
||||
});
|
||||
|
||||
// Privacy level combobox
|
||||
// Num tx over num blocks
|
||||
QList<QPair<int, int>> privOptions;
|
||||
privOptions.push_back(QPair<double, double>(3, 3));
|
||||
privOptions.push_back(QPair<double, double>(5, 5));
|
||||
privOptions.push_back(QPair<double, double>(10, 7));
|
||||
|
||||
QObject::connect(turnstile.privLevel, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (auto idx) {
|
||||
// Update the fees
|
||||
turnstile.minerFee->setText(
|
||||
Settings::getInstance()->getZECUSDDisplayFormat(privOptions[idx].first * Utils::getMinerFee()));
|
||||
});
|
||||
|
||||
turnstile.privLevel->addItem("Good - 3 tx over 3 blocks");
|
||||
turnstile.privLevel->addItem("Excellent - 5 tx over 5 blocks");
|
||||
turnstile.privLevel->addItem("Paranoid - 10 tx over 7 blocks");
|
||||
|
||||
turnstile.buttonBox->button(QDialogButtonBox::Ok)->setText("Start");
|
||||
|
||||
if (d.exec() == QDialog::Accepted) {
|
||||
auto privLevel = privOptions[turnstile.privLevel->currentIndex()];
|
||||
rpc->getTurnstile()->planMigration(
|
||||
turnstile.migrateZaddList->currentText(),
|
||||
turnstile.migrateTo->currentText(),
|
||||
privLevel.first, privLevel.second);
|
||||
|
||||
QMessageBox::information(this, "Backup your wallet.dat",
|
||||
"The migration will now start. You can check progress in the File -> Turnstile Migration menu.\n\nYOU MUST BACKUP YOUR wallet.dat NOW!.\n\nNew Addresses have been added to your wallet which will be used for the migration.",
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setupTurnstileDialog() {
|
||||
// Turnstile migration
|
||||
QObject::connect(ui->actionTurnstile_Migration, &QAction::triggered, [=] () {
|
||||
Ui_Turnstile turnstile;
|
||||
QDialog d(this);
|
||||
turnstile.setupUi(&d);
|
||||
|
||||
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation);
|
||||
turnstile.msgIcon->setPixmap(icon.pixmap(64, 64));
|
||||
|
||||
auto fnGetAllSproutBalance = [=] () {
|
||||
double bal = 0;
|
||||
for (auto addr : *rpc->getAllZAddresses()) {
|
||||
if (Settings::getInstance()->isSproutAddress(addr)) {
|
||||
bal += rpc->getAllBalances()->value(addr);
|
||||
}
|
||||
}
|
||||
|
||||
return bal;
|
||||
};
|
||||
|
||||
turnstile.migrateZaddList->addItem("All Sprout z-Addrs");
|
||||
turnstile.fromBalance->setText(Settings::getInstance()->getZECUSDDisplayFormat(fnGetAllSproutBalance()));
|
||||
for (auto addr : *rpc->getAllZAddresses()) {
|
||||
if (Settings::getInstance()->isSaplingAddress(addr)) {
|
||||
turnstile.migrateTo->addItem(addr);
|
||||
} else {
|
||||
if (rpc->getAllBalances()->value(addr) > 0)
|
||||
turnstile.migrateZaddList->addItem(addr);
|
||||
}
|
||||
}
|
||||
|
||||
QObject::connect(turnstile.migrateZaddList, &QComboBox::currentTextChanged, [=] (auto addr) {
|
||||
double bal = 0;
|
||||
if (addr.startsWith("All")) {
|
||||
bal = fnGetAllSproutBalance();
|
||||
} else {
|
||||
bal = rpc->getAllBalances()->value(addr);
|
||||
}
|
||||
|
||||
turnstile.fromBalance->setText(Settings::getInstance()->getZECUSDDisplayFormat(bal));
|
||||
});
|
||||
|
||||
// Privacy level combobox
|
||||
// Num tx over num blocks
|
||||
QList<QPair<int, int>> privOptions;
|
||||
privOptions.push_back(QPair<double, double>(3, 3));
|
||||
privOptions.push_back(QPair<double, double>(5, 5));
|
||||
privOptions.push_back(QPair<double, double>(10, 7));
|
||||
|
||||
QObject::connect(turnstile.privLevel, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (auto idx) {
|
||||
// Update the fees
|
||||
turnstile.minerFee->setText(
|
||||
Settings::getInstance()->getZECUSDDisplayFormat(privOptions[idx].first * Utils::getMinerFee()));
|
||||
});
|
||||
|
||||
turnstile.privLevel->addItem("Good - 3 tx over 3 blocks");
|
||||
turnstile.privLevel->addItem("Excellent - 5 tx over 5 blocks");
|
||||
turnstile.privLevel->addItem("Paranoid - 10 tx over 7 blocks");
|
||||
|
||||
turnstile.buttonBox->button(QDialogButtonBox::Ok)->setText("Start");
|
||||
|
||||
if (d.exec() == QDialog::Accepted) {
|
||||
auto privLevel = privOptions[turnstile.privLevel->currentIndex()];
|
||||
rpc->getTurnstile()->planMigration(
|
||||
turnstile.migrateZaddList->currentText(),
|
||||
turnstile.migrateTo->currentText(),
|
||||
privLevel.first, privLevel.second);
|
||||
|
||||
QMessageBox::information(this, "Backup your wallet.dat",
|
||||
"The migration will now start. You can check progress in the File -> Turnstile Migration menu.\n\nYOU MUST BACKUP YOUR wallet.dat NOW!.\n\nNew Addresses have been added to your wallet which will be used for the migration.",
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
// If there is current migration that is present, show the progress button
|
||||
if (rpc->getTurnstile()->isMigrationPresent())
|
||||
turnstileProgress();
|
||||
else
|
||||
turnstileDoMigration();
|
||||
});
|
||||
|
||||
// Progress update button
|
||||
QObject::connect(ui->actionProgress, &QAction::triggered, [=] () {
|
||||
Ui_TurnstileProgress progress;
|
||||
QDialog d(this);
|
||||
progress.setupUi(&d);
|
||||
|
||||
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning);
|
||||
progress.msgIcon->setPixmap(icon.pixmap(64, 64));
|
||||
|
||||
progress.buttonBox->button(QDialogButtonBox::Cancel)->setText("Abort");
|
||||
|
||||
auto fnUpdateProgressUI = [=] () {
|
||||
// Get the plan progress
|
||||
if (rpc->getTurnstile()->isMigrationActive()) {
|
||||
auto curProgress = rpc->getTurnstile()->getPlanProgress();
|
||||
|
||||
progress.progressTxt->setText(QString::number(curProgress.step) % QString(" / ") % QString::number(curProgress.totalSteps));
|
||||
progress.progressBar->setValue(100 * curProgress.step / curProgress.totalSteps);
|
||||
|
||||
auto nextTxBlock = curProgress.nextBlock - Settings::getInstance()->getBlockNumber();
|
||||
|
||||
if (curProgress.step == curProgress.totalSteps) {
|
||||
auto txt = QString("Turnstile migration finished");
|
||||
if (curProgress.hasErrors) {
|
||||
txt = txt + ". There were some errors.\n\nYour funds are all in your wallet, so you should be able to finish moving them manually.";
|
||||
}
|
||||
progress.nextTx->setText(txt);
|
||||
} else {
|
||||
progress.nextTx->setText(QString("Next transaction in ")
|
||||
% QString::number(nextTxBlock < 0 ? 0 : nextTxBlock)
|
||||
% " blocks");
|
||||
}
|
||||
|
||||
} else {
|
||||
progress.progressTxt->setText("");
|
||||
progress.progressBar->setValue(0);
|
||||
progress.nextTx->setText("No turnstile migration is in progress");
|
||||
}
|
||||
};
|
||||
|
||||
QTimer progressTimer(this);
|
||||
QObject::connect(&progressTimer, &QTimer::timeout, fnUpdateProgressUI);
|
||||
progressTimer.start(Utils::updateSpeed);
|
||||
fnUpdateProgressUI();
|
||||
|
||||
d.exec();
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::setupStatusBar() {
|
||||
|
||||
@@ -58,6 +58,9 @@ private:
|
||||
Tx createTxFromSendPage();
|
||||
bool confirmTx(Tx tx, ToFields devFee);
|
||||
|
||||
void turnstileDoMigration();
|
||||
void turnstileProgress();
|
||||
|
||||
void cancelButton();
|
||||
void sendButton();
|
||||
void inputComboTextChanged(const QString& text);
|
||||
|
||||
@@ -724,7 +724,6 @@
|
||||
</property>
|
||||
<addaction name="actionImport_Private_Keys"/>
|
||||
<addaction name="actionTurnstile_Migration"/>
|
||||
<addaction name="actionProgress"/>
|
||||
<addaction name="actionSettings"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExit"/>
|
||||
@@ -779,11 +778,6 @@
|
||||
<string>Turnstile Migration</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionProgress">
|
||||
<property name="text">
|
||||
<string>Progress</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<tabstops>
|
||||
|
||||
@@ -37,6 +37,10 @@ QString Turnstile::writeableFile() {
|
||||
}
|
||||
}
|
||||
|
||||
void Turnstile::removeFile() {
|
||||
QFile(writeableFile()).remove();
|
||||
}
|
||||
|
||||
// Data stream write/read methods for migration items
|
||||
QDataStream &operator<<(QDataStream& ds, const TurnstileMigrationItem& item) {
|
||||
return ds << QString("v1") << item.fromAddr << item.intTAddr
|
||||
@@ -210,7 +214,7 @@ Turnstile::getNextStep(QList<TurnstileMigrationItem>& plan) {
|
||||
return nextStep;
|
||||
}
|
||||
|
||||
bool Turnstile::isMigrationActive() {
|
||||
bool Turnstile::isMigrationPresent() {
|
||||
auto plan = readMigrationPlan();
|
||||
if (plan.isEmpty()) return false;
|
||||
|
||||
@@ -222,7 +226,11 @@ ProgressReport Turnstile::getPlanProgress() {
|
||||
|
||||
auto nextStep = getNextStep(plan);
|
||||
|
||||
auto step = std::distance(plan.begin(), nextStep);
|
||||
auto step = std::distance(plan.begin(), nextStep) * 2; // 2 steps per item
|
||||
if (nextStep != plan.end() &&
|
||||
nextStep->status == TurnstileMigrationItemStatus::SentToT)
|
||||
step++;
|
||||
|
||||
auto total = plan.size();
|
||||
|
||||
auto nextBlock = nextStep == plan.end() ? 0 : nextStep->blockNumber;
|
||||
@@ -232,7 +240,7 @@ ProgressReport Turnstile::getPlanProgress() {
|
||||
i.status == TurnstileMigrationItemStatus::UnknownError;
|
||||
}) != plan.end();
|
||||
|
||||
return ProgressReport{(int)step*2, total*2, nextBlock, hasErrors};
|
||||
return ProgressReport{(int)step, total*2, nextBlock, hasErrors};
|
||||
}
|
||||
|
||||
void Turnstile::executeMigrationStep() {
|
||||
|
||||
@@ -42,10 +42,11 @@ public:
|
||||
|
||||
QList<TurnstileMigrationItem> readMigrationPlan();
|
||||
void writeMigrationPlan(QList<TurnstileMigrationItem> plan);
|
||||
void removeFile();
|
||||
|
||||
void executeMigrationStep();
|
||||
ProgressReport getPlanProgress();
|
||||
bool isMigrationActive();
|
||||
bool isMigrationPresent();
|
||||
|
||||
private:
|
||||
QList<int> getBlockNumbers(int start, int end, int count);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
<string>Turnstile Migration Progress</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="0" colspan="3">
|
||||
|
||||
@@ -48,7 +48,6 @@ public:
|
||||
QAction *actionImport_Private_Keys;
|
||||
QAction *actionCheck_for_Updates;
|
||||
QAction *actionTurnstile_Migration;
|
||||
QAction *actionProgress;
|
||||
QWidget *centralWidget;
|
||||
QGridLayout *gridLayout_3;
|
||||
QTabWidget *tabWidget;
|
||||
@@ -163,8 +162,6 @@ public:
|
||||
actionCheck_for_Updates->setObjectName(QStringLiteral("actionCheck_for_Updates"));
|
||||
actionTurnstile_Migration = new QAction(MainWindow);
|
||||
actionTurnstile_Migration->setObjectName(QStringLiteral("actionTurnstile_Migration"));
|
||||
actionProgress = new QAction(MainWindow);
|
||||
actionProgress->setObjectName(QStringLiteral("actionProgress"));
|
||||
centralWidget = new QWidget(MainWindow);
|
||||
centralWidget->setObjectName(QStringLiteral("centralWidget"));
|
||||
gridLayout_3 = new QGridLayout(centralWidget);
|
||||
@@ -674,7 +671,6 @@ public:
|
||||
menuBar->addAction(menuHelp->menuAction());
|
||||
menuBalance->addAction(actionImport_Private_Keys);
|
||||
menuBalance->addAction(actionTurnstile_Migration);
|
||||
menuBalance->addAction(actionProgress);
|
||||
menuBalance->addAction(actionSettings);
|
||||
menuBalance->addSeparator();
|
||||
menuBalance->addAction(actionExit);
|
||||
@@ -700,7 +696,6 @@ public:
|
||||
actionImport_Private_Keys->setText(QApplication::translate("MainWindow", "Import Private Keys", nullptr));
|
||||
actionCheck_for_Updates->setText(QApplication::translate("MainWindow", "Check github.com for Updates", nullptr));
|
||||
actionTurnstile_Migration->setText(QApplication::translate("MainWindow", "Turnstile Migration", nullptr));
|
||||
actionProgress->setText(QApplication::translate("MainWindow", "Progress", nullptr));
|
||||
groupBox->setTitle(QApplication::translate("MainWindow", "Summary", nullptr));
|
||||
label->setText(QApplication::translate("MainWindow", "Shielded", nullptr));
|
||||
balSheilded->setText(QString());
|
||||
|
||||
@@ -122,7 +122,7 @@ public:
|
||||
|
||||
void retranslateUi(QDialog *TurnstileProgress)
|
||||
{
|
||||
TurnstileProgress->setWindowTitle(QApplication::translate("TurnstileProgress", "Dialog", nullptr));
|
||||
TurnstileProgress->setWindowTitle(QApplication::translate("TurnstileProgress", "Turnstile Migration Progress", nullptr));
|
||||
label_4->setText(QApplication::translate("TurnstileProgress", "Please Ensure you have your wallet.dat backed up!", nullptr));
|
||||
nextTx->setText(QApplication::translate("TurnstileProgress", "Next Transaction in 4 hours", nullptr));
|
||||
progressTxt->setText(QApplication::translate("TurnstileProgress", "4 / 12", nullptr));
|
||||
|
||||
Reference in New Issue
Block a user