Merge pull request #3308 from javierbitpay/feat/bws-config-2

bws per wallet
This commit is contained in:
Gustavo Maximiliano Cortez 2015-10-20 17:23:20 -03:00
commit 9df25cdde9
13 changed files with 267 additions and 177 deletions

View file

@ -131,6 +131,12 @@
<switch id="seed" name="setSeed" ng-model="setSeed" class="green right m5t m10b"></switch> <switch id="seed" name="setSeed" ng-model="setSeed" class="green right m5t m10b"></switch>
</label> </label>
<label for="bws" class="oh">
<span translate>Specify Bitcore Wallet Service URL
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl">
</span>
</label>
<label for="createPassphrase" class="line-b oh" ng-hide="setSeed || hwLedger || hwTrezor" ><span translate>Add a Seed Passphrase</span> <small translate>Add an optional passphrase to secure the seed</small> <label for="createPassphrase" class="line-b oh" ng-hide="setSeed || hwLedger || hwTrezor" ><span translate>Add a Seed Passphrase</span> <small translate>Add an optional passphrase to secure the seed</small>
<div class="input"> <div class="input">
<input type="text" class="form-control" <input type="text" class="form-control"
@ -168,7 +174,7 @@
<span translate>Create {{requiredCopayers}}-of-{{totalCopayers}} wallet</span> <span translate>Create {{requiredCopayers}}-of-{{totalCopayers}} wallet</span>
</button> </button>
<button type="submit" class="button round black expand m0" ng-show="totalCopayers == 1" ng-disabled="setupForm.$invalid || create.loading || create.hwWallet"> <button type="submit" class="button round black expand m0" ng-show="totalCopayers == 1" ng-disabled="setupForm.$invalid || create.loading || create.hwWallet">
<span translate>Create new wallet</span> <span translate>Create new wallet</span>
</button> </button>
</div> </div>

View file

@ -84,6 +84,12 @@
<switch id="network-name" name="isTestnet" ng-model="isTestnet" class="green right m5t m10b"></switch> <switch id="network-name" name="isTestnet" ng-model="isTestnet" class="green right m5t m10b"></switch>
</label> </label>
<label for="bws" class="oh">
<span translate>Specify Bitcore Wallet Service URL
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl">
</span>
</label>
<label for="passphrase" class="oh line-b"><span translate>Passphrase</span> <small translate>Wallet Seed could require a passphrase to be imported</small> <label for="passphrase" class="oh line-b"><span translate>Passphrase</span> <small translate>Wallet Seed could require a passphrase to be imported</small>
<div class="input"> <div class="input">
<input type="password" class="form-control" placeholder="{{'Seed passphrase'|translate}}" <input type="password" class="form-control" placeholder="{{'Seed passphrase'|translate}}"
@ -133,6 +139,27 @@
<input type="password" class="form-control" placeholder="{{'Your backup password'|translate}}" <input type="password" class="form-control" placeholder="{{'Your backup password'|translate}}"
name="password" ng-model="import.password"> name="password" ng-model="import.password">
</div> </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="bws" class="oh">
<span translate>Specify Bitcore Wallet Service URL
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl">
</span>
</label>
</div>
</div>
<button translate type="submit" class="button round expand black" <button translate type="submit" class="button round expand black"
ng-disabled="importForm.$invalid || !import.password || import.loading"> ng-disabled="importForm.$invalid || !import.password || import.loading">
Import backup Import backup
@ -159,6 +186,7 @@
<form name="importForm3" ng-submit="import.importLedger(importForm3)" ng-show="index.isChromeApp" novalidate> <form name="importForm3" ng-submit="import.importLedger(importForm3)" ng-show="index.isChromeApp" novalidate>
<div class="large-12 columns"> <div class="large-12 columns">
<!-- TODO: account <!-- TODO: account
<label class=" oh"> <label class=" oh">
<span translate>Ledger Slot</span> <span translate>Ledger Slot</span>
@ -171,18 +199,57 @@
ng-disabled="import.loading || import.ledger"> ng-disabled="import.loading || import.ledger">
Import from Ledger Import from Ledger
</button> </button>
<div class="m10t oh" ng-init="hideAdvLedger=true">
<a class="button outline light-gray expand tiny" ng-click="hideAdvLedger=!hideAdvLedger">
<i class="fi-widget m3r"></i>
<span translate ng-hide="!hideAdvLedger">Show advanced options</span>
<span translate ng-hide="hideAdvLedger">Hide advanced options</span>
<i ng-if="hideAdvLedger" class="icon-arrow-down4"></i>
<i ng-if="!hideAdvLedger" class="icon-arrow-up4"></i>
</a>
</div>
<div ng-hide="hideAdvLedger" class="row">
<div class="large-12 columns">
<label for="bws" class="oh">
<span translate>Specify Bitcore Wallet Service URL
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl">
</span>
</label>
</div>
</div>
</div> </div>
</form> </form>
<form name="importForm4" ng-submit="import.importTrezor(importForm4)" novalidate> <form name="importForm4" ng-submit="import.importTrezor(importForm4)" novalidate>
<div class="large-12 columns"> <div class="large-12 columns">
<!-- ng-disabled="import.loading || import.ledger" --> <!-- ng-disabled="import.loading || import.ledger" -->
<button translate type="submit" class="button round expand black" <button translate type="submit" class="button round expand black" ng-disabled="true">
ng-disabled="true"
>
Import from TREZOR Import from TREZOR
</button> </button>
</div>
<div class="m10t oh" ng-init="hideAdvTrezor=true">
<a class="button outline light-gray expand tiny" ng-click="hideAdvTrezor=!hideAdvTrezor">
<i class="fi-widget m3r"></i>
<span translate ng-hide="!hideAdvTrezor">Show advanced options</span>
<span translate ng-hide="hideAdvTrezor">Hide advanced options</span>
<i ng-if="hideAdvTrezor" class="icon-arrow-down4"></i>
<i ng-if="!hideAdvTrezor" class="icon-arrow-up4"></i>
</a>
</div>
<div ng-hide="hideAdvTrezor" class="row">
<div class="large-12 columns">
<label for="bws" class="oh">
<span translate>Specify Bitcore Wallet Service URL
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl">
</span>
</label>
</div>
</div>
</div>
</form> </form>
</div> </div>

