mirror of https://github.com/BTCPrivate/copay.git
fix history sync
This commit is contained in:
parent
1e9b99981e
commit
232b78ee8c
|
@ -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",
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
|
||||
<span ng-show="index.isShared"><span translate>{{index.m}}-of-{{index.n}}</span></span>
|
||||
<img style="height:1em" ng-show="index.network != 'livenet'" src="img/icon-testnet.svg">
|
||||
<img style="height:1em" ng-show="!index.canSign && !index.isPrivKeyExternal" src="img/icon-view.svg">
|
||||
<img style="height:1em" ng-show="!index.canSign && !index.isPrivKeyExternal" src="img/icon-read-only.svg">
|
||||
|
||||
<img style="height:1em" ng-show="index.externalSource == 'trezor'" src="img/icon-trezor.svg">
|
||||
<img style="height:1em" ng-show="index.externalSource == 'ledger'" src="img/icon-ledger.svg">
|
||||
<span style="height:1em" ng-show="index.account">#{{index.account || 0}} </span>
|
||||
|
||||
<img style="height:1em" ng-show="index.isPrivKeyEncrypted" src="img/icon-lock.svg">
|
||||
|
||||
<img style="height:1em" ng-show="index.preferences.email" src="img/icon-email.svg">
|
||||
<!-- <img style="height:1em" ng-show="index.preferences.email" src="img/icon-email.svg"> -->
|
||||
<img style="height:1em" ng-show="index.usingCustomBWS" src="img/icon-bws.svg">
|
||||
|
||||
<img style="height:1em" class="animated flash infinite" ng-show="index.updatingTxHistory[index.walletId]" src="img/icon-sync.svg">
|
||||
|
||||
|
|
|
@ -442,7 +442,7 @@
|
|||
|
||||
-->
|
||||
<div id="history" class="history tab-view">
|
||||
<div class="row m20t" ng-show="!index.txHistory[0] && !index.updatingTxHistory">
|
||||
<div class="row m20t" ng-show="!index.txHistory[0] && !index.updatingTxHistory[index.walletId]">
|
||||
<div class="large-12 columns">
|
||||
<div class="oh text-center">
|
||||
<span ng-show="index.txHistoryError && !index.notAuthorized" ng-click='index.updateTxHistory()'>
|
||||
|
@ -455,7 +455,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row m20t text-center" ng-show="index.updatingtxhistory">
|
||||
<div class="row m20t text-center" ng-show="index.updatingTxHistory[index.walletId]">
|
||||
<div class="columns large-12 medium-12 small-12">
|
||||
<div class="spinner">
|
||||
<div class="rect1"></div>
|
||||
|
@ -465,11 +465,11 @@
|
|||
<div class="rect5"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-show="index.showWaitingSign" translate class="size-12 text-gray m20t">
|
||||
<div ng-show="index.txProgress > 6" translate class="size-12 text-gray m20t">
|
||||
Initial transaction history synchronization can take some minutes for wallets with many transactions.</br>
|
||||
Please stand by.
|
||||
</div>
|
||||
<div ng-show="index.showWaitingSign" translate class="size-14 text-gray m20t">
|
||||
<div ng-show="index.txProgress > 6" translate class="size-14 text-gray m20t">
|
||||
<b>{{index.txProgress}}</b> Transactions<br>
|
||||
Downloaded
|
||||
</div>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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',
|
|||
});
|
||||
});
|
||||
};
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue