Merge remote-tracking branch 'origin/wallet/task/440' into wallet/task/514
# Conflicts: # i18n/po/template.pot # src/js/controllers/amount.js # www/css/main.css
This commit is contained in:
commit
391201471d
22 changed files with 702 additions and 47 deletions
|
|
@ -35,9 +35,9 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
vm.save = save;
|
||||
vm.sendMax = sendMax;
|
||||
vm.errorMessage = '';
|
||||
|
||||
|
||||
$scope.$on('$ionicView.beforeEnter', onBeforeEnter);
|
||||
$scope.$on('$ionicView.leave', onLeave);
|
||||
$scope.$on('$ionicView.leave', onLeave);
|
||||
|
||||
var LENGTH_EXPRESSION_LIMIT = 19;
|
||||
var LENGTH_BEFORE_COMMA_EXPRESSION_LIMIT = 8;
|
||||
|
|
@ -66,7 +66,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
}
|
||||
|
||||
function onBeforeEnter(event, data) {
|
||||
|
||||
|
||||
initCurrencies();
|
||||
|
||||
passthroughParams = data.stateParams;
|
||||
|
|
@ -81,7 +81,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
|
||||
setAvailableUnits();
|
||||
updateUnitUI();
|
||||
|
||||
|
||||
var reNr = /^[1234567890\.]$/;
|
||||
var reOp = /^[\*\+\-\/]$/;
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
|
||||
unitIndex = 0;
|
||||
|
||||
|
||||
|
||||
// currency have preference
|
||||
var fiatName;
|
||||
if (data.stateParams.currency) {
|
||||
|
|
@ -260,11 +260,11 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
if (vm.amount == '0' && digit == '0') return;
|
||||
if (availableUnits[unitIndex].isFiat && vm.amount.indexOf('.') > -1 && vm.amount[vm.amount.indexOf('.') + 2]) return;
|
||||
|
||||
if (vm.amount == '0' && digit != '.') {
|
||||
if (vm.amount == '0' && digit != '.') {
|
||||
vm.amount = '';
|
||||
}
|
||||
|
||||
if (vm.amount == '' && digit == '.') {
|
||||
if (vm.amount == '' && digit == '.') {
|
||||
vm.amount = '0';
|
||||
}
|
||||
|
||||
|
|
@ -335,16 +335,16 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
if (a) {
|
||||
amountInCrypto = a;
|
||||
var amountInSatoshis = a * unitToSatoshi;
|
||||
vm.fundsAreInsufficient = !!passthroughParams.fromWalletId
|
||||
&& availableSatoshis !== null
|
||||
vm.fundsAreInsufficient = !!passthroughParams.fromWalletId
|
||||
&& availableSatoshis !== null
|
||||
&& availableSatoshis < amountInSatoshis;
|
||||
|
||||
vm.alternativeAmount = txFormatService.formatAmount(amountInSatoshis, true);
|
||||
vm.allowSend = lodash.isNumber(a)
|
||||
vm.allowSend = lodash.isNumber(a)
|
||||
&& a > 0
|
||||
&& (!vm.shapeshiftOrderId
|
||||
|| (a >= vm.minAmount && a <= vm.maxAmount))
|
||||
&& !vm.fundsAreInsufficient;
|
||||
&& !vm.fundsAreInsufficient;
|
||||
} else {
|
||||
if (result) {
|
||||
vm.alternativeAmount = 'N/A';
|
||||
|
|
@ -356,16 +356,16 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
}
|
||||
} else {
|
||||
amountInCrypto = result;
|
||||
vm.fundsAreInsufficient = passthroughParams.fromWalletId
|
||||
&& availableSatoshis !== null
|
||||
vm.fundsAreInsufficient = passthroughParams.fromWalletId
|
||||
&& availableSatoshis !== null
|
||||
&& availableSatoshis < result * unitToSatoshi;
|
||||
|
||||
vm.alternativeAmount = $filter('formatFiatAmount')(toFiat(result));
|
||||
vm.allowSend = lodash.isNumber(result)
|
||||
vm.allowSend = lodash.isNumber(result)
|
||||
&& result > 0
|
||||
&& (!vm.shapeshiftOrderId
|
||||
|| (result >= vm.minAmount && result <= vm.maxAmount))
|
||||
&& !vm.fundsAreInsufficient;
|
||||
&& !vm.fundsAreInsufficient;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
@ -381,7 +381,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
|
||||
} else if (amountInCrypto > vm.maxAmount) {
|
||||
vm.errorMessage = gettextCatalog.getString('Amount is above maximum');
|
||||
|
||||
|
||||
} else {
|
||||
vm.errorMessage = '';
|
||||
}
|
||||
|
|
@ -474,7 +474,9 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
}
|
||||
}
|
||||
|
||||
$state.transitionTo('tabs.send.confirm', confirmData);
|
||||
$state.transitionTo('tabs.send.review', confirmData);
|
||||
}
|
||||
$scope.useSendMax = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -585,7 +587,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
close();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
function updateAvailableFundsStringIfNeeded() {
|
||||
if (passthroughParams.fromWalletId && availableSatoshis !== null) {
|
||||
availableFundsInFiat = '';
|
||||
|
|
|
|||
214
src/js/controllers/review.controller.js
Normal file
214
src/js/controllers/review.controller.js
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
'use strict';
|
||||
|
||||
angular
|
||||
.module('copayApp.controllers')
|
||||
.controller('reviewController', reviewController);
|
||||
|
||||
function reviewController(addressbookService, configService, profileService, $log, $scope, txFormatService) {
|
||||
var vm = this;
|
||||
|
||||
vm.destination = {
|
||||
address: '',
|
||||
balanceAmount: '',
|
||||
balanceCurrency: '',
|
||||
coin: '',
|
||||
color: '',
|
||||
currency: '',
|
||||
currencyColor: '',
|
||||
kind: '', // 'address', 'contact', 'wallet'
|
||||
name: ''
|
||||
};
|
||||
vm.feeCrypto = '';
|
||||
vm.feeFiat = '';
|
||||
vm.origin = {
|
||||
balanceAmount: '',
|
||||
balanceCurrency: '',
|
||||
color: '',
|
||||
currency: '',
|
||||
currencyColor: '',
|
||||
name: '',
|
||||
};
|
||||
vm.primaryAmount = '';
|
||||
vm.primaryCurrency = '';
|
||||
vm.secondaryAmount = '';
|
||||
vm.secondaryCurrency = '';
|
||||
|
||||
var config = null;
|
||||
var coin = '';
|
||||
var originWalletId = '';
|
||||
var priceDisplayIsFiat = true;
|
||||
var satoshis = null;
|
||||
var toAddress = '';
|
||||
var destinationWalletId = '';
|
||||
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", onBeforeEnter);
|
||||
|
||||
|
||||
function onBeforeEnter(event, data) {
|
||||
|
||||
originWalletId = data.stateParams.fromWalletId;
|
||||
satoshis = parseInt(data.stateParams.amount, 10);
|
||||
toAddress = data.stateParams.toAddr;
|
||||
|
||||
var originWallet = profileService.getWallet(originWalletId);
|
||||
vm.origin.currency = originWallet.coin.toUpperCase();
|
||||
vm.origin.color = originWallet.color;
|
||||
vm.origin.name = originWallet.name;
|
||||
coin = originWallet.coin;
|
||||
|
||||
configService.get(function onConfig(err, configCache) {
|
||||
if (err) {
|
||||
$log.err('Error getting config.', err);
|
||||
} else {
|
||||
config = configCache;
|
||||
priceDisplayIsFiat = config.wallet.settings.priceDisplay === 'fiat';
|
||||
vm.origin.currencyColor = originWallet.coin === 'btc' ? config.bitcoinWalletColor : config.bitcoinCashWalletColor;
|
||||
}
|
||||
updateSendAmounts();
|
||||
getOriginWalletBalance(originWallet);
|
||||
handleDestinationAsAddress(toAddress, coin);
|
||||
handleDestinationAsWallet(data.stateParams.toWalletId);
|
||||
});
|
||||
}
|
||||
|
||||
function getOriginWalletBalance(originWallet) {
|
||||
var balanceText = getWalletBalanceDisplayText(originWallet);
|
||||
vm.origin.balanceAmount = balanceText.amount;
|
||||
vm.origin.balanceCurrency = balanceText.currency;
|
||||
}
|
||||
|
||||
function getWalletBalanceDisplayText(wallet) {
|
||||
var balanceCryptoAmount = '';
|
||||
var balanceCryptoCurrencyCode = '';
|
||||
var balanceFiatAmount = '';
|
||||
var balanceFiatCurrency = ''
|
||||
var displayAmount = '';
|
||||
var displayCurrency = '';
|
||||
|
||||
var walletStatus = null;
|
||||
if (wallet.status.isValid) {
|
||||
walletStatus = wallet.status;
|
||||
} else if (wallet.cachedStatus.isValid) {
|
||||
walletStatus = wallet.cachedStatus;
|
||||
}
|
||||
|
||||
if (walletStatus) {
|
||||
var cryptoBalanceParts = walletStatus.spendableBalanceStr.split(' ');
|
||||
balanceCryptoAmount = cryptoBalanceParts[0];
|
||||
balanceCryptoCurrencyCode = cryptoBalanceParts.length > 1 ? cryptoBalanceParts[1] : '';
|
||||
|
||||
if (walletStatus.alternativeBalanceAvailable) {
|
||||
balanceFiatAmount = walletStatus.spendableBalanceAlternative;
|
||||
balanceFiatCurrency = walletStatus.alternativeIsoCode;
|
||||
}
|
||||
}
|
||||
|
||||
if (priceDisplayIsFiat) {
|
||||
displayAmount = balanceFiatAmount ? balanceFiatAmount : balanceCryptoAmount;
|
||||
displayCurrency = balanceFiatAmount ? balanceFiatCurrency : balanceCryptoCurrencyCode;
|
||||
} else {
|
||||
displayAmount = balanceCryptoAmount;
|
||||
displayCurrency = balanceCryptoCurrencyCode;
|
||||
}
|
||||
|
||||
return {
|
||||
amount: displayAmount,
|
||||
currency: displayCurrency
|
||||
};
|
||||
}
|
||||
|
||||
function handleDestinationAsAddress(address, originCoin) {
|
||||
if (!address) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the recipient is a contact
|
||||
addressbookService.get(originCoin + address, function(err, contact) {
|
||||
if (!err && contact) {
|
||||
console.log('destination is contact');
|
||||
handleDestinationAsContact(contact);
|
||||
} else {
|
||||
console.log('destination is address');
|
||||
vm.destination.address = address;
|
||||
vm.destination.kind = 'address';
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function handleDestinationAsContact(contact) {
|
||||
vm.destination.kind = 'contact';
|
||||
vm.destination.name = contact.name;
|
||||
vm.destination.color = contact.coin === 'btc' ? config.bitcoinWalletColor : config.bitcoinCashWalletColor;
|
||||
vm.destination.currency = contact.coin.toUpperCase();
|
||||
vm.destination.currencyColor = vm.destination.color;
|
||||
}
|
||||
|
||||
function handleDestinationAsWallet(walletId) {
|
||||
destinationWalletId = walletId;
|
||||
if (!destinationWalletId) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('destination is wallet');
|
||||
var destinationWallet = profileService.getWallet(destinationWalletId);
|
||||
vm.destination.coin = destinationWallet.coin;
|
||||
vm.destination.color = destinationWallet.color;
|
||||
vm.destination.currency = destinationWallet.coin.toUpperCase();
|
||||
vm.destination.kind = 'wallet';
|
||||
vm.destination.name = destinationWallet.name;
|
||||
|
||||
if (config) {
|
||||
vm.destination.currencyColor = vm.destination.coin === 'btc' ? config.bitcoinWalletColor : config.bitcoinCashWalletColor;
|
||||
}
|
||||
|
||||
var balanceText = getWalletBalanceDisplayText(destinationWallet);
|
||||
vm.destination.balanceAmount = balanceText.amount;
|
||||
vm.destination.balanceCurrency = balanceText.currency;
|
||||
}
|
||||
|
||||
function updateSendAmounts() {
|
||||
if (typeof satoshis !== 'number') {
|
||||
return;
|
||||
}
|
||||
|
||||
var cryptoAmount = '';
|
||||
var cryptoCurrencyCode = '';
|
||||
var amountStr = txFormatService.formatAmountStr(coin, satoshis);
|
||||
if (amountStr) {
|
||||
var amountParts = amountStr.split(' ');
|
||||
cryptoAmount = amountParts[0];
|
||||
cryptoCurrencyCode = amountParts.length > 1 ? amountParts[1] : '';
|
||||
}
|
||||
// Want to avoid flashing of amount strings so do all formatting after this has returned.
|
||||
txFormatService.formatAlternativeStr(coin, satoshis, function(v) {
|
||||
if (!v) {
|
||||
vm.primaryAmount = cryptoAmount;
|
||||
vm.primaryCurrency = cryptoCurrencyCode;
|
||||
vm.secondaryAmount = '';
|
||||
vm.secondaryCurrency = '';
|
||||
return;
|
||||
}
|
||||
vm.secondaryAmount = vm.primaryAmount;
|
||||
vm.secondaryCurrency = vm.primaryCurrency;
|
||||
|
||||
var fiatParts = v.split(' ');
|
||||
var fiatAmount = fiatParts[0];
|
||||
var fiatCurrency = fiatParts.length > 1 ? fiatParts[1] : '';
|
||||
|
||||
if (priceDisplayIsFiat) {
|
||||
vm.primaryAmount = fiatAmount;
|
||||
vm.primaryCurrency = fiatCurrency;
|
||||
vm.secondaryAmount = cryptoAmount;
|
||||
vm.secondaryCurrency = cryptoCurrencyCode;
|
||||
} else {
|
||||
vm.primaryAmount = cryptoAmount;
|
||||
vm.primaryCurrency = cryptoCurrencyCode;
|
||||
vm.secondaryAmount = fiatAmount;
|
||||
vm.secondaryCurrency = fiatCurrency;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue