From 8d1d59cb3b1a916a679d0a699266eedeec728fe0 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Sat, 14 Jan 2017 19:22:33 -0300 Subject: [PATCH] Clean UI. Adds amount parser for coinbaseService --- src/js/controllers/amount.js | 5 ++-- src/js/controllers/buyCoinbase.js | 14 +++++----- src/js/controllers/coinbase.js | 17 +++---------- src/js/controllers/sellCoinbase.js | 16 ++++++------ src/js/services/coinbaseService.js | 31 ++++++++++++++++++++++- src/sass/views/integrations/coinbase.scss | 4 +++ www/views/buyCoinbase.html | 22 +++++++++++----- www/views/coinbase.html | 2 +- www/views/sellCoinbase.html | 20 ++++++++++----- 9 files changed, 85 insertions(+), 46 deletions(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 0cb87268b..259c4930b 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -358,10 +358,9 @@ angular.module('copayApp.controllers').controller('amountController', function($ glideraAccessToken: $scope.glideraAccessToken }); } else if ($scope.nextStep) { - var amountAlternative = $scope.showAlternativeAmount ? _amount : $filter('formatFiatAmount')(toFiat(_amount)); $state.transitionTo($scope.nextStep, { - amount: amountAlternative, - currency: $scope.alternativeIsoCode + amount: _amount, + currency: $scope.showAlternativeAmount ? $scope.alternativeIsoCode : '' }); } else { var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount; diff --git a/src/js/controllers/buyCoinbase.js b/src/js/controllers/buyCoinbase.js index aa5be6a82..59bacde15 100644 --- a/src/js/controllers/buyCoinbase.js +++ b/src/js/controllers/buyCoinbase.js @@ -36,14 +36,10 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct $scope.$on("$ionicView.beforeEnter", function(event, data) { coinbaseService.setCredentials(); - amount = data.stateParams.amount; - currency = data.stateParams.currency; + [amount, currency, $scope.amountUnitStr] = coinbaseService.parseAmount( + data.stateParams.amount, + data.stateParams.currency); - if (amount < 1) { - showErrorAndBack('Amount must be at least 1.00 ' + currency); - return; - } - $scope.network = coinbaseService.getNetwork(); $scope.wallets = profileService.getWallets({ onlyComplete: true, @@ -60,6 +56,10 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct } var accessToken = res.accessToken; + coinbaseService.buyPrice(accessToken, coinbaseService.getAvailableCurrency(), function(err, b) { + $scope.buyPrice = b.data || null; + }); + $scope.paymentMethods = []; $scope.selectedPaymentMethodId = { value : null }; coinbaseService.getPaymentMethods(accessToken, function(err, p) { diff --git a/src/js/controllers/coinbase.js b/src/js/controllers/coinbase.js index 313e35c9b..8b23d9b28 100644 --- a/src/js/controllers/coinbase.js +++ b/src/js/controllers/coinbase.js @@ -1,13 +1,12 @@ 'use strict'; -angular.module('copayApp.controllers').controller('coinbaseController', function($rootScope, $scope, $timeout, $ionicModal, $log, profileService, configService, storageService, coinbaseService, lodash, platformInfo, ongoingProcess, popupService, gettextCatalog, externalLinkService) { +angular.module('copayApp.controllers').controller('coinbaseController', function($scope, $timeout, $ionicModal, $log, coinbaseService, lodash, platformInfo, ongoingProcess, popupService, externalLinkService) { var isNW = platformInfo.isNW; var isCordova = platformInfo.isCordova; var init = function() { - var config = configService.getSync().wallet.settings; - $scope.currency = getCurrency(config.alternativeIsoCode); + $scope.currency = coinbaseService.getAvailableCurrency(); coinbaseService.getStoredToken(function(at) { $scope.accessToken = at; @@ -17,7 +16,7 @@ angular.module('copayApp.controllers').controller('coinbaseController', function $scope.loading = false; if (err || lodash.isEmpty(data)) { if (err) { - popupService.showAlert(gettextCatalog.getString('Error'), err); + popupService.showAlert('Error', err); } return; } @@ -41,14 +40,6 @@ angular.module('copayApp.controllers').controller('coinbaseController', function }); }; - var getCurrency = function(code) { - // ONLY "USD" and "EUR" - switch(code) { - case 'EUR' : return 'EUR'; - default : return 'USD' - }; - }; - $scope.updateTransactions = function() { $log.debug('Getting transactions...'); $scope.pendingTransactions = { data: {} }; @@ -93,7 +84,7 @@ angular.module('copayApp.controllers').controller('coinbaseController', function coinbaseService.getToken(code, function(err, accessToken) { ongoingProcess.set('connectingCoinbase', false); if (err) { - popupService.showAlert(gettextCatalog.getString('Error'), err); + popupService.showAlert('Error', err); return; } $scope.accessToken = accessToken; diff --git a/src/js/controllers/sellCoinbase.js b/src/js/controllers/sellCoinbase.js index c90c48ce6..af0e62992 100644 --- a/src/js/controllers/sellCoinbase.js +++ b/src/js/controllers/sellCoinbase.js @@ -49,7 +49,7 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', func var accountId = res.accountId; var sellPrice = null; - coinbaseService.sellPrice(accessToken, currency, function(err, sell) { + coinbaseService.sellPrice(accessToken, coinbaseService.getAvailableCurrency(), function(err, sell) { if (err) { $log.debug(err); checkTransaction(count, txp); @@ -119,14 +119,10 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', func $scope.$on("$ionicView.beforeEnter", function(event, data) { coinbaseService.setCredentials(); - amount = data.stateParams.amount; - currency = data.stateParams.currency; + [amount, currency, $scope.amountUnitStr] = coinbaseService.parseAmount( + data.stateParams.amount, + data.stateParams.currency); - if (amount < 1) { - showErrorAndBack('Amount must be at least 1.00 ' + currency); - return; - } - $scope.priceSensitivity = coinbaseService.priceSensitivity; $scope.selectedPriceSensitivity = { data: coinbaseService.selectedPriceSensitivity }; @@ -147,6 +143,10 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', func } var accessToken = res.accessToken; + coinbaseService.sellPrice(accessToken, coinbaseService.getAvailableCurrency(), function(err, s) { + $scope.sellPrice = s.data || null; + }); + $scope.paymentMethods = []; $scope.selectedPaymentMethodId = { value : null }; coinbaseService.getPaymentMethods(accessToken, function(err, p) { diff --git a/src/js/services/coinbaseService.js b/src/js/services/coinbaseService.js index 7d04d100a..213e2e3e7 100644 --- a/src/js/services/coinbaseService.js +++ b/src/js/services/coinbaseService.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.services').factory('coinbaseService', function($http, $log, $window, platformInfo, lodash, storageService, configService, appConfigService) { +angular.module('copayApp.services').factory('coinbaseService', function($http, $log, $window, $filter, platformInfo, lodash, storageService, configService, appConfigService, txFormatService) { var root = {}; var credentials = {}; var isCordova = platformInfo.isCordova; @@ -104,6 +104,35 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }); }; + root.getAvailableCurrency = function() { + var config = configService.getSync().wallet.settings; + // ONLY "USD" and "EUR" + switch(config.alternativeIsoCode) { + case 'EUR' : return 'EUR'; + default : return 'USD' + }; + }; + + root.parseAmount = function(amount, currency) { + var config = configService.getSync().wallet.settings; + var satToBtc = 1 / 100000000; + var unitToSatoshi = config.unitToSatoshi; + var amountUnitStr; + + // IF 'USD' + if (currency) { + amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency; + } else { + var amountSat = parseInt((amount * unitToSatoshi).toFixed(0)); + amountUnitStr = txFormatService.formatAmountStr(amountSat); + // convert unit to BTC + amount = (amountSat * satToBtc).toFixed(8); + currency = 'BTC'; + } + + return [amount, currency, amountUnitStr]; + }; + root.getOauthCodeUrl = function() { return credentials.HOST + '/oauth/authorize?response_type=code&client_id=' diff --git a/src/sass/views/integrations/coinbase.scss b/src/sass/views/integrations/coinbase.scss index ab1c33e73..2221463f3 100644 --- a/src/sass/views/integrations/coinbase.scss +++ b/src/sass/views/integrations/coinbase.scss @@ -81,6 +81,10 @@ vertical-align: middle; } + .total-amount { + font-weight: bold; + } + &.single-line { display: flex; align-items: center; diff --git a/www/views/buyCoinbase.html b/www/views/buyCoinbase.html index 2b78e8a4d..01f9a5c87 100644 --- a/www/views/buyCoinbase.html +++ b/www/views/buyCoinbase.html @@ -15,8 +15,10 @@ Buying
-
{{buyRequestInfo.amount.amount}} {{buyRequestInfo.amount.currency}}
-
{{buyRequestInfo.subtotal.amount}} {{buyRequestInfo.subtotal.currency}}
+
{{amountUnitStr}}
+
+ @ ${{buyPrice.amount}} per BTC +
@@ -43,19 +45,25 @@
- Total to pay + Transaction details +
+
+ Amount + + {{buyRequestInfo.subtotal.amount}} {{buyRequestInfo.subtotal.currency}} +
- {{fee.type}} + {{fee.type}} fee - {{fee.amount.amount}} {{fee.amount.currency}} + {{fee.amount.amount}} {{fee.amount.currency}}
- Total - + Total to pay + {{buyRequestInfo.total.amount}} {{buyRequestInfo.total.currency}}
diff --git a/www/views/coinbase.html b/www/views/coinbase.html index ec6405d2d..cd953d9bc 100644 --- a/www/views/coinbase.html +++ b/www/views/coinbase.html @@ -60,7 +60,7 @@
- ... | ... + ... {{buyPrice.amount}} {{buyPrice.currency}} | diff --git a/www/views/sellCoinbase.html b/www/views/sellCoinbase.html index d698f3009..2cef05523 100644 --- a/www/views/sellCoinbase.html +++ b/www/views/sellCoinbase.html @@ -15,8 +15,10 @@ Selling
-
{{sellRequestInfo.amount.amount}} {{sellRequestInfo.amount.currency}}
-
{{sellRequestInfo.subtotal.amount}} {{sellRequestInfo.subtotal.currency}}
+
{{amountUnitStr}}
+
+ @ ${{sellPrice.amount}} per BTC +
@@ -75,11 +77,17 @@
- Total to receive + Transaction details +
+
+ Amount + + {{sellRequestInfo.subtotal.amount}} {{sellRequestInfo.subtotal.currency}} +
- {{fee.type}} + {{fee.type}} fee - @@ -87,8 +95,8 @@
- Total - + Total to receive + {{sellRequestInfo.total.amount}} {{sellRequestInfo.total.currency}}