From c2c35925bb953bf07e32c005dbe312d220b45749 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 6 Jan 2023 11:08:45 +0100 Subject: wallet-core: allow failure result in peer payment coin selection --- packages/taler-util/src/taler-error-codes.ts | 8 ++++ packages/taler-util/src/wallet-types.ts | 65 ++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 14 deletions(-) (limited to 'packages/taler-util') diff --git a/packages/taler-util/src/taler-error-codes.ts b/packages/taler-util/src/taler-error-codes.ts index 8bac5bffb..5e3c8fdfb 100644 --- a/packages/taler-util/src/taler-error-codes.ts +++ b/packages/taler-util/src/taler-error-codes.ts @@ -3240,6 +3240,14 @@ export enum TalerErrorCode { WALLET_DEPOSIT_GROUP_INSUFFICIENT_BALANCE = 7026, + /** + * The wallet does not have sufficient balance to create a peer push payment. + * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0). + * (A value of 0 indicates that the error is generated client-side). + */ + WALLET_PEER_PUSH_PAYMENT_INSUFFICIENT_BALANCE = 7027, + + /** * We encountered a timeout with our payment backend. * Returned with an HTTP status code of #MHD_HTTP_GATEWAY_TIMEOUT (504). diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index b63e043f5..3a1176021 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -419,7 +419,10 @@ export const codecForPreparePayResultInsufficientBalance = "status", codecForConstString(PreparePayResultType.InsufficientBalance), ) - .property("balanceDetails", codecForPayMerchantInsufficientBalanceDetails()) + .property( + "balanceDetails", + codecForPayMerchantInsufficientBalanceDetails(), + ) .build("PreparePayResultInsufficientBalance"); export const codecForPreparePayResultAlreadyConfirmed = @@ -2084,7 +2087,6 @@ export interface InitiatePeerPullPaymentResponse { transactionId: string; } - /** * Detailed reason for why the wallet's balance is insufficient. */ @@ -2124,23 +2126,58 @@ export interface PayMerchantInsufficientBalanceDetails { * (i.e. balanceMechantWireable >= amountRequested), * this field contains an estimate of the amount that would additionally * be required to cover the fees. - * + * * It is not possible to give an exact value here, since it depends * on the coin selection for the amount that would be additionally withdrawn. */ feeGapEstimate: AmountString; } -const codecForPayMerchantInsufficientBalanceDetails = -(): Codec => - buildCodecForObject() - .property("amountRequested", codecForAmountString()) - .property("balanceAgeAcceptable", codecForAmountString()) - .property("balanceAvailable", codecForAmountString()) - .property("balanceMaterial", codecForAmountString()) - .property("balanceMerchantAcceptable", codecForAmountString()) - .property("balanceMerchantDepositable", codecForAmountString()) - .property("feeGapEstimate", codecForAmountString()) - .build("PayMerchantInsufficientBalanceDetails"); +export const codecForPayMerchantInsufficientBalanceDetails = + (): Codec => + buildCodecForObject() + .property("amountRequested", codecForAmountString()) + .property("balanceAgeAcceptable", codecForAmountString()) + .property("balanceAvailable", codecForAmountString()) + .property("balanceMaterial", codecForAmountString()) + .property("balanceMerchantAcceptable", codecForAmountString()) + .property("balanceMerchantDepositable", codecForAmountString()) + .property("feeGapEstimate", codecForAmountString()) + .build("PayMerchantInsufficientBalanceDetails"); + +/** + * Detailed reason for why the wallet's balance is insufficient. + */ +export interface PayPeerInsufficientBalanceDetails { + /** + * Amount requested by the merchant. + */ + amountRequested: AmountString; + + /** + * Balance of type "available" (see balance.ts for definition). + */ + balanceAvailable: AmountString; + + /** + * Balance of type "material" (see balance.ts for definition). + */ + balanceMaterial: AmountString; + /** + * Acceptable balance based on restrictions on which + * exchange can be used. + */ + balanceExchangeAcceptable: AmountString + /** + * If the payment would succeed without fees + * (i.e. balanceExchangeAcceptable >= amountRequested), + * this field contains an estimate of the amount that would additionally + * be required to cover the fees. + * + * It is not possible to give an exact value here, since it depends + * on the coin selection for the amount that would be additionally withdrawn. + */ + feeGapEstimate: AmountString; +} -- cgit v1.2.3