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

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Zeug committed Jan 17, 2017
1 parent 5e1451e commit 3680041
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 46 deletions.
4 changes: 4 additions & 0 deletions interface/client/templates/popupWindows/onboardingScreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ <h1>{{i18n "mist.popupWindows.onboarding.doYouHaveAWalletFile"}}</h1>
<span class="dapp-identicon dapp-icon-loading"></span>
<h2 style="display: block; text-align: center;">{{i18n "mist.popupWindows.onboarding.importing"}}</h2>
{{else}}
{{#if TemplateVar.get "invalid"}}
<h2 style="display: block; text-align: center;">{{i18n "mist.popupWindows.onboarding.errors.unknownFile"}}</h2>
{{else}}
<form action="about:blank" target="dapp-form-helper-iframe">
<input type="{{showPassword}}" placeholder="{{i18n 'mist.popupWindows.requestAccount.enterPassword'}}" class="password">
<br><br>
Expand All @@ -159,6 +162,7 @@ <h2 style="display: block; text-align: center;">{{i18n "mist.popupWindows.onboar
<br><br>
<button type="submit" style="margin-left: 15px;">{{i18n "mist.popupWindows.onboarding.buttons.importAccount"}}</button>
</form>
{{/if}}
{{/if}}
</div>
{{else}}
Expand Down
19 changes: 12 additions & 7 deletions interface/client/templates/popupWindows/onboardingScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,26 +226,31 @@ Template['popupWindows_onboardingScreen_importAccount'].events({
@event drop .dropable
*/
'drop .dropable': function(e, template){
'drop .dropable': function(e, template) {
e.preventDefault();

if(e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files.length) {
if (e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files.length) {
TemplateVar.set('filePath', e.originalEvent.dataTransfer.files[0].path);

ipc.send('backendAction_checkWalletFile', TemplateVar.get('filePath'));
ipc.on('uiAction_checkedWalletFile', function(e, error, type){
if (type === "presale") {
Tracker.afterFlush(function(){

ipc.on('uiAction_checkedWalletFile', function(e, error, type) {
if (type === 'presale') {
Tracker.afterFlush(function() {
template.$('.password').focus();
});
} else if (type === "web3") {
} else if (type === 'web3') {
TemplateVar.set(template, 'importing', true);
setTimeout(() => {
ipc.send('backendAction_closePopupWindow');
}, 750);
} else if (type === 'invalid') {
TemplateVar.set(template, 'invalid', true);
}
});
ipc.on('uiAction_invalidWalletFile', function(e, error) {

});
} else {
GlobalNotification.warning({
content: TAPi18n.__('mist.popupWindows.onboarding.errors.unknownFile'),
Expand Down
59 changes: 20 additions & 39 deletions modules/ipcCommunicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,22 @@ ipc.on('backendAction_stopWebviewNavigation', (e, id) => {
e.returnValue = true;
});

// check wallet file type
// check wallet file
ipc.on('backendAction_checkWalletFile', (e, path) => {
fs.readFile(path, 'utf8', (event, data) => {
if (!event) {
try {
const wallet = JSON.parse(data);
const result = keyfileRecognizer(wallet);
/** result
* [ 'ethersale', undefined ] Ethersale keyfile
* [ 'web3', 3 ] web3 (v3) keyfile
* null no valid keyfile
*/

if (result[0] === 'ethersale') {
if (_.first(result) === 'ethersale') {
e.sender.send('uiAction_checkedWalletFile', null, 'presale');
} else if (result[0] === 'web3') {
} else if (_.first(result) === 'web3') {
e.sender.send('uiAction_checkedWalletFile', null, 'web3');

let keystorePath = Settings.userHomePath;
Expand All @@ -134,8 +139,7 @@ ipc.on('backendAction_checkWalletFile', (e, path) => {
} else {
keystorePath += '/.web3/keys';
}

// geth
// geth
} else {
if (process.platform === 'darwin') keystorePath += '/Library/Ethereum/keystore';

Expand All @@ -145,60 +149,37 @@ ipc.on('backendAction_checkWalletFile', (e, path) => {

if (process.platform === 'win32') keystorePath = `${Settings.appDataPath}\\Ethereum\\keystore`;
}
// TODO write async, naming
fs.writeFileSync(`${keystorePath}/0x${wallet.address}`, data);

fs.writeFile(`${keystorePath}/0x${wallet.address}`, data, (err) => {
if (err) throw new Error("Can't write file to disk");
});
} else {
log.warn('Wallet import: Cannot recognize format');
throw new Error('Wallet import: Cannot recognize keyfile');
}
} catch (err) {
log.error('Wallet import: Cannot parse file, no valid json');
e.sender.send('uiAction_checkedWalletFile', null, 'invalid');
log.error(err);
// TODO UI feedback
}
}
});
});


// import presale wallet
// TODO naming
ipc.on('backendAction_importWalletFile', (e, path, pw) => {
const spawn = require('child_process').spawn;
const ClientBinaryManager = require('./clientBinaryManager');
const spawn = require('child_process').spawn; // eslint-disable-line global-require
const ClientBinaryManager = require('./clientBinaryManager'); // eslint-disable-line global-require
let error = false;

const binPath = ClientBinaryManager.getClient('geth').binPath;

// start import process
fs.readFile(path, 'utf8', (e, data) => {
if (!e) {
try {
let 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]);
const nodeProcess = spawn(binPath, ['wallet', 'import', path]);

nodeProcess.once('error', () => {
error = true;
e.sender.send('uiAction_importedWalletFile', 'Couldn\'t start the "geth wallet import <file.json>" process.');
});
nodeProcess.stdout.on('data', (data) => {
var data = data.toString();
data = data.toString();
if (data) {
log.info('Imported presale: ', data);
}
Expand Down Expand Up @@ -230,7 +211,7 @@ ipc.on('backendAction_importWalletFile', (e, path, pw) => {
nodeProcess.stdin.write(`${pw}\n`);
pw = null;
}
}, 2000);*/
}, 2000);
});


Expand Down

0 comments on commit 3680041

Please sign in to comment.