mirror of https://github.com/BTCPrivate/copay.git
show status balance
This commit is contained in:
parent
5656caaa5a
commit
e3076d18ab
|
@ -33,7 +33,7 @@
|
|||
|
||||
<div class="oh pr" ng-show="wallet && wallet.isComplete()">
|
||||
<div ng-style="{'background-color':wallet.color}" class="amount">
|
||||
<div ng-if="!wallet.notAuthorized && !wallet.updating">
|
||||
<div ng-if="!wallet.notAuthorized && !updating">
|
||||
|
||||
<div class="m20t" ng-show="wallet.updateError" ng-click='update()'>
|
||||
<span class="size-12 db m10b">{{wallet.updateError|translate}}</span>
|
||||
|
@ -46,11 +46,11 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div ng-click='wallet.updateAll({triggerTxUpdate: true})' ng-show="!wallet.updateError && wallet.walletScanStatus != 'error' && !wallet.hideBalance" on-hold="hideToggle()">
|
||||
<strong class="size-36">{{wallet.totalBalanceStr}}</strong>
|
||||
<div class="size-14" ng-if="wallet.totalBalanceAlternative">{{wallet.totalBalanceAlternative}} {{wallet.alternativeIsoCode}}</div>
|
||||
<div ng-click='updateAll({triggerTxUpdate: true})' ng-show="!updateError && wallet.walletScanStatus != 'error' && !hideBalance" on-hold="hideToggle()">
|
||||
<strong class="size-36">{{status.totalBalanceStr}}</strong>
|
||||
<div class="size-14" ng-if="wallet.totalBalanceAlternative">{{status.totalBalanceAlternative}} {{status.alternativeIsoCode}}</div>
|
||||
<div class="size-14" ng-if="wallet.pendingAmount">
|
||||
<span translate>Pending Confirmation</span>: {{wallet.pendingAmountStr}}
|
||||
<span translate>Pending Confirmation</span>: {{status.pendingAmountStr}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -61,7 +61,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-if="wallet.updating">
|
||||
<div ng-if="updating">
|
||||
<div class="size-36">
|
||||
<strong>...</strong>
|
||||
</div>
|
||||
|
@ -82,7 +82,7 @@
|
|||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh pr m20t" ng-show="wallet.notAuthorized && !wallet.updating">
|
||||
<div class="oh pr m20t" ng-show="wallet.notAuthorized && !updating">
|
||||
<div class="text-center text-warning">
|
||||
<i class="fi-alert"></i>
|
||||
<span translate>
|
||||
|
@ -128,11 +128,11 @@
|
|||
</h4>
|
||||
|
||||
<div class="oh pr m20t text-gray size-12 text-center"
|
||||
ng-show="!wallet.loadingWallet && !wallet.txHistory[0] && !wallet.updatingTxHistory && !wallet.txHistoryError && !wallet.updateError && !wallet.notAuthorized"
|
||||
ng-show="!wallet.loadingWallet && !txHistory[0] && !wallet.updatingTxHistory && !wallet.txHistoryError && !wallet.updateError && !wallet.notAuthorized"
|
||||
translate>No transactions yet ZZZZ {{wallet.totalBalanceStr}}
|
||||
</div>
|
||||
|
||||
<div class="oh pr" ng-show="(wallet.txHistory[0] || wallet.txProgress > 5) && !wallet.notAuthorized">
|
||||
<div class="oh pr" ng-show="(txHistory[0] || wallet.txProgress > 5) && !wallet.notAuthorized">
|
||||
|
||||
<div ng-show="wallet.updatingTxHistory && wallet.txProgress > 5">
|
||||
<div class="row p20 text-center">
|
||||
|
@ -146,7 +146,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-if="wallet.txHistory[0] && wallet.updatingTxHistory && wallet.newTx" class="row collapse last-transactions-content animated fadeInDown">
|
||||
<div ng-if="txHistory[0] && wallet.updatingTxHistory && wallet.newTx" class="row collapse last-transactions-content animated fadeInDown">
|
||||
<div class="large-6 medium-6 small-6 columns size-14">
|
||||
<div class="m10r left">
|
||||
<img src="img/icon-new.svg" width="40">
|
||||
|
@ -160,7 +160,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-repeat="btx in wallet.txHistory track by btx.txid"
|
||||
<div ng-repeat="btx in txHistory track by btx.txid"
|
||||
ng-click="openTxModal(btx)"
|
||||
class="row collapse last-transactions-content">
|
||||
<div class="large-6 medium-6 small-6 columns size-14">
|
||||
|
|
|
@ -93,10 +93,9 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
|||
i = 0;
|
||||
|
||||
lodash.each(wallets, function(wallet) {
|
||||
walletService.updateStatus(wallet, {}, function(err) {
|
||||
var status = wallet.status;
|
||||
walletService.getStatus(wallet, {}, function(err, status) {
|
||||
if (err) {
|
||||
console.log('[tab-home.js.35:err:]',$log.error(err)); //TODO
|
||||
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
|
||||
return;
|
||||
} // TODO
|
||||
if (status.pendingTxps && status.pendingTxps[0]) {
|
||||
|
|
|
@ -61,12 +61,21 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
});
|
||||
};
|
||||
|
||||
$scope.updateAll = function() {
|
||||
$scope.update();
|
||||
}
|
||||
|
||||
$scope.update = function() {
|
||||
walletService.updateStatus(wallet, {
|
||||
$scope.updating = true;
|
||||
$timeout(function() {
|
||||
walletService.getStatus(wallet, {
|
||||
force: true
|
||||
}, function(err, status) {
|
||||
if (err) {} // TODO
|
||||
$scope.status = status;
|
||||
$scope.updating = false;
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
$scope.hideToggle = function() {
|
||||
|
@ -85,9 +94,15 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
$scope.wallet = wallet;
|
||||
|
||||
if (wallet) {
|
||||
walletService.updateStatus(wallet, {}, function(err, status) {
|
||||
console.log(status);
|
||||
walletService.getStatus(wallet, {}, function(err, status) {
|
||||
console.log('*** [walletDetails.js ln89] status:', status); // TODO
|
||||
if (err) {} // TODO
|
||||
$scope.status = status;
|
||||
});
|
||||
walletService.getHistory(wallet, {}, function(err, txHistory) {
|
||||
console.log('*** [walletDetails.js ln93] txHistory:', txHistory); // TODO
|
||||
if (err) {} // TODO
|
||||
$scope.txHistory = txHistory;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -128,64 +128,71 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
|
||||
var config = configService.getSync().wallet.settings;
|
||||
|
||||
var cache = wallet.cachedStatus;
|
||||
|
||||
// Address with Balance
|
||||
wallet.balanceByAddress = balance.byAddress;
|
||||
cache.balanceByAddress = balance.byAddress;
|
||||
|
||||
// Spend unconfirmed funds
|
||||
if (wallet.spendUnconfirmed) {
|
||||
wallet.totalBalanceSat = balance.totalAmount;
|
||||
wallet.lockedBalanceSat = balance.lockedAmount;
|
||||
wallet.availableBalanceSat = balance.availableAmount;
|
||||
wallet.totalBytesToSendMax = balance.totalBytesToSendMax;
|
||||
wallet.pendingAmount = null;
|
||||
if (cache.spendUnconfirmed) {
|
||||
cache.totalBalanceSat = balance.totalAmount;
|
||||
cache.lockedBalanceSat = balance.lockedAmount;
|
||||
cache.availableBalanceSat = balance.availableAmount;
|
||||
cache.totalBytesToSendMax = balance.totalBytesToSendMax;
|
||||
cache.pendingAmount = null;
|
||||
} else {
|
||||
wallet.totalBalanceSat = balance.totalConfirmedAmount;
|
||||
wallet.lockedBalanceSat = balance.lockedConfirmedAmount;
|
||||
wallet.availableBalanceSat = balance.availableConfirmedAmount;
|
||||
wallet.totalBytesToSendMax = balance.totalBytesToSendConfirmedMax;
|
||||
wallet.pendingAmount = balance.totalAmount - balance.totalConfirmedAmount;
|
||||
cache.totalBalanceSat = balance.totalConfirmedAmount;
|
||||
cache.lockedBalanceSat = balance.lockedConfirmedAmount;
|
||||
cache.availableBalanceSat = balance.availableConfirmedAmount;
|
||||
cache.totalBytesToSendMax = balance.totalBytesToSendConfirmedMax;
|
||||
cache.pendingAmount = balance.totalAmount - balance.totalConfirmedAmount;
|
||||
}
|
||||
|
||||
// Selected unit
|
||||
wallet.unitToSatoshi = config.unitToSatoshi;
|
||||
wallet.satToUnit = 1 / wallet.unitToSatoshi;
|
||||
wallet.unitName = config.unitName;
|
||||
cache.unitToSatoshi = config.unitToSatoshi;
|
||||
cache.satToUnit = 1 / cache.unitToSatoshi;
|
||||
cache.unitName = config.unitName;
|
||||
|
||||
//STR
|
||||
wallet.totalBalanceStr = root.formatAmount(wallet.totalBalanceSat) + ' ' + wallet.unitName;
|
||||
wallet.lockedBalanceStr = root.formatAmount(wallet.lockedBalanceSat) + ' ' + wallet.unitName;
|
||||
wallet.availableBalanceStr = root.formatAmount(wallet.availableBalanceSat) + ' ' + wallet.unitName;
|
||||
cache.totalBalanceStr = root.formatAmount(cache.totalBalanceSat) + ' ' + cache.unitName;
|
||||
cache.lockedBalanceStr = root.formatAmount(cache.lockedBalanceSat) + ' ' + cache.unitName;
|
||||
cache.availableBalanceStr = root.formatAmount(cache.availableBalanceSat) + ' ' + cache.unitName;
|
||||
|
||||
if (wallet.pendingAmount) {
|
||||
wallet.pendingAmountStr = root.formatAmount(wallet.pendingAmount) + ' ' + wallet.unitName;
|
||||
if (cache.pendingAmount) {
|
||||
cache.pendingAmountStr = root.formatAmount(cache.pendingAmount) + ' ' + cache.unitName;
|
||||
} else {
|
||||
wallet.pendingAmountStr = null;
|
||||
cache.pendingAmountStr = null;
|
||||
}
|
||||
|
||||
wallet.alternativeName = config.alternativeName;
|
||||
wallet.alternativeIsoCode = config.alternativeIsoCode;
|
||||
cache.alternativeName = config.alternativeName;
|
||||
cache.alternativeIsoCode = config.alternativeIsoCode;
|
||||
|
||||
rateService.whenAvailable(function() {
|
||||
|
||||
var totalBalanceAlternative = rateService.toFiat(wallet.totalBalanceSat, wallet.alternativeIsoCode);
|
||||
var lockedBalanceAlternative = rateService.toFiat(wallet.lockedBalanceSat, wallet.alternativeIsoCode);
|
||||
var alternativeConversionRate = rateService.toFiat(100000000, wallet.alternativeIsoCode);
|
||||
var totalBalanceAlternative = rateService.toFiat(cache.totalBalanceSat, cache.alternativeIsoCode);
|
||||
var lockedBalanceAlternative = rateService.toFiat(cache.lockedBalanceSat, cache.alternativeIsoCode);
|
||||
var alternativeConversionRate = rateService.toFiat(100000000, cache.alternativeIsoCode);
|
||||
|
||||
wallet.totalBalanceAlternative = $filter('formatFiatAmount')(totalBalanceAlternative);
|
||||
wallet.lockedBalanceAlternative = $filter('formatFiatAmount')(lockedBalanceAlternative);
|
||||
wallet.alternativeConversionRate = $filter('formatFiatAmount')(alternativeConversionRate);
|
||||
cache.totalBalanceAlternative = $filter('formatFiatAmount')(totalBalanceAlternative);
|
||||
cache.lockedBalanceAlternative = $filter('formatFiatAmount')(lockedBalanceAlternative);
|
||||
cache.alternativeConversionRate = $filter('formatFiatAmount')(alternativeConversionRate);
|
||||
|
||||
wallet.alternativeBalanceAvailable = true;
|
||||
wallet.isRateAvailable = true;
|
||||
cache.alternativeBalanceAvailable = true;
|
||||
cache.isRateAvailable = true;
|
||||
});
|
||||
};
|
||||
|
||||
function cacheStatus = (status) {
|
||||
wallet.status = status;
|
||||
wallet.statusUpdatedOn = Date.now();
|
||||
wallet.isValid = true;
|
||||
function isStatusCached() {
|
||||
return wallet.cachedStatus && wallet.cachedStatus.isValid;
|
||||
};
|
||||
|
||||
function cacheStatus(status) {
|
||||
wallet.cachedStatus = status || {};
|
||||
var cache = wallet.cachedStatus;
|
||||
cache.statusUpdatedOn = Date.now();
|
||||
cache.isValid = true;
|
||||
cache.email = status.preferences ? status.preferences.email : null;
|
||||
cacheBalance(wallet, status.balance);
|
||||
wallet.email = status.preferences.email;
|
||||
};
|
||||
|
||||
function walletStatusHash(status) {
|
||||
|
@ -193,7 +200,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
};
|
||||
|
||||
function _getStatus(initStatusHash, tries, cb) {
|
||||
if (wallet.isValid && !opts.force) return cb(null, wallet.status);
|
||||
if (isStatusCached() && !opts.force) return cb(null, wallet.cachedStatus);
|
||||
|
||||
tries = tries || 0;
|
||||
|
||||
|
@ -215,7 +222,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
|
||||
$log.debug('Got Wallet Status for:' + wallet.credentials.walletName);
|
||||
|
||||
root.cacheStatus(wallet, status);
|
||||
cacheStatus(status);
|
||||
|
||||
// wallet.setPendingTxps(status.pendingTxps);
|
||||
return cb(null, status);
|
||||
|
@ -354,7 +361,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
// First update
|
||||
if (walletId == wallet.credentials.walletId) {
|
||||
wallet.completeHistory = txsFromLocal;
|
||||
setCompactTxHistory(wallet);
|
||||
}
|
||||
|
||||
if (wallet.historyUpdateInProgress)
|
||||
|
@ -388,7 +394,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
var newHistory = processNewTxs(wallet, newTxs);
|
||||
newHistory = lodash.compact(newHistory.concat(confirmedTxs));
|
||||
wallet.completeHistory = newHistory;
|
||||
setCompactTxHistory(wallet);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -438,7 +443,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
// Final update
|
||||
if (walletId == wallet.credentials.walletId) {
|
||||
wallet.completeHistory = newHistory;
|
||||
setCompactTxHistory(wallet);
|
||||
}
|
||||
|
||||
return storageService.setTxHistory(historyToSave, walletId, function() {
|
||||
|
@ -452,28 +456,21 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
};
|
||||
|
||||
|
||||
root.updateHistory = function(wallet, cb) {
|
||||
root.getHistory = function(wallet, opts, cb) {
|
||||
opts = opts || {};
|
||||
opts.skip = opts.skip || 0;
|
||||
opts.limit = opts.limit || root.HISTORY_SHOW_LIMIT;
|
||||
|
||||
var walletId = wallet.credentials.walletId;
|
||||
|
||||
if (!wallet.isComplete()) return cb();
|
||||
|
||||
$log.debug('Updating Transaction History');
|
||||
wallet.txHistoryError = false;
|
||||
wallet.updatingTxHistory = true;
|
||||
|
||||
$timeout(function() {
|
||||
updateLocalTxHistory(wallet, function(err) {
|
||||
wallet.historyUpdateInProgress = wallet.updatingTxHistory = false;
|
||||
wallet.loadingWallet = false;
|
||||
wallet.txProgress = 0;
|
||||
if (err)
|
||||
wallet.txHistoryError = true;
|
||||
|
||||
$timeout(function() {
|
||||
wallet.newTx = false
|
||||
});
|
||||
|
||||
});
|
||||
if (err) return cb(err);
|
||||
var txs = wallet.completeHistory ? wallet.completeHistory.slice(opts.skip, opts.limit) : null;
|
||||
return cb(err, txs);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -662,15 +659,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
});
|
||||
};
|
||||
|
||||
var setCompactTxHistory = function(wallet) {
|
||||
|
||||
// TODO
|
||||
wallet.isSearching = false;
|
||||
wallet.nextTxHistory = root.HISTORY_SHOW_LIMIT;
|
||||
wallet.txHistory = wallet.completeHistory ? wallet.completeHistory.slice(0, root.HISTORY_SHOW_LIMIT) : null;
|
||||
wallet.historyShowMore = wallet.completeHistory ? wallet.completeHistory.length > root.HISTORY_SHOW_LIMIT : null;
|
||||
};
|
||||
|
||||
root.debounceUpdateHistory = lodash.debounce(function() {
|
||||
root.updateHistory();
|
||||
}, 1000);
|
||||
|
|
Loading…
Reference in New Issue