View file

@ -77,6 +77,13 @@
</a> </a>
<div ng-show="join.hideAdv" class="row"> <div ng-show="join.hideAdv" class="row">
<div class="large-12 columns"> <div class="large-12 columns">
<label for="bws" class="oh">
<span translate>Specify Bitcore Wallet Service URL
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl">
</span>
</label>
<label for="hw-ledger" class="oh" ng-show="index.isChromeApp"> <label for="hw-ledger" class="oh" ng-show="index.isChromeApp">
<span translate>Use Ledger hardware wallet</span> <span translate>Use Ledger hardware wallet</span>
<switch id="hw-ledger" name="hwLedger" ng-model="hwLedger" class="green right m5t m10b"></switch> <switch id="hw-ledger" name="hwLedger" ng-model="hwLedger" class="green right m5t m10b"></switch>

View file

@ -115,13 +115,6 @@
<span>Enable Glidera Service</span> <span>Enable Glidera Service</span>
<switch id="glidera-enabled" name="glideraEnabled" ng-model="glideraEnabled" class="green right"></switch> <switch id="glidera-enabled" name="glideraEnabled" ng-model="glideraEnabled" class="green right"></switch>
</li> </li>
<li ng-click="$root.go('preferencesBwsUrl')">
<span>Bitcore Wallet Service</span>
<span class="text-gray db">
<i class="icon-arrow-right3 size-24 right"></i>
{{preferences.bwsurl}}
</span>
</li>
<!-- Disabled for testnet <!-- Disabled for testnet
<li ng-show="!index.noFocusedWallet && glideraEnabled"> <li ng-show="!index.noFocusedWallet && glideraEnabled">

View file

@ -24,6 +24,11 @@
<i class="icon-arrow-right3 size-24 right text-gray"></i> <i class="icon-arrow-right3 size-24 right text-gray"></i>
<span translate>Export Wallet</span> <span translate>Export Wallet</span>
</li> </li>
<li ng-click="$root.go('preferencesBwsUrl')">
<i class="icon-arrow-right3 size-24 right text-gray"></i>
<span translate>Bitcore Wallet Service</span>
</li>
<li ng-click="$root.go('delete')"> <li ng-click="$root.go('delete')">
<i class="icon-arrow-right3 size-24 right text-gray"></i> <i class="icon-arrow-right3 size-24 right text-gray"></i>

View file

