Skip to content

Commit

Permalink
Utils, SettingsInfo, WizardCreateDevice1: use minimum value for resto…
Browse files Browse the repository at this point in the history
…re height of Ledger and Trezor
  • Loading branch information
rating89us authored and rating89us committed Jun 25, 2021
1 parent b58bff3 commit 6412a0a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
15 changes: 13 additions & 2 deletions js/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function removeTrailingZeros(value) {
return (value + '').replace(/(\.\d*?)0+$/, '$1').replace(/\.$/, '');
}

function parseDateStringOrRestoreHeightAsInteger(value) {
function parseDateStringOrRestoreHeightAsInteger(value, device) {
// Parse date string or restore height as integer
var restoreHeight = 0;
if (value.indexOf('-') === 4 && value.length === 10) {
Expand All @@ -125,8 +125,19 @@ function parseDateStringOrRestoreHeightAsInteger(value) {
// Correct date typed in a wrong format (20201225 instead of 2020-12-25)
var restoreHeightHyphenated = value.substring(0, 4) + "-" + value.substring(4, 6) + "-" + value.substring(6, 8);
restoreHeight = Wizard.getApproximateBlockchainHeight(restoreHeightHyphenated, Utils.netTypeToString());
} else if ((device == "Ledger" || device == "Trezor") && value == "" && Utils.netTypeToString() == "Mainnet") {
// 1522000 = 2018-03-04 (Ledger Nano S support)
var ledgerMinRestoreHeight = 1522000;
// 1697500 = 2018-11-04 (Trezor Model T support)
var trezorMinRestoreHeight = 1697500;
console.log("Restore height undefined. Changing restore height to %1.".arg(device == "Ledger" ? ledgerMinRestoreHeight : trezorMinRestoreHeight));
restoreHeight = (device == "Ledger" ? ledgerMinRestoreHeight : trezorMinRestoreHeight);
} else {
restoreHeight = parseInt(value);
if (value == "") {
restoreHeight = 0;
} else {
restoreHeight = parseInt(value);
}
}
return restoreHeight;
}
10 changes: 8 additions & 2 deletions pages/settings/SettingsInfo.qml
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,15 @@ Rectangle {
inputDialog.labelText = qsTr("Set a new restore height.\nYou can enter a block height or a date (YYYY-MM-DD):") + translationManager.emptyString;
inputDialog.onAcceptedCallback = function() {
var _restoreHeight;
if (inputDialog.inputText) {
_restoreHeight = Utils.parseDateStringOrRestoreHeightAsInteger(inputDialog.inputText);
var device = "";
if (currentWallet) {
if (currentWallet.isTrezor()) {
device = "Trezor";
} else if (currentWallet.isLedger()) {
device = "Ledger";
}
}
_restoreHeight = Utils.parseDateStringOrRestoreHeightAsInteger(inputDialog.inputText, device);
if (!isNaN(_restoreHeight)) {
if(_restoreHeight >= 0) {
currentWallet.walletCreationHeight = _restoreHeight
Expand Down
9 changes: 3 additions & 6 deletions wizard/WizardCreateDevice1.qml
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,13 @@ Rectangle {
id: restoreHeight
visible: !newDeviceWallet.checked
Layout.fillWidth: true
labelText: qsTr("Wallet creation date as `YYYY-MM-DD` or restore height") + translationManager.emptyString
labelText: qsTr("Wallet creation date or restore height") + " (" + "optional" + ")" + translationManager.emptyString
labelFontSize: 14
placeholderFontSize: 16
placeholderText: qsTr("Restore height") + translationManager.emptyString
placeholderText: qsTr("Date (YYYY-MM-DD) or restore height. Leave blank if you don't know.") + translationManager.emptyString
validator: RegExpValidator {
regExp: /^(\d+|\d{4}-\d{2}-\d{2})$/
}
text: "0"
}

MoneroComponents.StandardDropdown {
Expand Down Expand Up @@ -183,10 +182,8 @@ Rectangle {
wizardController.walletOptionsDeviceName = wizardCreateDevice1.deviceName;
if(lookahead.text)
wizardController.walletOptionsSubaddressLookahead = lookahead.text;
if(restoreHeight.text){
wizardController.walletOptionsRestoreHeight = Utils.parseDateStringOrRestoreHeightAsInteger(restoreHeight.text);
}

wizardController.walletOptionsRestoreHeight = Utils.parseDateStringOrRestoreHeightAsInteger(restoreHeight.text, wizardCreateDevice1.deviceName);
wizardController.walletCreatedFromDevice.connect(onCreateWalletFromDeviceCompleted);
wizardController.createWalletFromDevice();
}
Expand Down

0 comments on commit 6412a0a

Please sign in to comment.