diff options
| author | luigi1111 <luigi1111w@gmail.com> | 2019-02-22 11:30:58 -0600 |
|---|---|---|
| committer | luigi1111 <luigi1111w@gmail.com> | 2019-02-22 11:30:58 -0600 |
| commit | c2889c2b8173dda1e4fe50478c8d56ac00f2d255 (patch) | |
| tree | d7ba6e21f470a56d88fbe9be9ed8a7d068910c59 /js | |
| parent | 333f4aaf83bd64de02b07a56d86bbf90363e403b (diff) | |
| parent | c6107d8376244560068184cbfafd38d3b2f536b8 (diff) | |
| download | monzero-gui-c2889c2b8173dda1e4fe50478c8d56ac00f2d255.tar.gz monzero-gui-c2889c2b8173dda1e4fe50478c8d56ac00f2d255.tar.xz monzero-gui-c2889c2b8173dda1e4fe50478c8d56ac00f2d255.zip | |
Merge pull request #1909
f329a71 Wizard redesign (xmrdsc)
c6107d8 wizard: allow calendar date for restoration height (mmbyday)
Diffstat (limited to 'js')
| -rw-r--r-- | js/TxUtils.js | 1 | ||||
| -rw-r--r-- | js/Utils.js | 20 | ||||
| -rw-r--r-- | js/Wizard.js | 222 |
3 files changed, 243 insertions, 0 deletions
diff --git a/js/TxUtils.js b/js/TxUtils.js index c78436d7..e53424c6 100644 --- a/js/TxUtils.js +++ b/js/TxUtils.js @@ -12,6 +12,7 @@ function destinationsToAddress(destinations){ } function addressTruncate(address, range){ + if(typeof(address) === "undefined") return; if(typeof(range) === "undefined") range = 8; return address.substring(0, range) + "..." + address.substring(address.length-range); } diff --git a/js/Utils.js b/js/Utils.js index 8bf7660c..4f522a35 100644 --- a/js/Utils.js +++ b/js/Utils.js @@ -87,3 +87,23 @@ function ago(epoch) { } } } + +function netTypeToString(){ + // 0: mainnet, 1: testnet, 2: stagenet + var nettype = appWindow.persistentSettings.nettype; + return nettype == 1 ? qsTr("Testnet") : nettype == 2 ? qsTr("Stagenet") : qsTr("Mainnet"); +} + +function randomChoice(arr){ + return arr[Math.floor(Math.random() * arr.length)]; +} + +function filterNodes(nodes, port) { + if(typeof data === 'number') + port = port.toString(); + return nodes.filter(function(_){return _.indexOf(port) !== -1}); +} + +function epoch(){ + return Math.floor((new Date).getTime()/1000); +} diff --git a/js/Wizard.js b/js/Wizard.js new file mode 100644 index 00000000..6f0633c7 --- /dev/null +++ b/js/Wizard.js @@ -0,0 +1,222 @@ +.pragma library + +function updateFromQrCode(address, payment_id, amount, tx_description, recipient_name, extra_parameters) { + // Switch to recover from keys + recoverFromSeedMode = false + spendkey.text = "" + viewKeyLine.text = "" + restoreHeightItem.text = "" + + if(typeof extra_parameters.secret_view_key != "undefined") { + viewKeyLine.text = extra_parameters.secret_view_key + } + if(typeof extra_parameters.secret_spend_key != "undefined") { + spendkey.text = extra_parameters.secret_spend_key + } + if(typeof extra_parameters.restore_height != "undefined") { + restoreHeightItem.text = extra_parameters.restore_height + } + addressLine.text = address + + cameraUi.qrcode_decoded.disconnect(updateFromQrCode) + + // Check if keys are correct + checkNextButton(); +} + +function restart(){ + wizard.currentPage = 0; + wizard.settings = ({}) + wizard.currentPath = "create_wallet" + wizard.pages = paths[currentPath] + wizardRestarted(); + + //hide all pages except first + for (var i = 1; i < wizard.pages.length; i++){ + wizard.pages[i].opacity = 0; + } + //Show first pages + wizard.pages[0].opacity = 1; + +} + +function switchPage(next) { + // Android focus workaround + releaseFocus(); + + // save settings for current page; + if (next && typeof pages[currentPage].onPageClosed !== 'undefined') { + if (pages[currentPage].onPageClosed(settings) !== true) { + print ("Can't go to the next page"); + return; + }; + + } + console.log("switchpage: currentPage: ", currentPage); + + // Update prev/next button positions for mobile/desktop + prevButton.anchors.verticalCenter = (!isMobile) ? wizard.verticalCenter : undefined + prevButton.anchors.bottom = (isMobile) ? wizard.bottom : undefined + nextButton.anchors.verticalCenter = (!isMobile) ? wizard.verticalCenter : undefined + nextButton.anchors.bottom = (isMobile) ? wizard.bottom : undefined + + if (currentPage > 0 || currentPage < pages.length - 1) { + pages[currentPage].opacity = 0 + var step_value = next ? 1 : -1 + currentPage += step_value + pages[currentPage].opacity = 1; + + var nextButtonVisible = currentPage > 1 && currentPage < pages.length - 1 + nextButton.visible = nextButtonVisible + + if (typeof pages[currentPage].onPageOpened !== 'undefined') { + pages[currentPage].onPageOpened(settings,next) + } + } +} + +function openRecoveryWalletPage() { + wizardRestarted(); + print ("show recovery wallet page"); + currentPath = "recovery_wallet" + pages = paths[currentPath] + // Create temporary wallet + createWalletPage.createWallet(settings) + wizard.nextButton.visible = true + // goto next page + switchPage(true); +} + +function openCreateViewOnlyWalletPage(){ + pages[currentPage].opacity = 0 + currentPath = "create_view_only_wallet" + pages = paths[currentPath] + currentPage = pages.indexOf(createViewOnlyWalletPage) + createViewOnlyWalletPage.opacity = 1 + nextButton.visible = true + rootItem.state = "wizard"; +} + +function openCreateWalletFromDevicePage() { + wizardRestarted(); + print ("show create wallet from device page"); + currentPath = "create_wallet_from_device" + pages = paths[currentPath] + wizard.nextButton.visible = true + // goto next page + switchPage(true); +} + +function createWalletPath(isIOS, folder_path,account_name){ + // Remove trailing slash - (default on windows and mac) + if (folder_path.substring(folder_path.length -1) === "/"){ + folder_path = folder_path.substring(0,folder_path.length -1) + } + + // Store releative path on ios. + if(isIOS) + folder_path = ""; + + return folder_path + "/" + account_name + "/" + account_name +} + +function walletPathExists(directory, filename, isIOS, walletManager) { + if(!filename || filename === "") return false; + if(!directory || directory === "") return false; + + // make sure directory endswith path seperator + // @TODO: use .endswith() after Qt 5.8 + var trailing_path_sep = directory[directory.length-1]; + if(trailing_path_sep !== "/" && trailing_path_sep !== "\\") + directory += "/" + + if(isIOS) + var path = moneroAccountsDir + filename; + else + var path = directory + filename + "/" + filename; + + if (walletManager.walletExists(path)) + return true; + return false; +} + +function isAscii(str){ + for (var i = 0; i < str.length; i++) { + if (str.charCodeAt(i) > 127) + return false; + } + return true; +} + +function tr(text) { + return qsTr(text) + translationManager.emptyString +} + +function lineBreaksToSpaces(text) { + return text.trim().replace(/(\r\n|\n|\r)/gm, " "); +} + +function usefulName(path) { + // arbitrary "short enough" limit + if (path.length < 32) + return path + return path.replace(/.*[\/\\]/, '').replace(/\.keys$/, '') +} + +function checkSeed(seed) { + console.log("Checking seed") + var wordsArray = lineBreaksToSpaces(seed).split(" "); + return wordsArray.length === 25 || wordsArray.length === 24 +} + +function restoreWalletCheckViewSpendAddress(walletmanager, nettype, viewkey, spendkey, addressline){ + var addressOK = (viewkey.length > 0 || spendkey.length > 0) ? walletmanager.addressValid(addressline, nettype) : false + var viewKeyOK = (viewkey.length > 0) ? walletmanager.keyValid(viewkey, addressline, true, nettype) : true + // Spendkey is optional + var spendKeyOK = (spendkey.length > 0) ? walletmanager.keyValid(spendkey, addressline, false, nettype) : true + + return addressOK && viewKeyOK && spendKeyOK +} + +//usage: getApproximateBlockchainHeight("March 18 2016") or getApproximateBlockchainHeight("2016-11-11") +//returns estimated block height with 1 month buffer prior to requested date. +function getApproximateBlockchainHeight(_date){ + // time of monero birth 2014-04-18 10:49:53 (1397818193) + var moneroBirthTime = 1397818193; + // avg seconds per block in v1 + var secondsPerBlockV1 = 60; + // time of v2 fork 2016-03-23 15:57:38 (1458748658) + var forkTime = 1458748658; + // v2 fork block + var forkBlock = 1009827; + // avg seconds per block in V2 + var secondsPerBlockV2 = 120; + // time in UTC + var requestedTime = Math.floor(new Date(_date) / 1000); + var approxBlockchainHeight; + var secondsPerBlock; + // before monero's birth + if (requestedTime < moneroBirthTime){ + console.log("Calculated blockchain height: 0, requestedTime < moneroBirthTime " ); + return 0; + } + // time between during v1 + if (requestedTime > moneroBirthTime && requestedTime < forkTime){ + approxBlockchainHeight = Math.floor((requestedTime - moneroBirthTime)/secondsPerBlockV1); + console.log("Calculated blockchain height: " + approxBlockchainHeight ); + secondsPerBlock = secondsPerBlockV1; + } + // time is during V2 + else{ + approxBlockchainHeight = Math.floor(forkBlock + (requestedTime - forkTime)/secondsPerBlockV2); + console.log("Calculated blockchain height: " + approxBlockchainHeight ); + secondsPerBlock = secondsPerBlockV2; + } + var blocksPerMonth = 60*60*24*30/secondsPerBlock; + if(approxBlockchainHeight - blocksPerMonth > 0){ + return approxBlockchainHeight - blocksPerMonth; + } + else{ + return 0; + } +}
\ No newline at end of file |
