fix import

This commit is contained in:
Matias Alejo Garcia 2015-08-24 17:09:59 -03:00
parent c58cad3d8b
commit 1ab9d8507f
6 changed files with 206 additions and 38 deletions

View File

@ -36,7 +36,7 @@
</div>
</div>
<div class="row" ng-show="show" >
<div class="row enable_text_select" ng-show="show" >
<span class="m10" ng-repeat="word in wordsC.mywords">
{{word}}
</span>

View File

@ -123,6 +123,7 @@
type="text"
placeholder="{{'BIP32 master extended private key'|translate}}"
name="privateKey" ng-model="privateKey">
</label>
</div>
</div>

View File

@ -23,17 +23,17 @@
<div class="tab-container small-4 medium-4 large-4">
<a href
ng-class="{'selected': type =='12'}"
ng-click="create.setTotalCopayers(1)" translate>12 Words Backup</a>
ng-click="import.setType('12')" translate>12 Words Backup</a>
</div>
<div class="tab-container small-4 medium-4 large-4">
<a href
ng-class="{'selected': type=='file'}"
ng-click="create.setTotalCopayers(3)" translate>File/Text Backup</a>
ng-click="import.setType('file')" translate>File/Text Backup</a>
</div>
<div class="tab-container small-4 medium-4 large-4">
<a href
ng-class="{'selected': type=='qr'}"
ng-click="create.setTotalCopayers(3)" translate>QR Code</a>
ng-click="import.setType('qr')" translate>QR Code</a>
</div>
</div>
@ -42,10 +42,55 @@
<div class="row">
<div class="row" ng-show="type == '12' ">
<div class="large-12 columns">
<form name="importForm" ng-submit="import.import(importForm)" novalidate>
<form name="importForm12" ng-submit="import.importMnemonic(importForm12)" novalidate>
<div class="box-notification" ng-show="import.error">
<span class="text-warning size-14">
{{import.error|translate}}
</span>
</div>
<div >
<label for="words">
<span translate>Type the 12 backup words here</span>:
</label>
<textarea class="form-control" name="words" ng-model="import.words" rows="5"></textarea>
</div>
<div class="m10t oh" ng-init="hideAdv=true">
<a class="button outline light-gray expand tiny" ng-click="hideAdv=!hideAdv">
<i class="fi-widget m3r"></i>
<span translate ng-hide="!hideAdv">Show advanced options</span>
<span translate ng-hide="hideAdv">Hide advanced options</span>
<i ng-if="hideAdv" class="icon-arrow-down4"></i>
<i ng-if="!hideAdv" class="icon-arrow-up4"></i>
</a>
</div>
<div ng-hide="hideAdv" class="row">
<div class="large-12 columns">
<label for="passphrase" class="line-b oh"><span translate>Passphrase</span> <small translate>Mnemonics could required a passphrase to be imported</small>
<div class="input">
<input type="password" class="form-control" placeholder="{{'Your backup passhrase'|translate}}"
name="passphrase" ng-model="import.passphrase">
</div>
</label>
</div>
</div>
<button translate type="submit" class="button round expand black"
ng-disabled="importForm12.$invalid || import.loading">
Import
</button>
</form>
</div>
</div>
<div class="row" ng-show="type == 'file' ">
<div class="large-12 columns">
<form name="importForm" ng-submit="import.importBlob(importForm)" novalidate>
<div class="box-notification" ng-show="import.error">
<span class="text-warning size-14">
{{import.error|translate}}
@ -88,6 +133,14 @@
</div>
</div>
<div class="row" ng-show="type == 'qr'">
<div class="large-12 columns">
TODO
</div>
</div>
</div>
<div class="extra-margin-bottom"></div>

