Update: Removes usage of cacheBalance and directly call getLastKnownBalance to avoid potential async issues
This commit is contained in:
parent
33d8474fe1
commit
f2ad6abe75
4 changed files with 29 additions and 17 deletions
|
|
@ -24,8 +24,8 @@
|
|||
"windowsAppId": "804636ee-b017-4cad-8719-e58ac97ffa5c",
|
||||
"pushSenderId": "1036948132229",
|
||||
"description": "A Secure Bitcoin Wallet",
|
||||
"version": "4.7.3",
|
||||
"androidVersion": "407300",
|
||||
"version": "4.8.0",
|
||||
"androidVersion": "408000",
|
||||
"_extraCSS": "",
|
||||
"_enabledExtensions": {
|
||||
"coinbase": false,
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
|||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
$ionicNavBarDelegate.showBar(true);
|
||||
updateAllWallets();
|
||||
profileService.initBitcoinCoreDisplay();
|
||||
|
||||
addressbookService.list(function(err, ab) {
|
||||
if (err) $log.error(err);
|
||||
|
|
|
|||
|
|
@ -1315,7 +1315,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
$timeout(function() {
|
||||
emailService.init(); // Update email subscription if necessary
|
||||
openURLService.init();
|
||||
profileService.initBitcoinCoreDisplay();
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1038,27 +1038,39 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.initBitcoinCoreDisplay = function() {
|
||||
console.log('Init Bitcoin Core Display...');
|
||||
storageService.checkIfFlagIsSet('displayBitcoinCoreFlag').then(function(result) {
|
||||
if (!result) {
|
||||
var walletsBtc = root.getWallets({coin: 'btc'});
|
||||
var totalBtc = 0;
|
||||
var errorBalance = false;
|
||||
|
||||
walletsBtc.forEach(function(value, key, index) {
|
||||
totalBtc += parseFloat(value.cachedBalance);
|
||||
});
|
||||
|
||||
var enableDisplayBitcoinCore = totalBtc > 0 ? true : false;
|
||||
if (walletsBtc.length > 0) {
|
||||
walletsBtc.forEach(function(value, key, index) {
|
||||
// Do not trust cachedBalance as it is added asynchronously. Manually call getLastKnownBalance for each wallet ID
|
||||
root.getLastKnownBalance(value.id, function(err, data) {
|
||||
if (data) {
|
||||
var balanceData = JSON.parse(data);
|
||||
totalBtc += parseFloat(balanceData.balance);
|
||||
} else {
|
||||
errorBalance = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var opts = {
|
||||
displayBitcoinCore: {
|
||||
enabled: enableDisplayBitcoinCore
|
||||
}
|
||||
};
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.debug(err);
|
||||
});
|
||||
var enableDisplayBitcoinCore = (totalBtc > 0) && !errorBalance ? true : false;
|
||||
|
||||
storageService.activateDisplayBitcoinCoreFlag();
|
||||
var opts = {
|
||||
displayBitcoinCore: {
|
||||
enabled: enableDisplayBitcoinCore
|
||||
}
|
||||
};
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.debug(err);
|
||||
});
|
||||
|
||||
if (!errorBalance) storageService.activateDisplayBitcoinCoreFlag();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue