Merge pull request #5794 from cmgustavo/bug/bitpay-card-top-up
Show wallets with sufficient funds in order to top-up the bitpay card…
This commit is contained in:
commit
31f8a01d30
4 changed files with 41 additions and 18 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('topUpController', function($scope, $log, $state, $timeout, $ionicHistory, lodash, popupService, profileService, ongoingProcess, walletService, configService, platformInfo, bitpayService, bitpayCardService, payproService) {
|
||||
angular.module('copayApp.controllers').controller('topUpController', function($scope, $log, $state, $timeout, $ionicHistory, lodash, popupService, profileService, ongoingProcess, walletService, configService, platformInfo, bitpayService, bitpayCardService, payproService, bwcError) {
|
||||
|
||||
var amount;
|
||||
var currency;
|
||||
|
|
@ -17,11 +17,11 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
});
|
||||
};
|
||||
|
||||
var showError = function(err) {
|
||||
var showError = function(title, msg) {
|
||||
$scope.sendStatus = '';
|
||||
$log.error(err);
|
||||
err = err.errors ? err.errors[0].message : err;
|
||||
popupService.showAlert('Error', err);
|
||||
$log.error(msg);
|
||||
msg = msg.errors ? msg.errors[0].message : msg;
|
||||
popupService.showAlert(title, msg);
|
||||
};
|
||||
|
||||
var publishAndSign = function (wallet, txp, onSendStatusChange, cb) {
|
||||
|
|
@ -68,11 +68,17 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
|
||||
$scope.network = bitpayService.getEnvironment().network;
|
||||
$scope.wallets = profileService.getWallets({
|
||||
m: 1, // Only 1-signature wallet
|
||||
onlyComplete: true,
|
||||
network: $scope.network
|
||||
network: $scope.network,
|
||||
hasFunds: true,
|
||||
minAmount: parsedAmount.amountSat
|
||||
});
|
||||
$scope.wallet = $scope.wallets[0]; // Default first wallet
|
||||
|
||||
if (lodash.isEmpty($scope.wallets)) {
|
||||
showErrorAndBack('Insufficient funds');
|
||||
return;
|
||||
}
|
||||
$scope.onWalletSelect($scope.wallets[0]); // Default first wallet
|
||||
|
||||
bitpayCardService.getRates(currency, function(err, data) {
|
||||
if (err) $log.error(err);
|
||||
|
|
@ -109,14 +115,14 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
bitpayCardService.topUp(cardId, dataSrc, function(err, invoiceId) {
|
||||
if (err) {
|
||||
ongoingProcess.set('topup', false, statusChangeHandler);
|
||||
showError(err);
|
||||
showError('Could not create the invoice', err);
|
||||
return;
|
||||
}
|
||||
|
||||
bitpayCardService.getInvoice(invoiceId, function(err, invoice) {
|
||||
if (err) {
|
||||
ongoingProcess.set('topup', false, statusChangeHandler);
|
||||
showError(err);
|
||||
showError('Could not get the invoice', err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -124,14 +130,14 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
|
||||
if (!payProUrl) {
|
||||
ongoingProcess.set('topup', false, statusChangeHandler);
|
||||
showError('Error fetching invoice');
|
||||
showError('Error in Payment Protocol', 'Invalid URL');
|
||||
return;
|
||||
}
|
||||
|
||||
payproService.getPayProDetails(payProUrl, function(err, payProDetails) {
|
||||
if (err) {
|
||||
ongoingProcess.set('topup', false, statusChangeHandler);
|
||||
showError(err);
|
||||
showError('Error fetching invoice', err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('bitpayCardService', function($log, $rootScope, $filter, lodash, storageService, bitauthService, platformInfo, moment, appIdentityService, bitpayService, nextStepsService, configService, txFormatService, appConfigService) {
|
||||
angular.module('copayApp.services').factory('bitpayCardService', function($log, $rootScope, $filter, lodash, storageService, bitauthService, platformInfo, moment, appIdentityService, bitpayService, nextStepsService, configService, txFormatService, appConfigService, rateService) {
|
||||
var root = {};
|
||||
|
||||
var _setError = function(msg, e) {
|
||||
|
|
@ -44,12 +44,14 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
|||
var satToBtc = 1 / 100000000;
|
||||
var unitToSatoshi = config.unitToSatoshi;
|
||||
var amountUnitStr;
|
||||
var amountSat;
|
||||
|
||||
// IF 'USD'
|
||||
if (currency) {
|
||||
amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency;
|
||||
amountSat = rateService.fromFiat(amount, currency).toFixed(0);
|
||||
} else {
|
||||
var amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
|
||||
amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
|
||||
amountUnitStr = txFormatService.formatAmountStr(amountSat);
|
||||
// convert unit to BTC
|
||||
amount = (amountSat * satToBtc).toFixed(8);
|
||||
|
|
@ -59,6 +61,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
|||
return {
|
||||
amount: amount,
|
||||
currency: currency,
|
||||
amountSat: amountSat,
|
||||
amountUnitStr: amountUnitStr
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -762,6 +762,18 @@ angular.module('copayApp.services')
|
|||
});
|
||||
}
|
||||
|
||||
if (opts.hasFunds) {
|
||||
ret = lodash.filter(ret, function(w) {
|
||||
return (w.status.availableBalanceSat > 0);
|
||||
});
|
||||
}
|
||||
|
||||
if (opts.minAmount) {
|
||||
ret = lodash.filter(ret, function(w) {
|
||||
return (w.status.availableBalanceSat > opts.minAmount);
|
||||
});
|
||||
}
|
||||
|
||||
if (opts.onlyComplete) {
|
||||
ret = lodash.filter(ret, function(w) {
|
||||
return w.isComplete();
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@
|
|||
ng-if="!isCordova && cardInfo"
|
||||
click-send-status="sendStatus"
|
||||
has-wallet-chosen="wallet"
|
||||
insufficient-funds="false"
|
||||
insufficient-funds="insufficientFunds"
|
||||
no-matching-wallet="!cardInfo">
|
||||
Add funds
|
||||
</click-to-accept>
|
||||
|
|
@ -73,7 +73,7 @@
|
|||
slide-on-confirm="topUpConfirm()"
|
||||
slide-send-status="sendStatus"
|
||||
has-wallet-chosen="wallet"
|
||||
insufficient-funds="false"
|
||||
insufficient-funds="insufficientFunds"
|
||||
no-matching-wallet="!cardInfo">
|
||||
Slide to confirm
|
||||
</slide-to-accept>
|
||||
|
|
@ -81,9 +81,11 @@
|
|||
slide-success-show="sendStatus === 'success'"
|
||||
slide-success-on-confirm="goBackHome()"
|
||||
slide-success-hide-on-confirm="true">
|
||||
<span>Sent</span>
|
||||
<span ng-if="wallet.credentials.m == 1">Sent</span>
|
||||
<span ng-if="wallet.credentials.m > 1">Success</span>
|
||||
<div class="m10 size-14">
|
||||
Funds were added to debit card
|
||||
<span ng-if="wallet.credentials.m == 1">Funds were added to debit card</span>
|
||||
<span ng-if="wallet.credentials.m > 1">Transaction initiated</span>
|
||||
</div>
|
||||
</slide-to-accept-success>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue