summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-09-01 19:56:08 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-09-01 19:56:08 +0530
commit7f4ebca0c4330805ea8f3821dba075b34dd2be58 (patch)
tree39e9c0994969565ab9a227494beaf5e830315e9a
parent62406304d9a81a08797c09f5151de74d8ca43fe8 (diff)
downloadwallet-core-7f4ebca0c4330805ea8f3821dba075b34dd2be58.tar.gz
wallet-core-7f4ebca0c4330805ea8f3821dba075b34dd2be58.tar.bz2
wallet-core-7f4ebca0c4330805ea8f3821dba075b34dd2be58.zip
validation
-rw-r--r--packages/taler-wallet-core/src/operations/refund.ts15
-rw-r--r--packages/taler-wallet-core/src/types/talerTypes.ts12
-rw-r--r--packages/taler-wallet-core/src/types/walletTypes.ts30
-rw-r--r--packages/taler-wallet-core/src/util/codec.ts20
4 files changed, 45 insertions, 32 deletions
diff --git a/packages/taler-wallet-core/src/operations/refund.ts b/packages/taler-wallet-core/src/operations/refund.ts
index 787d2bb4c..373e17a10 100644
--- a/packages/taler-wallet-core/src/operations/refund.ts
+++ b/packages/taler-wallet-core/src/operations/refund.ts
@@ -28,6 +28,7 @@ import {
TalerErrorDetails,
RefreshReason,
CoinPublicKey,
+ ApplyRefundResponse,
} from "../types/walletTypes";
import {
Stores,
@@ -323,20 +324,6 @@ export interface RefundSummary {
amountRefundGone: AmountJson;
}
-export interface ApplyRefundResponse {
- contractTermsHash: string;
-
- proposalId: string;
-
- amountEffectivePaid: AmountString;
-
- amountRefundGranted: AmountString;
-
- amountRefundGone: AmountString;
-
- pendingAtExchange: boolean;
-}
-
/**
* Accept a refund, return the contract hash for the contract
* that was involved in the refund.
diff --git a/packages/taler-wallet-core/src/types/talerTypes.ts b/packages/taler-wallet-core/src/types/talerTypes.ts
index b9e7fae4a..b1061a1ae 100644
--- a/packages/taler-wallet-core/src/types/talerTypes.ts
+++ b/packages/taler-wallet-core/src/types/talerTypes.ts
@@ -985,7 +985,7 @@ export const codecForBankWithdrawalOperationPostResponse = (): Codec<
BankWithdrawalOperationPostResponse
> =>
buildCodecForObject<BankWithdrawalOperationPostResponse>()
- .property("transfer_done", codecForBoolean)
+ .property("transfer_done", codecForBoolean())
.build("BankWithdrawalOperationPostResponse");
export type AmountString = string;
@@ -1189,7 +1189,7 @@ export const codecForProposal = (): Codec<Proposal> =>
export const codecForCheckPaymentResponse = (): Codec<CheckPaymentResponse> =>
buildCodecForObject<CheckPaymentResponse>()
.property("order_status", codecForString())
- .property("refunded", codecOptional(codecForBoolean))
+ .property("refunded", codecOptional(codecForBoolean()))
.property("refunded_amount", codecOptional(codecForString()))
.property("contract_terms", codecOptional(codecForAny()))
.property("taler_pay_uri", codecOptional(codecForString()))
@@ -1200,9 +1200,9 @@ export const codecForWithdrawOperationStatusResponse = (): Codec<
WithdrawOperationStatusResponse
> =>
buildCodecForObject<WithdrawOperationStatusResponse>()
- .property("selection_done", codecForBoolean)
- .property("transfer_done", codecForBoolean)
- .property("aborted", codecForBoolean)
+ .property("selection_done", codecForBoolean())
+ .property("transfer_done", codecForBoolean())
+ .property("aborted", codecForBoolean())
.property("amount", codecForString())
.property("sender_wire", codecOptional(codecForString()))
.property("suggested_exchange", codecOptional(codecForString()))
@@ -1298,7 +1298,7 @@ export const codecForMerchantOrderStatusPaid = (): Codec<
> =>
buildCodecForObject<MerchantOrderStatusPaid>()
.property("refund_amount", codecForString())
- .property("refunded", codecForBoolean)
+ .property("refunded", codecForBoolean())
.build("MerchantOrderStatusPaid");
export const codecForMerchantOrderRefundPickupResponse = (): Codec<
diff --git a/packages/taler-wallet-core/src/types/walletTypes.ts b/packages/taler-wallet-core/src/types/walletTypes.ts
index 89c8b4a8b..dbaefae3b 100644
--- a/packages/taler-wallet-core/src/types/walletTypes.ts
+++ b/packages/taler-wallet-core/src/types/walletTypes.ts
@@ -180,10 +180,10 @@ export interface BalancesResponse {
export const codecForBalance = (): Codec<Balance> =>
buildCodecForObject<Balance>()
.property("available", codecForString())
- .property("hasPendingTransactions", codecForBoolean)
+ .property("hasPendingTransactions", codecForBoolean())
.property("pendingIncoming", codecForString())
.property("pendingOutgoing", codecForString())
- .property("requiresUserInput", codecForBoolean)
+ .property("requiresUserInput", codecForBoolean())
.build("Balance");
export const codecForBalancesResponse = (): Codec<BalancesResponse> =>
@@ -413,7 +413,7 @@ export const codecForPreparePayResultAlreadyConfirmed = (): Codec<
)
.property("amountEffective", codecForAmountString())
.property("amountRaw", codecForAmountString())
- .property("paid", codecForBoolean)
+ .property("paid", codecForBoolean())
.property("contractTerms", codecForAny())
.property("contractTermsHash", codecForString())
.build("PreparePayResultAlreadyConfirmed");
@@ -843,3 +843,27 @@ export const codecForWithdrawTestBalance = (): Codec<
.property("bankBaseUrl", codecForString())
.property("exchangeBaseUrl", codecForString())
.build("WithdrawTestBalanceRequest");
+
+export interface ApplyRefundResponse {
+ contractTermsHash: string;
+
+ proposalId: string;
+
+ amountEffectivePaid: AmountString;
+
+ amountRefundGranted: AmountString;
+
+ amountRefundGone: AmountString;
+
+ pendingAtExchange: boolean;
+}
+
+export const codecForApplyRefundResponse = (): Codec<ApplyRefundResponse> =>
+ buildCodecForObject<ApplyRefundResponse>()
+ .property("amountEffectivePaid", codecForAmountString())
+ .property("amountRefundGone", codecForAmountString())
+ .property("amountRefundGranted", codecForAmountString())
+ .property("contractTermsHash", codecForString())
+ .property("pendingAtExchange", codecForBoolean())
+ .property("proposalId", codecForString())
+ .build("ApplyRefundResponse");
diff --git a/packages/taler-wallet-core/src/util/codec.ts b/packages/taler-wallet-core/src/util/codec.ts
index 111abc38c..741a5b172 100644
--- a/packages/taler-wallet-core/src/util/codec.ts
+++ b/packages/taler-wallet-core/src/util/codec.ts
@@ -292,15 +292,17 @@ export function codecForNumber(): Codec<number> {
/**
* Return a codec for a value that must be a number.
*/
-export const codecForBoolean: Codec<boolean> = {
- decode(x: any, c?: Context): boolean {
- if (typeof x === "boolean") {
- return x;
- }
- throw new DecodingError(
- `expected boolean at ${renderContext(c)} but got ${typeof x}`,
- );
- },
+export function codecForBoolean(): Codec<boolean> {
+ return {
+ decode(x: any, c?: Context): boolean {
+ if (typeof x === "boolean") {
+ return x;
+ }
+ throw new DecodingError(
+ `expected boolean at ${renderContext(c)} but got ${typeof x}`,
+ );
+ },
+ }
};
/**