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:
Sebastiaan Pasma 2018-08-02 15:12:40 +02:00
commit 391201471d
No known key found for this signature in database
GPG key ID: 9A2B0C8B95A1D26F
22 changed files with 702 additions and 47 deletions

View file

@ -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 = '';

View 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;
}
});
}
}

View file

@ -48,37 +48,44 @@ angular.module('bitcoincom.directives')
return '2';
};
switch (getDecimalPlaces($scope.currency)) {
case '0':
var valueFormatted = numberWithCommas(Math.round(parseFloat($scope.value)));
buildAmount(valueFormatted, '', '');
break;
case '2':
var valueProcessing = parseFloat(parseFloat($scope.value).toFixed(2));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '3':
var valueProcessing = parseFloat(parseFloat($scope.value).toFixed(3));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '8':
var valueFormatted = parseFloat($scope.value).toFixed(8);
if (parseFloat($scope.value) == 0) {
buildAmount('0', '', '');
} else {
var formatNumbers = function(currency, value) {
switch (getDecimalPlaces(currency)) {
case '0':
var valueFormatted = numberWithCommas(Math.round(parseFloat(value)));
buildAmount(valueFormatted, '', '');
var start = numberWithCommas(valueFormatted.slice(0, -5));
var middle = valueFormatted.slice(-5, -2);
var end = valueFormatted.substr(valueFormatted.length - 2);
buildAmount(start, middle, end);
}
break;
break;
case '2':
var valueProcessing = parseFloat(parseFloat(value).toFixed(2));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '3':
var valueProcessing = parseFloat(parseFloat(value).toFixed(3));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '8':
var valueFormatted = parseFloat(value).toFixed(8);
if (parseFloat(value) == 0) {
buildAmount('0', '', '');
} else {
buildAmount(valueFormatted, '', '');
var start = numberWithCommas(valueFormatted.slice(0, -5));
var middle = valueFormatted.slice(-5, -2);
var end = valueFormatted.substr(valueFormatted.length - 2);
buildAmount(start, middle, end);
}
break;
}
}
formatNumbers($scope.currency, $scope.value);
$scope.$watchGroup(['currency', 'value'], function() {
formatNumbers($scope.currency, $scope.value);
});
}]
};
}

View file

@ -344,6 +344,19 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
}
})
.state('tabs.send.review', {
url: '/review/:amount/:fromWalletId/:sendMax/:toAddr/:toWalletId',
views: {
'tab-send@tabs': {
controller: 'reviewController',
controllerAs: 'vm',
templateUrl: 'views/review.html'
}
},
params: {
paypro: null
}
})
/*
*