diff --git a/bower.json b/bower.json index 94551fa1a..45f6bf216 100644 --- a/bower.json +++ b/bower.json @@ -8,7 +8,7 @@ ], "dependencies": { "angular": "1.4.6", - "angular-bitcore-wallet-client": "1.1.5", + "angular-bitcore-wallet-client": "1.1.6", "angular-foundation": "0.7.0", "angular-gettext": "2.1.0", "angular-moment": "0.10.1", diff --git a/public/views/includes/walletInfo.html b/public/views/includes/walletInfo.html index df2c921d7..4b9af85c5 100644 --- a/public/views/includes/walletInfo.html +++ b/public/views/includes/walletInfo.html @@ -1,11 +1,16 @@ {{index.m}}-of-{{index.n}} - + + #{{index.account || 0}} - + + + + + diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 0c48b107b..b91cde671 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -442,7 +442,7 @@ -->
-
+
@@ -455,7 +455,7 @@
-
+
@@ -465,11 +465,11 @@
-
+
Initial transaction history synchronization can take some minutes for wallets with many transactions.
Please stand by.
-
+
{{index.txProgress}} Transactions
Downloaded
diff --git a/src/js/controllers/create.js b/src/js/controllers/create.js index 0a19e1726..490cbd82c 100644 --- a/src/js/controllers/create.js +++ b/src/js/controllers/create.js @@ -96,7 +96,6 @@ angular.module('copayApp.controllers').controller('createController', myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null, networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet', bwsurl: $scope.bwsurl, - use48: $scope.fromHardware, }; var setSeed = self.seedSourceId == 'set'; if (setSeed) { diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index ca78dc132..9184fc5db 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -8,6 +8,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.isSafari = isMobile.Safari(); self.onGoingProcess = {}; self.historyShowLimit = 10; + self.updatingTxHistory = {}; function strip(number) { return (parseFloat(number.toPrecision(12))); @@ -123,6 +124,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.initGlidera(); + self.setCustomBWSFlag(); if (fc.isPrivKeyExternal()) { self.needsBackup = false; self.openWallet(); @@ -135,6 +137,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }; + self.setCustomBWSFlag = function() { + var defaults = configService.getDefaults(); + var config = configService.getSync(); + + self.usingCustomBWS = config.bwsFor && (config.bwsFor[self.walletId] != defaults.bws.url); + }; + self.setTab = function(tab, reset, tries, switchState) { tries = tries || 0; @@ -753,17 +762,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); } - self.getConfirmedTxs = function(cb) { - var fc = profileService.focusedClient; - var c = fc.credentials; + self.getConfirmedTxs = function(walletId, cb) { - storageService.getTxHistory(c.walletId, function(err, txs) { + storageService.getTxHistory(walletId, function(err, txs) { if (err) return cb(err); var localTxs = []; if (!txs) { - self.showWaitingSign = true; return cb(null, localTxs); } @@ -776,20 +782,21 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); } - self.updateLocalTxHistory = function(cb) { + self.updateLocalTxHistory = function(client, cb) { var requestLimit = 6; + var walletId = client.credentials.walletId; - self.getConfirmedTxs(function(err, txsFromLocal) { + self.getConfirmedTxs(walletId, function(err, txsFromLocal) { if (err) return cb(err); var endingTxid = txsFromLocal[0] ? txsFromLocal[0].txid : null; function getNewTxs(newTxs, skip, i_cb) { - self.getTxsFromServer(skip, endingTxid, requestLimit, function(err, res, shouldContinue) { + self.getTxsFromServer(client, skip, endingTxid, requestLimit, function(err, res, shouldContinue) { if (err) return i_cb(err); - newTxs = newTxs.concat(res); + newTxs = newTxs.concat(lodash.compact(res)); skip = skip + requestLimit; $log.debug('Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue); @@ -800,8 +807,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r return i_cb(null, newTxs); } - self.txProgress = newTxs.length; - $timeout(function(){ + if (walletId == profileService.focusedClient.credentials.walletId) + self.txProgress = newTxs.length; + + $timeout(function() { $rootScope.$apply(); }); getNewTxs(newTxs, skip, i_cb); @@ -814,13 +823,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r var newHistory = lodash.compact(txs.concat(txsFromLocal)); $log.debug('Tx History synced. Total Txs: ' + newHistory.length); - self.completeHistory = newHistory; - self.txHistory = newHistory.slice(0, self.historyShowLimit); - self.historyShowShowAll = newHistory.length >= self.historyShowLimit; + if (walletId == profileService.focusedClient.credentials.walletId) { + self.completeHistory = newHistory; + self.txHistory = newHistory.slice(0, self.historyShowLimit); + self.historyShowShowAll = newHistory.length >= self.historyShowLimit; + } - var fc = profileService.focusedClient; - var c = fc.credentials; - return storageService.setTxHistory(JSON.stringify(newHistory), c.walletId, function() { + return storageService.setTxHistory(JSON.stringify(newHistory), walletId, function() { return cb(); }); }); @@ -838,11 +847,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }; - self.getTxsFromServer = function(skip, endingTxid, limit, cb) { + self.getTxsFromServer = function(client, skip, endingTxid, limit, cb) { var res = []; - var fc = profileService.focusedClient; - fc.getTxHistory({ + client.getTxHistory({ skip: skip, limit: limit }, function(err, txsFromServer) { @@ -861,18 +869,18 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.updateHistory = function() { var fc = profileService.focusedClient; - if (!fc.isComplete() || self.updatingTxHistory) return; + var walletId = fc.credentials.walletId; + + if (!fc.isComplete() || self.updatingTxHistory[walletId]) return; $log.debug('Updating Transaction History'); self.txHistoryError = false; - self.updatingTxHistory = true; + self.updatingTxHistory[walletId] = true; $timeout(function() { - self.updateLocalTxHistory(function(err) { - self.updatingTxHistory = false; - self.showWaitingSign = false; - - if (err) + self.updateLocalTxHistory(fc, function(err) { + self.updatingTxHistory[walletId] = false; + if (err) self.txHistoryError = true; $rootScope.$apply(); @@ -1325,4 +1333,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.setFocusedWallet(); }); }); + + $rootScope.$on('Local/NewEncryptionSetting', function() { + var fc = profileService.focusedClient; + self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted(); + $timeout(function() { + $rootScope.$apply(); + }); + }); }); diff --git a/src/js/controllers/preferences.js b/src/js/controllers/preferences.js index d5c29fadf..b06098502 100644 --- a/src/js/controllers/preferences.js +++ b/src/js/controllers/preferences.js @@ -55,6 +55,7 @@ angular.module('copayApp.controllers').controller('preferencesController', return; } profileService.setPrivateKeyEncryptionFC(password, function() { + $rootScope.$emit('Local/NewEncryptionSetting'); $scope.encrypt = true; }); }); @@ -66,6 +67,7 @@ angular.module('copayApp.controllers').controller('preferencesController', return; } profileService.disablePrivateKeyEncryptionFC(function(err) { + $rootScope.$emit('Local/NewEncryptionSetting'); if (err) { $scope.encrypt = true; $log.error(err); diff --git a/src/js/controllers/preferencesBwsUrl.js b/src/js/controllers/preferencesBwsUrl.js index c27786220..d7d4afc6d 100644 --- a/src/js/controllers/preferencesBwsUrl.js +++ b/src/js/controllers/preferencesBwsUrl.js @@ -13,7 +13,7 @@ angular.module('copayApp.controllers').controller('preferencesBwsUrlController', this.bwsurl = (config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url; this.resetDefaultUrl = function() { - this.bwsurl = 'https://bws.bitpay.com/bws/api'; + this.bwsurl = defaults.bws.url; }; this.save = function() { @@ -50,4 +50,4 @@ angular.module('copayApp.controllers').controller('preferencesBwsUrlController', }); }); }; - }); \ No newline at end of file + }); diff --git a/src/js/controllers/preferencesInformation.js b/src/js/controllers/preferencesInformation.js index 8f04e8077..6ecbcfcab 100644 --- a/src/js/controllers/preferencesInformation.js +++ b/src/js/controllers/preferencesInformation.js @@ -7,7 +7,7 @@ angular.module('copayApp.controllers').controller('preferencesInformation', var c = fc.credentials; this.init = function() { - var basePath = profileService.getUtils().getBaseAddressDerivationPath(c.derivationStrategy, c.network, c.account); + var basePath = c.getBaseAddressDerivationPath(); $scope.walletName = c.walletName; $scope.walletId = c.walletId; diff --git a/src/js/services/hwWallet.js b/src/js/services/hwWallet.js index cf81f71f1..55d3ccc79 100644 --- a/src/js/services/hwWallet.js +++ b/src/js/services/hwWallet.js @@ -16,28 +16,28 @@ angular.module('copayApp.services') return msg; }; - root.getAddressPath = function(isMultisig, account) { - var rootPath; - if (account) { - rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH; - } else { - // Old ledger wallet compat - rootPath = 44; - } - return rootPath + "'/" + root.LIVENET_PATH + "'/" + account + "'"; + root.getRootPath = function(device, isMultisig, account) { + if (!isMultisig) return root.UNISIG_ROOTPATH; + + // Compat + if (device == 'ledger' && account ==0) return root.UNISIG_ROOTPATH; + + return root.MULTISIG_ROOTPATH; + }; + + root.getAddressPath = function(device, isMultisig, account) { + return root.getRootPath(device,isMultisig,account) + "'/" + root.LIVENET_PATH + "'/" + account + "'"; } - root.getEntropyPath = function(isMultisig, account) { + root.getEntropyPath = function(device, isMultisig, account) { var path; - if (account) { - var rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH; - path = root.ENTROPY_INDEX_PATH + rootPath + "'/" + account + "'"; - } else { - // Old ledger wallet compat - path = root.ENTROPY_INDEX_PATH + "0'"; - } - return path; + + // Old ledger wallet compat + if (device == 'ledger' && account == 0) + return root.ENTROPY_INDEX_PATH + "0'"; + + return root.ENTROPY_INDEX_PATH + root.getRootPath(device,isMultisig,account) + "'/" + account + "'"; }; root.pubKeyToEntropySource = function(xPubKey) { diff --git a/src/js/services/ledger.js b/src/js/services/ledger.js index 9da58ace1..bb54ae0ab 100644 --- a/src/js/services/ledger.js +++ b/src/js/services/ledger.js @@ -13,7 +13,7 @@ angular.module('copayApp.services') } root.getEntropySource = function(isMultisig, account, callback) { - root.getXPubKey(hwWallet.getEntropyPath(isMultisig, account), function(data) { + root.getXPubKey(hwWallet.getEntropyPath('ledger', isMultisig, account), function(data) { if (!data.success) return callback(hwWallet._err(data)); @@ -37,7 +37,7 @@ angular.module('copayApp.services') if (err) return callback(err); opts.entropySource = entropySource; - root.getXPubKey(hwWallet.getAddressPath(isMultisig, account), function(data) { + root.getXPubKey(hwWallet.getAddressPath('ledger', isMultisig, account), function(data) { if (!data.success) { $log.warn(data.message); return callback(data); @@ -45,6 +45,9 @@ angular.module('copayApp.services') opts.extendedPublicKey = data.xpubkey; opts.externalSource = 'ledger'; opts.account = account; + + // Old ledger compat + opts.derivationStrategy = account ? 'BIP48' : 'BIP44'; return callback(null, opts); }); }); @@ -54,11 +57,10 @@ angular.module('copayApp.services') root.callbacks["sign_p2sh"] = callback; var redeemScripts = []; var paths = []; - - var tx = bwcService.getUtils().buildTx(txp); + var tx = bwcService.buildTx(txp); for (var i = 0; i < tx.inputs.length; i++) { redeemScripts.push(new ByteString(tx.inputs[i].redeemScript.toBuffer().toString('hex'), GP.HEX).toString()); - paths.push(hwWallet.getAddressPath(isMultisig, account) + txp.inputs[i].path.substring(1)); + paths.push(hwWallet.getAddressPath('ledger', isMultisig, account) + txp.inputs[i].path.substring(1)); } var splitTransaction = root._splitTransaction(new ByteString(tx.toString(), GP.HEX)); var inputs = []; diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 8ac0ead58..bb55cf604 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -173,12 +173,6 @@ angular.module('copayApp.services') var walletClient = bwcService.getClient(); var network = opts.networkName || 'livenet'; - // TODO refactor this and use bwc contants? - var derivationStrategy = 'BIP44'; - if (opts.fromHardware && opts.n > 1) { - derivationStrategy = 'BIP48'; - } - if (opts.mnemonic) { try { @@ -187,7 +181,7 @@ angular.module('copayApp.services') network: network, passphrase: opts.passphrase, account: opts.account || 0, - derivationStrategy: derivationStrategy, + derivationStrategy: opts.derivationStrategy || 'BIP44', }); } catch (ex) { @@ -205,7 +199,7 @@ angular.module('copayApp.services') try { walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, { account: opts.account || 0, - derivationStrategy: derivationStrategy, + derivationStrategy: opts.derivationStrategy || 'BIP44', }); } catch (ex) { $log.warn("Creating wallet from Extended Public Key Arg:", ex, opts); @@ -319,7 +313,7 @@ angular.module('copayApp.services') walletId: walletId }); - delete root.walletClients[walletId]; + delete root.walletClients[walletId]; root.focusedClient = null; storageService.clearLastAddress(walletId, function(err) { @@ -446,6 +440,7 @@ angular.module('copayApp.services') walletClient.importFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, { account: opts.account || 0, + derivationStrategy: opts.derivationStrategy || 'BIP44', }, function(err) { if (err) { diff --git a/src/js/services/trezor.js b/src/js/services/trezor.js index 4a16df8de..7c1827814 100644 --- a/src/js/services/trezor.js +++ b/src/js/services/trezor.js @@ -8,7 +8,7 @@ angular.module('copayApp.services') root.callbacks = {}; root.getEntropySource = function(isMultisig, account, callback) { - root.getXPubKey(hwWallet.getEntropyPath(isMultisig, account), function(data) { + root.getXPubKey(hwWallet.getEntropyPath('trezor', isMultisig, account), function(data) { if (!data.success) return callback(hwWallet._err(data)); @@ -31,13 +31,17 @@ angular.module('copayApp.services') $log.debug('Waiting TREZOR to settle...'); $timeout(function() { - root.getXPubKey(hwWallet.getAddressPath(isMultisig, account), function(data) { + root.getXPubKey(hwWallet.getAddressPath('trezor', isMultisig, account), function(data) { if (!data.success) return callback(hwWallet._err(data)); opts.extendedPublicKey = data.xpubkey; opts.externalSource = 'trezor'; opts.account = account; + + if (isMultisig) + opts.derivationStrategy = 'BIP48'; + return callback(null, opts); }); }, SETTLE_TIME);