From c3188d7d178510defac0d861f4d392ce15758961 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 26 Aug 2016 11:11:14 -0300 Subject: [PATCH] Adds next step for external services --- public/views/amount.html | 5 +- public/views/buyandsell.html | 20 +++++ public/views/tab-home.html | 115 ++++++++++++++------------- public/views/tab-send.html | 40 +++++----- public/views/walletDetails.html | 2 +- src/js/controllers/tab-home.js | 11 ++- src/js/routes.js | 5 +- src/js/services/amazonService.js | 3 + src/js/services/bitpayCardService.js | 2 + src/js/services/coinbaseService.js | 46 ++++++----- src/js/services/glideraService.js | 2 + src/js/services/storageService.js | 12 +++ 12 files changed, 159 insertions(+), 104 deletions(-) create mode 100644 public/views/buyandsell.html diff --git a/public/views/amount.html b/public/views/amount.html index 373eacf42..51a2f2422 100644 --- a/public/views/amount.html +++ b/public/views/amount.html @@ -12,7 +12,7 @@ -
+
Recipient @@ -22,7 +22,9 @@ {{toName || toAddress}}
+
+
Amount
@@ -41,7 +43,6 @@ {{globalResult}} {{alternativeResult || '0.00'}} {{unitName}}
-
diff --git a/public/views/buyandsell.html b/public/views/buyandsell.html new file mode 100644 index 000000000..3649604be --- /dev/null +++ b/public/views/buyandsell.html @@ -0,0 +1,20 @@ + + + + + + Buy and sell + + + + + + + + TODO + + + + diff --git a/public/views/tab-home.html b/public/views/tab-home.html index 4d7072da5..1fae3a978 100644 --- a/public/views/tab-home.html +++ b/public/views/tab-home.html @@ -4,21 +4,20 @@ Home - -

Recent Activity -

+ -
-
- +
+
+ Recent Activity
-
- -
-
-
+
+ +
Updating activity. Please stand by
+
+
+ -
+ @@ -32,56 +31,62 @@
-
-
-

Wallets

+
+
+ Wallets +
-
- -
-
- -
No Wallet
-
- - {{item.name || item.id}} - - {{item.m}}-of-{{item.n}} - - - Incomplete - - - {{item.status.availableBalanceStr}} - -
-
- -
-

Buy & Sell Bitcoin

-
-
- -
-
- TODO -
-
-
- -

Next steps

-
- - + +
+
+ Buy & Sell Bitcoin
+ + + + + TODO + +
+ + diff --git a/public/views/tab-send.html b/public/views/tab-send.html index 13d5a76e6..078fc2fcd 100644 --- a/public/views/tab-send.html +++ b/public/views/tab-send.html @@ -4,33 +4,31 @@ Send - + -
-

Recipient

- -
- -
-
-

Contacts & Wallets

