The Origin screen can now display payment requests properly.
This commit is contained in:
parent
4203a449d9
commit
b0e46f18a1
3 changed files with 71 additions and 23 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $log, $ionicHistory, configService, gettextCatalog, profileService, txFormatService) {
|
||||
|
||||
var fromWalletId = '';
|
||||
var priceDisplayAsFiat = false;
|
||||
var requestedSatoshis = 0;
|
||||
var unitDecimals = 0;
|
||||
|
|
@ -29,6 +30,7 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
|
|||
$scope.params = $state.params;
|
||||
$scope.coin = false; // Wallets to show (for destination screen or contacts)
|
||||
$scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
|
||||
fromWalletId = data.stateParams && data.stateParams.fromWalletId;
|
||||
|
||||
if ($scope.params.coin) {
|
||||
$scope.coin = $scope.params.coin; // Contacts have a coin embedded
|
||||
|
|
@ -51,30 +53,13 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
|
|||
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
|
||||
});
|
||||
|
||||
$scope.walletsEmpty = []; // empty wallets for origin screen
|
||||
|
||||
if ($scope.type === 'origin') {
|
||||
$scope.headerTitle = gettextCatalog.getString('Choose a wallet to send from');
|
||||
$scope.walletsEmpty = profileService.getWallets({coin: $scope.coin, hasNoFunds: true});
|
||||
} else if ($scope.type === 'destination') {
|
||||
$scope.fromWallet = profileService.getWallet(data.stateParams.fromWalletId);
|
||||
$scope.coin = $scope.fromWallet.coin; // Only show wallets with the select origin wallet coin
|
||||
$scope.headerTitle = gettextCatalog.getString('Choose a wallet to send to');
|
||||
}
|
||||
|
||||
if ($scope.thirdParty) {
|
||||
// Third party services specific logic
|
||||
handleThirdPartyIfBip70PaymentProtocol();
|
||||
handleThirdPartyIfShapeshift();
|
||||
}
|
||||
|
||||
if (!$scope.coin || $scope.coin === 'bch') { // if no specific coin is set or coin is set to bch
|
||||
$scope.walletsBch = profileService.getWallets({coin: 'bch', hasFunds: $scope.type==='origin'});
|
||||
}
|
||||
if (!$scope.coin || $scope.coin === 'btc') { // if no specific coin is set or coin is set btc
|
||||
$scope.walletsBtc = profileService.getWallets({coin: 'btc', hasFunds: $scope.type === 'origin'});
|
||||
}
|
||||
|
||||
prepareWalletLists();
|
||||
formatRequestedAmount();
|
||||
});
|
||||
|
||||
|
|
@ -116,14 +101,17 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
|
|||
} else if (!$scope.params.amount) { // If we have no amount
|
||||
return 'tabs.send.amount';
|
||||
} else { // If we do have them
|
||||
return 'tabs.send.confirm';
|
||||
return 'tabs.send.review';
|
||||
}
|
||||
}
|
||||
|
||||
function handleThirdPartyIfBip70PaymentProtocol() {
|
||||
if ($scope.thirdParty.id === 'bip70PaymentProtocol') {
|
||||
requestedSatoshis = $scope.thirdParty.details.amount;
|
||||
$scope.coin = $scope.thirdParty.coin;
|
||||
$scope.requestAmount = unitsFromSatoshis * $scope.thirdParty.details.amount;
|
||||
$scope.requestAmount = unitsFromSatoshis * requestedSatoshis;
|
||||
$scope.params.amount = requestedSatoshis;
|
||||
$scope.params.toAddr = $scope.thirdParty.details.toAddress;
|
||||
console.log('paypro details:', $scope.thirdParty.details);
|
||||
}
|
||||
}
|
||||
|
|
@ -138,6 +126,66 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
|
|||
}
|
||||
}
|
||||
|
||||
function prepareWalletLists() {
|
||||
var walletsAll = [];
|
||||
var walletsSufficientFunds = [];
|
||||
$scope.walletsInsufficientFunds = []; // For origin screen
|
||||
|
||||
if ($scope.type === 'origin') {
|
||||
$scope.headerTitle = gettextCatalog.getString('Choose a wallet to send from');
|
||||
|
||||
if ($scope.params.amount) {
|
||||
|
||||
walletsAll = profileService.getWallets({coin: $scope.coin});
|
||||
|
||||
walletsAll.forEach(function forWallet(wallet){
|
||||
if (wallet.status.availableBalanceSat > $scope.params.amount) {
|
||||
walletsSufficientFunds.push(wallet);
|
||||
} else {
|
||||
$scope.walletsInsufficientFunds.push(wallet);
|
||||
}
|
||||
});
|
||||
|
||||
if ($scope.coin === 'btc') {
|
||||
$scope.walletsBtc = walletsSufficientFunds;
|
||||
} else {
|
||||
$scope.walletsBch = walletsSufficientFunds;
|
||||
}
|
||||
|
||||
} else if ($scope.coin) {
|
||||
walletsAll = profileService.getWallets({coin: $scope.coin});
|
||||
walletsAll.forEach(function forWallet(wallet){
|
||||
if (wallet.status.availableBalanceSat > 0) {
|
||||
walletsSufficientFunds.push(wallet);
|
||||
} else {
|
||||
$scope.walletsInsufficientFunds.push(wallet);
|
||||
}
|
||||
});
|
||||
|
||||
if ($scope.coin === 'btc') {
|
||||
$scope.walletsBtc = walletsSufficientFunds;
|
||||
} else {
|
||||
$scope.walletsBch = walletsSufficientFunds;
|
||||
}
|
||||
} else {
|
||||
$scope.walletsBch = profileService.getWallets({coin: 'bch', hasFunds: true});
|
||||
$scope.walletsBtc = profileService.getWallets({coin: 'btc', hasFunds: true});
|
||||
$scope.walletsInsufficientFunds = profileService.getWallets({coin: $scope.coin, hasNoFunds: true});
|
||||
}
|
||||
|
||||
} else if ($scope.type === 'destination') {
|
||||
$scope.fromWallet = profileService.getWallet(fromWalletId);
|
||||
$scope.coin = $scope.fromWallet.coin; // Only show wallets with the select origin wallet coin
|
||||
$scope.headerTitle = gettextCatalog.getString('Choose a wallet to send to');
|
||||
|
||||
if ($scope.coin === 'btc') { // if no specific coin is set or coin is set btc
|
||||
$scope.walletsBtc = profileService.getWallets({coin: $scope.coin});
|
||||
} else {
|
||||
$scope.walletsBch = profileService.getWallets({coin: $scope.coin});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$scope.useWallet = function(wallet) {
|
||||
|
|
|
|||
|
|
@ -427,7 +427,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
};
|
||||
var stateParams = {
|
||||
amount: payProDetails.amount,
|
||||
toAddr: payProDetails.toAddress,
|
||||
toAddress: payProDetails.toAddress,
|
||||
thirdParty: JSON.stringify(thirdPartyData)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -42,12 +42,12 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list card card-insufficient" ng-if="walletsEmpty.length > 0">
|
||||
<div class="list card card-insufficient" ng-if="walletsInsufficientFunds.length > 0">
|
||||
<div class="item item-icon-right item-heading">
|
||||
<span class="card-insufficient__dot"></span><div translate>Insufficient funds</div>
|
||||
</div>
|
||||
<div>
|
||||
<a ng-repeat="wallet in walletsEmpty track by $index"
|
||||
<a ng-repeat="wallet in walletsInsufficientFunds track by $index"
|
||||
class="item item-sub item-icon-left item-big-icon-left item-icon-right wallet">
|
||||
<span ng-include="'views/includes/walletList.html'"></span>
|
||||
</a>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue