Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
update the import-screen depending on wallet type
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Zeug committed Sep 24, 2016
1 parent 56dcf81 commit 8e8a65f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 32 deletions.
16 changes: 14 additions & 2 deletions interface/client/templates/popupWindows/onboardingScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
4 changes: 3 additions & 1 deletion interface/client/templates/popupWindows/splashScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand All @@ -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)
Expand Down
63 changes: 35 additions & 28 deletions modules/ipcCommunicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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._;

Expand Down Expand Up @@ -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");
}
Expand All @@ -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(){
Expand Down
2 changes: 1 addition & 1 deletion modules/menuItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,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: {
Expand Down

0 comments on commit 8e8a65f

Please sign in to comment.