@ -1,7 +1,7 @@
<div <div
class="topbar-container" class="topbar-container"
ng-include="'views/includes/topbar.html'" ng-include="'views/includes/topbar.html'"
ng-init="titleSection='Bitcore Wallet Service'; goBackToState = 'preferences'; noColor = true"> ng-init="titleSection='Bitcore Wallet Service'; goBackToState = 'preferencesAdvanced'; noColor = true">
</div> </div>

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('createController', angular.module('copayApp.controllers').controller('createController',
function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isCordova, gettext, ledger, trezor, isMobile) { function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isCordova, gettext, ledger, trezor, isMobile) {
var self = this; var self = this;
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
@ -23,6 +23,9 @@ angular.module('copayApp.controllers').controller('createController',
12: 1, 12: 1,
}; };
var defaults = configService.getDefaults();
$scope.bwsurl = defaults.bws.url;
// ng-repeat defined number of times instead of repeating over array? // ng-repeat defined number of times instead of repeating over array?
this.getNumber = function(num) { this.getNumber = function(num) {
return new Array(num); return new Array(num);
@ -53,6 +56,7 @@ angular.module('copayApp.controllers').controller('createController',
name: form.walletName.$modelValue, name: form.walletName.$modelValue,
myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null, myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null,
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet', networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet',
bwsurl: $scope.bwsurl
}; };
var setSeed = form.setSeed.$modelValue; var setSeed = form.setSeed.$modelValue;
if (setSeed) { if (setSeed) {
@ -73,9 +77,9 @@ angular.module('copayApp.controllers').controller('createController',
} }
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) { if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR'; self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
var src= form.hwLedger.$modelValue ? ledger : trezor; var src = form.hwLedger.$modelValue ? ledger : trezor;
// TODO : account // TODO : account
var account = 0; var account = 0;
@ -106,13 +110,13 @@ angular.module('copayApp.controllers').controller('createController',
$rootScope.$apply(); $rootScope.$apply();
}); });
return; return;
} }
if (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey) { if (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey) {
if (opts.n == 1) { if (opts.n == 1) {
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
} }
} }
go.walletHome();
}); });
}, 100); }, 100);
} }

View file

