From 0590244aa309c4d8a2a4f19bf51974c973c68973 Mon Sep 17 00:00:00 2001 From: Luca Zeug Date: Sat, 24 Sep 2016 20:31:01 +0530 Subject: [PATCH] update the import-screen depending on wallet type --- .../popupWindows/onboardingScreen.js | 16 ++++- .../templates/popupWindows/splashScreen.js | 4 +- modules/ipcCommunicator.js | 63 ++++++++++--------- modules/menuItems.js | 2 +- 4 files changed, 53 insertions(+), 32 deletions(-) diff --git a/interface/client/templates/popupWindows/onboardingScreen.js b/interface/client/templates/popupWindows/onboardingScreen.js index c3622fb59..0e717fe2e 100644 --- a/interface/client/templates/popupWindows/onboardingScreen.js +++ b/interface/client/templates/popupWindows/onboardingScreen.js @@ -231,8 +231,20 @@ Template['popupWindows_onboardingScreen_importAccount'].events({ if(e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files.length) { TemplateVar.set('filePath', e.originalEvent.dataTransfer.files[0].path); - Tracker.afterFlush(function(){ - template.$('.password').focus(); + + ipc.send('backendAction_checkWalletFile', TemplateVar.get('filePath')); + + ipc.on('uiAction_checkedWalletFile', function(e, error, type){ + if (type === "presale") { + Tracker.afterFlush(function(){ + template.$('.password').focus(); + }); + } else if (type === "web3") { + TemplateVar.set(template, 'importing', true); + setTimeout(() => { + ipc.send('backendAction_closePopupWindow'); + }, 750); + } }); } else { GlobalNotification.warning({ diff --git a/interface/client/templates/popupWindows/splashScreen.js b/interface/client/templates/popupWindows/splashScreen.js index 8d47c9e0e..1a9912eb4 100644 --- a/interface/client/templates/popupWindows/splashScreen.js +++ b/interface/client/templates/popupWindows/splashScreen.js @@ -87,8 +87,10 @@ Template['popupWindows_splashScreen'].onCreated(function(){ if (status == 'inProgress') { TemplateVar.set(template, 'showStartAppButton', true); TemplateVar.set(template, 'startAppButtonText', TAPi18n.__('mist.startScreen.launchApp')); + ipc.send('backendAction_skipSync'); if (data != false) { + // if state is "in progress" and we have data showNodeLog = false; var translationString = ''; @@ -114,7 +116,7 @@ Template['popupWindows_splashScreen'].onCreated(function(){ } } else { // Not online - translationString = 'mist.startScreen.nodeSyncConnecting'; + translationString = 'mist.startScreen.nodeSyncConnecting'; } // Saves data as numbers (hex) diff --git a/modules/ipcCommunicator.js b/modules/ipcCommunicator.js index cd5e46593..bf2bf8abf 100644 --- a/modules/ipcCommunicator.js +++ b/modules/ipcCommunicator.js @@ -13,6 +13,8 @@ const appMenu = require('./menuItems'); const logger = require('./utils/logger'); const Windows = require('./windows'); const ipc = electron.ipcMain; +const Settings = require('./settings'); +const ethereumNode = require('./ethereumNode.js'); const _ = global._; const log = logger.create('ipcCommunicator'); @@ -97,19 +99,44 @@ ipc.on('backendAction_setLanguage', function(e, lang){ // check wallet file type -ipc.on('backendAction_checkWalletFile', function(e, path, pw) { - fs.readFile(path, 'utf8', function (e, data) { - if(!e) { +ipc.on('backendAction_checkWalletFile', function(e, path) { + fs.readFile(path, 'utf8', function (event, data) { + if(!event) { try { - var wallet = JSON.parse(data); + var wallet = JSON.parse(data); // TODO web3-storage-definition matching } catch (err) { log.error("Wallet import: Cannot read file"); log.error(err); } if(data.indexOf('"ethaddr"') !== -1) { // Presale wallet - console.info("presale"); + e.sender.send('uiAction_checkedWalletFile', null, 'presale'); } else if(data.indexOf('"address"') !== -1) { // web3 secret storage wallet - console.info("myether"); + e.sender.send('uiAction_checkedWalletFile', null, 'web3'); + + // TODO bad practice, copied from menuItems.js + var path = Settings.userHomePath; + // eth + if(ethereumNode.isEth) { + if(process.platform === 'win32') + path = Settings.appDataPath + '\\Web3\\keys'; + else + path += '/.web3/keys'; + + // geth + } else { + if(process.platform === 'darwin') + path += '/Library/Ethereum/keystore'; + + if(process.platform === 'freebsd' || + process.platform === 'linux' || + process.platform === 'sunos') + path += '/.ethereum/keystore'; + + if(process.platform === 'win32') + path = Settings.appDataPath + '\\Ethereum\\keystore'; + } + // TODO write async, naming + fs.writeFileSync(path + '/0x' + wallet['address'], data); } else { log.warn("Wallet import: Cannot recognize format"); } @@ -118,33 +145,13 @@ ipc.on('backendAction_checkWalletFile', function(e, path, pw) { }); -// import wallet file +// import presale wallet +// TODO naming ipc.on('backendAction_importWalletFile', function(e, path, pw) { const spawn = require('child_process').spawn; const getNodePath = require('./getNodePath.js'); var error = false; - // start import process - fs.readFile(path, 'utf8', function (e, data) { - if(!e) { - try { - var wallet = JSON.parse(data); - } catch (err) { - log.error("Wallet import: Cannot read file"); - log.error(err); - } - if(data.indexOf('"ethaddr"') !== -1) { // Presale wallet - console.info("presale"); - } else if(data.indexOf('"address"') !== -1) { // web3 secret storage wallet - console.info("myether"); - } else { - log.warn("Wallet import: Cannot recognize format"); - } - } - }); - - return false; // temporary stopper - var nodeProcess = spawn(getNodePath('geth'), ['wallet', 'import', path]); nodeProcess.once('error',function(){ diff --git a/modules/menuItems.js b/modules/menuItems.js index 01f354e92..2d553286e 100644 --- a/modules/menuItems.js +++ b/modules/menuItems.js @@ -136,7 +136,7 @@ var menuTempl = function(webviews) { { label: i18n.t('mist.applicationMenu.accounts.importPresale'), accelerator: 'CommandOrControl+I', - enabled: ethereumNode.isMainNetwork, + enabled: true, //ethereumNode.isMainNetwork, click: function(){ Windows.createPopup('importAccount', { electronOptions: {