Skip to content

Commit

Permalink
Improve console messages (ethereum#2067)
Browse files Browse the repository at this point in the history
  • Loading branch information
luclu authored and evertonfraga committed Mar 27, 2017
1 parent 3955af4 commit 30a9b3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions interface/client/templates/popupWindows/onboardingScreen.js
Expand Up @@ -265,12 +265,14 @@ Template['popupWindows_onboardingScreen_importAccount'].events({
ipc.on('uiAction_checkedWalletFile', function (e, error, type) {
switch (type) {
case 'presale':
console.log(`Imported ${type} account`);
TemplateVar.set(template, 'filePath', files[0].path);
Tracker.afterFlush(function () {
template.$('.password').focus();
});
break;
case 'web3':
console.log(`Imported ${type} account`);
TemplateVar.set(template, 'filePath', files[0].path);
TemplateVar.set(template, 'importing', true);
setTimeout(function () {
Expand Down
2 changes: 1 addition & 1 deletion interface/i18n/mist.de.i18n.json
Expand Up @@ -206,7 +206,7 @@
"gotoMainnetDescription": " Sie werden etwas Ether benötigen, um Verträge anzulegen und auszuführen. Wir werden Ihnen helfen, etwas zu bekommen ...",
"doYouHaveAWalletFile": "Haben Sie eine Wallet-Datei?",
"walletFileDescription": "<p>Wallet-Datei zum importieren in dieses Fenster ziehen.<br>Wenn Sie 2014 am Ethereum-Pre-sale teilgenommen haben, sollten Sie über eine Datei mit dem Dateinamen <code>ethereum_wallet_backup.json</code> verfügen. Sie wurde nach dem Kauf heruntergeladen und Ihnen auch per E-Mail geschickt.</p>",
"dropFilesHere": "Pre-sale Datei hochladen",
"dropFilesHere": "Pre-sale Datei laden",
"creating": "Erstellen...",
"importing": "Importieren...",
"skip": "Diesen Schritt überspringen",
Expand Down
24 changes: 15 additions & 9 deletions modules/ipcCommunicator.js
Expand Up @@ -115,21 +115,23 @@ ipc.on('backendAction_stopWebviewNavigation', (e, id) => {

// check wallet file
ipc.on('backendAction_checkWalletFile', (e, path) => {

log.warn(111);
fs.readFile(path, 'utf8', (event, data) => {
try {
const wallet = JSON.parse(data);
const result = keyfileRecognizer(wallet);
const keyfile = JSON.parse(data);
const result = keyfileRecognizer(keyfile);
/** result
* [ 'ethersale', undefined ] Ethersale keyfile
* [ 'web3', 3 ] web3 (v3) keyfile
* null no valid keyfile
*/

if (_.first(result) === 'ethersale') {
const type = _.first(result);

log.debug(`Importing ${type} account...`);

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

let keystorePath = Settings.userHomePath;
Expand All @@ -151,15 +153,19 @@ ipc.on('backendAction_checkWalletFile', (e, path) => {
if (process.platform === 'win32') keystorePath = `${Settings.appDataPath}\\Ethereum\\keystore`;
}

fs.writeFile(`${keystorePath}/0x${wallet.address}`, data, (err) => {
fs.writeFile(`${keystorePath}/0x${keyfile.address}`, data, (err) => {
if (err) throw new Error("Can't write file to disk");
});
} else {
throw new Error('Wallet import: Cannot recognize keyfile');
throw new Error('Account import: Cannot recognize keyfile (invalid)');
}
} catch (err) {
e.sender.send('uiAction_checkedWalletFile', null, 'invalid');
log.error(err);
if (/Unexpected token . in JSON at position 0/.test(err.message) === true) {
log.error('Account import: Cannot recognize keyfile (no JSON)');
} else {
log.error(err);
}
}
});
});
Expand Down

0 comments on commit 30a9b3a

Please sign in to comment.