From edeb9f26b556bb9686e188ac476c197ce87c1a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Thu, 24 Nov 2016 11:42:25 -0300 Subject: [PATCH] custom amount --- src/js/controllers/amount.js | 26 ++++++++++----- src/js/controllers/customAmount.js | 19 +++++++++++ src/js/controllers/modals/customAmount.js | 2 +- src/js/controllers/tab-receive.js | 28 +++++++++++++++- src/js/routes.js | 25 +++++++++++++++ src/sass/views/amount.scss | 33 ++++++++++++++++++- src/sass/views/custom-amount.scss | 16 ++++++++++ src/sass/views/tab-receive.scss | 2 +- src/sass/views/views.scss | 1 + www/views/amount.html | 6 ++-- www/views/customAmount.html | 39 +++++++++++++++++++++++ www/views/tab-receive.html | 5 +++ 12 files changed, 187 insertions(+), 15 deletions(-) create mode 100644 src/js/controllers/customAmount.js create mode 100644 src/sass/views/custom-amount.scss create mode 100644 www/views/customAmount.html diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 5eee4d003..32729e054 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -24,7 +24,10 @@ angular.module('copayApp.controllers').controller('amountController', function($ $scope.showAlternativeAmount = !!$scope.cardId; $scope.toColor = data.stateParams.toColor; - if (!$scope.cardId && !$stateParams.toAddress) { + $scope.customAmount = data.stateParams.customAmount; + + $scope.title = $scope.customAmount ? gettextCatalog.getString('Request Specific Amount') : gettextCatalog.getString('Enter Amount'); + if (!$scope.cardId && !data.stateParams.toAddress && !data.stateParams.customAmount) { $log.error('Bad params at amount') throw ('bad params'); } @@ -240,13 +243,20 @@ angular.module('copayApp.controllers').controller('amountController', function($ } else { var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount; - $state.transitionTo('tabs.send.confirm', { - isWallet: $scope.isWallet, - toAmount: (amount * unitToSatoshi).toFixed(0), - toAddress: $scope.toAddress, - toName: $scope.toName, - toEmail: $scope.toEmail - }); + if ($scope.customAmount) { + $state.transitionTo('tabs.receive.customAmount', { + toAmount: (amount * unitToSatoshi).toFixed(0), + toAddress: $scope.toAddress + }); + } else { + $state.transitionTo('tabs.send.confirm', { + isWallet: $scope.isWallet, + toAmount: (amount * unitToSatoshi).toFixed(0), + toAddress: $scope.toAddress, + toName: $scope.toName, + toEmail: $scope.toEmail + }); + } } }; }); diff --git a/src/js/controllers/customAmount.js b/src/js/controllers/customAmount.js new file mode 100644 index 000000000..a5dad8701 --- /dev/null +++ b/src/js/controllers/customAmount.js @@ -0,0 +1,19 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('customAmountController', function($rootScope, $scope, $stateParams, txFormatService, platformInfo) { + + $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.shareAddress = function(uri) { + window.plugins.socialsharing.share(uri, null, null, null); + }; + +}); diff --git a/src/js/controllers/modals/customAmount.js b/src/js/controllers/modals/customAmount.js index 386ed1073..38048a9c6 100644 --- a/src/js/controllers/modals/customAmount.js +++ b/src/js/controllers/modals/customAmount.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('customAmountController', function($scope, $timeout, $filter, platformInfo, rateService) { +angular.module('copayApp.controllers').controller('custommAmountController', function($scope, $timeout, $filter, platformInfo, rateService) { var self = $scope.self; $scope.unitName = self.unitName; diff --git a/src/js/controllers/tab-receive.js b/src/js/controllers/tab-receive.js index cae89c917..14a61732a 100644 --- a/src/js/controllers/tab-receive.js +++ b/src/js/controllers/tab-receive.js @@ -1,8 +1,9 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError) { +angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, $ionicPopover, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError) { var listeners = []; + var MENU_ITEM_HEIGHT = 55; $scope.isCordova = platformInfo.isCordova; $scope.isNW = platformInfo.isNW; $scope.walletAddrs = {}; @@ -139,6 +140,31 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi }); }; + var goRequestAmount = function() { + $scope.menu.hide(); + $state.go('tabs.receive.amount', { + customAmount: true, + toAddress: $scope.addr + }); + } + + $scope.showMenu = function(allAddresses, $event) { + var requestAmountObj = { + text: gettextCatalog.getString('Request Specific amount'), + action: goRequestAmount, + }; + + $scope.items = [requestAmountObj]; + $scope.height = $scope.items.length * MENU_ITEM_HEIGHT; + + $ionicPopover.fromTemplateUrl('views/includes/menu-popover.html', { + scope: $scope + }).then(function(popover) { + $scope.menu = popover; + $scope.menu.show($event); + }); + }; + $scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.wallets = profileService.getWallets(); diff --git a/src/js/routes.js b/src/js/routes.js index 1141c5a33..6aa16fa48 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -632,6 +632,31 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) + /* + * + * Request Specific amount + * + */ + + .state('tabs.receive.amount', { + url: '/amount/:customAmount/:toAddress', + views: { + 'tab-receive@tabs': { + controller: 'amountController', + templateUrl: 'views/amount.html' + } + } + }) + .state('tabs.receive.customAmount', { + url: '/customAmount/:toAmount/:toAddress', + views: { + 'tab-receive@tabs': { + controller: 'customAmountController', + templateUrl: 'views/customAmount.html' + } + } + }) + /* * * Init backup flow diff --git a/src/sass/views/amount.scss b/src/sass/views/amount.scss index 47df0f90f..0933f08ad 100644 --- a/src/sass/views/amount.scss +++ b/src/sass/views/amount.scss @@ -34,7 +34,7 @@ position: absolute; top: 10px; } - .amount-pane { + .amount-pane-send { position: absolute; top: 95px; bottom: 0; @@ -65,6 +65,37 @@ } } } + .amount-pane-receive { + position: absolute; + top: 0; + bottom: 0; + width: 100%; + background-color: #fff; + padding: 0 16px; + + .amount-bar { + padding: 24px 0; + font-size: 18px; + .title { + float: left; + padding-top: 10px; + color: $dark-gray; + font-weight: bold; + } + } + .amount { + display: flex; + flex-direction: column; + justify-content: center; + flex-grow: 1; + position: absolute; + bottom: 254px; + top: 66px; + .light { + color: $light-gray; + } + } + } .amount { &__editable { margin-bottom: 1rem; diff --git a/src/sass/views/custom-amount.scss b/src/sass/views/custom-amount.scss new file mode 100644 index 000000000..11d529355 --- /dev/null +++ b/src/sass/views/custom-amount.scss @@ -0,0 +1,16 @@ +#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; + } + } + } +} diff --git a/src/sass/views/tab-receive.scss b/src/sass/views/tab-receive.scss index 4d36162a4..084baed3b 100644 --- a/src/sass/views/tab-receive.scss +++ b/src/sass/views/tab-receive.scss @@ -200,7 +200,7 @@ } } #bit-address { - position: realtive; + position: relative; } } } diff --git a/src/sass/views/views.scss b/src/sass/views/views.scss index 08bcddf5e..1e88f8af0 100644 --- a/src/sass/views/views.scss +++ b/src/sass/views/views.scss @@ -41,3 +41,4 @@ @import "includes/walletSelector"; @import "integrations/coinbase"; @import "integrations/glidera"; +@import "custom-amount"; diff --git a/www/views/amount.html b/www/views/amount.html index bafed47af..cbfaf49ae 100644 --- a/www/views/amount.html +++ b/www/views/amount.html @@ -1,7 +1,7 @@ - {{'Enter Amount'|translate}} + {{title}} @@ -9,7 +9,7 @@ -
+
Recipient
@@ -26,7 +26,7 @@
-
+
Amount
diff --git a/www/views/customAmount.html b/www/views/customAmount.html new file mode 100644 index 000000000..80513de35 --- /dev/null +++ b/www/views/customAmount.html @@ -0,0 +1,39 @@ + + + + {{'Custom Amount' | translate}} + + + + + + + + +
+ + +
+
+
+ Address + + {{address}} + +
+
+ Amount + + {{amountStr}} - {{altAmountStr}} + +
+
+
+
diff --git a/www/views/tab-receive.html b/www/views/tab-receive.html index d07713685..fed491ad4 100644 --- a/www/views/tab-receive.html +++ b/www/views/tab-receive.html @@ -1,6 +1,11 @@ {{'Receive' | translate}} + + +