View File

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('importController',
function($scope, $rootScope, $location, $timeout, $log, profileService, notification, go, isMobile, isCordova, sjcl, gettext) {
function($scope, $rootScope, $location, $timeout, $log, profileService, notification, go, isMobile, isCordova, sjcl, gettext, lodash) {
var self = this;
@ -11,15 +11,22 @@ angular.module('copayApp.controllers').controller('importController',
window.ignoreMobilePause = true;
$scope.$on('$destroy', function() {
$timeout(function(){
$timeout(function() {
window.ignoreMobilePause = false;
}, 100);
});
var _import = function(str, opts) {
this.setType = function(type) {
$scope.type = type;
$timeout(function() {
$rootScope.$apply();
});
};
var _importBlob = function(str, opts) {
var str2, err;
try {
str2 = sjcl.decrypt(self.password, str);
str2 = sjcl.decrypt(self.password, str);
} catch (e) {
err = gettext('Could not decrypt file, check your password');
$log.warn(e);
@ -27,7 +34,9 @@ angular.module('copayApp.controllers').controller('importController',
if (err) {
self.error = err;
$rootScope.$apply();
$timeout(function() {
$rootScope.$apply();
});
return;
}
@ -41,8 +50,7 @@ angular.module('copayApp.controllers').controller('importController',
self.loading = false;
if (err) {
self.error = err;
}
else {
} else {
$rootScope.$emit('Local/WalletImported', walletId);
go.walletHome();
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
@ -51,19 +59,54 @@ angular.module('copayApp.controllers').controller('importController',
}, 100);
};
var _importMnemonic = function(words, passphrase, opts) {
self.loading = true;
console.log('[import.js.64:opts:]', opts); //TODO
$timeout(function() {
profileService.importWalletMnemonic(words, {
passphrase: passphrase,
}, function(err, ret) {
console.log('[import.js.70:err:]',err, ret); //TODO
self.loading = false;
if (err) {
self.error = err;
return $timeout(function() {
$scope.$apply();
});
}
return
$rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
});
}, 100);
};
// {
// network: opts.network,
// m: opts.m,
// n: opts.n,
// publicKeyRing: opts.publicKeyRing,
// },
//
$scope.getFile = function() {
// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
_import(evt.target.result);
_importBlob(evt.target.result);
}
}
};
this.import = function(form) {
this.importBlob = function(form) {
if (form.$invalid) {
this.error = gettext('There is an error in the form');
$scope.$apply();
$timeout(function() {
$scope.$apply();
});
return;
}
@ -73,14 +116,48 @@ angular.module('copayApp.controllers').controller('importController',
if (!backupFile && !backupText) {
this.error = gettext('Please, select your backup file');
$scope.$apply();
$timeout(function() {
$scope.$apply();
});
return;
}
if (backupFile) {
reader.readAsBinaryString(backupFile);
} else {
_import(backupText);
_importBlob(backupText);
}
};
this.importMnemonic = function(form) {
if (form.$invalid) {
this.error = gettext('There is an error in the form');
$timeout(function() {
$scope.$apply();
});
return;
}
var opts = {};
var passphrase = form.passphrase.$modelValue;
var words = form.words.$modelValue;
if (!words || words.split(' ').map(function(v) {
return lodash.trim(v);
}).length != 12) {
this.error = gettext('Please input 12 backup words');
$timeout(function() {
$scope.$apply();
});
return;
}
opts.passphrase = form.passphrase.$modelValue || null;
_importMnemonic(words, passphrase, opts);
};
});

View File

@ -1164,7 +1164,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.sendAll = function(amount, feeStr, feeRate) {
var self = this;
var msg = gettextCatalog.getString("{{fee}} will be discounted for bitcoin networking fees", {
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", {
fee: feeStr
});

View File

@ -25,7 +25,7 @@ angular.module('copayApp.services')
// Set local object
if (walletId)
root.focusedClient = root.walletClients[walletId];
else
else
root.focusedClient = [];
if (lodash.isEmpty(root.focusedClient)) {
@ -174,7 +174,7 @@ angular.module('copayApp.services')
var walletClient = bwcService.getClient();
// TODO LANG...
// TODO...
log.warn("TODO LANG!")
$log.warn("TODO LANG!")
walletClient.seedFromRandomWithMnemonic('livenet');
walletClient.createWallet('Personal Wallet', 'me', 1, 1, {
@ -207,7 +207,7 @@ log.warn("TODO LANG!")
}
// TODO LANG...
// TODO...
log.warn("TODO LANG!")
$log.warn("TODO LANG!")
walletClient.seedFromRandomWithMnemonic(opts.networkName);
walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, {
@ -250,7 +250,7 @@ log.warn("TODO LANG!")
if (lodash.find(root.profile.credentials, {
'walletId': walletData.walletId
})) {
return cb(gettext('Cannot join the same wallet more that once'));
return cb(gettext('Cannot join the same wallet more that once'));
}
} catch (ex) {
return cb(gettext('Bad wallet invitation'));
@ -298,18 +298,7 @@ log.warn("TODO LANG!")
});
};
root.importWallet = function(str, opts, cb) {
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet:', opts);
try {
walletClient.import(str, {
compressed: opts.compressed,
password: opts.password
});
} catch (err) {
return cb(gettext('Could not import. Check input file and password'));
}
root._addWalletClient = function(walletClient, cb) {
var walletId = walletClient.credentials.walletId;
// check if exist
@ -327,8 +316,52 @@ log.warn("TODO LANG!")
return cb(null, walletId);
});
});
};
root.importWallet = function(str, opts, cb) {
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet:', opts);
try {
walletClient.import(str, {
compressed: opts.compressed,
password: opts.password
});
} catch (err) {
return cb(gettext('Could not import. Check input file and password'));
}
root._addWalletClient(walletClient, cb);
};
root.importWalletMnemonic = function(words, opts, cb) {
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet Mnemonic');
walletClient.importFromMnemonic(words, {
passphrase: opts.passphrase,
}, function(err) {
if (err)
return bwsError.cb(err, gettext('Could not import'), cb);
root._addWalletClient(walletClient, cb);
});
};
root.importWalletMnemonicEx = function(words, opts, cb) {
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet Mnemonic EX', opts);
walletClient.importFromMnemonic(words, opts,
function(err) {
if (err)
return bwsError.cb(err, gettext('Could not import'), cb);
root._addWalletClient(walletClient, cb);
});
};
root.create = function(opts, cb) {
$log.info('Creating profile');
configService.get(function(err) {
@ -420,13 +453,17 @@ log.warn("TODO LANG!")
$log.debug('Wallet is encrypted');
$rootScope.$emit('Local/NeedsPassword', false, function(err2, password) {
if (err2 || !password) {
return cb({message: (err2 || gettext('Password needed'))});
return cb({
message: (err2 || gettext('Password needed'))
});
}
try {
fc.unlock(password);
} catch (e) {
$log.debug(e);
return cb({message: gettext('Wrong password')});
return cb({
message: gettext('Wrong password')
});
}
$timeout(function() {
if (fc.isPrivKeyEncrypted()) {