Merge pull request #5544 from matiu/bug/bitpay-card

Bug/bitpay card
This commit is contained in:
Gustavo Maximiliano Cortez 2017-01-31 17:51:06 -03:00 committed by GitHub
commit 8a0957304c
40 changed files with 927 additions and 1017 deletions

View file

@ -3,27 +3,18 @@
angular.module('copayApp.controllers').controller('advancedSettingsController', function($scope, $rootScope, $log, $window, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService, storageService, $ionicHistory, $timeout, $ionicScrollDelegate) {
var updateConfig = function() {
var config = configService.getSync();
$scope.spendUnconfirmed = {
value: config.wallet.spendUnconfirmed
};
$scope.bitpayCardEnabled = {
value: config.bitpayCard.enabled
};
$scope.amazonEnabled = {
value: config.amazon.enabled
};
$scope.glideraEnabled = {
value: config.glidera.enabled
};
$scope.coinbaseEnabled = {
value: config.coinbaseV2
};
$scope.recentTransactionsEnabled = {
value: config.recentTransactions.enabled
};
$scope.hideNextSteps = {
value: config.hideNextSteps.enabled
};
};
$scope.spendUnconfirmedChange = function() {
@ -37,42 +28,11 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
});
};
$scope.bitpayCardChange = function() {
$scope.nextStepsChange = function() {
var opts = {
bitpayCard: {
enabled: $scope.bitpayCardEnabled.value
}
};
configService.set(opts, function(err) {
if (err) $log.debug(err);
});
};
$scope.amazonChange = function() {
var opts = {
amazon: {
enabled: $scope.amazonEnabled.value
}
};
configService.set(opts, function(err) {
if (err) $log.debug(err);
});
};
$scope.glideraChange = function() {
var opts = {
glidera: {
enabled: $scope.glideraEnabled.value
}
};
configService.set(opts, function(err) {
if (err) $log.debug(err);
});
};
$scope.coinbaseChange = function() {
var opts = {
coinbaseV2: $scope.coinbaseEnabled.value
hideNextSteps: {
enabled: $scope.hideNextSteps.value
},
};
configService.set(opts, function(err) {
if (err) $log.debug(err);

View file

@ -9,16 +9,6 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
};
$scope.network = bitpayService.getEnvironment().network;
var updateHistoryFromCache = function(cb) {
bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) {
if (err ||  lodash.isEmpty(data)) return cb();
$scope.historyCached = true;
self.bitpayCardTransactionHistory = data.transactions;
self.bitpayCardCurrentBalance = data.balance;
return cb();
});
};
var setDateRange = function(preset) {
var startDate, endDate;
preset = preset ||  'last30Days';
@ -45,13 +35,19 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
};
var setGetStarted = function(history, cb) {
if (lodash.isEmpty(history.transactionList)) {
var dateRange = setDateRange('all');
bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) {
if (lodash.isEmpty(history.transactionList)) return cb(true);
return cb(false);
});
} else return cb(false);
// Is the card new?
if (!lodash.isEmpty(history.transactionList))
return cb();
var dateRange = setDateRange('all');
bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) {
if (!err && lodash.isEmpty(history.transactionList))
self.getStated=true;
return cb();
});
};
this.update = function() {
@ -59,18 +55,18 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
$scope.loadingHistory = true;
bitpayCardService.getHistory($scope.cardId, dateRange, function(err, history) {
$scope.loadingHistory = false;
if (err) {
$log.error(err);
self.bitpayCardTransactionHistory = null;
self.bitpayCardCurrentBalance = null;
self.balance = null;
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not get transactions'));
return;
}
setGetStarted(history, function(getStarted) {
self.getStarted = getStarted;
setGetStarted(history, function() {
var txs = lodash.clone(history.txs);
runningBalance = parseFloat(history.endingBalance);
@ -83,18 +79,21 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
_runningBalance(txs[i]);
}
self.bitpayCardTransactionHistory = txs;
self.bitpayCardCurrentBalance = history.currentCardBalance;
self.balance = history.currentCardBalance;
self.updatedOn = null;
if ($scope.dateRange.value == 'last30Days') {
$log.debug('BitPay Card: store cache history');
var cacheHistory = {
balance: history.currentCardBalance,
transactions: history.txs
};
bitpayCardService.setBitpayDebitCardsHistory($scope.cardId, cacheHistory, {}, function(err) {
if (err) $log.error(err);
$scope.historyCached = true;
});
// TODO?
// $log.debug('BitPay Card: storing cache history');
// var cacheHistory = {
// balance: history.currentCardBalance,
// transactions: history.txs
// };
// bitpayCardService.setHistory($scope.cardId, cacheHistory, {}, function(err) {
// if (err) $log.error(err);
// $scope.historyCached = true;
// });
}
$timeout(function() {
$scope.$apply();
@ -136,24 +135,25 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.cardId = data.stateParams.id;
if (!$scope.cardId) {
var msg = gettextCatalog.getString('Bad param');
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$state.go('tabs.home');
popupService.showAlert(gettextCatalog.getString('Error'), msg);
} else {
updateHistoryFromCache(function() {
self.update();
});
bitpayCardService.getBitpayDebitCards(function(err, cards) {
if (err) return;
$scope.card = lodash.find(cards, function(card) {
return card.eid == $scope.cardId;
});
});
}
});
bitpayCardService.get({
cardId: $scope.cardId,
noRefresh: true,
}, function(err, cards) {
if (cards && cards[0]) {
self.lastFourDigits = cards[0].lastFourDigits;
self.balance = cards[0].balance;
self.updatedOn = cards[0].updatedOn;
}
self.update();
});
});
});

View file

@ -1,5 +1,5 @@
'use strict';
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $log, $state, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService, appIdentityService, bitpayService) {
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $log, $state, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService, appIdentityService, bitpayService, lodash) {
$scope.$on("$ionicView.beforeEnter", function(event, data) {
if (data.stateParams && data.stateParams.secret) {
@ -18,27 +18,23 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
return;
}
if (paired) {
bitpayCardService.fetchBitpayDebitCards(apiContext, function(err, data) {
bitpayCardService.sync(apiContext, function(err, cards) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error fetching Debit Cards'), err);
popupService.showAlert(gettextCatalog.getString('Error updating Debit Cards'), err);
return;
}
// Set flag for nextStep
storageService.setNextStep('BitpayCard', 'true', function(err) {});
// Save data
bitpayCardService.setBitpayDebitCards(data, function(err) {
if (err) return;
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$state.go('tabs.home').then(function() {
if (data.cards[0]) {
$state.transitionTo('tabs.bitpayCard', {
id: data.cards[0].id
});
}
});
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$state.go('tabs.home').then(function() {
if (cards[0]) {
$state.transitionTo('tabs.bitpayCard', {
id: cards[0].id
});
}
});
});
}

View file

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

View file

@ -34,8 +34,6 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
coinbaseService.setCredentials();
$scope.isFiat = data.stateParams.currency ? true : false;
[amount, currency, $scope.amountUnitStr] = coinbaseService.parseAmount(
data.stateParams.amount,

View file

@ -1,14 +1,11 @@
'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) {
configService.whenAvailable(function(config) {
$scope.isCoinbaseEnabled = config.coinbaseV2;
$scope.isGlideraEnabled = config.glidera.enabled;
$scope.services = buyAndSellService.get();
if (!$scope.isCoinbaseEnabled && !$scope.isGlideraEnabled)
$ionicHistory.goBack();
});
if (lodash.isEmpty($scope.services))
$ionicHistory.goBack();
});
});

View file

@ -112,7 +112,6 @@ angular.module('copayApp.controllers').controller('coinbaseController', function
var self = this;
$scope.$on("$ionicView.beforeEnter", function(event, data) {
coinbaseService.setCredentials();
if (data.stateParams && data.stateParams.code) {
coinbaseService.getStoredToken(function(at) {
if (!at) self.submitOauthCode(data.stateParams.code);

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

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

View file

@ -1,19 +1,21 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesBitpayCardController',
function($scope, $state, $timeout, $ionicHistory, bitpayCardService, popupService, gettextCatalog) {
function($scope, $state, $timeout, $ionicHistory, bitpayCardService, popupService, gettextCatalog, $log) {
$scope.remove = function(card) {
var msg = gettextCatalog.getString('Are you sure you would like to remove your BitPay Card ({{lastFourDigits}}) from this device?', {
lastFourDigits: card.lastFourDigits
});
popupService.showConfirm(null, msg, null, null, function(res) {
if (res) remove(card);
$log.info('Removing bitpay card:' + card.eid)
if (res)
remove(card.eid);
});
};
var remove = function(card) {
bitpayCardService.remove(card, function(err) {
var remove = function(cardEid) {
bitpayCardService.remove(cardEid, function(err) {
if (err) {
return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not remove card'));
}
@ -25,8 +27,9 @@ angular.module('copayApp.controllers').controller('preferencesBitpayCardControll
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
bitpayCardService.getBitpayDebitCards(function(err, data) {
bitpayCardService.getCards(function(err, data) {
if (err) return;
$scope.bitpayCards = data;
});
});

View file

@ -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)) {

View file

@ -117,8 +117,6 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', func
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
coinbaseService.setCredentials();
$scope.isFiat = data.stateParams.currency ? true : false;
[amount, currency, $scope.amountUnitStr] = coinbaseService.parseAmount(
data.stateParams.amount,

View file

@ -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, coinbaseService) {
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) {
var wallet;
var listeners = [];
var notifications = [];
@ -87,10 +87,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
var wallet = profileService.getWallet(walletId);
updateWallet(wallet);
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) {
$log.debug('Got action for wallet ' + walletId);
@ -100,31 +97,29 @@ angular.module('copayApp.controllers').controller('tabHomeController',
})
];
$scope.buyAndSellItems = buyAndSellService.getLinked();
$scope.homeIntegrations = homeIntegrationsService.get();
bitpayCardService.get({}, function(err, cards) {
$scope.bitpayCardItems = cards;
});
configService.whenAvailable(function() {
nextStep(function() {
var config = configService.getSync();
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
var config = configService.getSync();
$scope.recentTransactionsEnabled = config.recentTransactions.enabled;
if ($scope.recentTransactionsEnabled) getNotifications();
$scope.glideraEnabled = config.glidera.enabled && !isWindowsPhoneApp;
$scope.coinbaseEnabled = config.coinbaseV2 && !isWindowsPhoneApp;
$scope.amazonEnabled = config.amazon.enabled;
$scope.bitpayCardEnabled = config.bitpayCard.enabled;
if (config.hideNextSteps.enabled) {
$scope.nextStepsItems = null;
} else {
$scope.nextStepsItems = nextStepsService.get();
}
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;
if ($scope.recentTransactionsEnabled) getNotifications();
if ($scope.bitpayCardEnabled) bitpayCardCache();
$timeout(function() {
$ionicScrollDelegate.resize();
$scope.$apply();
}, 10);
});
$timeout(function() {
$ionicScrollDelegate.resize();
$scope.$apply();
}, 10);
});
});
@ -223,6 +218,9 @@ angular.module('copayApp.controllers').controller('tabHomeController',
} else {
wallet.error = null;
wallet.status = status;
// TODO service refactor? not in profile service
profileService.setLastKnownBalance(wallet.id, wallet.status.totalBalanceStr, function() {});
}
if (++j == i) {
updateTxps();
@ -269,46 +267,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() {
bitpayCardService.getBitpayDebitCards(function(err, data) {
if (err) return;
if (lodash.isEmpty(data)) {
$scope.bitpayCards = null;
return;
}
$scope.bitpayCards = data;
$timeout(function() {
$scope.$digest();
}, 100);
});
bitpayCardService.getBitpayDebitCardsHistory(null, function(err, data) {
if (err) return;
if (lodash.isEmpty(data)) {
$scope.cardsHistory = null;
return;
}
$scope.cardsHistory = data;
});
};
$scope.onRefresh = function() {
$timeout(function() {

View file

@ -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;
@ -24,30 +25,11 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
isoCode: config.wallet.settings.alternativeIsoCode
};
$scope.bitpayCardEnabled = config.bitpayCard.enabled;
$scope.glideraEnabled = config.glidera.enabled && !isWindowsPhoneApp;
$scope.coinbaseEnabled = config.coinbaseV2 && !isWindowsPhoneApp;
if ($scope.bitpayCardEnabled) {
bitpayCardService.getBitpayDebitCards(function(err, cards) {
if (err) $log.error(err);
$scope.bitpayCards = cards && cards.length > 0;
});
}
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;
});
}
// TODO move this to a generic service
bitpayCardService.getCards(function(err, cards) {
if (err) $log.error(err);
$scope.bitpayCards = cards && cards.length > 0;
});
});
};