From d85da2cc45c343b4d51943675ec9660dbd03c4cd Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 30 Jan 2017 18:04:17 -0300 Subject: [PATCH] buyAndSell services + nextSteps --- .../controllers/buyAndSellCardController.js | 14 ++ src/js/controllers/buyandsellController.js | 11 +- src/js/controllers/coinbase.js | 1 - src/js/controllers/nextStepsController.js | 16 ++ src/js/controllers/tab-home.js | 65 ++----- src/js/routes.js | 2 +- src/js/services/amazonService.js | 17 +- src/js/services/buyAndSellService.js | 60 ++++++ src/js/services/coinbaseService.js | 172 +++++++++++------- src/js/services/glideraService.js | 35 ++-- src/js/services/nextStepsService.js | 38 ++++ www/views/buyandsell.html | 12 +- www/views/includes/buyAndSellCard.html | 13 ++ www/views/includes/nextSteps.html | 28 +++ www/views/tab-home.html | 52 +----- 15 files changed, 342 insertions(+), 194 deletions(-) create mode 100644 src/js/controllers/buyAndSellCardController.js create mode 100644 src/js/controllers/nextStepsController.js create mode 100644 src/js/services/buyAndSellService.js create mode 100644 src/js/services/nextStepsService.js create mode 100644 www/views/includes/buyAndSellCard.html create mode 100644 www/views/includes/nextSteps.html diff --git a/src/js/controllers/buyAndSellCardController.js b/src/js/controllers/buyAndSellCardController.js new file mode 100644 index 000000000..1c33c8112 --- /dev/null +++ b/src/js/controllers/buyAndSellCardController.js @@ -0,0 +1,14 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('buyAndSellCardController', function($scope, nextStepsService, $ionicScrollDelegate, buyAndSellService) { + + $scope.services = buyAndSellService.getLinked(); + + $scope.toggle = function() { + $scope.hide = !$scope.hide; + $timeout(function() { + $ionicScrollDelegate.resize(); + $scope.$apply(); + }, 10); + }; +}); diff --git a/src/js/controllers/buyandsellController.js b/src/js/controllers/buyandsellController.js index 93df71069..643ba401a 100644 --- a/src/js/controllers/buyandsellController.js +++ b/src/js/controllers/buyandsellController.js @@ -1,14 +1,11 @@ 'use strict'; -angular.module('copayApp.controllers').controller('buyandsellController', function($scope, $ionicHistory, configService) { +angular.module('copayApp.controllers').controller('buyandsellController', function($scope, $ionicHistory, buyAndSellService, lodash) { $scope.$on("$ionicView.beforeEnter", function(event, data) { - configService.whenAvailable(function(config) { - $scope.isCoinbaseEnabled = config.coinbaseV2; - $scope.isGlideraEnabled = config.glidera.enabled; + $scope.services = buyAndSellService.get(); - if (!$scope.isCoinbaseEnabled && !$scope.isGlideraEnabled) - $ionicHistory.goBack(); - }); + if (lodash.isEmpty($scope.services)) + $ionicHistory.goBack(); }); }); diff --git a/src/js/controllers/coinbase.js b/src/js/controllers/coinbase.js index a038e6546..161b7e380 100644 --- a/src/js/controllers/coinbase.js +++ b/src/js/controllers/coinbase.js @@ -112,7 +112,6 @@ angular.module('copayApp.controllers').controller('coinbaseController', function var self = this; $scope.$on("$ionicView.beforeEnter", function(event, data) { - coinbaseService.setCredentials(); if (data.stateParams && data.stateParams.code) { coinbaseService.getStoredToken(function(at) { if (!at) self.submitOauthCode(data.stateParams.code); diff --git a/src/js/controllers/nextStepsController.js b/src/js/controllers/nextStepsController.js new file mode 100644 index 000000000..b745825ec --- /dev/null +++ b/src/js/controllers/nextStepsController.js @@ -0,0 +1,16 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('nextStepsController', function($scope, nextStepsService, $ionicScrollDelegate, $timeout) { + + $scope.hide = false; + $scope.services = nextStepsService.get(); + + $scope.toggle = function() { + $scope.hide = !$scope.hide; + $timeout(function() { + $ionicScrollDelegate.resize(); + $scope.$apply(); + }, 10); + }; + +}); diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 2564baea4..8653e9252 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, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, bitpayCardService, startupService, addressbookService, feedbackService, bwcError, coinbaseService) { + function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, bitpayCardService, startupService, addressbookService, feedbackService, bwcError, nextStepsService, buyAndSellService) { var wallet; var listeners = []; var notifications = []; @@ -83,10 +83,7 @@ angular.module('copayApp.controllers').controller('tabHomeController', var wallet = profileService.getWallet(walletId); updateWallet(wallet); if ($scope.recentTransactionsEnabled) getNotifications(); - if ($scope.coinbaseEnabled && type == 'NewBlock' && n && n.data && n.data.network == 'livenet') { - // Update Coinbase - coinbaseService.updatePendingTransactions(); - } + }), $rootScope.$on('Local/TxAction', function(e, walletId) { $log.debug('Got action for wallet ' + walletId); @@ -96,31 +93,22 @@ angular.module('copayApp.controllers').controller('tabHomeController', }) ]; + + $scope.nextStepsItems = nextStepsService.get(); + $scope.buyAndSellItems = buyAndSellService.getLinked(); + +console.log('[tab-home.js.99]', $scope.buyAndSellItems); //TODO + configService.whenAvailable(function() { - nextStep(function() { - var config = configService.getSync(); - var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova; + var config = configService.getSync(); + $scope.recentTransactionsEnabled = config.recentTransactions.enabled; + if ($scope.recentTransactionsEnabled) getNotifications(); - $scope.glideraEnabled = config.glidera.enabled && !isWindowsPhoneApp; - $scope.coinbaseEnabled = config.coinbaseV2 && !isWindowsPhoneApp; - $scope.amazonEnabled = config.amazon.enabled; - $scope.bitpayCardEnabled = config.bitpayCard.enabled; - - var buyAndSellEnabled = !$scope.externalServices.BuyAndSell && ($scope.glideraEnabled || $scope.coinbaseEnabled); - var amazonEnabled = !$scope.externalServices.AmazonGiftCards && $scope.amazonEnabled; - var bitpayCardEnabled = !$scope.externalServices.BitpayCard && $scope.bitpayCardEnabled; - - $scope.nextStepEnabled = buyAndSellEnabled || amazonEnabled || bitpayCardEnabled; - $scope.recentTransactionsEnabled = config.recentTransactions.enabled; - - if ($scope.recentTransactionsEnabled) getNotifications(); - - if ($scope.bitpayCardEnabled) bitpayCardCache(); - $timeout(function() { - $ionicScrollDelegate.resize(); - $scope.$apply(); - }, 10); - }); + if ($scope.bitpayCardEnabled) bitpayCardCache(); + $timeout(function() { + $ionicScrollDelegate.resize(); + $scope.$apply(); + }, 10); }); }); @@ -213,7 +201,7 @@ angular.module('copayApp.controllers').controller('tabHomeController', walletService.getStatus(wallet, {}, function(err, status) { if (err) { - wallet.error = (err === 'WALLET_NOT_REGISTERED') ? gettextCatalog.getString('Wallet not registered') : bwcError.msg(err); + wallet.error = (err === 'WALLET_NOT_REGISTERED') ? gettextCatalog.getString('Wallet not registered') : bwcError.msg(err); $log.error(err); } else { @@ -265,25 +253,6 @@ angular.module('copayApp.controllers').controller('tabHomeController', }); }; - var nextStep = function(cb) { - var i = 0; - var services = ['AmazonGiftCards', 'BitpayCard', 'BuyAndSell']; - lodash.each(services, function(service) { - storageService.getNextStep(service, function(err, value) { - $scope.externalServices[service] = value == 'true' ? true : false; - if (++i == services.length) return cb(); - }); - }); - }; - - $scope.shouldHideNextSteps = function() { - $scope.hideNextSteps = !$scope.hideNextSteps; - $timeout(function() { - $ionicScrollDelegate.resize(); - $scope.$apply(); - }, 10); - }; - var bitpayCardCache = function() { bitpayCardService.getCards(function(err, data) { if (err) return; diff --git a/src/js/routes.js b/src/js/routes.js index 315a26415..e3ddbab3f 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -1088,7 +1088,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); }) - .run(function($rootScope, $state, $location, $log, $timeout, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService) { + .run(function($rootScope, $state, $location, $log, $timeout, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, /* plugins START HERE => */ coinbaseService, glideraService, amazonService) { uxLanguage.init(); diff --git a/src/js/services/amazonService.js b/src/js/services/amazonService.js index e44166172..ff8b5e707 100644 --- a/src/js/services/amazonService.js +++ b/src/js/services/amazonService.js @@ -1,5 +1,5 @@ 'use strict'; -angular.module('copayApp.services').factory('amazonService', function($http, $log, lodash, moment, storageService, configService, platformInfo) { +angular.module('copayApp.services').factory('amazonService', function($http, $log, lodash, moment, storageService, configService, platformInfo, nextStepsService) { var root = {}; var credentials = {}; @@ -69,8 +69,9 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo }); }); + // TODO // Show pending task from the UI - storageService.setNextStep('AmazonGiftCards', 'true', function(err) {}); + // storageService.setNextStep('AmazonGiftCards', 'true', function(err) {}); }; root.getPendingGiftCards = function(cb) { @@ -144,6 +145,16 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo }); }; - return root; + var register = function () { + nextStepsService.register({ + name: 'amazon', + title: 'Buy a gift card', + icon: 'icon-amazon', + sref: 'tabs.giftcards.amazon', + }); + }; + register(); + + return root; }); diff --git a/src/js/services/buyAndSellService.js b/src/js/services/buyAndSellService.js new file mode 100644 index 000000000..326241a18 --- /dev/null +++ b/src/js/services/buyAndSellService.js @@ -0,0 +1,60 @@ +'use strict'; + +angular.module('copayApp.services').factory('buyAndSellService', function($log, nextStepsService, lodash, $ionicScrollDelegate, $timeout) { + var root = {}; + var services = []; + var linkedServices = []; + + root.updateNextSteps = function() { + + var newLinked = lodash.filter(services, function(x) { + return x.linked; + }); + + + // This is to preserve linkedServices pointer + while(linkedServices.length) + linkedServices.pop(); + + while(newLinked.length) + linkedServices.push(newLinked.pop()); + // + +console.log('[buyAndSellService.js.10:linkedServices:]',linkedServices); //TODO + + $log.debug('buyAndSell Service, updating nextSteps. linked/total: ' + linkedServices.length + '/'+ services.length); + + if (linkedServices.length == 0) { + nextStepsService.register({ + name: 'Buy and Sell', + icon: 'icon-buy-bitcoin', + sref: 'tabs.buyandsell', + }); + }; + + + $timeout(function() { + $ionicScrollDelegate.resize(); + }, 10); + }; + + var updateNextStepsDebunced = lodash.debounce(root.updateNextSteps, 1000); + + root.register = function(serviceInfo) { + services.push(serviceInfo); + $log.info('Adding Buy and Sell service:' + serviceInfo.name + ' linked:' + serviceInfo.linked); + updateNextStepsDebunced(); + }; + + root.get = function() { + return services; + }; + + + root.getLinked = function() { + return linkedServices; + }; + + + return root; +}); diff --git a/src/js/services/coinbaseService.js b/src/js/services/coinbaseService.js index 9057ae729..54139eafc 100644 --- a/src/js/services/coinbaseService.js +++ b/src/js/services/coinbaseService.js @@ -1,37 +1,32 @@ 'use strict'; -angular.module('copayApp.services').factory('coinbaseService', function($http, $log, $window, $filter, platformInfo, lodash, storageService, configService, appConfigService, txFormatService) { +angular.module('copayApp.services').factory('coinbaseService', function($http, $log, $window, $filter, platformInfo, lodash, storageService, configService, appConfigService, txFormatService, buyAndSellService, $rootScope) { var root = {}; var credentials = {}; var isCordova = platformInfo.isCordova; var isNW = platformInfo.isNW; + var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova; + + 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.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() { + var setCredentials = function() { if (!$window.externalServices || !$window.externalServices.coinbase) { return; @@ -46,19 +41,19 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ credentials.NETWORK = 'livenet'; // Coinbase permissions - credentials.SCOPE = '' - + 'wallet:accounts:read,' - + 'wallet:addresses:read,' - + 'wallet:addresses:create,' - + 'wallet:user:read,' - + 'wallet:user:email,' - + 'wallet:buys:read,' - + 'wallet:buys:create,' - + 'wallet:sells:read,' - + 'wallet:sells:create,' - + 'wallet:transactions:read,' - + 'wallet:transactions:send,' - + 'wallet:payment-methods:read'; + credentials.SCOPE = '' + + 'wallet:accounts:read,' + + 'wallet:addresses:read,' + + 'wallet:addresses:create,' + + 'wallet:user:read,' + + 'wallet:user:email,' + + 'wallet:buys:read,' + + 'wallet:buys:create,' + + 'wallet:sells:read,' + + 'wallet:sells:create,' + + 'wallet:transactions:read,' + + 'wallet:transactions:send,' + + 'wallet:payment-methods:read'; // NW has a bug with Window Object if (isCordova) { @@ -72,8 +67,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ credentials.API = coinbase.sandbox.api; credentials.CLIENT_ID = coinbase.sandbox.client_id; credentials.CLIENT_SECRET = coinbase.sandbox.client_secret; - } - else { + } else { credentials.HOST = coinbase.production.host; credentials.API = coinbase.production.api; credentials.CLIENT_ID = coinbase.production.client_id; @@ -107,8 +101,8 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ root.getAvailableCurrency = function() { var config = configService.getSync().wallet.settings; // ONLY "USD" - switch(config.alternativeIsoCode) { - default : return 'USD' + switch (config.alternativeIsoCode) { + default: return 'USD' }; }; @@ -117,7 +111,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ var satToBtc = 1 / 100000000; var unitToSatoshi = config.unitToSatoshi; var amountUnitStr; - + // IF 'USD' if (currency) { amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency; @@ -128,19 +122,19 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ amount = (amountSat * satToBtc).toFixed(8); currency = 'BTC'; } - + return [amount, currency, amountUnitStr]; }; root.getOauthCodeUrl = function() { - return credentials.HOST - + '/oauth/authorize?response_type=code&client_id=' - + credentials.CLIENT_ID - + '&redirect_uri=' - + credentials.REDIRECT_URI - + '&state=SECURE_RANDOM&scope=' - + credentials.SCOPE - + '&meta[send_limit_amount]=1000&meta[send_limit_currency]=USD&meta[send_limit_period]=day'; + return credentials.HOST + + '/oauth/authorize?response_type=code&client_id=' + + credentials.CLIENT_ID + + '&redirect_uri=' + + credentials.REDIRECT_URI + + '&state=SECURE_RANDOM&scope=' + + credentials.SCOPE + + '&meta[send_limit_amount]=1000&meta[send_limit_currency]=USD&meta[send_limit_period]=day'; }; root.getToken = function(code, cb) { @@ -152,9 +146,9 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ 'Accept': 'application/json' }, data: { - grant_type : 'authorization_code', + grant_type: 'authorization_code', code: code, - client_id : credentials.CLIENT_ID, + client_id: credentials.CLIENT_ID, client_secret: credentials.CLIENT_SECRET, redirect_uri: credentials.REDIRECT_URI } @@ -163,7 +157,6 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ $http(req).then(function(data) { $log.info('Coinbase Authorization Access Token: SUCCESS'); // Show pending task from the UI - storageService.setNextStep('BuyAndSell', 'true', function(err) {}); _afterTokenReceived(data.data, cb); }, function(data) { $log.error('Coinbase Authorization Access Token: ERROR ' + data.statusText); @@ -180,8 +173,8 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ 'Accept': 'application/json' }, data: { - grant_type : 'refresh_token', - client_id : credentials.CLIENT_ID, + grant_type: 'refresh_token', + client_id: credentials.CLIENT_ID, client_secret: credentials.CLIENT_SECRET, redirect_uri: credentials.REDIRECT_URI, refresh_token: refreshToken @@ -211,6 +204,19 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }); }; + root.isActive = function(cb) { + + if (isWindowsPhoneApp) + return cb(); + + if (lodash.isEmpty(credentials.CLIENT_ID)) + return cb(); + + storageService.getCoinbaseToken(credentials.NETWORK, function(err, accessToken) { + return cb(err, !!accessToken); + }); + } + root.init = lodash.throttle(function(cb) { if (lodash.isEmpty(credentials.CLIENT_ID)) { return cb('Coinbase is Disabled'); @@ -230,7 +236,10 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ if (err) return cb(err); _getMainAccountId(newToken, function(err, accountId) { if (err) return cb(err); - return cb(null, {accessToken: newToken, accountId: accountId}); + return cb(null, { + accessToken: newToken, + accountId: accountId + }); }); }); }); @@ -238,7 +247,10 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ return cb(err); } } else { - return cb(null, {accessToken: accessToken, accountId: accountId}); + return cb(null, { + accessToken: accessToken, + accountId: accountId + }); } }); } @@ -402,7 +414,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ var data = { amount: data.amount, currency: data.currency, - payment_method: data.payment_method || null, + payment_method: data.payment_method ||  null, commit: data.commit || false, quote: data.quote || false }; @@ -483,7 +495,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }; // Pending transactions - + root.savePendingTransaction = function(ctx, opts, cb) { _savePendingTransaction(ctx, opts, cb); }; @@ -516,7 +528,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ storageService.getCoinbaseTxs(credentials.NETWORK, function(err, txs) { txs = txs ? JSON.parse(txs) : {}; coinbasePendingTransactions.data = lodash.isEmpty(txs) ? null : txs; - + root.init(function(err, data) { if (err || lodash.isEmpty(data)) { if (err) $log.error(err); @@ -529,7 +541,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ if ((dataFromStorage.type == 'sell' && dataFromStorage.status == 'completed') || (dataFromStorage.type == 'buy' && dataFromStorage.status == 'completed') || dataFromStorage.status == 'error' || - (dataFromStorage.type == 'send' && dataFromStorage.status == 'completed')) + (dataFromStorage.type == 'send' && dataFromStorage.status == 'completed')) return; root.getTransaction(accessToken, accountId, txId, function(err, tx) { if (err || lodash.isEmpty(tx) || (tx.data && tx.data.error)) { @@ -591,9 +603,10 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ root.updatePendingTransactions = lodash.throttle(function() { $log.debug('Updating pending transactions...'); - root.setCredentials(); - var pendingTransactions = { data: {} }; - root.getPendingTransactions(pendingTransactions); + var pendingTransactions = { + data: {} + }; + root.getPendingTransactions(pendingTransactions); }, 20000); var _updateTxs = function(coinbasePendingTransactions) { @@ -707,6 +720,31 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }); }; - return root; + var register = function() { + root.isActive(function(err, isActive){ + if (err) return; + + buyAndSellService.register({ + name: 'Coinbase', + logo: 'img/coinbase-logo.png', + sref: 'tabs.buyandsell.coinbase', + linked: isActive, + }); + }); + }; + + setCredentials(); + register(); + + $rootScope.$on('bwsEvent', function(e, walletId, type, n) { + if (type == 'NewBlock' && n && n.data && n.data.network == 'livenet') { + root.isActive(function(err,isActive){ + // Update Coinbase + if (isActive) + root.updatePendingTransactions(); + }); + } + }); + return root; }); diff --git a/src/js/services/glideraService.js b/src/js/services/glideraService.js index 06e30cf14..01edc677a 100644 --- a/src/js/services/glideraService.js +++ b/src/js/services/glideraService.js @@ -1,11 +1,12 @@ 'use strict'; -angular.module('copayApp.services').factory('glideraService', function($http, $log, $window, platformInfo, storageService) { +angular.module('copayApp.services').factory('glideraService', function($http, $log, $window, platformInfo, storageService, buyAndSellService) { var root = {}; var credentials = {}; var isCordova = platformInfo.isCordova; + var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova; - var _setCredentials = function() { + var setCredentials = function() { if (!$window.externalServices || !$window.externalServices.glidera) { return; } @@ -16,7 +17,8 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l * Development: 'testnet' * Production: 'livenet' */ - credentials.NETWORK = 'livenet'; +// credentials.NETWORK = 'livenet'; + credentials.NETWORK = 'testnet'; if (credentials.NETWORK == 'testnet') { credentials.HOST = glidera.sandbox.host; @@ -44,24 +46,20 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l }; root.getEnvironment = function() { - _setCredentials(); return credentials.NETWORK; }; root.getOauthCodeUrl = function() { - _setCredentials(); return credentials.HOST + '/oauth2/auth?response_type=code&client_id=' + credentials.CLIENT_ID + '&redirect_uri=' + credentials.REDIRECT_URI; }; root.removeToken = function(cb) { - _setCredentials(); storageService.removeGlideraToken(credentials.NETWORK, function() { return cb(); }); }; root.getToken = function(code, cb) { - _setCredentials(); var req = { method: 'POST', url: credentials.HOST + '/api/v1/oauth/token', @@ -90,7 +88,6 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l }; var _get = function(endpoint, token) { - _setCredentials(); return { method: 'GET', url: credentials.HOST + '/api/v1' + endpoint, @@ -208,7 +205,6 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l }; var _post = function(endpoint, token, twoFaCode, data) { - _setCredentials(); return { method: 'POST', url: credentials.HOST + '/api/v1' + endpoint, @@ -285,7 +281,6 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l }; root.init = function(accessToken, cb) { - _setCredentials(); $log.debug('Init Glidera...'); var glidera = { @@ -317,6 +312,24 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l }); }; - return root; + var register = function() { + if (isWindowsPhoneApp) return; + + storageService.getGlideraToken(credentials.NETWORK, function(err, token) { + if (err) return cb(err); + +console.log('[glideraService.js.326:token:]',token); //TODO + buyAndSellService.register({ + name: 'Glidera', + logo: 'img/glidera-logo.png', + sref: 'tabs.buyandsell.glidera', + linked: !!token, + }); + }); + }; + + setCredentials(); + register(); + return root; }); diff --git a/src/js/services/nextStepsService.js b/src/js/services/nextStepsService.js new file mode 100644 index 000000000..3ca781dfa --- /dev/null +++ b/src/js/services/nextStepsService.js @@ -0,0 +1,38 @@ + 'use strict'; + angular.module('copayApp.services').factory('nextStepsService', function(configService, $log) { + var root = {}; + + // + // configService.whenAvailable(function() { + // nextStep(function() { + // var config = configService.getSync(); + // var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova; + // + // $scope.glideraEnabled = config.glidera.enabled && !isWindowsPhoneApp; + // $scope.coinbaseEnabled = config.coinbaseV2 && !isWindowsPhoneApp; + // $scope.amazonEnabled = config.amazon.enabled; + // $scope.bitpayCardEnabled = config.bitpayCard.enabled; + + + var services = []; + + root.register = function(serviceInfo) { + $log.info('Adding NextSteps entry:' + serviceInfo.name); + services.push(serviceInfo); + }; + + + root.unregister = function(serviceName) { + services = lodash.filter(services, function(x) { + return x.name != serviceName + }); + }; + + + root.get = function() { + return services; + }; + + return root; + + }); diff --git a/www/views/buyandsell.html b/www/views/buyandsell.html index b48b777f2..18d063a17 100644 --- a/www/views/buyandsell.html +++ b/www/views/buyandsell.html @@ -7,14 +7,10 @@
- -
- - -
-
- - +
+
+ +
diff --git a/www/views/includes/buyAndSellCard.html b/www/views/includes/buyAndSellCard.html new file mode 100644 index 000000000..a736b77fa --- /dev/null +++ b/www/views/includes/buyAndSellCard.html @@ -0,0 +1,13 @@ + +
+
+ Buy & Sell Bitcoin + +
+ +
diff --git a/www/views/includes/nextSteps.html b/www/views/includes/nextSteps.html new file mode 100644 index 000000000..8f19f31d2 --- /dev/null +++ b/www/views/includes/nextSteps.html @@ -0,0 +1,28 @@ +
+
+ Next steps + + +
+ +
+ + + + + + + + + + diff --git a/www/views/tab-home.html b/www/views/tab-home.html index 89a1a7fdc..a532a2a75 100644 --- a/www/views/tab-home.html +++ b/www/views/tab-home.html @@ -115,24 +115,10 @@
-
-
- Buy & Sell Bitcoin - -
-
- - - - - - - - -
-
-