Ref custom amount. Also fixes small screen issue

This commit is contained in:
Gustavo Maximiliano Cortez 2017-05-11 15:43:35 -03:00
commit 1c91420581
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
6 changed files with 170 additions and 71 deletions

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicScrollDelegate, $ionicHistory, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, popupService, bwcError, payproService, profileService, bitcore, amazonService, nodeWebkitService) {
var _cardId;
var _id;
var unitToSatoshi;
var satToUnit;
var unitDecimals;
@ -17,7 +17,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
$scope.$on("$ionicView.beforeEnter", function(event, data) {
// Go to...
_cardId = data.stateParams.id; // Optional (BitPay Card ID)
_id = data.stateParams.id; // Optional (BitPay Card ID or Wallet ID)
$scope.nextStep = data.stateParams.nextStep;
$scope.currency = data.stateParams.currency;
$scope.forceCurrency = data.stateParams.forceCurrency;
@ -30,11 +30,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
$scope.toEmail = data.stateParams.toEmail;
$scope.showAlternativeAmount = !!$scope.nextStep;
$scope.toColor = data.stateParams.toColor;
$scope.walletId = data.stateParams.walletId;
$scope.showSendMax = false;
$scope.customAmount = data.stateParams.customAmount;
if (!$scope.nextStep && !data.stateParams.toAddress) {
$log.error('Bad params at amount')
throw ('bad params');
@ -228,30 +225,22 @@ angular.module('copayApp.controllers').controller('amountController', function($
if ($scope.nextStep) {
$state.transitionTo($scope.nextStep, {
id: _cardId,
id: _id,
amount: $scope.useSendMax ? null : _amount,
currency: $scope.showAlternativeAmount ? $scope.alternativeIsoCode : $scope.unitName,
useSendMax: $scope.useSendMax
});
} else {
var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount;
if ($scope.customAmount) {
$state.transitionTo('tabs.receive.customAmount', {
walletId: $scope.walletId,
toAmount: (amount * unitToSatoshi).toFixed(0),
toAddress: $scope.toAddress
});
} else {
$state.transitionTo('tabs.send.confirm', {
recipientType: $scope.recipientType,
toAmount: $scope.useSendMax ? null : (amount * unitToSatoshi).toFixed(0),
toAddress: $scope.toAddress,
toName: $scope.toName,
toEmail: $scope.toEmail,
toColor: $scope.toColor,
useSendMax: $scope.useSendMax
});
}
$state.transitionTo('tabs.send.confirm', {
recipientType: $scope.recipientType,
toAmount: $scope.useSendMax ? null : (amount * unitToSatoshi).toFixed(0),
toAddress: $scope.toAddress,
toName: $scope.toName,
toEmail: $scope.toEmail,
toColor: $scope.toColor,
useSendMax: $scope.useSendMax
});
}
$scope.useSendMax = null;
};

View file

@ -1,23 +1,64 @@
'use strict';
angular.module('copayApp.controllers').controller('customAmountController', function($rootScope, $scope, $stateParams, $ionicHistory, txFormatService, platformInfo, profileService) {
angular.module('copayApp.controllers').controller('customAmountController', function($rootScope, $scope, $stateParams, $ionicHistory, txFormatService, platformInfo, configService, profileService, walletService, popupService) {
var showErrorAndBack = function(title, msg) {
popupService.showAlert(title, msg, function() {
$scope.close();
});
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
var satToBtc = 1 / 100000000;
$scope.isCordova = platformInfo.isCordova;
$scope.address = data.stateParams.toAddress;
$scope.amount = parseInt(data.stateParams.toAmount);
$scope.amountBtc = ($scope.amount * satToBtc).toFixed(8);
$scope.amountStr = txFormatService.formatAmountStr($scope.amount);
$scope.altAmountStr = txFormatService.formatAlternativeStr($scope.amount);
$scope.wallet = profileService.getWallet($stateParams.walletId);
var walletId = data.stateParams.id;
if (!walletId) {
showErrorAndBack('Error', 'No wallet selected');
return;
}
$scope.wallet = profileService.getWallet(walletId);
walletService.getAddress($scope.wallet, false, function(err, addr) {
if (!addr) {
showErrorAndBack('Error', 'Could not get the address');
return;
}
$scope.address = addr;
var parsedAmount = txFormatService.parseAmount(
data.stateParams.amount,
data.stateParams.currency);
// Amount in USD or BTC
var amount = parsedAmount.amount;
var currency = parsedAmount.currency;
$scope.amountUnitStr = parsedAmount.amountUnitStr;
if (currency != 'BTC') {
// Convert to BTC
var config = configService.getSync().wallet.settings;
var amountUnit = txFormatService.satToUnit(parsedAmount.amountSat);
var btcParsedAmount = txFormatService.parseAmount(amountUnit, config.unitName);
$scope.amountBtc = btcParsedAmount.amount;
$scope.altAmountStr = btcParsedAmount.amountUnitStr;
} else {
$scope.amountBtc = amount; // BTC
$scope.altAmountStr = txFormatService.formatAlternativeStr(parsedAmount.amountSat);
}
});
});
$scope.finish = function() {
$scope.close = function() {
$ionicHistory.nextViewOptions({
disableAnimate: false
disableAnimate: true
});
$ionicHistory.goBack(-2);
};
$scope.copyToClipboard = function() {
return 'bitcoin:' + $scope.address + '?amount=' + $scope.amountBtc;
};
});

View file

@ -7,10 +7,8 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
$scope.isNW = platformInfo.isNW;
$scope.requestSpecificAmount = function() {
$state.go('tabs.receive.amount', {
walletId: $scope.wallet.credentials.walletId,
customAmount: true,
toAddress: $scope.addr
$state.go('tabs.paymentRequest.amount', {
id: $scope.wallet.credentials.walletId
});
};

View file

@ -656,8 +656,17 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
*
*/
.state('tabs.receive.amount', {
url: '/amount/:walletId/:customAmount/:toAddress',
.state('tabs.paymentRequest', {
url: '/payment-request',
abstract: true,
params: {
id: null,
nextStep: 'tabs.paymentRequest.confirm'
}
})
.state('tabs.paymentRequest.amount', {
url: '/amount',
views: {
'tab-receive@tabs': {
controller: 'amountController',
@ -665,8 +674,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
}
})
.state('tabs.receive.customAmount', {
url: '/customAmount/:walletId/:toAmount/:toAddress',
.state('tabs.paymentRequest.confirm', {
url: '/confirm/:amount/:currency',
views: {
'tab-receive@tabs': {
controller: 'customAmountController',

View file

@ -1,15 +1,69 @@
#custom-amount {
.share {
justify-content: center;
}
.info {
.single-line {
display: flex;
align-items: center;
padding-top: 17px;
padding-bottom: 17px;
.item-note {
margin-left: 10px;
@extend .deflash-blue;
$item-lateral-padding: 20px;
$item-vertical-padding: 10px;
$item-label-color: #6C6C6E;
.address {
background: #fff;
overflow: auto;
height: 100%;
.qr-code {
text-align: center;
margin-top: 24vh;
margin-bottom: 7vh;
@media(max-height: 800px) {
margin-top: 18vh;
}
@media(max-height: 700px) {
margin-top: 14vh;
}
@media(max-height: 600px) {
margin-top: 8vh;
}
}
.info {
position: absolute;
width: 100%;
bottom: 0;
.badge {
border-radius: 0;
padding: .5rem;
}
.item {
color: #4A4A4A;
padding-top: $item-vertical-padding;
padding-bottom: $item-vertical-padding;
padding-left: $item-lateral-padding;
&:not(.item-icon-right) {
padding-right: $item-lateral-padding;
}
.label {
font-size: 14px;
color: $item-label-color;
margin-bottom: 8px;
}
.wallet {
float: right;
overflow: hidden;
}
.wallet .big-icon-svg > .bg {
height: 20px;
width: 20px;
padding: 1px;
box-shadow: none;
vertical-align: text-bottom;
}
.single-line {
display: flex;
align-items: center;
padding-top: 17px;
padding-bottom: 17px;
.item-note {
margin-left: 10px;
}
}
}
}
}

View file

@ -3,31 +3,39 @@
<ion-nav-title>
{{'Custom Amount' | translate}}
</ion-nav-title>
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="secondary">
<button class="button no-border" ng-click="finish()" translate>
<button class="button no-border" ng-click="close()" translate>
Close
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-content scroll="false">
<div class="item" ng-include="'views/includes/walletItem.html'"></div>
<div class="item head text-center" copy-to-clipboard="'bitcoin:' + address + '?amount=' + amountBtc">
<qrcode size="220" data="bitcoin:{{address + '?amount=' + amountBtc}}" color="#334"></qrcode>
</div>
<div class="info">
<div class="item single-line">
<span class="label" translate>Address</span>
<span class="item-note ellipsis">
{{address}}
</span>
<div class="address" ng-if="address && amountBtc">
<div class="qr-code" copy-to-clipboard="copyToClipboard()">
<qrcode size="220" data="bitcoin:{{address + '?amount=' + amountBtc}}" color="#334"></qrcode>
</div>
<div class="item single-line">
<span class="label" translate>Amount</span>
<span class="item-note">
{{amountStr}} - {{altAmountStr}}
</span>
<div class="info">
<div class="item single-line">
<span class="label" translate>Address</span>
<span class="item-note ellipsis">
{{address}}
</span>
</div>
<div class="item single-line">
<span class="label" translate>Amount</span>
<span class="item-note">
{{amountUnitStr}} - {{altAmountStr}}
</span>
</div>
<div class="item single-line">
<div class="wallet">
<i class="icon big-icon-svg">
<img src="img/icon-wallet.svg" ng-class="{'wallet-background-color-default': !wallet.color}" ng-style="{'background-color': wallet.color}" class="bg">
</i>
{{wallet.name}}
</div>
<div class="label">Receive in</div>
</div>
</div>
</div>
</ion-content>