mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #3308 from javierbitpay/feat/bws-config-2
bws per wallet
This commit is contained in:
commit
9df25cdde9
|
@ -131,6 +131,12 @@
|
|||
<switch id="seed" name="setSeed" ng-model="setSeed" class="green right m5t m10b"></switch>
|
||||
</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>
|
||||
<div class="input">
|
||||
<input type="text" class="form-control"
|
||||
|
@ -168,7 +174,7 @@
|
|||
<span translate>Create {{requiredCopayers}}-of-{{totalCopayers}} wallet</span>
|
||||
</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>
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -84,6 +84,12 @@
|
|||
<switch id="network-name" name="isTestnet" ng-model="isTestnet" class="green right m5t m10b"></switch>
|
||||
</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>
|
||||
<div class="input">
|
||||
<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}}"
|
||||
name="password" ng-model="import.password">
|
||||
</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"
|
||||
ng-disabled="importForm.$invalid || !import.password || import.loading">
|
||||
Import backup
|
||||
|
@ -159,6 +186,7 @@
|
|||
|
||||
<form name="importForm3" ng-submit="import.importLedger(importForm3)" ng-show="index.isChromeApp" novalidate>
|
||||
<div class="large-12 columns">
|
||||
|
||||
<!-- TODO: account
|
||||
<label class=" oh">
|
||||
<span translate>Ledger Slot</span>
|
||||
|
@ -171,18 +199,57 @@
|
|||
ng-disabled="import.loading || import.ledger">
|
||||
Import from Ledger
|
||||
</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>
|
||||
</form>
|
||||
|
||||
<form name="importForm4" ng-submit="import.importTrezor(importForm4)" novalidate>
|
||||
<div class="large-12 columns">
|
||||
|
||||
<!-- ng-disabled="import.loading || import.ledger" -->
|
||||
<button translate type="submit" class="button round expand black"
|
||||
ng-disabled="true"
|
||||
>
|
||||
<button translate type="submit" class="button round expand black" ng-disabled="true">
|
||||
Import from TREZOR
|
||||
</button>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<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>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -77,6 +77,13 @@
|
|||
</a>
|
||||
<div ng-show="join.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>
|
||||
|
||||
<label for="hw-ledger" class="oh" ng-show="index.isChromeApp">
|
||||
<span translate>Use Ledger hardware wallet</span>
|
||||
<switch id="hw-ledger" name="hwLedger" ng-model="hwLedger" class="green right m5t m10b"></switch>
|
||||
|
|
|
@ -115,13 +115,6 @@
|
|||
<span>Enable Glidera Service</span>
|
||||
<switch id="glidera-enabled" name="glideraEnabled" ng-model="glideraEnabled" class="green right"></switch>
|
||||
</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
|
||||
<li ng-show="!index.noFocusedWallet && glideraEnabled">
|
||||
|
|
|
@ -24,6 +24,11 @@
|
|||
<i class="icon-arrow-right3 size-24 right text-gray"></i>
|
||||
<span translate>Export Wallet</span>
|
||||
</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')">
|
||||
<i class="icon-arrow-right3 size-24 right text-gray"></i>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div
|
||||
class="topbar-container"
|
||||
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>
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
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 defaults = configService.getDefaults();
|
||||
|
@ -23,6 +23,9 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
12: 1,
|
||||
};
|
||||
|
||||
var defaults = configService.getDefaults();
|
||||
$scope.bwsurl = defaults.bws.url;
|
||||
|
||||
// ng-repeat defined number of times instead of repeating over array?
|
||||
this.getNumber = function(num) {
|
||||
return new Array(num);
|
||||
|
@ -53,6 +56,7 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
name: form.walletName.$modelValue,
|
||||
myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null,
|
||||
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet',
|
||||
bwsurl: $scope.bwsurl
|
||||
};
|
||||
var setSeed = form.setSeed.$modelValue;
|
||||
if (setSeed) {
|
||||
|
@ -73,9 +77,9 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
}
|
||||
|
||||
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
|
||||
var account = 0;
|
||||
|
@ -106,13 +110,13 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
$rootScope.$apply();
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey) {
|
||||
if (opts.n == 1) {
|
||||
$rootScope.$emit('Local/WalletImported', walletId);
|
||||
}
|
||||
}
|
||||
go.walletHome();
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
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 reader = new FileReader();
|
||||
var defaults = configService.getDefaults();
|
||||
$scope.bwsurl = defaults.bws.url;
|
||||
|
||||
window.ignoreMobilePause = true;
|
||||
$scope.$on('$destroy', function() {
|
||||
|
@ -40,30 +41,27 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
}
|
||||
|
||||
self.loading = true;
|
||||
opts.compressed = null;
|
||||
opts.password = null;
|
||||
|
||||
$timeout(function() {
|
||||
profileService.importWallet(str2, {
|
||||
compressed: null,
|
||||
password: null
|
||||
}, function(err, walletId) {
|
||||
profileService.importWallet(str2, opts, function(err, walletId) {
|
||||
self.loading = false;
|
||||
if (err) {
|
||||
self.error = err;
|
||||
} else {
|
||||
$rootScope.$emit('Local/WalletImported', walletId);
|
||||
go.walletHome();
|
||||
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
|
||||
}
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
||||
|
||||
var _importExtendedPrivateKey = function(xPrivKey) {
|
||||
var _importExtendedPrivateKey = function(xPrivKey, opts) {
|
||||
self.loading = true;
|
||||
|
||||
$timeout(function() {
|
||||
profileService.importExtendedPrivateKey(xPrivKey, function(err, walletId) {
|
||||
profileService.importExtendedPrivateKey(xPrivKey, opts, function(err, walletId) {
|
||||
self.loading = false;
|
||||
if (err) {
|
||||
self.error = err;
|
||||
|
@ -73,13 +71,10 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
}
|
||||
$rootScope.$emit('Local/WalletImported', walletId);
|
||||
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
|
||||
go.walletHome();
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
||||
|
||||
|
||||
var _importMnemonic = function(words, opts) {
|
||||
self.loading = true;
|
||||
|
||||
|
@ -94,7 +89,6 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
}
|
||||
$rootScope.$emit('Local/WalletImported', walletId);
|
||||
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
|
||||
go.walletHome();
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
@ -103,7 +97,9 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
// If we use onloadend, we need to check the readyState.
|
||||
reader.onloadend = function(evt) {
|
||||
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) {
|
||||
reader.readAsBinaryString(backupFile);
|
||||
} else {
|
||||
_importBlob(backupText);
|
||||
var opts = {};
|
||||
opts.bwsurl = $scope.bwsurl;
|
||||
_importBlob(backupText, opts);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.importMnemonic = function(form) {
|
||||
if (form.$invalid) {
|
||||
this.error = gettext('There is an error in the form');
|
||||
|
@ -150,6 +147,8 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
}
|
||||
|
||||
var opts = {};
|
||||
if ($scope.bwsurl)
|
||||
opts.bwsurl = $scope.bwsurl;
|
||||
|
||||
var passphrase = form.passphrase.$modelValue;
|
||||
var words = form.words.$modelValue;
|
||||
|
@ -157,8 +156,8 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
|
||||
if (!words) {
|
||||
this.error = gettext('Please enter the seed words');
|
||||
} else if (words.indexOf('xprv') == 0 || words.indexOf('tprv') == 0) {
|
||||
return _importExtendedPrivateKey(words)
|
||||
} else if (words.indexOf('xprv') == 0 || words.indexOf('tprv') == 0) {
|
||||
return _importExtendedPrivateKey(words, opts);
|
||||
} else {
|
||||
var wordList = words.split(/[\u3000\s]+/);
|
||||
|
||||
|
@ -173,7 +172,6 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
opts.passphrase = form.passphrase.$modelValue || null;
|
||||
opts.networkName = form.isTestnet.$modelValue ? 'testnet' : 'livenet';
|
||||
|
||||
|
@ -198,9 +196,12 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
$scope.$apply();
|
||||
return;
|
||||
}
|
||||
|
||||
lopts.externalSource = 'trezor';
|
||||
lopts.bwsurl = $scope.bwsurl;
|
||||
self.loading = true;
|
||||
$log.debug('Import opts', lopts);
|
||||
|
||||
profileService.importExtendedPublicKey(lopts, function(err, walletId) {
|
||||
self.loading = false;
|
||||
if (err) {
|
||||
|
@ -216,8 +217,6 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
}, 100);
|
||||
};
|
||||
|
||||
|
||||
|
||||
this.importLedger = function(form) {
|
||||
var self = this;
|
||||
if (form.$invalid) {
|
||||
|
@ -236,9 +235,12 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
$scope.$apply();
|
||||
return;
|
||||
}
|
||||
|
||||
lopts.externalSource = 'ledger';
|
||||
lopts.bwsurl = $scope.bwsurl;
|
||||
self.loading = true;
|
||||
$log.debug('Import opts', lopts);
|
||||
|
||||
profileService.importExtendedPublicKey(lopts, function(err, walletId) {
|
||||
self.loading = false;
|
||||
if (err) {
|
||||
|
@ -249,7 +251,6 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
}
|
||||
$rootScope.$emit('Local/WalletImported', walletId);
|
||||
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
|
||||
go.walletHome();
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
|
|
|
@ -840,9 +840,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
|
||||
self.initGlidera = function(accessToken) {
|
||||
self.glideraEnabled = configService.getSync().glidera.enabled;
|
||||
// self.glideraTestnet = configService.getSync().glidera.testnet;
|
||||
// var network = self.glideraTestnet ? 'testnet' : 'livenet';
|
||||
// Disabled for testnet
|
||||
// self.glideraTestnet = configService.getSync().glidera.testnet;
|
||||
// var network = self.glideraTestnet ? 'testnet' : 'livenet';
|
||||
// Disabled for testnet
|
||||
self.glideraTestnet = false;
|
||||
var network = 'livenet';
|
||||
|
||||
|
@ -1005,11 +1005,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
}, cb);
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/BWSUpdated', function(event) {
|
||||
profileService.applyConfig();
|
||||
storageService.setCleanAndScanAddresses(function() {});
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/WalletCompleted', function(event) {
|
||||
self.setFocusedWallet();
|
||||
go.walletHome();
|
||||
|
@ -1134,18 +1129,15 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.setFocusedWallet();
|
||||
self.updateTxHistory();
|
||||
go.walletHome();
|
||||
storageService.getCleanAndScanAddresses(function(err, val) {
|
||||
if (val) {
|
||||
$log.debug('Clear last address cache and Scan');
|
||||
lodash.each(lodash.keys(profileService.walletClients), function(walletId) {
|
||||
addressService.expireAddress(walletId, function(err) {
|
||||
self.startScan(walletId);
|
||||
});
|
||||
storageService.getCleanAndScanAddresses(function(err, walletId) {
|
||||
if (walletId && profileService.walletClients[walletId]) {
|
||||
$log.debug('Clear last address cache and Scan ', walletId);
|
||||
addressService.expireAddress(walletId, function(err) {
|
||||
self.startScan(walletId);
|
||||
});
|
||||
storageService.removeCleanAndScanAddresses(function() {});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/SetTab', function(event, tab, reset) {
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
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 defaults = configService.getDefaults();
|
||||
$scope.bwsurl = defaults.bws.url;
|
||||
|
||||
this.onQrCodeScanned = function(data) {
|
||||
$scope.secret = data;
|
||||
|
@ -21,10 +23,11 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
var opts = {
|
||||
secret: form.secret.$modelValue,
|
||||
myName: form.myName.$modelValue,
|
||||
bwsurl: $scope.bwsurl
|
||||
}
|
||||
|
||||
var setSeed = form.setSeed.$modelValue;
|
||||
if (setSeed) {
|
||||
if (setSeed) {
|
||||
var words = form.privateKey.$modelValue;
|
||||
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
|
||||
opts.extendedPrivateKey = words;
|
||||
|
@ -40,10 +43,10 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
this.error = gettext('Please enter the wallet seed');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
|
||||
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
|
||||
var src= form.hwLedger.$modelValue ? ledger : trezor;
|
||||
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
|
||||
var src = form.hwLedger.$modelValue ? ledger : trezor;
|
||||
|
||||
var account = 0;
|
||||
src.getInfoForNewWallet(account, function(err, lopts) {
|
||||
|
@ -68,15 +71,13 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
self.loading = false;
|
||||
self.error = err;
|
||||
$rootScope.$apply();
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
$timeout(function() {
|
||||
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);
|
||||
} else {
|
||||
go.walletHome();
|
||||
}
|
||||
}, 2000);
|
||||
});
|
||||
}, 100);
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
|
||||
function($scope,$log, configService, go, applicationService ) {
|
||||
function($scope, $log, configService, go, applicationService, profileService, storageService) {
|
||||
this.error = null;
|
||||
this.success = null;
|
||||
|
||||
var fc = profileService.focusedClient;
|
||||
var walletId = fc.credentials.walletId;
|
||||
var defaults = configService.getDefaults();
|
||||
var config = configService.getSync();
|
||||
|
||||
this.bwsurl = config.bws.url;
|
||||
this.bwsurl = (config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url;
|
||||
|
||||
this.save = function() {
|
||||
|
||||
|
@ -32,17 +35,15 @@ angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
|
|||
}
|
||||
|
||||
var opts = {
|
||||
bws: {
|
||||
url: this.bwsurl,
|
||||
}
|
||||
bwsFor: {}
|
||||
};
|
||||
opts.bwsFor[walletId] = this.bwsurl;
|
||||
|
||||
configService.set(opts, function(err) {
|
||||
if (err) console.log(err);
|
||||
$scope.$emit('Local/BWSUpdated');
|
||||
applicationService.restart();
|
||||
storageService.setCleanAndScanAddresses(walletId, function() {
|
||||
applicationService.restart();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
|
|
|
@ -48,81 +48,84 @@ angular.module('copayApp.services')
|
|||
});
|
||||
};
|
||||
|
||||
root.setWalletClients = function() {
|
||||
lodash.each(root.profile.credentials, function(credentials) {
|
||||
root.setBaseURL = function(walletId) {
|
||||
var config = configService.getSync();
|
||||
var defaults = configService.getDefaults();
|
||||
|
||||
if (root.walletClients[credentials.walletId] &&
|
||||
root.walletClients[credentials.walletId].started) {
|
||||
bwcService.setBaseUrl((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url);
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
root.setWalletClients = function() {
|
||||
var credentials = root.profile.credentials;
|
||||
lodash.each(credentials, function(credentials) {
|
||||
root.setWalletClient(credentials);
|
||||
});
|
||||
$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.profile = profile;
|
||||
|
||||
configService.get(function(err) {
|
||||
$log.debug('Preferences read');
|
||||
if (err) return cb(err);
|
||||
root.applyConfig();
|
||||
root.setWalletClients();
|
||||
storageService.getFocusedWalletId(function(err, focusedWalletId) {
|
||||
if (err) return cb(err);
|
||||
|
@ -166,6 +169,9 @@ angular.module('copayApp.services')
|
|||
|
||||
root._seedWallet = function(opts, cb) {
|
||||
opts = opts || {};
|
||||
if (opts.bwsurl)
|
||||
bwcService.setBaseUrl(opts.bwsurl);
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
var network = opts.networkName || 'livenet';
|
||||
|
||||
|
@ -241,18 +247,30 @@ angular.module('copayApp.services')
|
|||
}, function(err, secret) {
|
||||
if (err) return bwsError.cb(err, gettext('Error creating wallet'), 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(null, secret, walletClient.credentials.walletId);
|
||||
});
|
||||
});
|
||||
root.storeData(walletClient, opts.bwsurl, cb);
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
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) {
|
||||
var walletClient = bwcService.getClient();
|
||||
$log.debug('Joining Wallet:', opts);
|
||||
|
@ -278,20 +296,11 @@ angular.module('copayApp.services')
|
|||
|
||||
walletClient.joinWallet(opts.secret, opts.myName || 'me', {}, function(err) {
|
||||
if (err) return bwsError.cb(err, gettext('Could not join wallet'), 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.storeData(walletClient, opts.bwsurl, cb);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
root.getClient = function(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;
|
||||
|
||||
// check if exist
|
||||
|
@ -327,22 +336,17 @@ angular.module('copayApp.services')
|
|||
'walletId': walletId
|
||||
});
|
||||
if (w) {
|
||||
return cb(gettext('Wallet already in Copay' + ": ") + w.walletName );
|
||||
return cb(gettext('Wallet already in Copay' + ": ") + w.walletName);
|
||||
}
|
||||
|
||||
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.storeData(walletClient, opts.bwsurl, cb);
|
||||
};
|
||||
|
||||
root.importWallet = function(str, opts, cb) {
|
||||
if (opts.bwsurl)
|
||||
bwcService.setBaseUrl(opts.bwsurl);
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
|
||||
$log.debug('Importing Wallet:', opts);
|
||||
try {
|
||||
walletClient.import(str, {
|
||||
|
@ -352,10 +356,13 @@ angular.module('copayApp.services')
|
|||
} catch (err) {
|
||||
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();
|
||||
$log.debug('Importing Wallet xPrivKey');
|
||||
|
||||
|
@ -363,19 +370,21 @@ angular.module('copayApp.services')
|
|||
if (err)
|
||||
return bwsError.cb(err, gettext('Could not import'), cb);
|
||||
|
||||
root._addWalletClient(walletClient, cb);
|
||||
root._addWalletClient(walletClient, opts, cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
root._normalizeMnemonic = function(words) {
|
||||
var isJA = words.indexOf('\u3000') > -1;
|
||||
var isJA = words.indexOf('\u3000') > -1;
|
||||
var wordList = words.split(/[\u3000\s]+/);
|
||||
|
||||
return wordList.join(isJA ? '\u3000' : ' ');
|
||||
};
|
||||
|
||||
root.importMnemonic = function(words, opts, cb) {
|
||||
if (opts.bwsurl)
|
||||
bwcService.setBaseUrl(opts.bwsurl);
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
|
||||
$log.debug('Importing Wallet Mnemonic');
|
||||
|
@ -388,11 +397,14 @@ angular.module('copayApp.services')
|
|||
if (err)
|
||||
return bwsError.cb(err, gettext('Could not import'), cb);
|
||||
|
||||
root._addWalletClient(walletClient, cb);
|
||||
root._addWalletClient(walletClient, opts, cb);
|
||||
});
|
||||
};
|
||||
|
||||
root.importExtendedPublicKey = function(opts, cb) {
|
||||
if (opts.bwsurl)
|
||||
bwcService.setBaseUrl(opts.bwsurl);
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
$log.debug('Importing Wallet XPubKey');
|
||||
|
||||
|
@ -406,16 +418,17 @@ angular.module('copayApp.services')
|
|||
return bwsError.cb(err, gettext('Could not import'), cb);
|
||||
}
|
||||
|
||||
root._addWalletClient(walletClient, cb);
|
||||
root._addWalletClient(walletClient, opts, cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
root.create = function(opts, cb) {
|
||||
$log.info('Creating profile');
|
||||
var defaults = configService.getDefaults();
|
||||
|
||||
configService.get(function(err) {
|
||||
root.applyConfig();
|
||||
bwcService.setBaseUrl(defaults.bws.url);
|
||||
bwcService.setTransports(['polling']);
|
||||
root._createNewProfile(opts, function(err, p) {
|
||||
if (err) return cb(err);
|
||||
|
||||
|
@ -552,7 +565,7 @@ angular.module('copayApp.services')
|
|||
$log.info('Requesting Ledger Chrome app to sign the transaction');
|
||||
|
||||
ledger.signTx(txp, 0, function(result) {
|
||||
$log.debug('Ledger response',result);
|
||||
$log.debug('Ledger response', result);
|
||||
if (!result.success)
|
||||
return cb(result.message || result.error);
|
||||
|
||||
|
@ -568,11 +581,11 @@ angular.module('copayApp.services')
|
|||
var fc = root.focusedClient;
|
||||
$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) {
|
||||
if (err) return cb(err);
|
||||
|
||||
$log.debug('Trezor response',result);
|
||||
$log.debug('Trezor response', result);
|
||||
txp.signatures = result.signatures;
|
||||
return fc.signTxProposal(txp, cb);
|
||||
});
|
||||
|
|
|
@ -124,7 +124,7 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.storeFocusedWalletId = function(id, cb) {
|
||||
storage.set('focusedWalletId', id||'', cb);
|
||||
storage.set('focusedWalletId', id || '', cb);
|
||||
};
|
||||
|
||||
root.getFocusedWalletId = function(cb) {
|
||||
|
@ -151,8 +151,8 @@ angular.module('copayApp.services')
|
|||
storage.get('backup-' + walletId, cb);
|
||||
};
|
||||
|
||||
root.setCleanAndScanAddresses = function(cb) {
|
||||
storage.set('CleanAndScanAddresses', Date.now(), cb);
|
||||
root.setCleanAndScanAddresses = function(walletId, cb) {
|
||||
storage.set('CleanAndScanAddresses', walletId, cb);
|
||||
};
|
||||
|
||||
root.getCleanAndScanAddresses = function(cb) {
|
||||
|
|
Loading…
Reference in New Issue