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 19, 2021
1 parent b970cad commit b456623
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion 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 @@ -128,5 +128,13 @@ function parseDateStringOrRestoreHeightAsInteger(value) {
} else {
restoreHeight = parseInt(value);
}
if (((device == "Ledger" && restoreHeight < 1522000) || (device == "Trezor" && restoreHeight < 1697500)) && 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 (%1) is lower than block height when %2 started supporting Monero. Changing restore height to %3.".arg(restoreHeight).arg(device == "Ledger" ? "Ledger" : "Trezor").arg(device == "Ledger" ? ledgerMinRestoreHeight : trezorMinRestoreHeight));
restoreHeight = (device == "Ledger" ? ledgerMinRestoreHeight : trezorMinRestoreHeight);
}
return restoreHeight;
}
10 changes: 9 additions & 1 deletion pages/settings/SettingsInfo.qml
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,16 @@ 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;
var device = "";
if (inputDialog.inputText) {
_restoreHeight = Utils.parseDateStringOrRestoreHeightAsInteger(inputDialog.inputText);
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) {
Expand Down
2 changes: 1 addition & 1 deletion wizard/WizardCreateDevice1.qml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Rectangle {
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);
Expand Down

0 comments on commit b456623

Please sign in to comment.