mirror of https://github.com/BTCPrivate/copay.git
buyAndSell services + nextSteps
This commit is contained in:
parent
19b3d9bb15
commit
d85da2cc45
|
@ -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);
|
||||||
|
};
|
||||||
|
});
|
|
@ -1,14 +1,11 @@
|
||||||
'use strict';
|
'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) {
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||||
configService.whenAvailable(function(config) {
|
$scope.services = buyAndSellService.get();
|
||||||
$scope.isCoinbaseEnabled = config.coinbaseV2;
|
|
||||||
$scope.isGlideraEnabled = config.glidera.enabled;
|
|
||||||
|
|
||||||
if (!$scope.isCoinbaseEnabled && !$scope.isGlideraEnabled)
|
if (lodash.isEmpty($scope.services))
|
||||||
$ionicHistory.goBack();
|
$ionicHistory.goBack();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
|
@ -112,7 +112,6 @@ angular.module('copayApp.controllers').controller('coinbaseController', function
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||||
coinbaseService.setCredentials();
|
|
||||||
if (data.stateParams && data.stateParams.code) {
|
if (data.stateParams && data.stateParams.code) {
|
||||||
coinbaseService.getStoredToken(function(at) {
|
coinbaseService.getStoredToken(function(at) {
|
||||||
if (!at) self.submitOauthCode(data.stateParams.code);
|
if (!at) self.submitOauthCode(data.stateParams.code);
|
||||||
|
|
|
@ -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);
|
||||||
|
};
|
||||||
|
|
||||||
|
});
|
|
@ -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, 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 wallet;
|
||||||
var listeners = [];
|
var listeners = [];
|
||||||
var notifications = [];
|
var notifications = [];
|
||||||
|
@ -83,10 +83,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
var wallet = profileService.getWallet(walletId);
|
var wallet = profileService.getWallet(walletId);
|
||||||
updateWallet(wallet);
|
updateWallet(wallet);
|
||||||
if ($scope.recentTransactionsEnabled) getNotifications();
|
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) {
|
$rootScope.$on('Local/TxAction', function(e, walletId) {
|
||||||
$log.debug('Got action for wallet ' + walletId);
|
$log.debug('Got action for wallet ' + walletId);
|
||||||
|
@ -96,23 +93,15 @@ 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() {
|
configService.whenAvailable(function() {
|
||||||
nextStep(function() {
|
|
||||||
var config = configService.getSync();
|
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 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;
|
$scope.recentTransactionsEnabled = config.recentTransactions.enabled;
|
||||||
|
|
||||||
if ($scope.recentTransactionsEnabled) getNotifications();
|
if ($scope.recentTransactionsEnabled) getNotifications();
|
||||||
|
|
||||||
if ($scope.bitpayCardEnabled) bitpayCardCache();
|
if ($scope.bitpayCardEnabled) bitpayCardCache();
|
||||||
|
@ -122,7 +111,6 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
}, 10);
|
}, 10);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
$scope.$on("$ionicView.leave", function(event, data) {
|
$scope.$on("$ionicView.leave", function(event, data) {
|
||||||
lodash.each(listeners, function(x) {
|
lodash.each(listeners, function(x) {
|
||||||
|
@ -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() {
|
var bitpayCardCache = function() {
|
||||||
bitpayCardService.getCards(function(err, data) {
|
bitpayCardService.getCards(function(err, data) {
|
||||||
if (err) return;
|
if (err) return;
|
||||||
|
|
|
@ -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();
|
uxLanguage.init();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
'use strict';
|
'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 root = {};
|
||||||
var credentials = {};
|
var credentials = {};
|
||||||
|
|
||||||
|
@ -69,8 +69,9 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO
|
||||||
// Show pending task from the UI
|
// Show pending task from the UI
|
||||||
storageService.setNextStep('AmazonGiftCards', 'true', function(err) {});
|
// storageService.setNextStep('AmazonGiftCards', 'true', function(err) {});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getPendingGiftCards = function(cb) {
|
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;
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
});
|
|
@ -1,37 +1,32 @@
|
||||||
'use strict';
|
'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 root = {};
|
||||||
var credentials = {};
|
var credentials = {};
|
||||||
var isCordova = platformInfo.isCordova;
|
var isCordova = platformInfo.isCordova;
|
||||||
var isNW = platformInfo.isNW;
|
var isNW = platformInfo.isNW;
|
||||||
|
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
|
||||||
|
|
||||||
root.priceSensitivity = [
|
root.priceSensitivity = [{
|
||||||
{
|
|
||||||
value: 0.5,
|
value: 0.5,
|
||||||
name: '0.5%'
|
name: '0.5%'
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
value: 1,
|
value: 1,
|
||||||
name: '1%'
|
name: '1%'
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
value: 2,
|
value: 2,
|
||||||
name: '2%'
|
name: '2%'
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
value: 5,
|
value: 5,
|
||||||
name: '5%'
|
name: '5%'
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
value: 10,
|
value: 10,
|
||||||
name: '10%'
|
name: '10%'
|
||||||
}
|
}];
|
||||||
];
|
|
||||||
|
|
||||||
root.selectedPriceSensitivity = root.priceSensitivity[1];
|
root.selectedPriceSensitivity = root.priceSensitivity[1];
|
||||||
|
|
||||||
root.setCredentials = function() {
|
var setCredentials = function() {
|
||||||
|
|
||||||
if (!$window.externalServices || !$window.externalServices.coinbase) {
|
if (!$window.externalServices || !$window.externalServices.coinbase) {
|
||||||
return;
|
return;
|
||||||
|
@ -46,19 +41,19 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
||||||
credentials.NETWORK = 'livenet';
|
credentials.NETWORK = 'livenet';
|
||||||
|
|
||||||
// Coinbase permissions
|
// Coinbase permissions
|
||||||
credentials.SCOPE = ''
|
credentials.SCOPE = '' +
|
||||||
+ 'wallet:accounts:read,'
|
'wallet:accounts:read,' +
|
||||||
+ 'wallet:addresses:read,'
|
'wallet:addresses:read,' +
|
||||||
+ 'wallet:addresses:create,'
|
'wallet:addresses:create,' +
|
||||||
+ 'wallet:user:read,'
|
'wallet:user:read,' +
|
||||||
+ 'wallet:user:email,'
|
'wallet:user:email,' +
|
||||||
+ 'wallet:buys:read,'
|
'wallet:buys:read,' +
|
||||||
+ 'wallet:buys:create,'
|
'wallet:buys:create,' +
|
||||||
+ 'wallet:sells:read,'
|
'wallet:sells:read,' +
|
||||||
+ 'wallet:sells:create,'
|
'wallet:sells:create,' +
|
||||||
+ 'wallet:transactions:read,'
|
'wallet:transactions:read,' +
|
||||||
+ 'wallet:transactions:send,'
|
'wallet:transactions:send,' +
|
||||||
+ 'wallet:payment-methods:read';
|
'wallet:payment-methods:read';
|
||||||
|
|
||||||
// NW has a bug with Window Object
|
// NW has a bug with Window Object
|
||||||
if (isCordova) {
|
if (isCordova) {
|
||||||
|
@ -72,8 +67,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
||||||
credentials.API = coinbase.sandbox.api;
|
credentials.API = coinbase.sandbox.api;
|
||||||
credentials.CLIENT_ID = coinbase.sandbox.client_id;
|
credentials.CLIENT_ID = coinbase.sandbox.client_id;
|
||||||
credentials.CLIENT_SECRET = coinbase.sandbox.client_secret;
|
credentials.CLIENT_SECRET = coinbase.sandbox.client_secret;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
credentials.HOST = coinbase.production.host;
|
credentials.HOST = coinbase.production.host;
|
||||||
credentials.API = coinbase.production.api;
|
credentials.API = coinbase.production.api;
|
||||||
credentials.CLIENT_ID = coinbase.production.client_id;
|
credentials.CLIENT_ID = coinbase.production.client_id;
|
||||||
|
@ -133,14 +127,14 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getOauthCodeUrl = function() {
|
root.getOauthCodeUrl = function() {
|
||||||
return credentials.HOST
|
return credentials.HOST +
|
||||||
+ '/oauth/authorize?response_type=code&client_id='
|
'/oauth/authorize?response_type=code&client_id=' +
|
||||||
+ credentials.CLIENT_ID
|
credentials.CLIENT_ID +
|
||||||
+ '&redirect_uri='
|
'&redirect_uri=' +
|
||||||
+ credentials.REDIRECT_URI
|
credentials.REDIRECT_URI +
|
||||||
+ '&state=SECURE_RANDOM&scope='
|
'&state=SECURE_RANDOM&scope=' +
|
||||||
+ credentials.SCOPE
|
credentials.SCOPE +
|
||||||
+ '&meta[send_limit_amount]=1000&meta[send_limit_currency]=USD&meta[send_limit_period]=day';
|
'&meta[send_limit_amount]=1000&meta[send_limit_currency]=USD&meta[send_limit_period]=day';
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getToken = function(code, cb) {
|
root.getToken = function(code, cb) {
|
||||||
|
@ -163,7 +157,6 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
||||||
$http(req).then(function(data) {
|
$http(req).then(function(data) {
|
||||||
$log.info('Coinbase Authorization Access Token: SUCCESS');
|
$log.info('Coinbase Authorization Access Token: SUCCESS');
|
||||||
// Show pending task from the UI
|
// Show pending task from the UI
|
||||||
storageService.setNextStep('BuyAndSell', 'true', function(err) {});
|
|
||||||
_afterTokenReceived(data.data, cb);
|
_afterTokenReceived(data.data, cb);
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
$log.error('Coinbase Authorization Access Token: ERROR ' + data.statusText);
|
$log.error('Coinbase Authorization Access Token: ERROR ' + data.statusText);
|
||||||
|
@ -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) {
|
root.init = lodash.throttle(function(cb) {
|
||||||
if (lodash.isEmpty(credentials.CLIENT_ID)) {
|
if (lodash.isEmpty(credentials.CLIENT_ID)) {
|
||||||
return cb('Coinbase is Disabled');
|
return cb('Coinbase is Disabled');
|
||||||
|
@ -230,7 +236,10 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
_getMainAccountId(newToken, function(err, accountId) {
|
_getMainAccountId(newToken, function(err, accountId) {
|
||||||
if (err) return cb(err);
|
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);
|
return cb(err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return cb(null, {accessToken: accessToken, accountId: accountId});
|
return cb(null, {
|
||||||
|
accessToken: accessToken,
|
||||||
|
accountId: accountId
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -591,8 +603,9 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
||||||
|
|
||||||
root.updatePendingTransactions = lodash.throttle(function() {
|
root.updatePendingTransactions = lodash.throttle(function() {
|
||||||
$log.debug('Updating pending transactions...');
|
$log.debug('Updating pending transactions...');
|
||||||
root.setCredentials();
|
var pendingTransactions = {
|
||||||
var pendingTransactions = { data: {} };
|
data: {}
|
||||||
|
};
|
||||||
root.getPendingTransactions(pendingTransactions);
|
root.getPendingTransactions(pendingTransactions);
|
||||||
}, 20000);
|
}, 20000);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
'use strict';
|
'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 root = {};
|
||||||
var credentials = {};
|
var credentials = {};
|
||||||
var isCordova = platformInfo.isCordova;
|
var isCordova = platformInfo.isCordova;
|
||||||
|
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
|
||||||
|
|
||||||
var _setCredentials = function() {
|
var setCredentials = function() {
|
||||||
if (!$window.externalServices || !$window.externalServices.glidera) {
|
if (!$window.externalServices || !$window.externalServices.glidera) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +17,8 @@ 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';
|
||||||
|
|
||||||
if (credentials.NETWORK == 'testnet') {
|
if (credentials.NETWORK == 'testnet') {
|
||||||
credentials.HOST = glidera.sandbox.host;
|
credentials.HOST = glidera.sandbox.host;
|
||||||
|
@ -44,24 +46,20 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getEnvironment = function() {
|
root.getEnvironment = function() {
|
||||||
_setCredentials();
|
|
||||||
return credentials.NETWORK;
|
return credentials.NETWORK;
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getOauthCodeUrl = function() {
|
root.getOauthCodeUrl = function() {
|
||||||
_setCredentials();
|
|
||||||
return credentials.HOST + '/oauth2/auth?response_type=code&client_id=' + credentials.CLIENT_ID + '&redirect_uri=' + credentials.REDIRECT_URI;
|
return credentials.HOST + '/oauth2/auth?response_type=code&client_id=' + credentials.CLIENT_ID + '&redirect_uri=' + credentials.REDIRECT_URI;
|
||||||
};
|
};
|
||||||
|
|
||||||
root.removeToken = function(cb) {
|
root.removeToken = function(cb) {
|
||||||
_setCredentials();
|
|
||||||
storageService.removeGlideraToken(credentials.NETWORK, function() {
|
storageService.removeGlideraToken(credentials.NETWORK, function() {
|
||||||
return cb();
|
return cb();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getToken = function(code, cb) {
|
root.getToken = function(code, cb) {
|
||||||
_setCredentials();
|
|
||||||
var req = {
|
var req = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: credentials.HOST + '/api/v1/oauth/token',
|
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) {
|
var _get = function(endpoint, token) {
|
||||||
_setCredentials();
|
|
||||||
return {
|
return {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: credentials.HOST + '/api/v1' + endpoint,
|
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) {
|
var _post = function(endpoint, token, twoFaCode, data) {
|
||||||
_setCredentials();
|
|
||||||
return {
|
return {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: credentials.HOST + '/api/v1' + endpoint,
|
url: credentials.HOST + '/api/v1' + endpoint,
|
||||||
|
@ -285,7 +281,6 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
||||||
};
|
};
|
||||||
|
|
||||||
root.init = function(accessToken, cb) {
|
root.init = function(accessToken, cb) {
|
||||||
_setCredentials();
|
|
||||||
$log.debug('Init Glidera...');
|
$log.debug('Init Glidera...');
|
||||||
|
|
||||||
var 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;
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
});
|
|
@ -7,13 +7,9 @@
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<div class="list">
|
<div class="list">
|
||||||
<div class="item item-divider"></div>
|
<div class="item item-divider"></div>
|
||||||
|
<div ng-repeat="service in services">
|
||||||
<div class="item item-icon-right" ui-sref="tabs.buyandsell.coinbase" ng-show="isCoinbaseEnabled">
|
<div class="item item-icon-right" ui-sref="{{service.sref}}">
|
||||||
<img src="img/coinbase-logo.png" width="90">
|
<img ng-src="{{service.logo}}" width="90">
|
||||||
<i class="icon bp-arrow-right"></i>
|
|
||||||
</div>
|
|
||||||
<div class="item item-icon-right" ui-sref="tabs.buyandsell.glidera" ng-show="isGlideraEnabled">
|
|
||||||
<img src="img/glidera-logo.png" width="90">
|
|
||||||
<i class="icon bp-arrow-right"></i>
|
<i class="icon bp-arrow-right"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
<div class="list card" ng-controller="buyAndSellCardController">
|
||||||
|
<div class="item item-sub item-icon-right item-heading">
|
||||||
|
<span translate>Buy & Sell Bitcoin</span>
|
||||||
|
<a ui-sref="tabs.buyandsell"><i class="icon ion-ios-plus-empty list-add-button"></i></a>
|
||||||
|
</div>
|
||||||
|
<div ng-repeat="service in services">
|
||||||
|
<a ui-sref="{{service.sref}}" class="item item-extra-padding item-sub item-icon-right">
|
||||||
|
<img ng-src="{{service.logo}}" width="90">
|
||||||
|
<i class="icon bp-arrow-right"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -0,0 +1,28 @@
|
||||||
|
<div class="list card" ng-controller="nextStepsController">
|
||||||
|
<div class="item item-icon-right item-heading" ng-click="toggle()" >
|
||||||
|
<span translate>Next steps</span>
|
||||||
|
<i class="icon bp-arrow-up" ng-show="!hide"></i>
|
||||||
|
<i class="icon bp-arrow-down" ng-show="hide"></i>
|
||||||
|
</div>
|
||||||
|
<div ng-show="!hide">
|
||||||
|
<div ng-repeat="service in services">
|
||||||
|
<a ui-sref="{{service.sref}}" class="item item-sub item-icon-left item-big-icon-left item-icon-right next-step">
|
||||||
|
<i class="icon big-icon-svg">
|
||||||
|
<div class="bg {{service.icon}}"></div>
|
||||||
|
</i>
|
||||||
|
<span>{{service.title || service.name}}</span>
|
||||||
|
<i class="icon bp-arrow-right"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
|
<!-- <a ui-sref="tabs.bitpayCardIntro" ng-if="!externalServices.BitpayCard && bitpayCardEnabled" class="item item-sub item-icon-left item-big-icon-left item-icon-right next-step"> -->
|
||||||
|
<!-- <i class="icon big-icon-svg"> -->
|
||||||
|
<!-- <div class="bg icon-bitpay-card"></div> -->
|
||||||
|
<!-- </i> -->
|
||||||
|
<!-- <span translate>Add BitPay Visa&reg; Card</span> -->
|
||||||
|
<!-- <i class="icon bp-arrow-right"></i> -->
|
||||||
|
<!-- </a> -->
|
||||||
|
|
|
@ -115,24 +115,10 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="list card" ng-if="wallets[0] && externalServices.BuyAndSell && (glideraEnabled || coinbaseEnabled)">
|
|
||||||
<div class="item item-sub item-icon-right item-heading">
|
|
||||||
<span translate>Buy & Sell Bitcoin</span>
|
|
||||||
<a ui-sref="tabs.buyandsell"><i class="icon ion-ios-plus-empty list-add-button"></i></a>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<a ng-if="glideraEnabled" ui-sref="tabs.buyandsell.glidera" class="item item-extra-padding item-sub item-icon-right">
|
|
||||||
<img src="img/glidera-logo.png" width="90"/>
|
|
||||||
<i class="icon bp-arrow-right"></i>
|
|
||||||
</a>
|
|
||||||
<a ng-if="coinbaseEnabled" ui-sref="tabs.buyandsell.coinbase" class="item item-extra-padding item-sub item-icon-right">
|
|
||||||
<img src="img/coinbase-logo.png" width="90">
|
|
||||||
<i class="icon bp-arrow-right"></i>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="list card" ng-if="wallets[0] && externalServices.AmazonGiftCards && amazonEnabled">
|
<div class="ng-hide" ng-show="wallets[0] && buyAndSellItems.length>0" ng-include="'views/includes/buyAndSellCard.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">
|
<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">
|
<i class="icon big-icon-svg">
|
||||||
<div class="bg icon-amazon"></div>
|
<div class="bg icon-amazon"></div>
|
||||||
|
@ -142,37 +128,7 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="list card"
|
<div class="ng-hide" ng-show="nextStepsItems.length>0" ng-include="'views/includes/nextSteps.html'"></div>
|
||||||
ng-show="nextStepEnabled && wallets[0]">
|
|
||||||
<div class="item item-icon-right item-heading" ng-click="shouldHideNextSteps()">
|
|
||||||
<span translate>Next steps</span>
|
|
||||||
<i class="icon bp-arrow-up" ng-show="!hideNextSteps"></i>
|
|
||||||
<i class="icon bp-arrow-down" ng-show="hideNextSteps"></i>
|
|
||||||
</div>
|
|
||||||
<div ng-show="!hideNextSteps">
|
|
||||||
<a ui-sref="tabs.bitpayCardIntro" ng-if="!externalServices.BitpayCard && bitpayCardEnabled" class="item item-sub item-icon-left item-big-icon-left item-icon-right next-step">
|
|
||||||
<i class="icon big-icon-svg">
|
|
||||||
<div class="bg icon-bitpay-card"></div>
|
|
||||||
</i>
|
|
||||||
<span translate>Add BitPay Visa® Card</span>
|
|
||||||
<i class="icon bp-arrow-right"></i>
|
|
||||||
</a>
|
|
||||||
<a ng-if="!externalServices.BuyAndSell && (coinbaseEnabled || glideraEnabled)" ui-sref="tabs.buyandsell" class="item item-sub item-icon-left item-big-icon-left item-icon-right next-step">
|
|
||||||
<i class="icon big-icon-svg">
|
|
||||||
<div class="bg icon-buy-bitcoin"></div>
|
|
||||||
</i>
|
|
||||||
<span translate>Buy or Sell Bitcoin</span>
|
|
||||||
<i class="icon bp-arrow-right"></i>
|
|
||||||
</a>
|
|
||||||
<a ui-sref="tabs.giftcards.amazon" ng-if="!externalServices.AmazonGiftCards && amazonEnabled" class="item item-sub item-icon-left item-big-icon-left item-icon-right next-step">
|
|
||||||
<i class="icon big-icon-svg">
|
|
||||||
<div class="bg icon-amazon"></div>
|
|
||||||
</i>
|
|
||||||
<span translate>Buy a gift card</span>
|
|
||||||
<i class="icon bp-arrow-right"></i>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</ion-content>
|
</ion-content>
|
||||||
</ion-view>
|
</ion-view>
|
||||||
|
|
Loading…
Reference in New Issue