fix refresh in home / settings
This commit is contained in:
parent
d85da2cc45
commit
5357ba7fcd
14 changed files with 150 additions and 96 deletions
16
src/js/controllers/homeIntegrations.js
Normal file
16
src/js/controllers/homeIntegrations.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('homeIntegrationsController', function($scope, homeIntegrationsService, $ionicScrollDelegate, $timeout) {
|
||||
|
||||
$scope.hide = false;
|
||||
$scope.services = homeIntegrationsService.get();
|
||||
|
||||
$scope.toggle = function() {
|
||||
$scope.hide = !$scope.hide;
|
||||
$timeout(function() {
|
||||
$ionicScrollDelegate.resize();
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
};
|
||||
|
||||
});
|
||||
|
|
@ -16,7 +16,6 @@ angular.module('copayApp.controllers').controller('preferencesCoinbaseController
|
|||
};
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data){
|
||||
coinbaseService.setCredentials();
|
||||
ongoingProcess.set('connectingCoinbase', true);
|
||||
coinbaseService.init(function(err, data) {
|
||||
if (err || lodash.isEmpty(data)) {
|
||||
|
|
|
|||
|
|
@ -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, nextStepsService, buyAndSellService) {
|
||||
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, homeIntegrationsService) {
|
||||
var wallet;
|
||||
var listeners = [];
|
||||
var notifications = [];
|
||||
|
|
@ -96,8 +96,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
|||
|
||||
$scope.nextStepsItems = nextStepsService.get();
|
||||
$scope.buyAndSellItems = buyAndSellService.getLinked();
|
||||
|
||||
console.log('[tab-home.js.99]', $scope.buyAndSellItems); //TODO
|
||||
$scope.homeIntegrations = homeIntegrationsService.get();
|
||||
|
||||
configService.whenAvailable(function() {
|
||||
var config = configService.getSync();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, appConfigService, $log, lodash, uxLanguage, platformInfo, profileService, feeService, configService, externalLinkService, bitpayCardService, storageService, glideraService, coinbaseService, gettextCatalog) {
|
||||
angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, appConfigService, $log, lodash, uxLanguage, platformInfo, profileService, feeService, configService, externalLinkService, bitpayCardService, storageService, glideraService, coinbaseService, gettextCatalog, buyAndSellService) {
|
||||
|
||||
var updateConfig = function() {
|
||||
var isCordova = platformInfo.isCordova;
|
||||
|
|
@ -16,6 +16,7 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
|
|||
$scope.currentFeeLevel = feeService.getCurrentFeeLevel();
|
||||
|
||||
$scope.wallets = profileService.getWallets();
|
||||
$scope.buyAndSellServices = buyAndSellService.getLinked();
|
||||
|
||||
configService.whenAvailable(function(config) {
|
||||
$scope.unitName = config.wallet.settings.unitName;
|
||||
|
|
@ -25,8 +26,6 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
|
|||
};
|
||||
|
||||
$scope.bitpayCardEnabled = config.bitpayCard.enabled;
|
||||
$scope.glideraEnabled = config.glidera.enabled && !isWindowsPhoneApp;
|
||||
$scope.coinbaseEnabled = config.coinbaseV2 && !isWindowsPhoneApp;
|
||||
|
||||
if ($scope.bitpayCardEnabled) {
|
||||
bitpayCardService.getCards(function(err, cards) {
|
||||
|
|
@ -35,20 +34,6 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
|
|||
});
|
||||
}
|
||||
|
||||
if ($scope.glideraEnabled) {
|
||||
storageService.getGlideraToken(glideraService.getEnvironment(), function(err, token) {
|
||||
if (err) $log.error(err);
|
||||
$scope.glideraToken = token;
|
||||
});
|
||||
}
|
||||
|
||||
if ($scope.coinbaseEnabled) {
|
||||
coinbaseService.setCredentials();
|
||||
coinbaseService.getStoredToken(function(at) {
|
||||
$scope.coinbaseToken = at;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.services').factory('amazonService', function($http, $log, lodash, moment, storageService, configService, platformInfo, nextStepsService) {
|
||||
angular.module('copayApp.services').factory('amazonService', function($http, $log, lodash, moment, storageService, configService, platformInfo, nextStepsService, homeIntegrationsService) {
|
||||
var root = {};
|
||||
var credentials = {};
|
||||
|
||||
var _setCredentials = function() {
|
||||
var setCredentials = function() {
|
||||
/*
|
||||
* Development: 'testnet'
|
||||
* Production: 'livenet'
|
||||
*/
|
||||
credentials.NETWORK = 'livenet';
|
||||
//credentials.NETWORK = 'livenet';
|
||||
credentials.NETWORK = 'testnet';
|
||||
|
||||
if (credentials.NETWORK == 'testnet') {
|
||||
credentials.BITPAY_API_URL = "https://test.bitpay.com";
|
||||
|
|
@ -18,7 +19,6 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
|||
};
|
||||
|
||||
var _getBitPay = function(endpoint) {
|
||||
_setCredentials();
|
||||
return {
|
||||
method: 'GET',
|
||||
url: credentials.BITPAY_API_URL + endpoint,
|
||||
|
|
@ -29,7 +29,6 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
|||
};
|
||||
|
||||
var _postBitPay = function(endpoint, data) {
|
||||
_setCredentials();
|
||||
return {
|
||||
method: 'POST',
|
||||
url: credentials.BITPAY_API_URL + endpoint,
|
||||
|
|
@ -41,7 +40,6 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
|||
};
|
||||
|
||||
root.getNetwork = function() {
|
||||
_setCredentials();
|
||||
return credentials.NETWORK;
|
||||
};
|
||||
|
||||
|
|
@ -68,10 +66,6 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
|||
return cb(err);
|
||||
});
|
||||
});
|
||||
|
||||
// TODO
|
||||
// Show pending task from the UI
|
||||
// storageService.setNextStep('AmazonGiftCards', 'true', function(err) {});
|
||||
};
|
||||
|
||||
root.getPendingGiftCards = function(cb) {
|
||||
|
|
@ -146,14 +140,26 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
|||
};
|
||||
|
||||
var register = function () {
|
||||
nextStepsService.register({
|
||||
name: 'amazon',
|
||||
title: 'Buy a gift card',
|
||||
icon: 'icon-amazon',
|
||||
sref: 'tabs.giftcards.amazon',
|
||||
storageService.getAmazonGiftCards(root.getNetwork(), function(err, giftCards) {
|
||||
if (giftCards) {
|
||||
homeIntegrationsService.register({
|
||||
name: 'amazon',
|
||||
title: 'Amazon Gift Cards',
|
||||
icon: 'icon-amazon',
|
||||
sref: 'tabs.giftcards.amazon',
|
||||
});
|
||||
} else {
|
||||
nextStepsService.register({
|
||||
name: 'amazon',
|
||||
title: 'Buy a gift card',
|
||||
icon: 'icon-amazon',
|
||||
sref: 'tabs.giftcards.amazon',
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
setCredentials();
|
||||
register();
|
||||
|
||||
return root;
|
||||
|
|
|
|||
|
|
@ -5,40 +5,41 @@ angular.module('copayApp.services').factory('buyAndSellService', function($log,
|
|||
var services = [];
|
||||
var linkedServices = [];
|
||||
|
||||
root.updateNextSteps = function() {
|
||||
root.update = function() {
|
||||
|
||||
var newLinked = lodash.filter(services, function(x) {
|
||||
return x.linked;
|
||||
});
|
||||
|
||||
|
||||
// This is to preserve linkedServices pointer
|
||||
while(linkedServices.length)
|
||||
while (linkedServices.length)
|
||||
linkedServices.pop();
|
||||
|
||||
while(newLinked.length)
|
||||
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);
|
||||
$log.debug('buyAndSell Service, updating nextSteps. linked/total: ' + linkedServices.length + '/' + services.length);
|
||||
|
||||
if (linkedServices.length == 0) {
|
||||
nextStepsService.register({
|
||||
name: 'Buy and Sell',
|
||||
title: 'Buy and Sell',
|
||||
name: 'buyandsell',
|
||||
icon: 'icon-buy-bitcoin',
|
||||
sref: 'tabs.buyandsell',
|
||||
});
|
||||
} else {
|
||||
nextStepsService.unregister({
|
||||
name: 'buyandsell',
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$timeout(function() {
|
||||
$ionicScrollDelegate.resize();
|
||||
}, 10);
|
||||
};
|
||||
|
||||
var updateNextStepsDebunced = lodash.debounce(root.updateNextSteps, 1000);
|
||||
var updateNextStepsDebunced = lodash.debounce(root.update, 1000);
|
||||
|
||||
root.register = function(serviceInfo) {
|
||||
services.push(serviceInfo);
|
||||
|
|
@ -46,6 +47,18 @@ console.log('[buyAndSellService.js.10:linkedServices:]',linkedServices); //TODO
|
|||
updateNextStepsDebunced();
|
||||
};
|
||||
|
||||
|
||||
root.updateLink = function(name, linked) {
|
||||
var service = lodash.find(services, function(x) {
|
||||
return x.name == name;
|
||||
});
|
||||
$log.info('Updating Buy and Sell service:' + name + ' linked:' + linked);
|
||||
service.linked = linked
|
||||
|
||||
root.update();
|
||||
};
|
||||
|
||||
|
||||
root.get = function() {
|
||||
return services;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
|||
if (data && data.access_token && data.refresh_token) {
|
||||
storageService.setCoinbaseToken(credentials.NETWORK, data.access_token, function() {
|
||||
storageService.setCoinbaseRefreshToken(credentials.NETWORK, data.refresh_token, function() {
|
||||
buyAndSellService.updateLink('coinbase', true);
|
||||
return cb(null, data.access_token);
|
||||
});
|
||||
});
|
||||
|
|
@ -712,6 +713,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
|||
|
||||
root.logout = function(cb) {
|
||||
storageService.removeCoinbaseToken(credentials.NETWORK, function() {
|
||||
buyAndSellService.updateLink('coinbase', false);
|
||||
storageService.removeCoinbaseRefreshToken(credentials.NETWORK, function() {
|
||||
storageService.removeCoinbaseTxs(credentials.NETWORK, function() {
|
||||
return cb();
|
||||
|
|
@ -726,9 +728,10 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
|||
if (err) return;
|
||||
|
||||
buyAndSellService.register({
|
||||
name: 'Coinbase',
|
||||
name: 'coinbase',
|
||||
logo: 'img/coinbase-logo.png',
|
||||
sref: 'tabs.buyandsell.coinbase',
|
||||
configSref: 'tabs.preferences.coinbase',
|
||||
linked: isActive,
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ 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') {
|
||||
|
|
@ -55,6 +55,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
|
||||
root.removeToken = function(cb) {
|
||||
storageService.removeGlideraToken(credentials.NETWORK, function() {
|
||||
buyAndSellService.updateLink('glidera', false);
|
||||
return cb();
|
||||
});
|
||||
};
|
||||
|
|
@ -299,6 +300,8 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
getToken(function(err, accessToken) {
|
||||
if (err || !accessToken) return cb();
|
||||
else {
|
||||
buyAndSellService.updateLink('glidera', true);
|
||||
|
||||
root.getAccessTokenPermissions(accessToken, function(err, p) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
|
|
@ -319,13 +322,13 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
storageService.getGlideraToken(credentials.NETWORK, function(err, token) {
|
||||
if (err) return cb(err);
|
||||
|
||||
console.log('[glideraService.js.326:token:]',token); //TODO
|
||||
buyAndSellService.register({
|
||||
name: 'Glidera',
|
||||
buyAndSellService.register({
|
||||
name: 'glidera',
|
||||
logo: 'img/glidera-logo.png',
|
||||
sref: 'tabs.buyandsell.glidera',
|
||||
configSref: 'tabs.preferences.glidera',
|
||||
linked: !!token,
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
23
src/js/services/homeIntegrations.js
Normal file
23
src/js/services/homeIntegrations.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.services').factory('', function(configService, $log) {
|
||||
var root = {};
|
||||
var services = [];
|
||||
|
||||
root.register = function(serviceInfo) {
|
||||
$log.info('Adding homeIntegration 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;
|
||||
|
||||
});
|
||||
23
src/js/services/homeIntegrationsService.js
Normal file
23
src/js/services/homeIntegrationsService.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.services').factory('homeIntegrationsService', function(configService, $log) {
|
||||
var root = {};
|
||||
var services = [];
|
||||
|
||||
root.register = function(serviceInfo) {
|
||||
$log.info('Adding home Integrations 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;
|
||||
|
||||
});
|
||||
|
|
@ -1,33 +1,32 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.services').factory('nextStepsService', function(configService, $log) {
|
||||
angular.module('copayApp.services').factory('nextStepsService', function(configService, $log, lodash) {
|
||||
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);
|
||||
};
|
||||
|
||||
if (!lodash.find(services, function(x) {
|
||||
return x.name == serviceInfo.name;
|
||||
})) {
|
||||
services.push(serviceInfo);
|
||||
}
|
||||
};
|
||||
|
||||
root.unregister = function(serviceName) {
|
||||
services = lodash.filter(services, function(x) {
|
||||
return x.name != serviceName
|
||||
});
|
||||
};
|
||||
console.log('[nextStepsService.js.16:serviceName:] UNR',serviceName); //TODO
|
||||
var newS = lodash.filter(services, function(x) {
|
||||
return x.name!=serviceName;
|
||||
});
|
||||
|
||||
// This is to preserve services pointer
|
||||
while(services.length)
|
||||
services.pop();
|
||||
|
||||
while(newS.length)
|
||||
services.push(newS.pop());
|
||||
console.log('[nextStepsService.js.26:services:]',services); //TODO
|
||||
};
|
||||
|
||||
root.get = function() {
|
||||
return services;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue