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';
|
'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 amount;
|
||||||
var currency;
|
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 = '';
|
$scope.sendStatus = '';
|
||||||
$log.error(err);
|
$log.error(msg);
|
||||||
err = err.errors ? err.errors[0].message : err;
|
msg = msg.errors ? msg.errors[0].message : msg;
|
||||||
popupService.showAlert('Error', err);
|
popupService.showAlert(title, msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
var publishAndSign = function (wallet, txp, onSendStatusChange, cb) {
|
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.network = bitpayService.getEnvironment().network;
|
||||||
$scope.wallets = profileService.getWallets({
|
$scope.wallets = profileService.getWallets({
|
||||||
m: 1, // Only 1-signature wallet
|
|
||||||
onlyComplete: true,
|
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) {
|
bitpayCardService.getRates(currency, function(err, data) {
|
||||||
if (err) $log.error(err);
|
if (err) $log.error(err);
|
||||||
|
|
@ -109,14 +115,14 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
||||||
bitpayCardService.topUp(cardId, dataSrc, function(err, invoiceId) {
|
bitpayCardService.topUp(cardId, dataSrc, function(err, invoiceId) {
|
||||||
if (err) {
|
if (err) {
|
||||||
ongoingProcess.set('topup', false, statusChangeHandler);
|
ongoingProcess.set('topup', false, statusChangeHandler);
|
||||||
showError(err);
|
showError('Could not create the invoice', err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bitpayCardService.getInvoice(invoiceId, function(err, invoice) {
|
bitpayCardService.getInvoice(invoiceId, function(err, invoice) {
|
||||||
if (err) {
|
if (err) {
|
||||||
ongoingProcess.set('topup', false, statusChangeHandler);
|
ongoingProcess.set('topup', false, statusChangeHandler);
|
||||||
showError(err);
|
showError('Could not get the invoice', err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,14 +130,14 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
||||||
|
|
||||||
if (!payProUrl) {
|
if (!payProUrl) {
|
||||||
ongoingProcess.set('topup', false, statusChangeHandler);
|
ongoingProcess.set('topup', false, statusChangeHandler);
|
||||||
showError('Error fetching invoice');
|
showError('Error in Payment Protocol', 'Invalid URL');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
payproService.getPayProDetails(payProUrl, function(err, payProDetails) {
|
payproService.getPayProDetails(payProUrl, function(err, payProDetails) {
|
||||||
if (err) {
|
if (err) {
|
||||||
ongoingProcess.set('topup', false, statusChangeHandler);
|
ongoingProcess.set('topup', false, statusChangeHandler);
|
||||||
showError(err);
|
showError('Error fetching invoice', err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'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 root = {};
|
||||||
|
|
||||||
var _setError = function(msg, e) {
|
var _setError = function(msg, e) {
|
||||||
|
|
@ -44,12 +44,14 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
||||||
var satToBtc = 1 / 100000000;
|
var satToBtc = 1 / 100000000;
|
||||||
var unitToSatoshi = config.unitToSatoshi;
|
var unitToSatoshi = config.unitToSatoshi;
|
||||||
var amountUnitStr;
|
var amountUnitStr;
|
||||||
|
var amountSat;
|
||||||
|
|
||||||
// IF 'USD'
|
// IF 'USD'
|
||||||
if (currency) {
|
if (currency) {
|
||||||
amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency;
|
amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency;
|
||||||
|
amountSat = rateService.fromFiat(amount, currency).toFixed(0);
|
||||||
} else {
|
} else {
|
||||||
var amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
|
amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
|
||||||
amountUnitStr = txFormatService.formatAmountStr(amountSat);
|
amountUnitStr = txFormatService.formatAmountStr(amountSat);
|
||||||
// convert unit to BTC
|
// convert unit to BTC
|
||||||
amount = (amountSat * satToBtc).toFixed(8);
|
amount = (amountSat * satToBtc).toFixed(8);
|
||||||
|
|
@ -59,6 +61,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
|
||||||
return {
|
return {
|
||||||
amount: amount,
|
amount: amount,
|
||||||
currency: currency,
|
currency: currency,
|
||||||
|
amountSat: amountSat,
|
||||||
amountUnitStr: amountUnitStr
|
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) {
|
if (opts.onlyComplete) {
|
||||||
ret = lodash.filter(ret, function(w) {
|
ret = lodash.filter(ret, function(w) {
|
||||||
return w.isComplete();
|
return w.isComplete();
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@
|
||||||
ng-if="!isCordova && cardInfo"
|
ng-if="!isCordova && cardInfo"
|
||||||
click-send-status="sendStatus"
|
click-send-status="sendStatus"
|
||||||
has-wallet-chosen="wallet"
|
has-wallet-chosen="wallet"
|
||||||
insufficient-funds="false"
|
insufficient-funds="insufficientFunds"
|
||||||
no-matching-wallet="!cardInfo">
|
no-matching-wallet="!cardInfo">
|
||||||
Add funds
|
Add funds
|
||||||
</click-to-accept>
|
</click-to-accept>
|
||||||
|
|
@ -73,7 +73,7 @@
|
||||||
slide-on-confirm="topUpConfirm()"
|
slide-on-confirm="topUpConfirm()"
|
||||||
slide-send-status="sendStatus"
|
slide-send-status="sendStatus"
|
||||||
has-wallet-chosen="wallet"
|
has-wallet-chosen="wallet"
|
||||||
insufficient-funds="false"
|
insufficient-funds="insufficientFunds"
|
||||||
no-matching-wallet="!cardInfo">
|
no-matching-wallet="!cardInfo">
|
||||||
Slide to confirm
|
Slide to confirm
|
||||||
</slide-to-accept>
|
</slide-to-accept>
|
||||||
|
|
@ -81,9 +81,11 @@
|
||||||
slide-success-show="sendStatus === 'success'"
|
slide-success-show="sendStatus === 'success'"
|
||||||
slide-success-on-confirm="goBackHome()"
|
slide-success-on-confirm="goBackHome()"
|
||||||
slide-success-hide-on-confirm="true">
|
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">
|
<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>
|
</div>
|
||||||
</slide-to-accept-success>
|
</slide-to-accept-success>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue