fix: withdrawal error when creating an invoice

This commit is contained in:
Sebastian 2023-01-18 13:12:38 -03:00
parent b0258d1909
commit 5e129abe9e
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1

View File

@ -29,6 +29,7 @@ import {
PaymentStatus,
PeerContractTerms,
RefundInfoShort,
TalerErrorCode,
TalerProtocolTimestamp,
Transaction,
TransactionByIdRequest,
@ -402,8 +403,23 @@ function buildTransactionForPullPaymentCredit(
wsr: WithdrawalGroupRecord,
ort?: OperationRetryRecord,
): Transaction {
if (wsr.wgInfo.withdrawalType !== WithdrawalRecordType.PeerPullCredit)
throw Error("");
if (wsr.wgInfo.withdrawalType !== WithdrawalRecordType.PeerPullCredit) {
throw Error(`Unexpected withdrawalType: ${wsr.wgInfo.withdrawalType}`);
}
/**
* FIXME: this should be handled in the withdrawal process.
* PeerPull withdrawal fails until reserve have funds but it is not
* an error from the user perspective.
*/
const silentWithdrawalErrorForInvoice =
ort?.lastError &&
ort.lastError.code === TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE &&
Object.values(ort.lastError.errorsPerCoin ?? {}).every((e) => {
return (
e.code === TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR &&
e.httpStatusCode === 409
);
});
return {
type: TransactionType.PeerPullCredit,
amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue),
@ -427,7 +443,9 @@ function buildTransactionForPullPaymentCredit(
wsr.withdrawalGroupId,
),
frozen: false,
...(ort?.lastError ? { error: ort.lastError } : {}),
...(ort?.lastError
? { error: silentWithdrawalErrorForInvoice ? undefined : ort.lastError }
: {}),
};
}