aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src/taler-types.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-10-22 13:50:34 -0300
committerSebastian <sebasjm@gmail.com>2023-10-22 13:50:34 -0300
commit2005273d1286819e68d3ea7a3290f8c357be5e40 (patch)
tree7808cc079800361c6fced024dc90c823a7a539d6 /packages/taler-util/src/taler-types.ts
parent2ac73949e7cb8de44e56f2fecae617efab15671e (diff)
downloadwallet-core-2005273d1286819e68d3ea7a3290f8c357be5e40.tar.xz
add codecAmountString for string field that are just amount, note that this does not add the validation so is just type checking for future validation
Diffstat (limited to 'packages/taler-util/src/taler-types.ts')
-rw-r--r--packages/taler-util/src/taler-types.ts20
1 files changed, 11 insertions, 9 deletions
diff --git a/packages/taler-util/src/taler-types.ts b/packages/taler-util/src/taler-types.ts
index 4b3a426f5..87925a3a4 100644
--- a/packages/taler-util/src/taler-types.ts
+++ b/packages/taler-util/src/taler-types.ts
@@ -1310,7 +1310,9 @@ export const codecForDenominationPubKey = () =>
.alternative(DenomKeyType.ClauseSchnorr, codecForCsDenominationPubKey())
.build("DenominationPubKey");
-export type AmountString = string;
+declare const __amount_str: unique symbol;
+export type AmountString = string & { [__amount_str]: true };
+// export type AmountString = string;
export type Base32String = string;
export type EddsaSignatureString = string;
export type EddsaPublicKeyString = string;
@@ -1381,7 +1383,7 @@ export const codecForMerchantInfo = (): Codec<MerchantInfo> =>
export const codecForTax = (): Codec<Tax> =>
buildCodecForObject<Tax>()
.property("name", codecForString())
- .property("tax", codecForString())
+ .property("tax", codecForAmountString())
.build("Tax");
export const codecForInternationalizedString =
@@ -1397,7 +1399,7 @@ export const codecForProduct = (): Codec<Product> =>
)
.property("quantity", codecOptional(codecForNumber()))
.property("unit", codecOptional(codecForString()))
- .property("price", codecOptional(codecForString()))
+ .property("price", codecOptional(codecForAmountString()))
.build("Tax");
export const codecForMerchantContractTerms = (): Codec<MerchantContractTerms> =>
@@ -1436,7 +1438,7 @@ export const codecForMerchantContractTerms = (): Codec<MerchantContractTerms> =>
export const codecForPeerContractTerms = (): Codec<PeerContractTerms> =>
buildCodecForObject<PeerContractTerms>()
.property("summary", codecForString())
- .property("amount", codecForString())
+ .property("amount", codecForAmountString())
.property("purse_expiration", codecForTimestamp)
.build("PeerContractTerms");
@@ -1624,7 +1626,7 @@ export const codecForMerchantCoinRefundSuccessStatus =
.property("exchange_status", codecForConstNumber(200))
.property("exchange_sig", codecForString())
.property("rtransaction_id", codecForNumber())
- .property("refund_amount", codecForString())
+ .property("refund_amount", codecForAmountString())
.property("exchange_pub", codecForString())
.property("execution_time", codecForTimestamp)
.build("MerchantCoinRefundSuccessStatus");
@@ -1636,7 +1638,7 @@ export const codecForMerchantCoinRefundFailureStatus =
.property("coin_pub", codecForString())
.property("exchange_status", codecForNumber())
.property("rtransaction_id", codecForNumber())
- .property("refund_amount", codecForString())
+ .property("refund_amount", codecForAmountString())
.property("exchange_code", codecOptional(codecForNumber()))
.property("exchange_reply", codecOptional(codecForAny()))
.property("execution_time", codecForTimestamp)
@@ -1653,8 +1655,8 @@ export const codecForMerchantCoinRefundStatus =
export const codecForMerchantOrderStatusPaid =
(): Codec<MerchantOrderStatusPaid> =>
buildCodecForObject<MerchantOrderStatusPaid>()
- .property("refund_amount", codecForString())
- .property("refund_taken", codecForString())
+ .property("refund_amount", codecForAmountString())
+ .property("refund_taken", codecForAmountString())
.property("refund_pending", codecForBoolean())
.property("refunded", codecForBoolean())
.build("MerchantOrderStatusPaid");
@@ -1663,7 +1665,7 @@ export const codecForMerchantOrderRefundPickupResponse =
(): Codec<MerchantOrderRefundResponse> =>
buildCodecForObject<MerchantOrderRefundResponse>()
.property("merchant_pub", codecForString())
- .property("refund_amount", codecForString())
+ .property("refund_amount", codecForAmountString())
.property("refunds", codecForList(codecForMerchantCoinRefundStatus()))
.build("MerchantOrderRefundPickupResponse");