wallet-balance directive displaying basic crypto balance.
This commit is contained in:
parent
678ad516ee
commit
afb3a1d49f
5 changed files with 97 additions and 1 deletions
88
src/js/directives/walletBalanceDirective.js
Normal file
88
src/js/directives/walletBalanceDirective.js
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
'use strict';
|
||||
|
||||
(function(){
|
||||
|
||||
angular
|
||||
.module('bitcoincom.directives')
|
||||
.directive('walletBalance', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
displayAsFiat: '@',
|
||||
totalBalanceSat: '@',
|
||||
wallet: '@'
|
||||
},
|
||||
templateUrl: 'views/includes/wallet-balance.html',
|
||||
controller: walletBalanceController
|
||||
}
|
||||
});
|
||||
|
||||
function walletBalanceController($log, $scope, $timeout, uxLanguage) {
|
||||
console.log('walletBalanceController');
|
||||
var cryptoBalanceHasBeenDisplayed = false;
|
||||
|
||||
formatBalance();
|
||||
$scope.$watchGroup(['displayAsFiat', 'totalBalanceSat'], function onWalletBalanceWatch() {
|
||||
formatBalance();
|
||||
});
|
||||
|
||||
function displayCryptoBalance(wallet) {
|
||||
console.log('displayCryptoBalance()');
|
||||
if (wallet.status) {
|
||||
if (wallet.status.totalBalanceStr) {
|
||||
$scope.displayAmount = wallet.status.totalBalanceStr;
|
||||
$scope.cachedBalanceUpdatedOn = '';
|
||||
console.log('Displaying wallet.status.totalBalanceStr');
|
||||
|
||||
} else if (wallet.status.cachedBalance) {
|
||||
$scope.displayAmount = wallet.status.cachedBalance;
|
||||
$scope.cachedBalanceUpdatedOn = wallet.status.cachedBalanceUpdatedOn;
|
||||
console.log('Displaying wallet.status.cachedBalance');
|
||||
|
||||
} else {
|
||||
$scope.displayAmount = '';
|
||||
$scope.cachedBalanceUpdatedOn = '';
|
||||
console.log('Displaying "" from status');
|
||||
}
|
||||
} else if (wallet.cachedBalance) {
|
||||
$scope.displayAmount = cachedBalance;
|
||||
$scope.cachedBalanceUpdatedOn = '';
|
||||
console.log('Displaying cachedBalance');
|
||||
|
||||
} else {
|
||||
$scope.displayAmount = '';
|
||||
$scope.cachedBalanceUpdatedOn = '';
|
||||
console.log('Displaying "" without status');
|
||||
}
|
||||
cryptoBalanceHasBeenDisplayed = true;
|
||||
}
|
||||
|
||||
function displayFiatBalance(wallet) {
|
||||
|
||||
}
|
||||
|
||||
function formatBalance() {
|
||||
//console.log('formatBalance() with wallet:', $scope.wallet,);
|
||||
console.log('formatBalance() with displayAsFiat: "' + $scope.displayAsFiat + '"');
|
||||
var wallet = null;
|
||||
try {
|
||||
wallet = JSON.parse($scope.wallet);
|
||||
} catch (e) {
|
||||
$log.error('Error parsing wallet to display balance.', e);
|
||||
$scope.displayAmount = '';
|
||||
$scope.cachedBalanceUpdatedOn = '';
|
||||
}
|
||||
|
||||
if (!$scope.displayAsFiat || $scope.displayAsFiat && !cryptoBalanceHasBeenDisplayed) {
|
||||
displayCryptoBalance(wallet);
|
||||
}
|
||||
|
||||
if ($scope.displayAsFiat) {
|
||||
displayFiatBalance(wallet);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
@ -9,3 +9,4 @@
|
|||
@import "expand-content";
|
||||
@import "fee-summary";
|
||||
@import "formatted-amount";
|
||||
@import "wallet-balance";
|
||||
|
|
|
|||
3
src/sass/components/wallet-balance.scss
Normal file
3
src/sass/components/wallet-balance.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.wallet-balance-directive {
|
||||
display: inline-block;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue