Strip leading/trailing whitespace from wallet birthdays

This commit is contained in:
Duke Leto
2022-02-17 23:44:54 -05:00
parent 4aeab433a4
commit 9e8e95200c

View File

@@ -649,7 +649,7 @@ RestoreSeedPage::RestoreSeedPage(FirstTimeWizard *parent) : QWizardPage(parent)
bool RestoreSeedPage::validatePage() {
// 1. Validate that we do have 24 words
QString seed = form.txtSeed->toPlainText().replace(QRegExp("[ \n\r\t]+"), " ");
QString seed = form.txtSeed->toPlainText().replace(QRegExp("[ \n\r\t]+"), " "); //TODO: use .simplified()
auto seedLength = seed.trimmed().split(" ").length();
qDebug() << __func__ << ": seed length=" << seedLength;
if (seedLength != 24) {
@@ -662,11 +662,12 @@ bool RestoreSeedPage::validatePage() {
// 2. Validate birthday
QString birthday_str = form.txtBirthday->text();
bool ok;
qint64 birthday = birthday_str.toUInt(&ok);
// simplified() Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.
qint64 birthday = birthday_str.simplified().toUInt(&ok);
if (!ok) {
qDebug() << __func__ << ": Failed to parse wallet birthday=" << birthday_str;
QMessageBox::warning(this, tr("Failed to parse wallet birthday"),
tr("Couldn't understand wallet birthday. This should be a block height from where to rescan the wallet. You can leave it as '0' if you don't know what it should be."),
tr("Couldn't understand wallet birthday. This should be a block height from where to rescan the wallet. You can leave the default if you don't know what it should be."),
QMessageBox::Ok);
return false;
}