From 7f4ebca0c4330805ea8f3821dba075b34dd2be58 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 1 Sep 2020 19:56:08 +0530 Subject: validation --- .../taler-wallet-core/src/operations/refund.ts | 15 +---------- packages/taler-wallet-core/src/types/talerTypes.ts | 12 ++++----- .../taler-wallet-core/src/types/walletTypes.ts | 30 +++++++++++++++++++--- packages/taler-wallet-core/src/util/codec.ts | 20 ++++++++------- 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() - .property("transfer_done", codecForBoolean) + .property("transfer_done", codecForBoolean()) .build("BankWithdrawalOperationPostResponse"); export type AmountString = string; @@ -1189,7 +1189,7 @@ export const codecForProposal = (): Codec => export const codecForCheckPaymentResponse = (): Codec => buildCodecForObject() .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() - .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() .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 => buildCodecForObject() .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 => @@ -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 => + buildCodecForObject() + .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 { /** * Return a codec for a value that must be a number. */ -export const codecForBoolean: Codec = { - 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 { + 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}`, + ); + }, + } }; /** -- cgit v1.2.3