aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-08-12 15:48:02 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-08-12 15:48:02 +0530
commit56f5a1e3abe2679b4913ac87ff82860bb9675823 (patch)
tree5780413d148ac9cd84ac05cbca51018ae87248fd /packages/taler-wallet-core
parent6d2d65bf630e82ec99b187b7572463db7bba3f7f (diff)
codec
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r--packages/taler-wallet-core/src/types/walletTypes.ts52
-rw-r--r--packages/taler-wallet-core/src/util/amounts.ts3
-rw-r--r--packages/taler-wallet-core/src/walletCoreApiHandler.ts42
3 files changed, 74 insertions, 23 deletions
diff --git a/packages/taler-wallet-core/src/types/walletTypes.ts b/packages/taler-wallet-core/src/types/walletTypes.ts
index 8faace033..d79ade971 100644
--- a/packages/taler-wallet-core/src/types/walletTypes.ts
+++ b/packages/taler-wallet-core/src/types/walletTypes.ts
@@ -27,7 +27,11 @@
/**
* Imports.
*/
-import { AmountJson, codecForAmountJson } from "../util/amounts";
+import {
+ AmountJson,
+ codecForAmountJson,
+ codecForAmountString,
+} from "../util/amounts";
import * as LibtoolVersion from "../util/libtoolVersion";
import {
ExchangeRecord,
@@ -42,8 +46,10 @@ import {
Codec,
makeCodecForList,
codecForBoolean,
+ makeCodecForConstString,
+ codecForAny,
} from "../util/codec";
-import { AmountString } from "./talerTypes";
+import { AmountString, codecForContractTerms } from "./talerTypes";
import { TransactionError } from "./transactions";
/**
@@ -351,6 +357,48 @@ export const enum PreparePayResultType {
AlreadyConfirmed = "already-confirmed",
}
+export const codecForPreparePayResultPaymentPossible = (): Codec<
+ PreparePayResultPaymentPossible
+> =>
+ makeCodecForObject<PreparePayResultPaymentPossible>()
+ .property("amountEffective", codecForAmountString())
+ .property("amountRaw", codecForAmountString())
+ .property("contractTerms", codecForAny)
+ .property("proposalId", codecForString)
+ .property(
+ "status",
+ makeCodecForConstString(PreparePayResultType.PaymentPossible),
+ )
+ .build("PreparePayResultPaymentPossible");
+
+export const codecForPreparePayResultInsufficientBalance = (): Codec<
+ PreparePayResultInsufficientBalance
+> =>
+ makeCodecForObject<PreparePayResultInsufficientBalance>()
+ .property("amountRaw", codecForAmountString())
+ .property("contractTerms", codecForAny)
+ .property("proposalId", codecForString)
+ .property(
+ "status",
+ makeCodecForConstString(PreparePayResultType.InsufficientBalance),
+ )
+ .build("PreparePayResultInsufficientBalance");
+
+export const codecForPreparePayResultAlreadyConfirmed = (): Codec<
+ PreparePayResultAlreadyConfirmed
+> =>
+ makeCodecForObject<PreparePayResultAlreadyConfirmed>()
+ .property(
+ "status",
+ makeCodecForConstString(PreparePayResultType.AlreadyConfirmed),
+ )
+ .property("amountEffective", codecForAmountString())
+ .property("amountRaw", codecForAmountString())
+ .property("nextUrl", codecForString)
+ .property("paid", codecForBoolean)
+ .property("contractTerms", codecForAny)
+ .build("PreparePayResultAlreadyConfirmed");
+
export type PreparePayResult =
| PreparePayResultInsufficientBalance
| PreparePayResultAlreadyConfirmed
diff --git a/packages/taler-wallet-core/src/util/amounts.ts b/packages/taler-wallet-core/src/util/amounts.ts
index 00f4b17d7..33faa868e 100644
--- a/packages/taler-wallet-core/src/util/amounts.ts
+++ b/packages/taler-wallet-core/src/util/amounts.ts
@@ -27,6 +27,7 @@ import {
codecForNumber,
Codec,
} from "./codec";
+import { AmountString } from "../types/talerTypes";
/**
* Number of fractional units that one value unit represents.
@@ -73,6 +74,8 @@ export const codecForAmountJson = (): Codec<AmountJson> =>
.property("fraction", codecForNumber)
.build("AmountJson");
+export const codecForAmountString = (): Codec<AmountString> => codecForString;
+
/**
* Result of a possibly overflowing operation.
*/
diff --git a/packages/taler-wallet-core/src/walletCoreApiHandler.ts b/packages/taler-wallet-core/src/walletCoreApiHandler.ts
index a0b205485..604439186 100644
--- a/packages/taler-wallet-core/src/walletCoreApiHandler.ts
+++ b/packages/taler-wallet-core/src/walletCoreApiHandler.ts
@@ -31,30 +31,30 @@ import {
import { Amounts } from "./util/amounts";
import { OperationErrorDetails } from "./types/walletTypes";
-interface AddExchangeRequest {
+export interface AddExchangeRequest {
exchangeBaseUrl: string;
}
-const codecForAddExchangeRequest = (): Codec<AddExchangeRequest> =>
+export const codecForAddExchangeRequest = (): Codec<AddExchangeRequest> =>
makeCodecForObject<AddExchangeRequest>()
.property("exchangeBaseUrl", codecForString)
.build("AddExchangeRequest");
-interface GetExchangeTosRequest {
+export interface GetExchangeTosRequest {
exchangeBaseUrl: string;
}
-const codecForGetExchangeTosRequest = (): Codec<GetExchangeTosRequest> =>
+export const codecForGetExchangeTosRequest = (): Codec<GetExchangeTosRequest> =>
makeCodecForObject<GetExchangeTosRequest>()
.property("exchangeBaseUrl", codecForString)
.build("GetExchangeTosRequest");
-interface AcceptManualWithdrawalRequest {
+export interface AcceptManualWithdrawalRequest {
exchangeBaseUrl: string;
amount: string;
}
-const codecForAcceptManualWithdrawalRequet = (): Codec<
+export const codecForAcceptManualWithdrawalRequet = (): Codec<
AcceptManualWithdrawalRequest
> =>
makeCodecForObject<AcceptManualWithdrawalRequest>()
@@ -62,17 +62,17 @@ const codecForAcceptManualWithdrawalRequet = (): Codec<
.property("amount", codecForString)
.build("AcceptManualWithdrawalRequest");
-interface GetWithdrawalDetailsForAmountRequest {
+export interface GetWithdrawalDetailsForAmountRequest {
exchangeBaseUrl: string;
amount: string;
}
-interface AcceptBankIntegratedWithdrawalRequest {
+export interface AcceptBankIntegratedWithdrawalRequest {
talerWithdrawUri: string;
exchangeBaseUrl: string;
}
-const codecForAcceptBankIntegratedWithdrawalRequest = (): Codec<
+export const codecForAcceptBankIntegratedWithdrawalRequest = (): Codec<
AcceptBankIntegratedWithdrawalRequest
> =>
makeCodecForObject<AcceptBankIntegratedWithdrawalRequest>()
@@ -80,7 +80,7 @@ const codecForAcceptBankIntegratedWithdrawalRequest = (): Codec<
.property("talerWithdrawUri", codecForString)
.build("AcceptBankIntegratedWithdrawalRequest");
-const codecForGetWithdrawalDetailsForAmountRequest = (): Codec<
+export const codecForGetWithdrawalDetailsForAmountRequest = (): Codec<
GetWithdrawalDetailsForAmountRequest
> =>
makeCodecForObject<GetWithdrawalDetailsForAmountRequest>()
@@ -88,47 +88,47 @@ const codecForGetWithdrawalDetailsForAmountRequest = (): Codec<
.property("amount", codecForString)
.build("GetWithdrawalDetailsForAmountRequest");
-interface AcceptExchangeTosRequest {
+export interface AcceptExchangeTosRequest {
exchangeBaseUrl: string;
etag: string;
}
-const codecForAcceptExchangeTosRequest = (): Codec<AcceptExchangeTosRequest> =>
+export const codecForAcceptExchangeTosRequest = (): Codec<AcceptExchangeTosRequest> =>
makeCodecForObject<AcceptExchangeTosRequest>()
.property("exchangeBaseUrl", codecForString)
.property("etag", codecForString)
.build("AcceptExchangeTosRequest");
-interface ApplyRefundRequest {
+export interface ApplyRefundRequest {
talerRefundUri: string;
}
-const codecForApplyRefundRequest = (): Codec<ApplyRefundRequest> =>
+export const codecForApplyRefundRequest = (): Codec<ApplyRefundRequest> =>
makeCodecForObject<ApplyRefundRequest>()
.property("talerRefundUri", codecForString)
.build("ApplyRefundRequest");
-interface GetWithdrawalDetailsForUriRequest {
+export interface GetWithdrawalDetailsForUriRequest {
talerWithdrawUri: string;
}
-const codecForGetWithdrawalDetailsForUri = (): Codec<
+export const codecForGetWithdrawalDetailsForUri = (): Codec<
GetWithdrawalDetailsForUriRequest
> =>
makeCodecForObject<GetWithdrawalDetailsForUriRequest>()
.property("talerWithdrawUri", codecForString)
.build("GetWithdrawalDetailsForUriRequest");
-interface AbortProposalRequest {
+export interface AbortProposalRequest {
proposalId: string;
}
-const codecForAbortProposalRequest = (): Codec<AbortProposalRequest> =>
+export const codecForAbortProposalRequest = (): Codec<AbortProposalRequest> =>
makeCodecForObject<AbortProposalRequest>()
.property("proposalId", codecForString)
.build("AbortProposalRequest");
-interface PreparePayRequest {
+export interface PreparePayRequest {
talerPayUri: string;
}
@@ -137,12 +137,12 @@ const codecForPreparePayRequest = (): Codec<PreparePayRequest> =>
.property("talerPayUri", codecForString)
.build("PreparePay");
-interface ConfirmPayRequest {
+export interface ConfirmPayRequest {
proposalId: string;
sessionId?: string;
}
-const codecForConfirmPayRequest = (): Codec<ConfirmPayRequest> =>
+export const codecForConfirmPayRequest = (): Codec<ConfirmPayRequest> =>
makeCodecForObject<ConfirmPayRequest>()
.property("proposalId", codecForString)
.property("sessionId", makeCodecOptional(codecForString))