mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-22 19:49:34 +00:00
Merge pull request #3564
dfe8146
SettingsInfo, WizardRestoreWallet1, WizardCreateDevice1: Correct restore height date when typed in wrong format (rating89us)
This commit is contained in:
commit
b970cad48b
4 changed files with 18 additions and 24 deletions
15
js/Utils.js
15
js/Utils.js
|
@ -115,3 +115,18 @@ function capitalize(s){
|
||||||
function removeTrailingZeros(value) {
|
function removeTrailingZeros(value) {
|
||||||
return (value + '').replace(/(\.\d*?)0+$/, '$1').replace(/\.$/, '');
|
return (value + '').replace(/(\.\d*?)0+$/, '$1').replace(/\.$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseDateStringOrRestoreHeightAsInteger(value) {
|
||||||
|
// Parse date string or restore height as integer
|
||||||
|
var restoreHeight = 0;
|
||||||
|
if (value.indexOf('-') === 4 && value.length === 10) {
|
||||||
|
restoreHeight = Wizard.getApproximateBlockchainHeight(value, Utils.netTypeToString());
|
||||||
|
} else if (parseInt(value.substring(0, 4)) >= 2014 && parseInt(value.substring(0, 4)) <= 2025 && value.length === 8) {
|
||||||
|
// 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 {
|
||||||
|
restoreHeight = parseInt(value);
|
||||||
|
}
|
||||||
|
return restoreHeight;
|
||||||
|
}
|
||||||
|
|
|
@ -189,13 +189,7 @@ Rectangle {
|
||||||
inputDialog.onAcceptedCallback = function() {
|
inputDialog.onAcceptedCallback = function() {
|
||||||
var _restoreHeight;
|
var _restoreHeight;
|
||||||
if (inputDialog.inputText) {
|
if (inputDialog.inputText) {
|
||||||
var restoreHeightText = inputDialog.inputText;
|
_restoreHeight = Utils.parseDateStringOrRestoreHeightAsInteger(inputDialog.inputText);
|
||||||
// Parse date string or restore height as integer
|
|
||||||
if(restoreHeightText.indexOf('-') === 4 && restoreHeightText.length === 10) {
|
|
||||||
_restoreHeight = Wizard.getApproximateBlockchainHeight(restoreHeightText, Utils.netTypeToString());
|
|
||||||
} else {
|
|
||||||
_restoreHeight = parseInt(restoreHeightText)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!isNaN(_restoreHeight)) {
|
if (!isNaN(_restoreHeight)) {
|
||||||
if(_restoreHeight >= 0) {
|
if(_restoreHeight >= 0) {
|
||||||
|
|
|
@ -183,15 +183,8 @@ Rectangle {
|
||||||
wizardController.walletOptionsDeviceName = wizardCreateDevice1.deviceName;
|
wizardController.walletOptionsDeviceName = wizardCreateDevice1.deviceName;
|
||||||
if(lookahead.text)
|
if(lookahead.text)
|
||||||
wizardController.walletOptionsSubaddressLookahead = lookahead.text;
|
wizardController.walletOptionsSubaddressLookahead = lookahead.text;
|
||||||
var _restoreHeight = 0;
|
|
||||||
if(restoreHeight.text){
|
if(restoreHeight.text){
|
||||||
// Parse date string or restore height as integer
|
wizardController.walletOptionsRestoreHeight = Utils.parseDateStringOrRestoreHeightAsInteger(restoreHeight.text);
|
||||||
if(restoreHeight.text.indexOf('-') === 4 && restoreHeight.text.length === 10){
|
|
||||||
_restoreHeight = Wizard.getApproximateBlockchainHeight(restoreHeight.text, Utils.netTypeToString());
|
|
||||||
} else {
|
|
||||||
_restoreHeight = parseInt(restoreHeight.text)
|
|
||||||
}
|
|
||||||
wizardController.walletOptionsRestoreHeight = _restoreHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wizardController.walletCreatedFromDevice.connect(onCreateWalletFromDeviceCompleted);
|
wizardController.walletCreatedFromDevice.connect(onCreateWalletFromDeviceCompleted);
|
||||||
|
|
|
@ -314,16 +314,8 @@ Rectangle {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var _restoreHeight = 0;
|
|
||||||
if(restoreHeight.text){
|
if(restoreHeight.text){
|
||||||
// Parse date string or restore height as integer
|
wizardController.walletOptionsRestoreHeight = Utils.parseDateStringOrRestoreHeightAsInteger(restoreHeight.text);
|
||||||
if(restoreHeight.text.indexOf('-') === 4 && restoreHeight.text.length === 10){
|
|
||||||
_restoreHeight = Wizard.getApproximateBlockchainHeight(restoreHeight.text, Utils.netTypeToString());
|
|
||||||
} else {
|
|
||||||
_restoreHeight = parseInt(restoreHeight.text)
|
|
||||||
}
|
|
||||||
|
|
||||||
wizardController.walletOptionsRestoreHeight = _restoreHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wizardStateView.state = "wizardRestoreWallet2";
|
wizardStateView.state = "wizardRestoreWallet2";
|
||||||
|
|
Loading…
Reference in a new issue