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 1/5] 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}} + + +
From 172f8a8021fac779eddd2181b0d308065aaa5726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Thu, 24 Nov 2016 11:46:49 -0300 Subject: [PATCH 2/5] little fixes --- src/js/controllers/amount.js | 3 +- src/js/controllers/modals/customAmount.js | 79 -------------------- www/views/amount.html | 2 +- www/views/modals/customAmount.html | 88 ----------------------- 4 files changed, 2 insertions(+), 170 deletions(-) delete mode 100644 src/js/controllers/modals/customAmount.js delete mode 100644 www/views/modals/customAmount.html diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 32729e054..73c53515d 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -26,8 +26,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ $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) { + if (!$scope.cardId && !data.stateParams.toAddress) { $log.error('Bad params at amount') throw ('bad params'); } diff --git a/src/js/controllers/modals/customAmount.js b/src/js/controllers/modals/customAmount.js deleted file mode 100644 index 38048a9c6..000000000 --- a/src/js/controllers/modals/customAmount.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict'; - -angular.module('copayApp.controllers').controller('custommAmountController', function($scope, $timeout, $filter, platformInfo, rateService) { - var self = $scope.self; - - $scope.unitName = self.unitName; - $scope.alternativeAmount = self.alternativeAmount; - $scope.alternativeName = self.alternativeName; - $scope.alternativeIsoCode = self.alternativeIsoCode; - $scope.isRateAvailable = self.isRateAvailable; - $scope.unitToSatoshi = self.unitToSatoshi; - $scope.unitDecimals = self.unitDecimals; - var satToUnit = 1 / self.unitToSatoshi; - $scope.showAlternative = false; - $scope.isCordova = platformInfo.isCordova; - - Object.defineProperty($scope, - "_customAlternative", { - get: function() { - return $scope.customAlternative; - }, - set: function(newValue) { - $scope.customAlternative = newValue; - if (typeof(newValue) === 'number' && $scope.isRateAvailable) { - $scope.customAmount = parseFloat((rateService.fromFiat(newValue, $scope.alternativeIsoCode) * satToUnit).toFixed($scope.unitDecimals), 10); - } else { - $scope.customAmount = null; - } - }, - enumerable: true, - configurable: true - }); - - Object.defineProperty($scope, - "_customAmount", { - get: function() { - return $scope.customAmount; - }, - set: function(newValue) { - $scope.customAmount = newValue; - if (typeof(newValue) === 'number' && $scope.isRateAvailable) { - $scope.customAlternative = parseFloat((rateService.toFiat(newValue * $scope.unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10); - } else { - $scope.customAlternative = null; - } - $scope.alternativeAmount = $scope.customAlternative; - }, - enumerable: true, - configurable: true - }); - - $scope.submitForm = function(form) { - var satToBtc = 1 / 100000000; - var amount = form.amount.$modelValue; - var amountSat = parseInt((amount * $scope.unitToSatoshi).toFixed(0)); - $timeout(function() { - $scope.customizedAmountUnit = amount + ' ' + $scope.unitName; - $scope.customizedAlternativeUnit = $filter('formatFiatAmount')(form.alternative.$modelValue) + ' ' + $scope.alternativeIsoCode; - if ($scope.unitName == 'bits') { - amount = (amountSat * satToBtc).toFixed(8); - } - $scope.customizedAmountBtc = amount; - }, 1); - }; - - $scope.toggleAlternative = function() { - $scope.showAlternative = !$scope.showAlternative; - }; - - $scope.shareAddress = function(uri) { - if (platformInfo.isCordova) { - window.plugins.socialsharing.share(uri, null, null, null); - } - }; - - $scope.cancel = function() { - $scope.customAmountModal.hide(); - }; -}); diff --git a/www/views/amount.html b/www/views/amount.html index cbfaf49ae..d18346423 100644 --- a/www/views/amount.html +++ b/www/views/amount.html @@ -1,7 +1,7 @@ - {{title}} + {{'Enter Amount'}} diff --git a/www/views/modals/customAmount.html b/www/views/modals/customAmount.html deleted file mode 100644 index 2f33a3158..000000000 --- a/www/views/modals/customAmount.html +++ /dev/null @@ -1,88 +0,0 @@ - - - -

Request a specific amount

-
- - -
-
-

QR Code

-
    -
  • - -
    - - - Share address - -
    -
  • -
- -

Details

-
    -
  • - Address: - - {{addr}} - -
  • -
  • - Amount: - - {{customizedAmountUnit}} - {{customizedAlternativeUnit}} - -
  • -
-
- -
-
-
-
- - - Not valid - - - - -
-
- -
- - - {{unitName}} -
-
-
- - -
- - -
-
-
-
-
- From b8cf6997e4b241b2013f24acd20f9adbefe5c972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Thu, 24 Nov 2016 11:48:30 -0300 Subject: [PATCH 3/5] add translate to title --- www/views/amount.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/views/amount.html b/www/views/amount.html index d18346423..3dd481bb1 100644 --- a/www/views/amount.html +++ b/www/views/amount.html @@ -1,7 +1,7 @@ - {{'Enter Amount'}} + {{'Enter Amount' | translate}} From 7af9a48009cb3c0d926ad6cffee86dbc495dfd18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Fri, 25 Nov 2016 10:09:23 -0300 Subject: [PATCH 4/5] show share button only for cordova devices --- www/views/customAmount.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/views/customAmount.html b/www/views/customAmount.html index 80513de35..4a5d48496 100644 --- a/www/views/customAmount.html +++ b/www/views/customAmount.html @@ -14,7 +14,7 @@
-