Adds bitcoin cash basic support (unit convertion, integrations, request specific amount, etc)
This commit is contained in:
parent
60ae2d2117
commit
94363704ab
24 changed files with 376 additions and 302 deletions
|
|
@ -33,6 +33,52 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct
|
|||
}
|
||||
};
|
||||
|
||||
var processPaymentInfo = function() {
|
||||
ongoingProcess.set('connectingCoinbase', true);
|
||||
coinbaseService.init(function(err, res) {
|
||||
if (err) {
|
||||
ongoingProcess.set('connectingCoinbase', false);
|
||||
showErrorAndBack(err);
|
||||
return;
|
||||
}
|
||||
var accessToken = res.accessToken;
|
||||
|
||||
coinbaseService.buyPrice(accessToken, coinbaseService.getAvailableCurrency(), function(err, b) {
|
||||
$scope.buyPrice = b.data || null;
|
||||
});
|
||||
|
||||
$scope.paymentMethods = [];
|
||||
$scope.selectedPaymentMethodId = { value : null };
|
||||
coinbaseService.getPaymentMethods(accessToken, function(err, p) {
|
||||
if (err) {
|
||||
ongoingProcess.set('connectingCoinbase', false);
|
||||
showErrorAndBack(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var hasPrimary;
|
||||
var pm;
|
||||
for(var i = 0; i < p.data.length; i++) {
|
||||
pm = p.data[i];
|
||||
if (pm.allow_buy) {
|
||||
$scope.paymentMethods.push(pm);
|
||||
}
|
||||
if (pm.allow_buy && pm.primary_buy) {
|
||||
hasPrimary = true;
|
||||
$scope.selectedPaymentMethodId.value = pm.id;
|
||||
}
|
||||
}
|
||||
if (lodash.isEmpty($scope.paymentMethods)) {
|
||||
ongoingProcess.set('connectingCoinbase', false);
|
||||
showErrorAndBack('No payment method available to buy');
|
||||
return;
|
||||
}
|
||||
if (!hasPrimary) $scope.selectedPaymentMethodId.value = $scope.paymentMethods[0].id;
|
||||
$scope.buyRequest();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.beforeLeave", function(event, data) {
|
||||
$ionicConfig.views.swipeBackEnabled(true);
|
||||
});
|
||||
|
|
@ -42,81 +88,22 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct
|
|||
});
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
$scope.isFiat = data.stateParams.currency != 'bits' && data.stateParams.currency != 'BTC' ? true : false;
|
||||
var parsedAmount = txFormatService.parseAmount(
|
||||
data.stateParams.amount,
|
||||
data.stateParams.currency);
|
||||
$scope.isFiat = data.stateParams.currency != 'BCH' && data.stateParams.currency != 'BTC' ? true : false;
|
||||
amount = data.stateParams.amount;
|
||||
currency = data.stateParams.currency;
|
||||
|
||||
// Buy always in BTC
|
||||
amount = (parsedAmount.amountSat / 100000000).toFixed(8);
|
||||
currency = 'BTC';
|
||||
|
||||
$scope.amountUnitStr = parsedAmount.amountUnitStr;
|
||||
|
||||
ongoingProcess.set('calculatingFee', true);
|
||||
coinbaseService.checkEnoughFundsForFee(amount, function(err) {
|
||||
ongoingProcess.set('calculatingFee', false);
|
||||
if (err) {
|
||||
showErrorAndBack(err);
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.network = coinbaseService.getNetwork();
|
||||
$scope.wallets = profileService.getWallets({
|
||||
onlyComplete: true,
|
||||
network: $scope.network
|
||||
});
|
||||
|
||||
if (lodash.isEmpty($scope.wallets)) {
|
||||
showErrorAndBack('No wallets available');
|
||||
return;
|
||||
}
|
||||
$scope.wallet = $scope.wallets[0]; // Default first wallet
|
||||
|
||||
ongoingProcess.set('connectingCoinbase', true);
|
||||
coinbaseService.init(function(err, res) {
|
||||
if (err) {
|
||||
ongoingProcess.set('connectingCoinbase', false);
|
||||
showErrorAndBack(err);
|
||||
return;
|
||||
}
|
||||
var accessToken = res.accessToken;
|
||||
|
||||
coinbaseService.buyPrice(accessToken, coinbaseService.getAvailableCurrency(), function(err, b) {
|
||||
$scope.buyPrice = b.data || null;
|
||||
});
|
||||
|
||||
$scope.paymentMethods = [];
|
||||
$scope.selectedPaymentMethodId = { value : null };
|
||||
coinbaseService.getPaymentMethods(accessToken, function(err, p) {
|
||||
if (err) {
|
||||
ongoingProcess.set('connectingCoinbase', false);
|
||||
showErrorAndBack(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var hasPrimary;
|
||||
var pm;
|
||||
for(var i = 0; i < p.data.length; i++) {
|
||||
pm = p.data[i];
|
||||
if (pm.allow_buy) {
|
||||
$scope.paymentMethods.push(pm);
|
||||
}
|
||||
if (pm.allow_buy && pm.primary_buy) {
|
||||
hasPrimary = true;
|
||||
$scope.selectedPaymentMethodId.value = pm.id;
|
||||
}
|
||||
}
|
||||
if (lodash.isEmpty($scope.paymentMethods)) {
|
||||
ongoingProcess.set('connectingCoinbase', false);
|
||||
showErrorAndBack('No payment method available to buy');
|
||||
return;
|
||||
}
|
||||
if (!hasPrimary) $scope.selectedPaymentMethodId.value = $scope.paymentMethods[0].id;
|
||||
$scope.buyRequest();
|
||||
});
|
||||
});
|
||||
$scope.network = coinbaseService.getNetwork();
|
||||
$scope.wallets = profileService.getWallets({
|
||||
onlyComplete: true,
|
||||
network: $scope.network,
|
||||
chain: 'BTC'
|
||||
});
|
||||
|
||||
if (lodash.isEmpty($scope.wallets)) {
|
||||
showErrorAndBack('No wallets available');
|
||||
return;
|
||||
}
|
||||
$scope.onWalletSelect($scope.wallets[0]); // Default first wallet
|
||||
});
|
||||
|
||||
$scope.buyRequest = function() {
|
||||
|
|
@ -248,6 +235,25 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct
|
|||
|
||||
$scope.onWalletSelect = function(wallet) {
|
||||
$scope.wallet = wallet;
|
||||
var parsedAmount = txFormatService.parseAmount(
|
||||
wallet,
|
||||
amount,
|
||||
currency);
|
||||
|
||||
// Buy always in BTC
|
||||
amount = (parsedAmount.amountSat / 100000000).toFixed(8);
|
||||
currency = 'BTC';
|
||||
|
||||
$scope.amountUnitStr = parsedAmount.amountUnitStr;
|
||||
ongoingProcess.set('calculatingFee', true);
|
||||
coinbaseService.checkEnoughFundsForFee(amount, function(err) {
|
||||
ongoingProcess.set('calculatingFee', false);
|
||||
if (err) {
|
||||
showErrorAndBack(err);
|
||||
return;
|
||||
}
|
||||
processPaymentInfo();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.goBackHome = function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue