fix refresh in home / settings

This commit is contained in:
Matias Alejo Garcia 2017-01-30 19:38:52 -03:00
commit 5357ba7fcd
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
14 changed files with 150 additions and 96 deletions

View 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);
};
});

View file

@ -16,7 +16,6 @@ angular.module('copayApp.controllers').controller('preferencesCoinbaseController
}; };
$scope.$on("$ionicView.enter", function(event, data){ $scope.$on("$ionicView.enter", function(event, data){
coinbaseService.setCredentials();
ongoingProcess.set('connectingCoinbase', true); ongoingProcess.set('connectingCoinbase', true);
coinbaseService.init(function(err, data) { coinbaseService.init(function(err, data) {
if (err || lodash.isEmpty(data)) { if (err || lodash.isEmpty(data)) {

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('tabHomeController', 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 wallet;
var listeners = []; var listeners = [];
var notifications = []; var notifications = [];
@ -96,8 +96,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
$scope.nextStepsItems = nextStepsService.get(); $scope.nextStepsItems = nextStepsService.get();
$scope.buyAndSellItems = buyAndSellService.getLinked(); $scope.buyAndSellItems = buyAndSellService.getLinked();
$scope.homeIntegrations = homeIntegrationsService.get();
console.log('[tab-home.js.99]', $scope.buyAndSellItems); //TODO
configService.whenAvailable(function() { configService.whenAvailable(function() {
var config = configService.getSync(); var config = configService.getSync();

View file

@ -1,6 +1,6 @@
'use strict'; '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 updateConfig = function() {
var isCordova = platformInfo.isCordova; var isCordova = platformInfo.isCordova;
@ -16,6 +16,7 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
$scope.currentFeeLevel = feeService.getCurrentFeeLevel(); $scope.currentFeeLevel = feeService.getCurrentFeeLevel();
$scope.wallets = profileService.getWallets(); $scope.wallets = profileService.getWallets();
$scope.buyAndSellServices = buyAndSellService.getLinked();
configService.whenAvailable(function(config) { configService.whenAvailable(function(config) {
$scope.unitName = config.wallet.settings.unitName; $scope.unitName = config.wallet.settings.unitName;
@ -25,8 +26,6 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
}; };
$scope.bitpayCardEnabled = config.bitpayCard.enabled; $scope.bitpayCardEnabled = config.bitpayCard.enabled;
$scope.glideraEnabled = config.glidera.enabled && !isWindowsPhoneApp;
$scope.coinbaseEnabled = config.coinbaseV2 && !isWindowsPhoneApp;
if ($scope.bitpayCardEnabled) { if ($scope.bitpayCardEnabled) {
bitpayCardService.getCards(function(err, cards) { 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;
});
}
}); });
}; };

View file

@ -1,14 +1,15 @@
'use strict'; '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 root = {};
var credentials = {}; var credentials = {};
var _setCredentials = function() { var setCredentials = function() {
/* /*
* Development: 'testnet' * Development: 'testnet'
* Production: 'livenet' * Production: 'livenet'
*/ */
credentials.NETWORK = 'livenet'; //credentials.NETWORK = 'livenet';
credentials.NETWORK = 'testnet';
if (credentials.NETWORK == 'testnet') { if (credentials.NETWORK == 'testnet') {
credentials.BITPAY_API_URL = "https://test.bitpay.com"; 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) { var _getBitPay = function(endpoint) {
_setCredentials();
return { return {
method: 'GET', method: 'GET',
url: credentials.BITPAY_API_URL + endpoint, url: credentials.BITPAY_API_URL + endpoint,
@ -29,7 +29,6 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
}; };
var _postBitPay = function(endpoint, data) { var _postBitPay = function(endpoint, data) {
_setCredentials();
return { return {
method: 'POST', method: 'POST',
url: credentials.BITPAY_API_URL + endpoint, url: credentials.BITPAY_API_URL + endpoint,
@ -41,7 +40,6 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
}; };
root.getNetwork = function() { root.getNetwork = function() {
_setCredentials();
return credentials.NETWORK; return credentials.NETWORK;
}; };
@ -68,10 +66,6 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
return cb(err); return cb(err);
}); });
}); });
// TODO
// Show pending task from the UI
// storageService.setNextStep('AmazonGiftCards', 'true', function(err) {});
}; };
root.getPendingGiftCards = function(cb) { root.getPendingGiftCards = function(cb) {
@ -146,14 +140,26 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
}; };
var register = function () { var register = function () {
nextStepsService.register({ storageService.getAmazonGiftCards(root.getNetwork(), function(err, giftCards) {
name: 'amazon', if (giftCards) {
title: 'Buy a gift card', homeIntegrationsService.register({
icon: 'icon-amazon', name: 'amazon',
sref: 'tabs.giftcards.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(); register();
return root; return root;

View file

@ -5,40 +5,41 @@ angular.module('copayApp.services').factory('buyAndSellService', function($log,
var services = []; var services = [];
var linkedServices = []; var linkedServices = [];
root.updateNextSteps = function() { root.update = function() {
var newLinked = lodash.filter(services, function(x) { var newLinked = lodash.filter(services, function(x) {
return x.linked; return x.linked;
}); });
// This is to preserve linkedServices pointer // This is to preserve linkedServices pointer
while(linkedServices.length) while (linkedServices.length)
linkedServices.pop(); linkedServices.pop();
while(newLinked.length) while (newLinked.length)
linkedServices.push(newLinked.pop()); 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) { if (linkedServices.length == 0) {
nextStepsService.register({ nextStepsService.register({
name: 'Buy and Sell', title: 'Buy and Sell',
name: 'buyandsell',
icon: 'icon-buy-bitcoin', icon: 'icon-buy-bitcoin',
sref: 'tabs.buyandsell', sref: 'tabs.buyandsell',
}); });
} else {
nextStepsService.unregister({
name: 'buyandsell',
});
}; };
$timeout(function() { $timeout(function() {
$ionicScrollDelegate.resize(); $ionicScrollDelegate.resize();
}, 10); }, 10);
}; };
var updateNextStepsDebunced = lodash.debounce(root.updateNextSteps, 1000); var updateNextStepsDebunced = lodash.debounce(root.update, 1000);
root.register = function(serviceInfo) { root.register = function(serviceInfo) {
services.push(serviceInfo); services.push(serviceInfo);
@ -46,6 +47,18 @@ console.log('[buyAndSellService.js.10:linkedServices:]',linkedServices); //TODO
updateNextStepsDebunced(); 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() { root.get = function() {
return services; return services;
}; };

View file

@ -79,6 +79,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
if (data && data.access_token && data.refresh_token) { if (data && data.access_token && data.refresh_token) {
storageService.setCoinbaseToken(credentials.NETWORK, data.access_token, function() { storageService.setCoinbaseToken(credentials.NETWORK, data.access_token, function() {
storageService.setCoinbaseRefreshToken(credentials.NETWORK, data.refresh_token, function() { storageService.setCoinbaseRefreshToken(credentials.NETWORK, data.refresh_token, function() {
buyAndSellService.updateLink('coinbase', true);
return cb(null, data.access_token); return cb(null, data.access_token);
}); });
}); });
@ -712,6 +713,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
root.logout = function(cb) { root.logout = function(cb) {
storageService.removeCoinbaseToken(credentials.NETWORK, function() { storageService.removeCoinbaseToken(credentials.NETWORK, function() {
buyAndSellService.updateLink('coinbase', false);
storageService.removeCoinbaseRefreshToken(credentials.NETWORK, function() { storageService.removeCoinbaseRefreshToken(credentials.NETWORK, function() {
storageService.removeCoinbaseTxs(credentials.NETWORK, function() { storageService.removeCoinbaseTxs(credentials.NETWORK, function() {
return cb(); return cb();
@ -726,9 +728,10 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
if (err) return; if (err) return;
buyAndSellService.register({ buyAndSellService.register({
name: 'Coinbase', name: 'coinbase',
logo: 'img/coinbase-logo.png', logo: 'img/coinbase-logo.png',
sref: 'tabs.buyandsell.coinbase', sref: 'tabs.buyandsell.coinbase',
configSref: 'tabs.preferences.coinbase',
linked: isActive, linked: isActive,
}); });
}); });

View file

@ -17,7 +17,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
* Development: 'testnet' * Development: 'testnet'
* Production: 'livenet' * Production: 'livenet'
*/ */
// credentials.NETWORK = 'livenet'; // credentials.NETWORK = 'livenet';
credentials.NETWORK = 'testnet'; credentials.NETWORK = 'testnet';
if (credentials.NETWORK == 'testnet') { if (credentials.NETWORK == 'testnet') {
@ -55,6 +55,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
root.removeToken = function(cb) { root.removeToken = function(cb) {
storageService.removeGlideraToken(credentials.NETWORK, function() { storageService.removeGlideraToken(credentials.NETWORK, function() {
buyAndSellService.updateLink('glidera', false);
return cb(); return cb();
}); });
}; };
@ -299,6 +300,8 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
getToken(function(err, accessToken) { getToken(function(err, accessToken) {
if (err || !accessToken) return cb(); if (err || !accessToken) return cb();
else { else {
buyAndSellService.updateLink('glidera', true);
root.getAccessTokenPermissions(accessToken, function(err, p) { root.getAccessTokenPermissions(accessToken, function(err, p) {
if (err) { if (err) {
return cb(err); return cb(err);
@ -319,13 +322,13 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
storageService.getGlideraToken(credentials.NETWORK, function(err, token) { storageService.getGlideraToken(credentials.NETWORK, function(err, token) {
if (err) return cb(err); if (err) return cb(err);
console.log('[glideraService.js.326:token:]',token); //TODO buyAndSellService.register({
buyAndSellService.register({ name: 'glidera',
name: 'Glidera',
logo: 'img/glidera-logo.png', logo: 'img/glidera-logo.png',
sref: 'tabs.buyandsell.glidera', sref: 'tabs.buyandsell.glidera',
configSref: 'tabs.preferences.glidera',
linked: !!token, linked: !!token,
}); });
}); });
}; };

View 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;
});

View 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;
});

View file

@ -1,33 +1,32 @@
'use strict'; 'use strict';
angular.module('copayApp.services').factory('nextStepsService', function(configService, $log) { angular.module('copayApp.services').factory('nextStepsService', function(configService, $log, lodash) {
var root = {}; 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 = []; var services = [];
root.register = function(serviceInfo) { root.register = function(serviceInfo) {
$log.info('Adding NextSteps entry:' + serviceInfo.name); $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) { root.unregister = function(serviceName) {
services = lodash.filter(services, function(x) { console.log('[nextStepsService.js.16:serviceName:] UNR',serviceName); //TODO
return x.name != serviceName 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() { root.get = function() {
return services; return services;

View file

@ -25,4 +25,5 @@
<!-- <span translate>Add BitPay Visa&#38;reg; Card</span> --> <!-- <span translate>Add BitPay Visa&#38;reg; Card</span> -->
<!-- <i class="icon bp&#45;arrow&#45;right"></i> --> <!-- <i class="icon bp&#45;arrow&#45;right"></i> -->
<!-- </a> --> <!-- </a> -->
<!-- </a> -->

View file

@ -117,17 +117,7 @@
<div class="ng-hide" ng-show="wallets[0] && buyAndSellItems.length>0" ng-include="'views/includes/buyAndSellCard.html'"></div> <div class="ng-hide" ng-show="wallets[0] && buyAndSellItems.length>0" ng-include="'views/includes/buyAndSellCard.html'"></div>
<div class="ng-hide" ng-show="homeIntegrations.length>0" ng-include="'views/includes/homeIntegrations.html'"></div>
<div class="list card" ng-if="externalServices.AmazonGiftCards && amazonEnabled">
<a class="item item-sub item-icon-left item-icon-right item-big-icon-left" ui-sref="tabs.giftcards.amazon">
<i class="icon big-icon-svg">
<div class="bg icon-amazon"></div>
</i>
<span>Amazon.com Gift Cards</span>
<i class="icon bp-arrow-right"></i>
</a>
</div>
<div class="ng-hide" ng-show="nextStepsItems.length>0" ng-include="'views/includes/nextSteps.html'"></div> <div class="ng-hide" ng-show="nextStepsItems.length>0" ng-include="'views/includes/nextSteps.html'"></div>
</ion-content> </ion-content>

View file

@ -126,19 +126,13 @@
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
</a> </a>
<a class="item item-icon-right" <div ng-repeat="service in buyAndSellServices">
ng-if="glideraEnabled && glideraToken" <a class="item item-icon-right"
ui-sref="tabs.preferences.glidera"> ui-sref="{{service.configSref}}">
<img src="img/glidera-logo.png" width="90"/> <img ng-src="{{service.logo}}" width="90">
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
</a> </a>
</div>
<a class="item item-icon-right"
ng-if="coinbaseEnabled && coinbaseToken"
ui-sref="tabs.preferences.coinbase">
<img src="img/coinbase-logo.png" width="90"/>
<i class="icon bp-arrow-right"></i>
</a>
<div class="item item-divider"></div> <div class="item item-divider"></div>