mirror of https://github.com/BTCPrivate/copay.git
fix import
This commit is contained in:
parent
c58cad3d8b
commit
1ab9d8507f
|
@ -36,7 +36,7 @@
|
||||||
</div>
|
</div>
|
||||||
</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">
|
<span class="m10" ng-repeat="word in wordsC.mywords">
|
||||||
{{word}}
|
{{word}}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -123,6 +123,7 @@
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="{{'BIP32 master extended private key'|translate}}"
|
placeholder="{{'BIP32 master extended private key'|translate}}"
|
||||||
name="privateKey" ng-model="privateKey">
|
name="privateKey" ng-model="privateKey">
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -23,17 +23,17 @@
|
||||||
<div class="tab-container small-4 medium-4 large-4">
|
<div class="tab-container small-4 medium-4 large-4">
|
||||||
<a href
|
<a href
|
||||||
ng-class="{'selected': type =='12'}"
|
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>
|
||||||
<div class="tab-container small-4 medium-4 large-4">
|
<div class="tab-container small-4 medium-4 large-4">
|
||||||
<a href
|
<a href
|
||||||
ng-class="{'selected': type=='file'}"
|
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>
|
||||||
<div class="tab-container small-4 medium-4 large-4">
|
<div class="tab-container small-4 medium-4 large-4">
|
||||||
<a href
|
<a href
|
||||||
ng-class="{'selected': type=='qr'}"
|
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>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -42,10 +42,55 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="row" ng-show="type == '12' ">
|
||||||
<div class="row">
|
|
||||||
<div class="large-12 columns">
|
<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">
|
<div class="box-notification" ng-show="import.error">
|
||||||
<span class="text-warning size-14">
|
<span class="text-warning size-14">
|
||||||
{{import.error|translate}}
|
{{import.error|translate}}
|
||||||
|
@ -88,6 +133,14 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row" ng-show="type == 'qr'">
|
||||||
|
<div class="large-12 columns">
|
||||||
|
TODO
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="extra-margin-bottom"></div>
|
<div class="extra-margin-bottom"></div>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('importController',
|
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;
|
var self = this;
|
||||||
|
|
||||||
|
@ -11,15 +11,22 @@ angular.module('copayApp.controllers').controller('importController',
|
||||||
|
|
||||||
window.ignoreMobilePause = true;
|
window.ignoreMobilePause = true;
|
||||||
$scope.$on('$destroy', function() {
|
$scope.$on('$destroy', function() {
|
||||||
$timeout(function(){
|
$timeout(function() {
|
||||||
window.ignoreMobilePause = false;
|
window.ignoreMobilePause = false;
|
||||||
}, 100);
|
}, 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;
|
var str2, err;
|
||||||
try {
|
try {
|
||||||
str2 = sjcl.decrypt(self.password, str);
|
str2 = sjcl.decrypt(self.password, str);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = gettext('Could not decrypt file, check your password');
|
err = gettext('Could not decrypt file, check your password');
|
||||||
$log.warn(e);
|
$log.warn(e);
|
||||||
|
@ -27,7 +34,9 @@ angular.module('copayApp.controllers').controller('importController',
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err;
|
self.error = err;
|
||||||
$rootScope.$apply();
|
$timeout(function() {
|
||||||
|
$rootScope.$apply();
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +50,7 @@ angular.module('copayApp.controllers').controller('importController',
|
||||||
self.loading = false;
|
self.loading = false;
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err;
|
self.error = err;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$rootScope.$emit('Local/WalletImported', walletId);
|
$rootScope.$emit('Local/WalletImported', walletId);
|
||||||
go.walletHome();
|
go.walletHome();
|
||||||
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
|
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
|
||||||
|
@ -51,19 +59,54 @@ angular.module('copayApp.controllers').controller('importController',
|
||||||
}, 100);
|
}, 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() {
|
$scope.getFile = function() {
|
||||||
// If we use onloadend, we need to check the readyState.
|
// If we use onloadend, we need to check the readyState.
|
||||||
reader.onloadend = function(evt) {
|
reader.onloadend = function(evt) {
|
||||||
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
|
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) {
|
if (form.$invalid) {
|
||||||
this.error = gettext('There is an error in the form');
|
this.error = gettext('There is an error in the form');
|
||||||
$scope.$apply();
|
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,14 +116,48 @@ angular.module('copayApp.controllers').controller('importController',
|
||||||
|
|
||||||
if (!backupFile && !backupText) {
|
if (!backupFile && !backupText) {
|
||||||
this.error = gettext('Please, select your backup file');
|
this.error = gettext('Please, select your backup file');
|
||||||
$scope.$apply();
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (backupFile) {
|
if (backupFile) {
|
||||||
reader.readAsBinaryString(backupFile);
|
reader.readAsBinaryString(backupFile);
|
||||||
} else {
|
} 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);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -1164,7 +1164,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
|
|
||||||
this.sendAll = function(amount, feeStr, feeRate) {
|
this.sendAll = function(amount, feeStr, feeRate) {
|
||||||
var self = this;
|
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
|
fee: feeStr
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ angular.module('copayApp.services')
|
||||||
// Set local object
|
// Set local object
|
||||||
if (walletId)
|
if (walletId)
|
||||||
root.focusedClient = root.walletClients[walletId];
|
root.focusedClient = root.walletClients[walletId];
|
||||||
else
|
else
|
||||||
root.focusedClient = [];
|
root.focusedClient = [];
|
||||||
|
|
||||||
if (lodash.isEmpty(root.focusedClient)) {
|
if (lodash.isEmpty(root.focusedClient)) {
|
||||||
|
@ -174,7 +174,7 @@ angular.module('copayApp.services')
|
||||||
var walletClient = bwcService.getClient();
|
var walletClient = bwcService.getClient();
|
||||||
// TODO LANG...
|
// TODO LANG...
|
||||||
// TODO...
|
// TODO...
|
||||||
log.warn("TODO LANG!")
|
$log.warn("TODO LANG!")
|
||||||
walletClient.seedFromRandomWithMnemonic('livenet');
|
walletClient.seedFromRandomWithMnemonic('livenet');
|
||||||
|
|
||||||
walletClient.createWallet('Personal Wallet', 'me', 1, 1, {
|
walletClient.createWallet('Personal Wallet', 'me', 1, 1, {
|
||||||
|
@ -207,7 +207,7 @@ log.warn("TODO LANG!")
|
||||||
}
|
}
|
||||||
// TODO LANG...
|
// TODO LANG...
|
||||||
// TODO...
|
// TODO...
|
||||||
log.warn("TODO LANG!")
|
$log.warn("TODO LANG!")
|
||||||
walletClient.seedFromRandomWithMnemonic(opts.networkName);
|
walletClient.seedFromRandomWithMnemonic(opts.networkName);
|
||||||
|
|
||||||
walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, {
|
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, {
|
if (lodash.find(root.profile.credentials, {
|
||||||
'walletId': walletData.walletId
|
'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) {
|
} catch (ex) {
|
||||||
return cb(gettext('Bad wallet invitation'));
|
return cb(gettext('Bad wallet invitation'));
|
||||||
|
@ -298,18 +298,7 @@ log.warn("TODO LANG!")
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.importWallet = function(str, opts, cb) {
|
root._addWalletClient = function(walletClient, 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'));
|
|
||||||
}
|
|
||||||
|
|
||||||
var walletId = walletClient.credentials.walletId;
|
var walletId = walletClient.credentials.walletId;
|
||||||
|
|
||||||
// check if exist
|
// check if exist
|
||||||
|
@ -327,8 +316,52 @@ log.warn("TODO LANG!")
|
||||||
return cb(null, walletId);
|
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) {
|
root.create = function(opts, cb) {
|
||||||
$log.info('Creating profile');
|
$log.info('Creating profile');
|
||||||
configService.get(function(err) {
|
configService.get(function(err) {
|
||||||
|
@ -420,13 +453,17 @@ log.warn("TODO LANG!")
|
||||||
$log.debug('Wallet is encrypted');
|
$log.debug('Wallet is encrypted');
|
||||||
$rootScope.$emit('Local/NeedsPassword', false, function(err2, password) {
|
$rootScope.$emit('Local/NeedsPassword', false, function(err2, password) {
|
||||||
if (err2 || !password) {
|
if (err2 || !password) {
|
||||||
return cb({message: (err2 || gettext('Password needed'))});
|
return cb({
|
||||||
|
message: (err2 || gettext('Password needed'))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
fc.unlock(password);
|
fc.unlock(password);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$log.debug(e);
|
$log.debug(e);
|
||||||
return cb({message: gettext('Wrong password')});
|
return cb({
|
||||||
|
message: gettext('Wrong password')
|
||||||
|
});
|
||||||
}
|
}
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
if (fc.isPrivKeyEncrypted()) {
|
if (fc.isPrivKeyEncrypted()) {
|
||||||
|
|
Loading…
Reference in New Issue