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

Commit

Permalink
rename 'presaleFile' IPC actions to generic 'walletFile'
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Zeug committed Sep 24, 2016
1 parent f8ec2dc commit b2e786a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
6 changes: 3 additions & 3 deletions interface/client/templates/popupWindows/onboardingScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,15 @@ Template['popupWindows_onboardingScreen_importAccount'].events({
var pw = template.find('input.password').value;


ipc.send('backendAction_importPresaleFile', TemplateVar.get('filePath'), pw);
ipc.send('backendAction_importWalletFile', TemplateVar.get('filePath'), pw);

TemplateVar.set('importing', true);
ipc.on('uiAction_importedPresaleFile', function(e, error, address){
ipc.on('uiAction_importedWalletFile', function(e, error, address){
TemplateVar.set(template, 'importing', false);
TemplateVar.set(template, 'filePath', false);

if(address) {
ipc.removeAllListeners('uiAction_importedPresaleFile');
ipc.removeAllListeners('uiAction_importedWalletFile');
console.log('Imported account: ', address);

// move to add account screen, when in the onboarding window
Expand Down
34 changes: 28 additions & 6 deletions modules/ipcCommunicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,30 @@ ipc.on('backendAction_setLanguage', function(e, lang){
});


// import presale file
ipc.on('backendAction_importPresaleFile', function(e, path, pw) {
// check wallet file type
ipc.on('backendAction_checkWalletFile', function(e, path, pw) {
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");
}
}
});
});


// import wallet file
ipc.on('backendAction_importWalletFile', function(e, path, pw) {
const spawn = require('child_process').spawn;
const getNodePath = require('./getNodePath.js');
var error = false;
Expand Down Expand Up @@ -127,23 +149,23 @@ ipc.on('backendAction_importPresaleFile', function(e, path, pw) {

nodeProcess.once('error',function(){
error = true;
e.sender.send('uiAction_importedPresaleFile', 'Couldn\'t start the "geth wallet import <file.json>" process.');
e.sender.send('uiAction_importedWalletFile', 'Couldn\'t start the "geth wallet import <file.json>" process.');
});
nodeProcess.stdout.on('data', function(data) {
var data = data.toString();
if(data)
log.info('Imported presale: ', data);

if(/Decryption failed|not equal to expected addr|could not decrypt/.test(data)) {
e.sender.send('uiAction_importedPresaleFile', 'Decryption Failed');
e.sender.send('uiAction_importedWalletFile', 'Decryption Failed');

// if imported, return the address
} else if(data.indexOf('Address:') !== -1) {
var find = data.match(/\{([a-f0-9]+)\}/i);
if(find.length && find[1])
e.sender.send('uiAction_importedPresaleFile', null, '0x'+ find[1]);
e.sender.send('uiAction_importedWalletFile', null, '0x'+ find[1]);
else
e.sender.send('uiAction_importedPresaleFile', data);
e.sender.send('uiAction_importedWalletFile', data);

// if not stop, so we don't kill the process
} else {
Expand Down

0 comments on commit b2e786a

Please sign in to comment.