From 3b0dceccf5854426e39708f052ef4bce41563cd4 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Mon, 12 Dec 2016 14:45:12 -0300 Subject: [PATCH] Fix amount process --- src/js/controllers/amount.js | 21 +++++--- src/js/controllers/confirm.js | 11 ++-- src/js/services/coinbaseService.js | 83 ++++++++++++++++++++++++++++++ www/views/amount.html | 17 +++--- www/views/confirm.html | 29 ++++++----- 5 files changed, 132 insertions(+), 29 deletions(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 81d819e94..f9c5a554e 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -66,11 +66,20 @@ angular.module('copayApp.controllers').controller('amountController', function($ $scope.coinbasePaymentMethods = []; coinbaseService.getPaymentMethods(data.accessToken, function(err, p) { lodash.each(p.data, function(pm) { - if (pm.allow_buy) { - $scope.coinbasePaymentMethods.push(pm); - } - if (pm.allow_buy && pm.primary_buy) { - $scope.coinbaseSelectedPaymentMethod = pm; + if ($scope.isCoinbase == 'sell') { + if (pm.allow_sell) { + $scope.coinbasePaymentMethods.push(pm); + } + if (pm.allow_sell && pm.primary_sell) { + $scope.coinbaseSelectedPaymentMethod = pm; + } + } else { + if (pm.allow_buy) { + $scope.coinbasePaymentMethods.push(pm); + } + if (pm.allow_buy && pm.primary_buy) { + $scope.coinbaseSelectedPaymentMethod = pm; + } } }); }); @@ -386,7 +395,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ return; } var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount; - $state.transitionTo('tabs.buyandsell.glidera.confirm', { + $state.transitionTo('tabs.buyandsell.coinbase.confirm', { toAmount: (amount * unitToSatoshi).toFixed(0), isCoinbase: $scope.isCoinbase, coinbasePaymentMethodId: $scope.coinbaseSelectedPaymentMethod.id diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 9ebcf507f..96cb1429a 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, amazonService, glideraService, bwcError, bitpayCardService) { +angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, amazonService, glideraService, bwcError, coinbaseService, bitpayCardService) { var cachedTxp = {}; var toAmount; var isChromeApp = platformInfo.isChromeApp; @@ -25,6 +25,10 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.isGlidera = data.stateParams.isGlidera; $scope.glideraAccessToken = data.stateParams.glideraAccessToken; + // Coinbase parameters + $scope.isCoinbase = data.stateParams.isCoinbase; + $scope.coinbasePaymentMethodId = data.stateParams.coinbasePaymentMethodId; + toAmount = data.stateParams.toAmount; cachedSendMax = {}; $scope.useSendMax = data.stateParams.useSendMax == 'true' ? true : false; @@ -50,6 +54,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( var feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal'; $scope.feeLevel = feeService.feeOpts[feeLevel]; if ($scope.isGlidera) $scope.network = glideraService.getEnvironment(); + else if ($scope.isCoinbase) $scope.network = coinbaseService.getEnvironment(); else $scope.network = (new bitcore.Address($scope.toAddress)).network.name; resetValues(); setwallets(); @@ -283,7 +288,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( }); $scope.showWalletSelector = function() { - $scope.walletSelectorTitle = $scope.isGlidera == 'buy' ? 'Receive in' : $scope.isGlidera == 'sell' ? 'Sell From' : gettextCatalog.getString('Send from'); + $scope.walletSelectorTitle = ($scope.isGlidera || $scope.isCoinbase) == 'buy' ? 'Receive in' : ($scope.isGlidera || $scope.isCoinbase) == 'sell' ? 'Sell From' : gettextCatalog.getString('Send from'); if (!$scope.useSendMax && ($scope.insufficientFunds || $scope.noMatchingWallet)) return; $scope.showWallets = true; }; @@ -362,7 +367,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.wallet = wallet; $scope.fee = $scope.txp = null; - if ($scope.isGlidera) return; + if ($scope.isGlidera || $scope.isCoinbase) return; if (stop) { $timeout.cancel(stop); stop = null; diff --git a/src/js/services/coinbaseService.js b/src/js/services/coinbaseService.js index 842d1dc50..6a05b99cb 100644 --- a/src/js/services/coinbaseService.js +++ b/src/js/services/coinbaseService.js @@ -6,6 +6,34 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ var isCordova = platformInfo.isCordova; var isNW = platformInfo.isNW; + // FAKE DATA + var isFake = true; + + root.priceSensitivity = [ + { + value: 0.5, + name: '0.5%' + }, + { + value: 1, + name: '1%' + }, + { + value: 2, + name: '2%' + }, + { + value: 5, + name: '5%' + }, + { + value: 10, + name: '10%' + } + ]; + + root.selectedPriceSensitivity = root.priceSensitivity[1]; + root.setCredentials = function() { if (!$window.externalServices || !$window.externalServices.coinbase) { @@ -304,6 +332,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }; root.getPaymentMethods = function(token, cb) { + if (isFake) return cb(null, payment_methods); $http(_get('/payment-methods', token)).then(function(data) { $log.info('Coinbase Get Payment Methods: SUCCESS'); return cb(null, data.data); @@ -603,6 +632,60 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }); }; + var payment_methods = { + "pagination": { + "ending_before": null, + "starting_after": null, + "limit": 25, + "order": "desc", + "previous_uri": null, + "next_uri": null + }, + "data": [ + { + "id": "127b4d76-a1a0-5de7-8185-3657d7b526ec", + "type": "fiat_account", + "name": "USD Wallet", + "currency": "USD", + "primary_buy": false, + "primary_sell": false, + "allow_buy": true, + "allow_sell": true, + "allow_deposit": true, + "allow_withdraw": true, + "instant_buy": true, + "instant_sell": true, + "created_at": "2015-02-24T14:30:30-08:00", + "updated_at": "2015-02-24T14:30:30-08:00", + "resource": "payment_method", + "resource_path": "/v2/payment-methods/127b4d76-a1a0-5de7-8185-3657d7b526ec", + "fiat_account": { + "id": "a077fff9-312b-559b-af98-146c33e27388", + "resource": "account", + "resource_path": "/v2/accounts/a077fff9-312b-559b-af98-146c33e27388" + } + }, + { + "id": "83562370-3e5c-51db-87da-752af5ab9559", + "type": "ach_bank_account", + "name": "International Bank *****1111", + "currency": "USD", + "primary_buy": true, + "primary_sell": true, + "allow_buy": true, + "allow_sell": true, + "allow_deposit": true, + "allow_withdraw": true, + "instant_buy": false, + "instant_sell": false, + "created_at": "2015-01-31T20:49:02Z", + "updated_at": "2015-02-11T16:53:57-08:00", + "resource": "payment_method", + "resource_path": "/v2/payment-methods/83562370-3e5c-51db-87da-752af5ab9559" + } + ] + }; + return root; }); diff --git a/www/views/amount.html b/www/views/amount.html index 312d50943..c5366bdc4 100644 --- a/www/views/amount.html +++ b/www/views/amount.html @@ -43,7 +43,7 @@
- Amount + Amount
Purchase Amount is limited to USD 1000 per day
{{exchangeRate}}
@@ -68,22 +68,23 @@
-
- 1 BTC ~ {{coinbaseBuyPrice.amount}} {{coinbaseBuyPrice.currency}} -
-
- 1 BTC ~ {{coinbaseSellPrice.amount}} {{coinbaseSellPrice.currency}} -
+
+ 1 BTC ~ {{coinbaseBuyPrice.amount}} {{coinbaseBuyPrice.currency}} +
+
+ 1 BTC ~ {{coinbaseSellPrice.amount}} {{coinbaseSellPrice.currency}} +
diff --git a/www/views/confirm.html b/www/views/confirm.html index 9612e42dc..9bfdcdeeb 100644 --- a/www/views/confirm.html +++ b/www/views/confirm.html @@ -12,10 +12,10 @@
- Sending + Sending Sending maximum amount - Buying - Selling + Buying + Selling
{{displayAmount || '...'}} {{displayUnit}}
@@ -30,16 +30,17 @@ Expired
- To - From - To + To + From + To - +
+
@@ -57,9 +58,9 @@
- From - To - From + From + To + From
@@ -74,14 +75,14 @@
- + Add Memo {{description}} -
+
{{'Fee' | translate}}: {{feeLevel | translate}} {{fee || '...'}} @@ -153,6 +154,10 @@ A transfer has been initiated from your bank account. Your bitcoins should arrive to your wallet in 2-4 business day A transfer has been initiated to your bank account. Should arrive in 4-6 business days
+
+ Bitcoin purchase completed. Coinbase has queued the transfer to your selected Copay wallet + Sale initiated +