diff options
author | Florian Dold <florian@dold.me> | 2023-08-05 23:34:25 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-08-05 23:34:37 +0200 |
commit | 6286699f26f486a9406827ef7359f62896a2dada (patch) | |
tree | 6f8deeb955c7bf3792b75c72544280c13feee5d3 /packages/taler-util | |
parent | 308a4282cbdde7376d88ca76e3eca967a1f02c46 (diff) | |
download | wallet-core-6286699f26f486a9406827ef7359f62896a2dada.tar.xz |
-validation
Diffstat (limited to 'packages/taler-util')
-rw-r--r-- | packages/taler-util/src/wallet-types.ts | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 922b20862..42d54752a 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -379,11 +379,44 @@ export interface Balance { requiresUserInput: boolean; } +export const codecForScopeInfoGlobal = (): Codec<ScopeInfoGlobal> => + buildCodecForObject<ScopeInfoGlobal>() + .property("currency", codecForString()) + .property("type", codecForConstString(ScopeType.Global)) + .build("ScopeInfoGlobal"); + +export const codecForScopeInfoExchange = (): Codec<ScopeInfoExchange> => + buildCodecForObject<ScopeInfoExchange>() + .property("currency", codecForString()) + .property("type", codecForConstString(ScopeType.Exchange)) + .property("url", codecForString()) + .build("ScopeInfoExchange"); + +export const codecForScopeInfoAuditor = (): Codec<ScopeInfoAuditor> => + buildCodecForObject<ScopeInfoAuditor>() + .property("currency", codecForString()) + .property("type", codecForConstString(ScopeType.Auditor)) + .property("url", codecForString()) + .build("ScopeInfoAuditor"); + +export const codecForScopeInfo = (): Codec<ScopeInfo> => + buildCodecForUnion<ScopeInfo>() + .discriminateOn("type") + .alternative(ScopeType.Global, codecForScopeInfoGlobal()) + .alternative(ScopeType.Exchange, codecForScopeInfoExchange()) + .alternative(ScopeType.Auditor, codecForScopeInfoAuditor()) + .build("ScopeInfo"); + export interface GetCurrencyInfoRequest { - currency: string; scope: ScopeInfo; } +export const codecForGetCurrencyInfoRequest = + (): Codec<GetCurrencyInfoRequest> => + buildCodecForObject<GetCurrencyInfoRequest>() + .property("scope", codecForScopeInfo()) + .build("GetCurrencyInfoRequest"); + export interface GetCurrencyInfoResponse { decimalSeparator: string; numFractionalDigits: number; @@ -407,10 +440,19 @@ export enum ScopeType { Auditor = "auditor", } -export type ScopeInfo = - | { type: ScopeType.Global; currency: string } - | { type: ScopeType.Exchange; currency: string; url: string } - | { type: ScopeType.Auditor; currency: string; url: string }; +export type ScopeInfoGlobal = { type: ScopeType.Global; currency: string }; +export type ScopeInfoExchange = { + type: ScopeType.Exchange; + currency: string; + url: string; +}; +export type ScopeInfoAuditor = { + type: ScopeType.Auditor; + currency: string; + url: string; +}; + +export type ScopeInfo = ScopeInfoGlobal | ScopeInfoExchange | ScopeInfoAuditor; export interface BalancesResponse { balances: Balance[]; |