@ -1,11 +1,12 @@
'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, sjcl, gettext, lodash, ledger, trezor) { function($scope, $rootScope, $location, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, lodash, ledger, trezor) {
var self = this; var self = this;
var reader = new FileReader(); var reader = new FileReader();
var defaults = configService.getDefaults();
$scope.bwsurl = defaults.bws.url;
window.ignoreMobilePause = true; window.ignoreMobilePause = true;
$scope.$on('$destroy', function() { $scope.$on('$destroy', function() {
@ -40,30 +41,27 @@ angular.module('copayApp.controllers').controller('importController',
} }
self.loading = true; self.loading = true;
opts.compressed = null;
opts.password = null;
$timeout(function() { $timeout(function() {
profileService.importWallet(str2, { profileService.importWallet(str2, opts, function(err, walletId) {
compressed: null,
password: null
}, function(err, walletId) {
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();
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
} }
}); });
}, 100); }, 100);
}; };
var _importExtendedPrivateKey = function(xPrivKey, opts) {
var _importExtendedPrivateKey = function(xPrivKey) {
self.loading = true; self.loading = true;
$timeout(function() { $timeout(function() {
profileService.importExtendedPrivateKey(xPrivKey, function(err, walletId) { profileService.importExtendedPrivateKey(xPrivKey, opts, function(err, walletId) {
self.loading = false; self.loading = false;
if (err) { if (err) {
self.error = err; self.error = err;
@ -73,13 +71,10 @@ angular.module('copayApp.controllers').controller('importController',
} }
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
}); });
}, 100); }, 100);
}; };
var _importMnemonic = function(words, opts) { var _importMnemonic = function(words, opts) {
self.loading = true; self.loading = true;
@ -94,7 +89,6 @@ angular.module('copayApp.controllers').controller('importController',
} }
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
}); });
}, 100); }, 100);
}; };
@ -103,7 +97,9 @@ angular.module('copayApp.controllers').controller('importController',
// 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
_importBlob(evt.target.result); var opts = {};
opts.bwsurl = $scope.bwsurl;
_importBlob(evt.target.result, opts);
} }
} }
}; };
@ -134,11 +130,12 @@ angular.module('copayApp.controllers').controller('importController',
if (backupFile) { if (backupFile) {
reader.readAsBinaryString(backupFile); reader.readAsBinaryString(backupFile);
} else { } else {
_importBlob(backupText); var opts = {};
opts.bwsurl = $scope.bwsurl;
_importBlob(backupText, opts);
} }
}; };
this.importMnemonic = function(form) { this.importMnemonic = 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');
@ -150,6 +147,8 @@ angular.module('copayApp.controllers').controller('importController',
} }
var opts = {}; var opts = {};
if ($scope.bwsurl)
opts.bwsurl = $scope.bwsurl;
var passphrase = form.passphrase.$modelValue; var passphrase = form.passphrase.$modelValue;
var words = form.words.$modelValue; var words = form.words.$modelValue;
@ -157,8 +156,8 @@ angular.module('copayApp.controllers').controller('importController',
if (!words) { if (!words) {
this.error = gettext('Please enter the seed words'); this.error = gettext('Please enter the seed words');
} else if (words.indexOf('xprv') == 0 || words.indexOf('tprv') == 0) { } else if (words.indexOf('xprv') == 0 || words.indexOf('tprv') == 0) {
return _importExtendedPrivateKey(words) return _importExtendedPrivateKey(words, opts);
} else { } else {
var wordList = words.split(/[\u3000\s]+/); var wordList = words.split(/[\u3000\s]+/);
@ -173,7 +172,6 @@ angular.module('copayApp.controllers').controller('importController',
return; return;
} }
opts.passphrase = form.passphrase.$modelValue || null; opts.passphrase = form.passphrase.$modelValue || null;
opts.networkName = form.isTestnet.$modelValue ? 'testnet' : 'livenet'; opts.networkName = form.isTestnet.$modelValue ? 'testnet' : 'livenet';
@ -198,9 +196,12 @@ angular.module('copayApp.controllers').controller('importController',
$scope.$apply(); $scope.$apply();
return; return;
} }
lopts.externalSource = 'trezor'; lopts.externalSource = 'trezor';
lopts.bwsurl = $scope.bwsurl;
self.loading = true; self.loading = true;
$log.debug('Import opts', lopts); $log.debug('Import opts', lopts);
profileService.importExtendedPublicKey(lopts, function(err, walletId) { profileService.importExtendedPublicKey(lopts, function(err, walletId) {
self.loading = false; self.loading = false;
if (err) { if (err) {
@ -216,8 +217,6 @@ angular.module('copayApp.controllers').controller('importController',
}, 100); }, 100);
}; };
this.importLedger = function(form) { this.importLedger = function(form) {
var self = this; var self = this;
if (form.$invalid) { if (form.$invalid) {
@ -236,9 +235,12 @@ angular.module('copayApp.controllers').controller('importController',
$scope.$apply(); $scope.$apply();
return; return;
} }
lopts.externalSource = 'ledger'; lopts.externalSource = 'ledger';
lopts.bwsurl = $scope.bwsurl;
self.loading = true; self.loading = true;
$log.debug('Import opts', lopts); $log.debug('Import opts', lopts);
profileService.importExtendedPublicKey(lopts, function(err, walletId) { profileService.importExtendedPublicKey(lopts, function(err, walletId) {
self.loading = false; self.loading = false;
if (err) { if (err) {
@ -249,7 +251,6 @@ angular.module('copayApp.controllers').controller('importController',
} }
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
}); });
}, 100); }, 100);
}; };

View file

