diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 1332287b6..3a56e6d5c 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, startupService, addressbookService, feedbackService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) { + function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, startupService, addressbookService, feedbackService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) { var wallet; var listeners = []; var notifications = []; @@ -16,9 +16,19 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.isNW = platformInfo.isNW; $scope.showRateCard = {}; $scope.showServices = false; + $scope.bannerIsLoading = true; + $scope.bannerImageUrl = ''; + $scope.bannerUrl = ''; + $scope.$on("$ionicView.afterEnter", function() { startupService.ready(); + + bannerService.getBanner(function (banner) { + $scope.bannerImageUrl = banner.imageURL; + $scope.bannerUrl = banner.url; + $scope.bannerIsLoading = false; + }); }); $scope.$on("$ionicView.beforeEnter", function(event, data) { @@ -155,8 +165,8 @@ angular.module('copayApp.controllers').controller('tabHomeController', externalLinkService.open(url, optIn, title, message, okText, cancelText); }; - $scope.openStore = function() { - externalLinkService.open('https://store.bitcoin.com/', false); + $scope.openBannerUrl = function() { + externalLinkService.open($scope.bannerUrl, false); }; $scope.openNotificationModal = function(n) { diff --git a/src/js/services/bannerService.js b/src/js/services/bannerService.js new file mode 100644 index 000000000..d48d8861e --- /dev/null +++ b/src/js/services/bannerService.js @@ -0,0 +1,78 @@ +'use strict'; +angular.module('copayApp.services').factory('bannerService', function ($http, $log) { + // Export + var root = {}; + + // Constant + var API_URL = 'https://bwscash.bitcoin.com/bws/api/v1/marketing'; + + // Variable + var hasFetched = false; + var banners = []; + var defaultBanner = { + id: 'default-banner', + imageURL: 'img/banner-store.png', + url: 'https://store.bitcoin.com/', + isLocal: true + }; + + // Private methods + var fetchSettings = function (cb) { + var req = { + method: 'GET', + url: API_URL+'/settings', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }; + $http(req).then(function (response) { + $log.info('Get banner settings: SUCCESS'); + banners = response.data; + return cb(true); + }, function (error) { + $log.error('Get banner settings: ERROR ' + error.statusText); + return cb(false); + }); + }; + + root.getBanner = function (cb) { + + // If not fetch get the banner + if (!hasFetched) { + hasFetched = true; + + // If never fetch, lets fetch + fetchSettings(function (isSuccess) { + root.getBanner(cb); + }); + + // If fetch, and got banners, lets have a look + } else if (banners.length > 0) { + var selectedBanners = []; + for(var i in banners) { + var banner = banners[i]; + + // Generate the URL for the banner + var fileName = banner.image.substring(0, banner.image.lastIndexOf('.')); + var extension = banner.image.substring(banner.image.lastIndexOf('.')+1); + banner.imageURL = API_URL +'/banners/'+fileName+"/"+extension; + + // Add the banner + selectedBanners.push(banners[i]); + } + + // If no banner activated, return the default one + if (selectedBanners.length == 0) { + return cb(defaultBanner); + } else { + return cb(selectedBanners[Math.floor(Math.random()*banners.length)]); + } + + } else { + return cb(defaultBanner); + } + }; + + return root; +}); \ No newline at end of file diff --git a/src/sass/views/tab-home.scss b/src/sass/views/tab-home.scss index 46fb15224..66a2f1d58 100644 --- a/src/sass/views/tab-home.scss +++ b/src/sass/views/tab-home.scss @@ -59,6 +59,9 @@ } } &-banner { + svg { + margin: 40px auto 40px; + } padding: 0; &__img { width: 100%; diff --git a/www/views/tab-home.html b/www/views/tab-home.html index 1ac17a0f6..4d494e9ec 100644 --- a/www/views/tab-home.html +++ b/www/views/tab-home.html @@ -91,9 +91,11 @@
- - + + + +