gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] 01/03: get operation plan types


From: gnunet
Subject: [taler-wallet-core] 01/03: get operation plan types
Date: Tue, 13 Jun 2023 21:46:39 +0200

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

commit 671342818fb79123f231cfcbaf8251f1672effd1
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Tue Jun 13 16:45:42 2023 -0300

    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<T>()
+    .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<GetPlanForWithdrawRequest>()
+    .property("type", codecForConstString(TransactionType.Withdrawal))
+    .property("exchangeUrl", codecOptional(codecForString()))
+    .build("GetPlanForWithdrawRequest");
+
+const codecForGetPlanForDepositRequest =
+  codecForGetPlanForWalletInitiatedOperation<GetPlanForDepositRequest>()
+    .property("type", codecForConstString(TransactionType.Deposit))
+    .property("account", codecForString())
+    .build("GetPlanForDepositRequest");
+
+const codecForGetPlanForPushDebitRequest =
+  codecForGetPlanForWalletInitiatedOperation<GetPlanForPushDebitRequest>()
+    .property("type", codecForConstString(TransactionType.PeerPushDebit))
+    .build("GetPlanForPushDebitRequest");
+
+const codecForGetPlanForPullCreditRequest =
+  codecForGetPlanForWalletInitiatedOperation<GetPlanForPullCreditRequest>()
+    .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<GetPlanForPaymentRequest>()
+    .property("type", codecForConstString(TransactionType.Payment))
+    .property("maxDepositFee", codecForAmountString())
+    .property("maxWireFee", codecForAmountString())
+    .build("GetPlanForPaymentRequest");
+
+const codecForGetPlanForPullDebitRequest =
+  buildCodecForObject<GetPlanForPullDebitRequest>()
+    .property("type", codecForConstString(TransactionType.PeerPullDebit))
+    .build("GetPlanForPullDebitRequest");
+
+const codecForGetPlanForPushCreditRequest =
+  buildCodecForObject<GetPlanForPushCreditRequest>()
+    .property("type", codecForConstString(TransactionType.PeerPushCredit))
+    .build("GetPlanForPushCreditRequest");
+
+export const codecForGetPlanForOperationRequest =
+  (): Codec<GetPlanForOperationRequest> =>
+    buildCodecForUnion<GetPlanForOperationRequest>()
+      .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<GetPlanForOperationResponse> =>
+    buildCodecForObject<GetPlanForOperationResponse>()
+      .property("effectiveAmount", codecForAmountString())
+      .property("rawAmount", codecForAmountString())
+      .property("details", codecForAny())
+      .property("counterPartyAmount", codecOptional(codecForAmountString()))
+      .build("GetPlanForOperationResponse");
+
 export interface Balance {
   scopeInfo: ScopeInfo;
   available: AmountString;

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]