@ -840,9 +840,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.initGlidera = function(accessToken) { self.initGlidera = function(accessToken) {
self.glideraEnabled = configService.getSync().glidera.enabled; self.glideraEnabled = configService.getSync().glidera.enabled;
// self.glideraTestnet = configService.getSync().glidera.testnet; // self.glideraTestnet = configService.getSync().glidera.testnet;
// var network = self.glideraTestnet ? 'testnet' : 'livenet'; // var network = self.glideraTestnet ? 'testnet' : 'livenet';
// Disabled for testnet // Disabled for testnet
self.glideraTestnet = false; self.glideraTestnet = false;
var network = 'livenet'; var network = 'livenet';
@ -1005,11 +1005,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}, cb); }, cb);
}); });
$rootScope.$on('Local/BWSUpdated', function(event) {
profileService.applyConfig();
storageService.setCleanAndScanAddresses(function() {});
});
$rootScope.$on('Local/WalletCompleted', function(event) { $rootScope.$on('Local/WalletCompleted', function(event) {
self.setFocusedWallet(); self.setFocusedWallet();
go.walletHome(); go.walletHome();
@ -1134,18 +1129,15 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setFocusedWallet(); self.setFocusedWallet();
self.updateTxHistory(); self.updateTxHistory();
go.walletHome(); go.walletHome();
storageService.getCleanAndScanAddresses(function(err, val) { storageService.getCleanAndScanAddresses(function(err, walletId) {
if (val) { if (walletId && profileService.walletClients[walletId]) {
$log.debug('Clear last address cache and Scan'); $log.debug('Clear last address cache and Scan ', walletId);
lodash.each(lodash.keys(profileService.walletClients), function(walletId) { addressService.expireAddress(walletId, function(err) {
addressService.expireAddress(walletId, function(err) { self.startScan(walletId);
self.startScan(walletId);
});
}); });
storageService.removeCleanAndScanAddresses(function() {}); storageService.removeCleanAndScanAddresses(function() {});
} }
}); });
}); });
$rootScope.$on('Local/SetTab', function(event, tab, reset) { $rootScope.$on('Local/SetTab', function(event, tab, reset) {

View file

@ -1,9 +1,11 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('joinController', angular.module('copayApp.controllers').controller('joinController',
function($scope, $rootScope, $timeout, go, notification, profileService, isCordova, $modal, gettext, lodash, ledger, trezor) { function($scope, $rootScope, $timeout, go, notification, profileService, configService, isCordova, storageService, applicationService, $modal, gettext, lodash, ledger, trezor) {
var self = this; var self = this;
var defaults = configService.getDefaults();
$scope.bwsurl = defaults.bws.url;
this.onQrCodeScanned = function(data) { this.onQrCodeScanned = function(data) {
$scope.secret = data; $scope.secret = data;
@ -21,10 +23,11 @@ angular.module('copayApp.controllers').controller('joinController',
var opts = { var opts = {
secret: form.secret.$modelValue, secret: form.secret.$modelValue,
myName: form.myName.$modelValue, myName: form.myName.$modelValue,
bwsurl: $scope.bwsurl
} }
var setSeed = form.setSeed.$modelValue; var setSeed = form.setSeed.$modelValue;
if (setSeed) { if (setSeed) {
var words = form.privateKey.$modelValue; var words = form.privateKey.$modelValue;
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) { if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
opts.extendedPrivateKey = words; opts.extendedPrivateKey = words;
@ -40,10 +43,10 @@ angular.module('copayApp.controllers').controller('joinController',
this.error = gettext('Please enter the wallet seed'); this.error = gettext('Please enter the wallet seed');
return; return;
} }
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) { if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR'; self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
var src= form.hwLedger.$modelValue ? ledger : trezor; var src = form.hwLedger.$modelValue ? ledger : trezor;
var account = 0; var account = 0;
src.getInfoForNewWallet(account, function(err, lopts) { src.getInfoForNewWallet(account, function(err, lopts) {
@ -68,15 +71,13 @@ angular.module('copayApp.controllers').controller('joinController',
self.loading = false; self.loading = false;
self.error = err; self.error = err;
$rootScope.$apply(); $rootScope.$apply();
return return;
} }
$timeout(function() { $timeout(function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if ( fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) { if (fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey))
$rootScope.$emit('Local/WalletImported', fc.credentials.walletId); $rootScope.$emit('Local/WalletImported', fc.credentials.walletId);
} else {
go.walletHome();
}
}, 2000); }, 2000);
}); });
}, 100); }, 100);

View file

@ -1,13 +1,16 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('preferencesBwsUrlController', angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
function($scope,$log, configService, go, applicationService ) { function($scope, $log, configService, go, applicationService, profileService, storageService) {
this.error = null; this.error = null;
this.success = null; this.success = null;
var fc = profileService.focusedClient;
var walletId = fc.credentials.walletId;
var defaults = configService.getDefaults();
var config = configService.getSync(); var config = configService.getSync();
this.bwsurl = config.bws.url; this.bwsurl = (config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url;
this.save = function() { this.save = function() {
@ -32,17 +35,15 @@ angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
} }
var opts = { var opts = {
bws: { bwsFor: {}
url: this.bwsurl,
}
}; };
opts.bwsFor[walletId] = this.bwsurl;
configService.set(opts, function(err) { configService.set(opts, function(err) {
if (err) console.log(err); if (err) console.log(err);
$scope.$emit('Local/BWSUpdated'); storageService.setCleanAndScanAddresses(walletId, function() {
applicationService.restart(); applicationService.restart();
});
}); });
}; };
}); });

View file

@ -48,81 +48,84 @@ angular.module('copayApp.services')
}); });
}; };
root.setWalletClients = function() { root.setBaseURL = function(walletId) {
lodash.each(root.profile.credentials, function(credentials) { var config = configService.getSync();
var defaults = configService.getDefaults();
if (root.walletClients[credentials.walletId] && bwcService.setBaseUrl((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url);
root.walletClients[credentials.walletId].started) { bwcService.setTransports(['polling']);
}
root.setWalletClient = function(credentials) {
if (root.walletClients[credentials.walletId] &&
root.walletClients[credentials.walletId].started) {
return;
}
root.setBaseURL(credentials.walletId);
var client = bwcService.getClient(JSON.stringify(credentials));
root.walletClients[credentials.walletId] = client;
client.removeAllListeners();
client.on('reconnect', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$log.debug('### Online');
}
});
client.on('reconnecting', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$log.debug('### Offline');
}
});
client.on('notification', function(n) {
$log.debug('BWC Notification:', n);
notificationService.newBWCNotification(n,
client.credentials.walletId, client.credentials.walletName);
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$rootScope.$emit(n.type);
} else {
$rootScope.$apply();
}
});
client.on('walletCompleted', function() {
$log.debug('Wallet completed');
root.updateCredentialsFC(function() {
$rootScope.$emit('Local/WalletCompleted')
});
});
root.walletClients[credentials.walletId].started = true;
root.walletClients[credentials.walletId].doNotVerifyPayPro = isChromeApp;
client.initNotifications(function(err) {
if (err) {
$log.error('Could not init notifications err:', err);
return; return;
} }
});
}
var client = bwcService.getClient(JSON.stringify(credentials)); root.setWalletClients = function() {
root.walletClients[credentials.walletId] = client; var credentials = root.profile.credentials;
client.removeAllListeners(); lodash.each(credentials, function(credentials) {
root.setWalletClient(credentials);
client.on('reconnect', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$log.debug('### Online');
}
});
client.on('reconnecting', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$log.debug('### Offline');
}
});
client.on('notification', function(n) {
$log.debug('BWC Notification:', n);
notificationService.newBWCNotification(n,
client.credentials.walletId, client.credentials.walletName);
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$rootScope.$emit(n.type);
} else {
$rootScope.$apply();
}
});
client.on('walletCompleted', function() {
$log.debug('Wallet completed');
root.updateCredentialsFC(function() {
$rootScope.$emit('Local/WalletCompleted')
});
});
root.walletClients[credentials.walletId].started = true;
root.walletClients[credentials.walletId].doNotVerifyPayPro = isChromeApp;
client.initNotifications(function(err) {
if (err) {
$log.error('Could not init notifications err:', err);
return;
}
});
}); });
$rootScope.$emit('Local/WalletListUpdated'); $rootScope.$emit('Local/WalletListUpdated');
}; };
root.applyConfig = function() {
var config = configService.getSync();
$log.debug('Applying preferences');
bwcService.setBaseUrl(config.bws.url);
bwcService.setTransports(['polling']);
};
root.bindProfile = function(profile, cb) { root.bindProfile = function(profile, cb) {
root.profile = profile; root.profile = profile;
configService.get(function(err) { configService.get(function(err) {
$log.debug('Preferences read'); $log.debug('Preferences read');
if (err) return cb(err); if (err) return cb(err);
root.applyConfig();
root.setWalletClients(); root.setWalletClients();
storageService.getFocusedWalletId(function(err, focusedWalletId) { storageService.getFocusedWalletId(function(err, focusedWalletId) {
if (err) return cb(err); if (err) return cb(err);
@ -166,6 +169,9 @@ angular.module('copayApp.services')
root._seedWallet = function(opts, cb) { root._seedWallet = function(opts, cb) {
opts = opts || {}; opts = opts || {};
if (opts.bwsurl)
bwcService.setBaseUrl(opts.bwsurl);
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
var network = opts.networkName || 'livenet'; var network = opts.networkName || 'livenet';
@ -241,18 +247,30 @@ angular.module('copayApp.services')
}, function(err, secret) { }, function(err, secret) {
if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb);
root.profile.credentials.push(JSON.parse(walletClient.export())); root.storeData(walletClient, opts.bwsurl, cb);
root.setWalletClients();
root.setAndStoreFocus(walletClient.credentials.walletId, function() {
storageService.storeProfile(root.profile, function(err) {
return cb(null, secret, walletClient.credentials.walletId);
});
});
}) })
}); });
}; };
root.storeData = function(walletClient, bwsurl, cb) {
var walletId = walletClient.credentials.walletId;
var defaults = configService.getDefaults();
var opts_ = {
bwsFor: {}
};
opts_.bwsFor[walletId] = bwsurl || defaults.bws.url;
configService.set(opts_, function(err) {
if (err) console.log(err);
root.profile.credentials.push(JSON.parse(walletClient.export()));
root.setWalletClients();
root.setAndStoreFocus(walletId, function() {
storageService.storeProfile(root.profile, cb);
});
});
}
root.joinWallet = function(opts, cb) { root.joinWallet = function(opts, cb) {
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
$log.debug('Joining Wallet:', opts); $log.debug('Joining Wallet:', opts);
@ -278,20 +296,11 @@ angular.module('copayApp.services')
walletClient.joinWallet(opts.secret, opts.myName || 'me', {}, function(err) { walletClient.joinWallet(opts.secret, opts.myName || 'me', {}, function(err) {
if (err) return bwsError.cb(err, gettext('Could not join wallet'), cb); if (err) return bwsError.cb(err, gettext('Could not join wallet'), cb);
root.storeData(walletClient, opts.bwsurl, cb);
root.profile.credentials.push(JSON.parse(walletClient.export())); });
root.setWalletClients(); });
root.setAndStoreFocus(walletClient.credentials.walletId, function() {
storageService.storeProfile(root.profile, function(err) {
return cb();
});
});
})
})
}; };
root.getClient = function(walletId) { root.getClient = function(walletId) {
return root.walletClients[walletId]; return root.walletClients[walletId];
}; };
@ -319,7 +328,7 @@ angular.module('copayApp.services')
}); });
}; };
root._addWalletClient = function(walletClient, cb) { root._addWalletClient = function(walletClient, opts, cb) {
var walletId = walletClient.credentials.walletId; var walletId = walletClient.credentials.walletId;
// check if exist // check if exist
@ -327,22 +336,17 @@ angular.module('copayApp.services')
'walletId': walletId 'walletId': walletId
}); });
if (w) { if (w) {
return cb(gettext('Wallet already in Copay' + ": ") + w.walletName ); return cb(gettext('Wallet already in Copay' + ": ") + w.walletName);
} }
root.storeData(walletClient, opts.bwsurl, cb);
root.profile.credentials.push(JSON.parse(walletClient.export()));
root.setWalletClients();
root.setAndStoreFocus(walletId, function() {
storageService.storeProfile(root.profile, function(err) {
return cb(null, walletId);
});
});
}; };
root.importWallet = function(str, opts, cb) { root.importWallet = function(str, opts, cb) {
if (opts.bwsurl)
bwcService.setBaseUrl(opts.bwsurl);
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
$log.debug('Importing Wallet:', opts); $log.debug('Importing Wallet:', opts);
try { try {
walletClient.import(str, { walletClient.import(str, {
@ -352,10 +356,13 @@ angular.module('copayApp.services')
} catch (err) { } catch (err) {
return cb(gettext('Could not import. Check input file and password')); return cb(gettext('Could not import. Check input file and password'));
} }
root._addWalletClient(walletClient, cb); root._addWalletClient(walletClient, opts, cb);
}; };
root.importExtendedPrivateKey = function(xPrivKey, cb) { root.importExtendedPrivateKey = function(xPrivKey, opts, cb) {
if (opts.bwsurl)
bwcService.setBaseUrl(opts.bwsurl);
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
$log.debug('Importing Wallet xPrivKey'); $log.debug('Importing Wallet xPrivKey');
@ -363,19 +370,21 @@ angular.module('copayApp.services')
if (err) if (err)
return bwsError.cb(err, gettext('Could not import'), cb); return bwsError.cb(err, gettext('Could not import'), cb);
root._addWalletClient(walletClient, cb); root._addWalletClient(walletClient, opts, cb);
}); });
}; };
root._normalizeMnemonic = function(words) { root._normalizeMnemonic = function(words) {
var isJA = words.indexOf('\u3000') > -1; var isJA = words.indexOf('\u3000') > -1;
var wordList = words.split(/[\u3000\s]+/); var wordList = words.split(/[\u3000\s]+/);
return wordList.join(isJA ? '\u3000' : ' '); return wordList.join(isJA ? '\u3000' : ' ');
}; };
root.importMnemonic = function(words, opts, cb) { root.importMnemonic = function(words, opts, cb) {
if (opts.bwsurl)
bwcService.setBaseUrl(opts.bwsurl);
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
$log.debug('Importing Wallet Mnemonic'); $log.debug('Importing Wallet Mnemonic');
@ -388,11 +397,14 @@ angular.module('copayApp.services')
if (err) if (err)
return bwsError.cb(err, gettext('Could not import'), cb); return bwsError.cb(err, gettext('Could not import'), cb);
root._addWalletClient(walletClient, cb); root._addWalletClient(walletClient, opts, cb);
}); });
}; };
root.importExtendedPublicKey = function(opts, cb) { root.importExtendedPublicKey = function(opts, cb) {
if (opts.bwsurl)
bwcService.setBaseUrl(opts.bwsurl);
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
$log.debug('Importing Wallet XPubKey'); $log.debug('Importing Wallet XPubKey');
@ -406,16 +418,17 @@ angular.module('copayApp.services')
return bwsError.cb(err, gettext('Could not import'), cb); return bwsError.cb(err, gettext('Could not import'), cb);
} }
root._addWalletClient(walletClient, cb); root._addWalletClient(walletClient, opts, cb);
}); });
}; };
root.create = function(opts, cb) { root.create = function(opts, cb) {
$log.info('Creating profile'); $log.info('Creating profile');
var defaults = configService.getDefaults();
configService.get(function(err) { configService.get(function(err) {
root.applyConfig(); bwcService.setBaseUrl(defaults.bws.url);
bwcService.setTransports(['polling']);
root._createNewProfile(opts, function(err, p) { root._createNewProfile(opts, function(err, p) {
if (err) return cb(err); if (err) return cb(err);
@ -552,7 +565,7 @@ angular.module('copayApp.services')
$log.info('Requesting Ledger Chrome app to sign the transaction'); $log.info('Requesting Ledger Chrome app to sign the transaction');
ledger.signTx(txp, 0, function(result) { ledger.signTx(txp, 0, function(result) {
$log.debug('Ledger response',result); $log.debug('Ledger response', result);
if (!result.success) if (!result.success)
return cb(result.message || result.error); return cb(result.message || result.error);
@ -568,11 +581,11 @@ angular.module('copayApp.services')
var fc = root.focusedClient; var fc = root.focusedClient;
$log.info('Requesting Trezor to sign the transaction'); $log.info('Requesting Trezor to sign the transaction');
var xPubKeys = lodash.pluck(fc.credentials.publicKeyRing,'xPubKey'); var xPubKeys = lodash.pluck(fc.credentials.publicKeyRing, 'xPubKey');
trezor.signTx(xPubKeys, txp, 0, function(err, result) { trezor.signTx(xPubKeys, txp, 0, function(err, result) {
if (err) return cb(err); if (err) return cb(err);
$log.debug('Trezor response',result); $log.debug('Trezor response', result);
txp.signatures = result.signatures; txp.signatures = result.signatures;
return fc.signTxProposal(txp, cb); return fc.signTxProposal(txp, cb);
}); });

View file

@ -124,7 +124,7 @@ angular.module('copayApp.services')
}; };
root.storeFocusedWalletId = function(id, cb) { root.storeFocusedWalletId = function(id, cb) {
storage.set('focusedWalletId', id||'', cb); storage.set('focusedWalletId', id || '', cb);
}; };
root.getFocusedWalletId = function(cb) { root.getFocusedWalletId = function(cb) {
@ -151,8 +151,8 @@ angular.module('copayApp.services')
storage.get('backup-' + walletId, cb); storage.get('backup-' + walletId, cb);
}; };
root.setCleanAndScanAddresses = function(cb) { root.setCleanAndScanAddresses = function(walletId, cb) {
storage.set('CleanAndScanAddresses', Date.now(), cb); storage.set('CleanAndScanAddresses', walletId, cb);
}; };
root.getCleanAndScanAddresses = function(cb) { root.getCleanAndScanAddresses = function(cb) {