Added $scope.availableFunds.
This commit is contained in:
parent
3cedfa5146
commit
61f1603bbf
1 changed files with 39 additions and 12 deletions
|
|
@ -3,11 +3,14 @@
|
||||||
angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicModal, $ionicScrollDelegate, $ionicHistory, walletService, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, popupService, profileService, nodeWebkitService) {
|
angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicModal, $ionicScrollDelegate, $ionicHistory, walletService, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, popupService, profileService, nodeWebkitService) {
|
||||||
|
|
||||||
var _id;
|
var _id;
|
||||||
|
var availableFundsInCrypto = '';
|
||||||
|
var availableFundsInFiat = '';
|
||||||
|
var availableSatoshis = null;
|
||||||
var unitToSatoshi;
|
var unitToSatoshi;
|
||||||
var satToUnit;
|
var satToUnit;
|
||||||
var unitDecimals;
|
var unitDecimals;
|
||||||
var satToBtc;
|
var satToBtc;
|
||||||
var spendableAmountInSatoshis = null;
|
|
||||||
|
|
||||||
var SMALL_FONT_SIZE_LIMIT = 10;
|
var SMALL_FONT_SIZE_LIMIT = 10;
|
||||||
var LENGTH_EXPRESSION_LIMIT = 19;
|
var LENGTH_EXPRESSION_LIMIT = 19;
|
||||||
|
|
@ -23,6 +26,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
var fixedUnit;
|
var fixedUnit;
|
||||||
|
|
||||||
$scope.amountModel = { amount: 0 };
|
$scope.amountModel = { amount: 0 };
|
||||||
|
$scope.availableFunds = '';
|
||||||
|
|
||||||
|
|
||||||
// Use insufficient for logic, as when the amount is invalid, funds being
|
// Use insufficient for logic, as when the amount is invalid, funds being
|
||||||
// either sufficent or insufficient doesn't make sense.
|
// either sufficent or insufficient doesn't make sense.
|
||||||
|
|
@ -143,8 +148,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
if ($scope.fromWalletId) {
|
if ($scope.fromWalletId) {
|
||||||
var fromWallet = profileService.getWallet($scope.fromWalletId);
|
var fromWallet = profileService.getWallet($scope.fromWalletId);
|
||||||
console.log('got fromWallet.');
|
updateAvailableFundsFromWallet(fromWallet);
|
||||||
updateSpendableAmountInSatoshisFromWallet(fromWallet);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -281,12 +285,15 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
if (availableUnits[unitIndex].isFiat) {
|
if (availableUnits[unitIndex].isFiat) {
|
||||||
altUnitIndex = altUnitIndex == 0 && availableUnits.length > 2 ? 1 : 0;
|
altUnitIndex = altUnitIndex == 0 && availableUnits.length > 2 ? 1 : 0;
|
||||||
|
$scope.availableFunds = availableFundsInFiat || availableFundsInCrypto;
|
||||||
} else {
|
} else {
|
||||||
altUnitIndex = lodash.findIndex(availableUnits, {
|
altUnitIndex = lodash.findIndex(availableUnits, {
|
||||||
isFiat: true
|
isFiat: true
|
||||||
});
|
});
|
||||||
|
$scope.availableFunds = availableFundsInCrypto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('availableFunds: ' + $scope.availableFunds);
|
||||||
updateUnitUI();
|
updateUnitUI();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -401,8 +408,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
if (a) {
|
if (a) {
|
||||||
var amountInSatoshis = a * unitToSatoshi;
|
var amountInSatoshis = a * unitToSatoshi;
|
||||||
$scope.fundsAreInsufficient = !!$scope.fromWalletId
|
$scope.fundsAreInsufficient = !!$scope.fromWalletId
|
||||||
&& spendableAmountInSatoshis !== null
|
&& availableSatoshis !== null
|
||||||
&& spendableAmountInSatoshis < amountInSatoshis;
|
&& availableSatoshis < amountInSatoshis;
|
||||||
|
|
||||||
$scope.alternativeAmount = txFormatService.formatAmount(amountInSatoshis, true);
|
$scope.alternativeAmount = txFormatService.formatAmount(amountInSatoshis, true);
|
||||||
$scope.allowSend = lodash.isNumber(a)
|
$scope.allowSend = lodash.isNumber(a)
|
||||||
|
|
@ -421,8 +428,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$scope.fundsAreInsufficient = !!$scope.fromWalletId
|
$scope.fundsAreInsufficient = !!$scope.fromWalletId
|
||||||
&& spendableAmountInSatoshis !== null
|
&& availableSatoshis !== null
|
||||||
&& spendableAmountInSatoshis < result * unitToSatoshi;
|
&& availableSatoshis < result * unitToSatoshi;
|
||||||
|
|
||||||
$scope.alternativeAmount = $filter('formatFiatAmount')(toFiat(result));
|
$scope.alternativeAmount = $filter('formatFiatAmount')(toFiat(result));
|
||||||
$scope.allowSend = lodash.isNumber(result)
|
$scope.allowSend = lodash.isNumber(result)
|
||||||
|
|
@ -664,13 +671,33 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateSpendableAmountInSatoshisFromWallet(wallet) {
|
function updateAvailableFundsFromWallet(wallet) {
|
||||||
if (wallet.status) {
|
if (wallet.status) {
|
||||||
spendableAmountInSatoshis = wallet.status.spendableAmount;
|
availableFundsInCrypto = wallet.status.spendableBalanceStr;
|
||||||
} else if (fromWallet.cachedStatus) {
|
availableSatoshis = wallet.status.spendableAmount;
|
||||||
spendableAmountInSatoshis = wallet.cachedStatus.spendableAmount;
|
if (wallet.status.alternativeBalanceAvailable) {
|
||||||
|
availableFundsInFiat = wallet.status.spendableBalanceAlternative + ' ' + wallet.status.alternativeIsoCode;
|
||||||
|
} else {
|
||||||
|
availableFundsInFiat = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (wallet.cachedStatus) {
|
||||||
|
|
||||||
|
if (wallet.cachedStatus.alternativeBalanceAvailable) {
|
||||||
|
availableFundsInFiat = wallet.cachedStatus.spendableBalanceAlternative + ' ' + wallet.cachedStatus.alternativeIsoCode;
|
||||||
|
} else {
|
||||||
|
availableFundsInFiat = '';
|
||||||
|
}
|
||||||
|
availableFundsInCrypto = wallet.cachedStatus.spendableBalanceStr;
|
||||||
|
availableSatoshis = wallet.cachedStatus.spendableAmount;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
spendableAmountInSatoshis = null;
|
|
||||||
|
availableFundsInFiat = '';
|
||||||
|
availableFundsInCrypto = '';
|
||||||
|
availableSatoshis = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue