diff --git a/public/views/backup.html b/public/views/backup.html index b3afff887..ef8b0f3ee 100644 --- a/public/views/backup.html +++ b/public/views/backup.html @@ -36,7 +36,7 @@ -
+
{{word}} diff --git a/public/views/create.html b/public/views/create.html index 01e34ed24..20fe87eea 100644 --- a/public/views/create.html +++ b/public/views/create.html @@ -123,6 +123,7 @@ type="text" placeholder="{{'BIP32 master extended private key'|translate}}" name="privateKey" ng-model="privateKey"> +
diff --git a/public/views/import.html b/public/views/import.html index cea6ce572..74507f5eb 100644 --- a/public/views/import.html +++ b/public/views/import.html @@ -23,17 +23,17 @@
12 Words Backup + ng-click="import.setType('12')" translate>12 Words Backup
File/Text Backup + ng-click="import.setType('file')" translate>File/Text Backup
QR Code + ng-click="import.setType('qr')" translate>QR Code
@@ -42,10 +42,55 @@ - -
+
-
+ +
+ + {{import.error|translate}} + +
+ +
+ + +
+ + +
+
+ +
+
+ + +
+
+
+ + + +
+
+
{{import.error|translate}} @@ -88,6 +133,14 @@
+ +
+
+TODO +
+
+ +
diff --git a/src/js/controllers/import.js b/src/js/controllers/import.js index 9be197764..0f94e9574 100644 --- a/src/js/controllers/import.js +++ b/src/js/controllers/import.js @@ -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); + }; }); diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index fb59383c6..20f9948bf 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -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 }); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index c4ef8f997..143c2724d 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -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()) {