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",
|
"windowsAppId": "804636ee-b017-4cad-8719-e58ac97ffa5c",
|
||||||
"pushSenderId": "1036948132229",
|
"pushSenderId": "1036948132229",
|
||||||
"description": "A Secure Bitcoin Wallet",
|
"description": "A Secure Bitcoin Wallet",
|
||||||
"version": "4.7.3",
|
"version": "4.8.0",
|
||||||
"androidVersion": "407300",
|
"androidVersion": "408000",
|
||||||
"_extraCSS": "",
|
"_extraCSS": "",
|
||||||
"_enabledExtensions": {
|
"_enabledExtensions": {
|
||||||
"coinbase": false,
|
"coinbase": false,
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
$scope.$on("$ionicView.enter", function(event, data) {
|
$scope.$on("$ionicView.enter", function(event, data) {
|
||||||
$ionicNavBarDelegate.showBar(true);
|
$ionicNavBarDelegate.showBar(true);
|
||||||
updateAllWallets();
|
updateAllWallets();
|
||||||
|
profileService.initBitcoinCoreDisplay();
|
||||||
|
|
||||||
addressbookService.list(function(err, ab) {
|
addressbookService.list(function(err, ab) {
|
||||||
if (err) $log.error(err);
|
if (err) $log.error(err);
|
||||||
|
|
|
||||||
|
|
@ -1315,7 +1315,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
emailService.init(); // Update email subscription if necessary
|
emailService.init(); // Update email subscription if necessary
|
||||||
openURLService.init();
|
openURLService.init();
|
||||||
profileService.initBitcoinCoreDisplay();
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1038,27 +1038,39 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.initBitcoinCoreDisplay = function() {
|
root.initBitcoinCoreDisplay = function() {
|
||||||
|
console.log('Init Bitcoin Core Display...');
|
||||||
storageService.checkIfFlagIsSet('displayBitcoinCoreFlag').then(function(result) {
|
storageService.checkIfFlagIsSet('displayBitcoinCoreFlag').then(function(result) {
|
||||||
if (!result) {
|
if (!result) {
|
||||||
var walletsBtc = root.getWallets({coin: 'btc'});
|
var walletsBtc = root.getWallets({coin: 'btc'});
|
||||||
var totalBtc = 0;
|
var totalBtc = 0;
|
||||||
|
var errorBalance = false;
|
||||||
|
|
||||||
walletsBtc.forEach(function(value, key, index) {
|
if (walletsBtc.length > 0) {
|
||||||
totalBtc += parseFloat(value.cachedBalance);
|
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) {
|
||||||
var enableDisplayBitcoinCore = totalBtc > 0 ? true : false;
|
if (data) {
|
||||||
|
var balanceData = JSON.parse(data);
|
||||||
|
totalBtc += parseFloat(balanceData.balance);
|
||||||
|
} else {
|
||||||
|
errorBalance = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var opts = {
|
var enableDisplayBitcoinCore = (totalBtc > 0) && !errorBalance ? true : false;
|
||||||
displayBitcoinCore: {
|
|
||||||
enabled: enableDisplayBitcoinCore
|
|
||||||
}
|
|
||||||
};
|
|
||||||
configService.set(opts, function(err) {
|
|
||||||
if (err) $log.debug(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
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