+
+
+ Recipient
-
- - - +
+
-
- No Wallet - Contact -
- -
+
+
+ Contacts & Wallets + +
+
No Wallet - Contact
diff --git a/public/views/walletDetails.html b/public/views/walletDetails.html index 268ae1482..c69b571a6 100644 --- a/public/views/walletDetails.html +++ b/public/views/walletDetails.html @@ -5,7 +5,7 @@ {{wallet.name}} diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 0d2929670..da9538144 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('tabHomeController', - function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo) { + function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo, storageService) { var setNotifications = function(notifications) { var n = walletService.processNotifications(notifications, 5); @@ -68,7 +68,14 @@ console.log('[tab-home.js.39]', wallet.name, n); //TODO }); }; - + $scope.externalServices = {}; + $scope.nextStep = function() { + lodash.each(['AmazonGiftCards', 'BitpayCard', 'BuyAndSell'], function(service) { + storageService.getNextStep(service, function(err, value) { + $scope.externalServices[service] = value ? true : false; + }); + }); + }; $scope.bitpayCardEnabled = true; // TODO diff --git a/src/js/routes.js b/src/js/routes.js index a69c7508b..da4adaf89 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -105,7 +105,10 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr templateUrl: 'views/starting.html' }) - + .state('buyandsell', { + url: '/buyandsell', + templateUrl: 'views/buyandsell.html' + }) /* * diff --git a/src/js/services/amazonService.js b/src/js/services/amazonService.js index a656849ad..6a39d7812 100644 --- a/src/js/services/amazonService.js +++ b/src/js/services/amazonService.js @@ -68,6 +68,9 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo return cb(err); }); }); + + // Show pending task from the UI + storageService.setNextStep('AmazonGiftCards', true, function(err) {}); }; root.getPendingGiftCards = function(cb) { diff --git a/src/js/services/bitpayCardService.js b/src/js/services/bitpayCardService.js index 7a0368cb5..fd122d36b 100644 --- a/src/js/services/bitpayCardService.js +++ b/src/js/services/bitpayCardService.js @@ -36,6 +36,8 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http, storageService.setBitpayCard(credentials.NETWORK, user, function(err) { return cb(err); }); + // Show pending task from the UI + storageService.setNextStep('BitpayCard', true, function(err) {}); }; var _getSession = function(cb) { diff --git a/src/js/services/coinbaseService.js b/src/js/services/coinbaseService.js index 3827c6651..ce5b984cd 100644 --- a/src/js/services/coinbaseService.js +++ b/src/js/services/coinbaseService.js @@ -41,9 +41,9 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }; root.getOauthCodeUrl = function() { - return credentials.HOST - + '/oauth/authorize?response_type=code&client_id=' - + credentials.CLIENT_ID + return credentials.HOST + + '/oauth/authorize?response_type=code&client_id=' + + credentials.CLIENT_ID + '&redirect_uri=' + credentials.REDIRECT_URI + '&state=SECURE_RANDOM&scope=' @@ -59,7 +59,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ 'Content-Type': 'application/json', 'Accept': 'application/json' }, - data: { + data: { grant_type : 'authorization_code', code: code, client_id : credentials.CLIENT_ID, @@ -70,7 +70,9 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ $http(req).then(function(data) { $log.info('Coinbase Authorization Access Token: SUCCESS'); - return cb(null, data.data); + // Show pending task from the UI + storageService.setNextStep('BuyAndSell', true, function(err) {}); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Authorization Access Token: ERROR ' + data.statusText); return cb(data.data); @@ -85,18 +87,18 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ 'Content-Type': 'application/json', 'Accept': 'application/json' }, - data: { + data: { grant_type : 'refresh_token', client_id : credentials.CLIENT_ID, client_secret: credentials.CLIENT_SECRET, redirect_uri: credentials.REDIRECT_URI, - refresh_token: refreshToken + refresh_token: refreshToken } }; $http(req).then(function(data) { $log.info('Coinbase Refresh Access Token: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Refresh Access Token: ERROR ' + data.statusText); return cb(data.data); @@ -195,17 +197,17 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ root.sellPrice = function(token, currency, cb) { $http(_get('/prices/sell?currency=' + currency, token)).then(function(data) { $log.info('Coinbase Sell Price: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Sell Price: ERROR ' + data.statusText); return cb(data.data); }); - }; + }; root.buyPrice = function(token, currency, cb) { $http(_get('/prices/buy?currency=' + currency, token)).then(function(data) { $log.info('Coinbase Buy Price: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Buy Price: ERROR ' + data.statusText); return cb(data.data); @@ -215,7 +217,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ root.getPaymentMethods = function(token, cb) { $http(_get('/payment-methods', token)).then(function(data) { $log.info('Coinbase Get Payment Methods: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Get Payment Methods: ERROR ' + data.statusText); return cb(data.data); @@ -225,7 +227,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ root.getPaymentMethod = function(token, paymentMethodId, cb) { $http(_get('/payment-methods/' + paymentMethodId, token)).then(function(data) { $log.info('Coinbase Get Payment Method: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Get Payment Method: ERROR ' + data.statusText); return cb(data.data); @@ -243,7 +245,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }, data: data }; - }; + }; root.sellRequest = function(token, accountId, data, cb) { var data = { @@ -254,7 +256,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }; $http(_post('/accounts/' + accountId + '/sells', token, data)).then(function(data) { $log.info('Coinbase Sell Request: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Sell Request: ERROR ' + data.statusText); return cb(data.data); @@ -264,12 +266,12 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ root.sellCommit = function(token, accountId, sellId, cb) { $http(_post('/accounts/' + accountId + '/sells/' + sellId + '/commit', token)).then(function(data) { $log.info('Coinbase Sell Commit: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Sell Commit: ERROR ' + data.statusText); return cb(data.data); }); - }; + }; root.buyRequest = function(token, accountId, data, cb) { var data = { @@ -280,7 +282,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }; $http(_post('/accounts/' + accountId + '/buys', token, data)).then(function(data) { $log.info('Coinbase Buy Request: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Buy Request: ERROR ' + data.statusText); return cb(data.data); @@ -290,7 +292,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ root.buyCommit = function(token, accountId, buyId, cb) { $http(_post('/accounts/' + accountId + '/buys/' + buyId + '/commit', token)).then(function(data) { $log.info('Coinbase Buy Commit: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Buy Commit: ERROR ' + data.statusText); return cb(data.data); @@ -303,7 +305,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }; $http(_post('/accounts/' + accountId + '/addresses', token, data)).then(function(data) { $log.info('Coinbase Create Address: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Create Address: ERROR ' + data.statusText); return cb(data.data); @@ -320,7 +322,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }; $http(_post('/accounts/' + accountId + '/transactions', token, data)).then(function(data) { $log.info('Coinbase Create Address: SUCCESS'); - return cb(null, data.data); + return cb(null, data.data); }, function(data) { $log.error('Coinbase Create Address: ERROR ' + data.statusText); return cb(data.data); @@ -328,7 +330,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }; // Pending transactions - + root.savePendingTransaction = function(ctx, opts, cb) { var network = configService.getSync().coinbase.testnet ? 'testnet' : 'livenet'; storageService.getCoinbaseTxs(network, function(err, oldTxs) { diff --git a/src/js/services/glideraService.js b/src/js/services/glideraService.js index 31b373105..7665a5767 100644 --- a/src/js/services/glideraService.js +++ b/src/js/services/glideraService.js @@ -74,6 +74,8 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l $http(req).then(function(data) { $log.info('Glidera Authorization Access Token: SUCCESS'); + // Show pending task from the UI + storageService.setNextStep('BuyAndSell', true, function(err) {}); return cb(null, data.data); }, function(data) { $log.error('Glidera Authorization Access Token: ERROR ' + data.statusText); diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 6ff8a794f..a498dfb89 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -264,6 +264,18 @@ angular.module('copayApp.services') storage.remove('addressbook-' + network, cb); }; + root.setNextStep = function(service, status, cb) { + storage.set('nextStep-' + service, status, cb); + }; + + root.getNextStep = function(service, cb) { + storage.get('nextStep-' + service, cb); + }; + + root.removeNextStep = function(service, cb) { + storage.remove('nextStep-' + service, cb); + }; + root.checkQuota = function() { var block = '';