UI for destination as wallet.

This commit is contained in:
Brendon Duncan 2018-08-02 18:14:54 +12:00
commit e525b2e8ad
3 changed files with 67 additions and 35 deletions

View file

@ -10,8 +10,12 @@ function reviewController(configService, gettextCatalog, profileService, $scope,
vm.destination = { vm.destination = {
address: '', address: '',
balanceAmount: '', balanceAmount: '',
balanceCurrecy: '', balanceCurrency: '',
coin: '',
color: '', color: '',
currency: '',
currencyColor: '',
kind: '', // 'address', 'contact', 'wallet'
name: '' name: ''
}; };
vm.feeCrypto = ''; vm.feeCrypto = '';
@ -29,6 +33,7 @@ function reviewController(configService, gettextCatalog, profileService, $scope,
vm.secondaryAmount = ''; vm.secondaryAmount = '';
vm.secondaryCurrency = ''; vm.secondaryCurrency = '';
var config = null;
var coin = ''; var coin = '';
var originWalletId = ''; var originWalletId = '';
var priceDisplayIsFiat = true; var priceDisplayIsFiat = true;
@ -54,61 +59,83 @@ function reviewController(configService, gettextCatalog, profileService, $scope,
vm.origin.color = originWallet.color; vm.origin.color = originWallet.color;
vm.origin.name = originWallet.name; vm.origin.name = originWallet.name;
destinationWalletId = data.stateParams.toWalletId; configService.get(function onConfig(err, configCache) {
if (destinationWalletId) {
var destinationWallet = profileService.getWallet(destinationWalletId);
vm.destination.color = destinationWallet.color;
vm.destination.name = destinationWallet.name;
}
configService.get(function onConfig(err, config) {
if (err) { if (err) {
$log.err('Error getting config.', err); $log.err('Error getting config.', err);
} else { } else {
config = configCache;
priceDisplayIsFiat = config.wallet.settings.priceDisplay === 'fiat'; priceDisplayIsFiat = config.wallet.settings.priceDisplay === 'fiat';
vm.origin.currencyColor = originWallet.coin === 'btc' ? config.bitcoinWalletColor : config.bitcoinCashWalletColor; vm.origin.currencyColor = originWallet.coin === 'btc' ? config.bitcoinWalletColor : config.bitcoinCashWalletColor;
} }
updateSendAmounts(); updateSendAmounts();
getOriginWalletBalance(originWallet); getOriginWalletBalance(originWallet);
handleDestinationAsWallet(data.stateParams.toWalletId);
}); });
} }
function getOriginWalletBalance(originWallet) { function getOriginWalletBalance(originWallet) {
console.log('origin wallet error:', originWallet.error); var balanceText = getWalletBalanceDisplayText(originWallet);
vm.origin.balanceAmount = balanceText.amount;
vm.origin.balanceCurrecny = balanceText.currency;
}
function getWalletBalanceDisplayText(wallet) {
var balanceCryptoAmount = ''; var balanceCryptoAmount = '';
var balanceCryptoCurrencyCode = ''; var balanceCryptoCurrencyCode = '';
var balanceFiatAmount = ''; var balanceFiatAmount = '';
var balanceFiatCurrency = '' var balanceFiatCurrency = ''
var displayAmount = '';
var displayCurrency = '';
var originWalletStatus = null; var walletStatus = null;
if (originWallet.status.isValid) { if (wallet.status.isValid) {
originWalletStatus = originWallet.status; walletStatus = wallet.status;
} else if (originWallet.cachedStatus.isValid) { } else if (wallet.cachedStatus.isValid) {
originWalletStatus = originWallet.cachedStatus; walletStatus = wallet.cachedStatus;
} else {
vm.origin.balanceAmount = '';
vm.origin.balanceCurrency = '';
return;
} }
if (originWalletStatus) { if (walletStatus) {
var cryptoBalanceParts = originWalletStatus.spendableBalanceStr.split(' '); var cryptoBalanceParts = walletStatus.spendableBalanceStr.split(' ');
balanceCryptoAmount = cryptoBalanceParts[0]; balanceCryptoAmount = cryptoBalanceParts[0];
balanceCryptoCurrencyCode = cryptoBalanceParts.length > 1 ? cryptoBalanceParts[1] : ''; balanceCryptoCurrencyCode = cryptoBalanceParts.length > 1 ? cryptoBalanceParts[1] : '';
if (originWalletStatus.alternativeBalanceAvailable) { if (walletStatus.alternativeBalanceAvailable) {
balanceFiatAmount = originWalletStatus.spendableBalanceAlternative; balanceFiatAmount = walletStatus.spendableBalanceAlternative;
balanceFiatCurrency = originWalletStatus.alternativeIsoCode; balanceFiatCurrency = walletStatus.alternativeIsoCode;
} }
} }
if (priceDisplayIsFiat) { if (priceDisplayIsFiat) {
vm.origin.balanceAmount = balanceFiatAmount ? balanceFiatAmount : balanceCryptoAmount; displayAmount = balanceFiatAmount ? balanceFiatAmount : balanceCryptoAmount;
vm.origin.balanceCurrency = balanceFiatAmount ? balanceFiatCurrency : balanceCryptoCurrencyCode; displayCurrency = balanceFiatAmount ? balanceFiatCurrency : balanceCryptoCurrencyCode;
} else { } else {
vm.origin.balanceAmount = balanceCryptoAmount; displayAmount = balanceCryptoAmount;
vm.origin.balanceCurrency = balanceCryptoCurrencyCode; displayCurrency = balanceCryptoCurrencyCode;
}
return {
amount: displayAmount,
currency: displayCurrency
};
}
function handleDestinationAsWallet(walletId) {
destinationWalletId = walletId;
if (destinationWalletId) {
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;
} }
} }

View file

@ -317,7 +317,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
} }
}) })
.state('tabs.send.review', { .state('tabs.send.review', {
url: '/review/:coin/:fromWalletId/:amount/:useSendMax', url: '/review/:amount/:fromWalletId/:sendMax/:toWalletId',
views: { views: {
'tab-send@tabs': { 'tab-send@tabs': {
controller: 'reviewController', controller: 'reviewController',

View file

@ -36,11 +36,16 @@
<div class="item item-compact" translate>To:</div> <div class="item item-compact" translate>To:</div>
<div class="item item-gutterless item-complex item-avatar"> <div class="item item-gutterless item-complex item-avatar">
<div class="item-content item-content-avatar"> <div class="item-content item-content-avatar">
<img src="img/contact-placeholder.svg" class="bg"> <img src="img/contact-placeholder.svg" class="bg" ng-if="vm.destination.kind === 'contact'">
<h2>{{vm.destination.name}}</h2> <i class="icon big-icon-svg theme-circle theme-circle-services" ng-if="vm.destination.kind === 'wallet'">
<p>128.67</p> <div class="bg icon-wallet"
style="background-color: {{vm.destination.color}}"
></div>
</i>
<h2>{{vm.destination.name}}<span class="highlight" style="color: {{vm.destination.currencyColor}}" ng-if="vm.destination.currency"> ({{vm.destination.currency}})</span></h2></h2>
<p ng-if="vm.destination.balanceAmount">{{vm.destination.balanceAmount}} {{vm.destination.balanceCurrency}}</p>
</div> </div>
<div class="item-content item-content-compact" ng-init="addressExpanded = false"> <div class="item-content item-content-compact" ng-init="addressExpanded = false" ng-if="vm.destination.kind === 'address'">
<div class="address" ng-class="{ 'expanded': addressExpanded }" ng-click="addressExpanded = !addressExpanded"><span class="prefix">qz9cq</span><span class="mid">q5pryv9hnqwa8q8mccmynk9uf4vlu5nxer</span><span class="suffix">pzmc</span></div> <div class="address" ng-class="{ 'expanded': addressExpanded }" ng-click="addressExpanded = !addressExpanded"><span class="prefix">qz9cq</span><span class="mid">q5pryv9hnqwa8q8mccmynk9uf4vlu5nxer</span><span class="suffix">pzmc</span></div>
</div> </div>
</div> </div>