From 671342818fb79123f231cfcbaf8251f1672effd1 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 13 Jun 2023 16:45:42 -0300 Subject: [PATCH] get operation plan types --- packages/taler-util/src/wallet-types.ts | 159 +++++++++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-) diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index af02807a6..e33f9318d 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -71,7 +71,7 @@ import { codecForAbsoluteTime, codecForTimestamp, } from "./time.js"; -import { OrderShortInfo } from "./transactions-types.js"; +import { OrderShortInfo, TransactionType } from "./transactions-types.js"; /** * Identifier for a transaction in the wallet. @@ -159,6 +159,163 @@ export const codecForGetBalanceDetailRequest = .property("currency", codecForString()) .build("GetBalanceDetailRequest"); +export type GetPlanForOperationRequest = + | GetPlanForWithdrawRequest + | GetPlanForDepositRequest; +// | GetPlanForPushDebitRequest +// | GetPlanForPullCreditRequest +// | GetPlanForPaymentRequest +// | GetPlanForTipRequest +// | GetPlanForRefundRequest +// | GetPlanForPullDebitRequest +// | GetPlanForPushCreditRequest; + +interface GetPlanForWalletInitiatedOperation { + instructedAmount: AmountString; + mode: "raw" | "effective"; +} + +interface GetPlanToCompleteOperation { + instructedAmount: AmountString; +} + +const codecForGetPlanForWalletInitiatedOperation = < + T extends GetPlanForWalletInitiatedOperation, +>() => + buildCodecForObject() + .property( + "mode", + codecForEither( + codecForConstString("raw"), + codecForConstString("effective"), + ), + ) + .property("instructedAmount", codecForAmountString()); + +interface GetPlanForWithdrawRequest extends GetPlanForWalletInitiatedOperation { + type: TransactionType.Withdrawal; + exchangeUrl?: string; +} +interface GetPlanForDepositRequest extends GetPlanForWalletInitiatedOperation { + type: TransactionType.Deposit; + account: string; //payto string +} +interface GetPlanForPushDebitRequest + extends GetPlanForWalletInitiatedOperation { + type: TransactionType.PeerPushDebit; +} + +interface GetPlanForPullCreditRequest + extends GetPlanForWalletInitiatedOperation { + type: TransactionType.PeerPullCredit; + exchangeUrl: string; +} + +const codecForGetPlanForWithdrawRequest = + codecForGetPlanForWalletInitiatedOperation() + .property("type", codecForConstString(TransactionType.Withdrawal)) + .property("exchangeUrl", codecOptional(codecForString())) + .build("GetPlanForWithdrawRequest"); + +const codecForGetPlanForDepositRequest = + codecForGetPlanForWalletInitiatedOperation() + .property("type", codecForConstString(TransactionType.Deposit)) + .property("account", codecForString()) + .build("GetPlanForDepositRequest"); + +const codecForGetPlanForPushDebitRequest = + codecForGetPlanForWalletInitiatedOperation() + .property("type", codecForConstString(TransactionType.PeerPushDebit)) + .build("GetPlanForPushDebitRequest"); + +const codecForGetPlanForPullCreditRequest = + codecForGetPlanForWalletInitiatedOperation() + .property("type", codecForConstString(TransactionType.PeerPullCredit)) + .property("exchangeUrl", codecForString()) + .build("GetPlanForPullCreditRequest"); + +interface GetPlanForPaymentRequest extends GetPlanToCompleteOperation { + type: TransactionType.Payment; + wireMethod: string; + ageRestriction: number; + maxDepositFee: AmountString; + maxWireFee: AmountString; +} + +// interface GetPlanForTipRequest extends GetPlanForOperationBase { +// type: TransactionType.Tip; +// } +// interface GetPlanForRefundRequest extends GetPlanForOperationBase { +// type: TransactionType.Refund; +// } +interface GetPlanForPullDebitRequest extends GetPlanToCompleteOperation { + type: TransactionType.PeerPullDebit; +} +interface GetPlanForPushCreditRequest extends GetPlanToCompleteOperation { + type: TransactionType.PeerPushCredit; +} + +const codecForGetPlanForPaymentRequest = + buildCodecForObject() + .property("type", codecForConstString(TransactionType.Payment)) + .property("maxDepositFee", codecForAmountString()) + .property("maxWireFee", codecForAmountString()) + .build("GetPlanForPaymentRequest"); + +const codecForGetPlanForPullDebitRequest = + buildCodecForObject() + .property("type", codecForConstString(TransactionType.PeerPullDebit)) + .build("GetPlanForPullDebitRequest"); + +const codecForGetPlanForPushCreditRequest = + buildCodecForObject() + .property("type", codecForConstString(TransactionType.PeerPushCredit)) + .build("GetPlanForPushCreditRequest"); + +export const codecForGetPlanForOperationRequest = + (): Codec => + buildCodecForUnion() + .discriminateOn("type") + .alternative( + TransactionType.Withdrawal, + codecForGetPlanForWithdrawRequest, + ) + .alternative(TransactionType.Deposit, codecForGetPlanForDepositRequest) + // .alternative( + // TransactionType.PeerPushDebit, + // codecForGetPlanForPushDebitRequest, + // ) + // .alternative( + // TransactionType.PeerPullCredit, + // codecForGetPlanForPullCreditRequest, + // ) + // .alternative(TransactionType.Payment, codecForGetPlanForPaymentRequest) + // .alternative( + // TransactionType.PeerPullDebit, + // codecForGetPlanForPullDebitRequest, + // ) + // .alternative( + // TransactionType.PeerPushCredit, + // codecForGetPlanForPushCreditRequest, + // ) + .build("GetPlanForOperationRequest"); + +export interface GetPlanForOperationResponse { + effectiveAmount: AmountString; + rawAmount: AmountString; + counterPartyAmount?: AmountString; + details: any; +} + +export const codecForGetPlanForOperationResponse = + (): Codec => + buildCodecForObject() + .property("effectiveAmount", codecForAmountString()) + .property("rawAmount", codecForAmountString()) + .property("details", codecForAny()) + .property("counterPartyAmount", codecOptional(codecForAmountString())) + .build("GetPlanForOperationResponse"); + export interface Balance { scopeInfo: ScopeInfo; available: AmountString;