mirror of https://github.com/BTCPrivate/copay.git
fix TX history delay
This commit is contained in:
parent
b574b6909b
commit
784031a7c0
|
@ -467,18 +467,16 @@
|
||||||
<div class="rect5"></div>
|
<div class="rect5"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p ng-show="index.showWaitingSign" translate class="size-12 text-gray">
|
<div ng-show="index.showWaitingSign" translate class="size-12 text-gray m20t">
|
||||||
Initial transaction history synchronization can take some minutes for wallets with many transactions.</br>
|
Initial transaction history synchronization can take some minutes for wallets with many transactions.</br>
|
||||||
Please stand by.
|
Please stand by.
|
||||||
</p>
|
</div>
|
||||||
</div>
|
<div ng-show="index.showWaitingSign" translate class="size-14 text-gray m20t">
|
||||||
<div ng-if="!index.isCordova && index.txHistory[0] && !index.updatingTxHistory" class="m20t text-center">
|
<b>{{index.txProgress}}</b> Transactions<br>
|
||||||
<input id="export_file" type="file" nwsaveas="Copay-{{index.alias || index.walletName}}.csv" accept=".csv" style="display:none">
|
Downloaded
|
||||||
<a class="text-gray size-12" ng-click="index.csvHistory();">
|
</div>
|
||||||
<i class="fi-page-export-csv"></i>
|
|
||||||
<span translate>Download CSV file</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-show="index.txHistory[0]">
|
<div ng-show="index.txHistory[0]">
|
||||||
<div ng-repeat="btx in index.txHistory"
|
<div ng-repeat="btx in index.txHistory"
|
||||||
ng-click="home.openTxModal(btx)"
|
ng-click="home.openTxModal(btx)"
|
||||||
|
@ -522,6 +520,22 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="row m20t">
|
||||||
|
<div class="large-6 medium-6 small-6 columns">
|
||||||
|
<button type="submit" class="button black round expand" ng-show="index.historyShowShowAll" ng-click="index.showAllHistory()" ng-style="{'background-color':index.backgroundColor}" translate>
|
||||||
|
<span translate>Show All</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="large-6 medium-6 small-6 columns" ng-show="!index.isCordova">
|
||||||
|
<input id="export_file" type="file" nwsaveas="Copay-{{index.alias || index.walletName}}.csv" accept=".csv" style="display:none">
|
||||||
|
<a class="button outline dark-gray round" ng-click="index.csvHistory();">
|
||||||
|
<i class="fi-page-export-csv"></i>
|
||||||
|
<span translate>Download CSV file</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="extra-margin-bottom"></div>
|
<div class="extra-margin-bottom"></div>
|
||||||
</div> <!-- END History -->
|
</div> <!-- END History -->
|
||||||
|
|
|
@ -7,7 +7,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.isChromeApp = isChromeApp;
|
self.isChromeApp = isChromeApp;
|
||||||
self.isSafari = isMobile.Safari();
|
self.isSafari = isMobile.Safari();
|
||||||
self.onGoingProcess = {};
|
self.onGoingProcess = {};
|
||||||
self.limitHistory = 6;
|
self.historyShowLimit = 10;
|
||||||
|
|
||||||
function strip(number) {
|
function strip(number) {
|
||||||
return (parseFloat(number.toPrecision(12)));
|
return (parseFloat(number.toPrecision(12)));
|
||||||
|
@ -83,7 +83,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.currentFeeLevel = null;
|
self.currentFeeLevel = null;
|
||||||
self.notAuthorized = false;
|
self.notAuthorized = false;
|
||||||
self.txHistory = [];
|
self.txHistory = [];
|
||||||
self.txHistoryUnique = {};
|
self.completeHistory = [];
|
||||||
|
self.txProgress = 0;
|
||||||
|
self.historyShowShowAll = false;
|
||||||
self.balanceByAddress = null;
|
self.balanceByAddress = null;
|
||||||
self.pendingTxProposalsCountForUs = null;
|
self.pendingTxProposalsCountForUs = null;
|
||||||
self.setSpendUnconfirmed();
|
self.setSpendUnconfirmed();
|
||||||
|
@ -490,12 +492,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
|
|
||||||
var SAFE_CONFIRMATIONS = 6;
|
var SAFE_CONFIRMATIONS = 6;
|
||||||
|
|
||||||
self.setTxHistory = function(txs) {
|
self.processNewTxs = function(txs) {
|
||||||
var config = configService.getSync().wallet.settings;
|
var config = configService.getSync().wallet.settings;
|
||||||
var now = Math.floor(Date.now() / 1000);
|
var now = Math.floor(Date.now() / 1000);
|
||||||
self.txHistoryUnique = {};
|
var txHistoryUnique = {};
|
||||||
|
var ret = [];
|
||||||
self.hasUnsafeConfirmed = false;
|
self.hasUnsafeConfirmed = false;
|
||||||
|
|
||||||
lodash.each(txs, function(tx) {
|
lodash.each(txs, function(tx) {
|
||||||
tx = txFormatService.processTx(tx);
|
tx = txFormatService.processTx(tx);
|
||||||
|
|
||||||
|
@ -510,13 +513,15 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.hasUnsafeConfirmed = true;
|
self.hasUnsafeConfirmed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self.txHistoryUnique[tx.txid]) {
|
if (!txHistoryUnique[tx.txid]) {
|
||||||
self.txHistory.push(tx);
|
ret.push(tx);
|
||||||
self.txHistoryUnique[tx.txid] = true;
|
txHistoryUnique[tx.txid] = true;
|
||||||
} else {
|
} else {
|
||||||
$log.debug('Ignoring duplicate TX in history: ' + tx.txid)
|
$log.debug('Ignoring duplicate TX in history: ' + tx.txid)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.updateAlias = function() {
|
self.updateAlias = function() {
|
||||||
|
@ -740,13 +745,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
self.stopSync = function(remoteTx, localTx) {
|
|
||||||
if (remoteTx.txid == localTx.txid)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.removeSoftConfirmedTx = function(txs) {
|
self.removeSoftConfirmedTx = function(txs) {
|
||||||
return lodash.map(txs, function(tx) {
|
return lodash.map(txs, function(tx) {
|
||||||
if (tx.confirmations >= SOFT_CONFIRMATION_LIMIT)
|
if (tx.confirmations >= SOFT_CONFIRMATION_LIMIT)
|
||||||
|
@ -778,60 +776,84 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
}
|
}
|
||||||
|
|
||||||
self.updateLocalTxHistory = function(cb) {
|
self.updateLocalTxHistory = function(cb) {
|
||||||
|
var requestLimit = 6;
|
||||||
|
|
||||||
self.getConfirmedTxs(function(err, txsFromLocal) {
|
self.getConfirmedTxs(function(err, txsFromLocal) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
var endingTxid = txsFromLocal[0] ? txsFromLocal[0].txid : null;
|
||||||
|
console.log('[index.js.791:endingTxid:]', endingTxid); //TODO
|
||||||
|
|
||||||
var fc = profileService.focusedClient;
|
function getNewTxs(newTxs, skip, i_cb) {
|
||||||
var c = fc.credentials;
|
|
||||||
fillTxsObject();
|
|
||||||
|
|
||||||
function fillTxsObject(txsResult, index) {
|
self.getTxsFromServer(skip, endingTxid, requestLimit, function(err, res, shouldContinue) {
|
||||||
txsResult = txsResult || [];
|
if (err) return i_cb(err);
|
||||||
index = index || 0;
|
|
||||||
|
|
||||||
self.makeTxHistoryRequest(txsResult, index, txsFromLocal[0], function(err, newIndex, exitLoop) {
|
|
||||||
if (err) return cb(err);
|
newTxs = newTxs.concat(res);
|
||||||
if (exitLoop) {
|
skip = skip + requestLimit;
|
||||||
self.txHistory = [];
|
|
||||||
self.setTxHistory(lodash.compact(txsResult.concat(txsFromLocal)));
|
$log.debug('Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue);
|
||||||
return storageService.setTxHistory(JSON.stringify(self.txHistory), c.walletId, function() {
|
|
||||||
return cb(null);
|
if (!shouldContinue) {
|
||||||
});
|
newTxs = self.processNewTxs(newTxs);
|
||||||
|
$log.debug('Finish Sync: New Txs: ' + newTxs.length);
|
||||||
|
return i_cb(null, newTxs);
|
||||||
}
|
}
|
||||||
fillTxsObject(txsResult, newIndex);
|
|
||||||
|
self.txProgress = newTxs.length;
|
||||||
|
$timeout(function(){
|
||||||
|
$rootScope.$apply();
|
||||||
|
});
|
||||||
|
getNewTxs(newTxs, skip, i_cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getNewTxs([], 0, function(err, txs) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
var fc = profileService.focusedClient;
|
||||||
|
var c = fc.credentials;
|
||||||
|
return storageService.setTxHistory(JSON.stringify(newHistory), c.walletId, function() {
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
self.showAllHistory = function() {
|
||||||
|
self.historyShowShowAll = false;
|
||||||
|
self.txHistory = self.completeHistory;
|
||||||
|
$timeout(function() {
|
||||||
|
$rootScope.$apply();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
self.getTxsFromServer = function(skip, endingTxid, limit, cb) {
|
||||||
|
var res = [];
|
||||||
|
|
||||||
self.makeTxHistoryRequest = function(txsResult, index, endingTx, cb) {
|
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
var c = fc.credentials;
|
|
||||||
var exitLoop = false;
|
|
||||||
|
|
||||||
fc.getTxHistory({
|
fc.getTxHistory({
|
||||||
skip: index,
|
skip: skip,
|
||||||
limit: self.limitHistory + 1
|
limit: limit
|
||||||
}, function(err, txsFromBWC) {
|
}, function(err, txsFromServer) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
if (!txsFromBWC[0])
|
if (!txsFromServer.length)
|
||||||
exitLoop = true;
|
return cb();
|
||||||
|
|
||||||
lodash.each(txsFromBWC, function(t) {
|
var res = lodash.takeWhile(txsFromServer, function(tx) {
|
||||||
if (!endingTx) txsResult.push(t);
|
return tx.txid != endingTxid;
|
||||||
else {
|
|
||||||
if (!self.stopSync(t, endingTx) && !exitLoop) {
|
|
||||||
txsResult.push(t);
|
|
||||||
} else {
|
|
||||||
exitLoop = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
index = index + self.limitHistory;
|
|
||||||
return cb(null, index, exitLoop);
|
return cb(null, res, res.length == limit);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
self.updateHistory = function() {
|
self.updateHistory = function() {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
|
|
Loading…
Reference in New Issue