Merge pull request #207 from Bitcoin-com/wallet/task/412
Wallet/task/412
This commit is contained in:
commit
c033f39628
4 changed files with 98 additions and 5 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
78
src/js/services/bannerService.js
Normal file
78
src/js/services/bannerService.js
Normal file
|
|
@ -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;
|
||||
});
|
||||
|
|
@ -59,6 +59,9 @@
|
|||
}
|
||||
}
|
||||
&-banner {
|
||||
svg {
|
||||
margin: 40px auto 40px;
|
||||
}
|
||||
padding: 0;
|
||||
&__img {
|
||||
width: 100%;
|
||||
|
|
|
|||
|
|
@ -91,9 +91,11 @@
|
|||
<div class="ng-hide list card" ng-show="showServices && (walletsBch[0] || walletsBtc[0])" ng-include="'views/includes/services.html'"></div>
|
||||
|
||||
<div class="list card card-banner">
|
||||
<a ng-click="openStore()">
|
||||
<img class="card-banner__img" src="img/banner-store.png"/>
|
||||
<ion-spinner ng-if="bannerIsLoading"></ion-spinner>
|
||||
<a ng-if="!bannerIsLoading" ng-click="openBannerUrl()">
|
||||
<img class="card-banner__img" ng-src="{{bannerImageUrl}}"/>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="ng-hide list card" ng-show="nextStepsItems.length>0 && !isWindowsPhoneApp" ng-include="'views/includes/community.html'"></div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue