diff options
author | Sebastian <sebasjm@gmail.com> | 2023-10-30 15:27:25 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-10-30 15:27:25 -0300 |
commit | 768838285c25cbb1b171f645e8efb37a3c14273a (patch) | |
tree | 3404a7ea452a357baf4ebfc6c3b400f601849744 /packages/taler-util/src/taleruri.ts | |
parent | b7ba3119c1ff0d9ae3432cf0de1ef8cf92fc193c (diff) | |
download | wallet-core-768838285c25cbb1b171f645e8efb37a3c14273a.tar.gz wallet-core-768838285c25cbb1b171f645e8efb37a3c14273a.tar.bz2 wallet-core-768838285c25cbb1b171f645e8efb37a3c14273a.zip |
local error impl: errors shown fixed position that are wiped when moved from the view
Diffstat (limited to 'packages/taler-util/src/taleruri.ts')
-rw-r--r-- | packages/taler-util/src/taleruri.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/taler-util/src/taleruri.ts b/packages/taler-util/src/taleruri.ts index 9568636b8..cf5d3f413 100644 --- a/packages/taler-util/src/taleruri.ts +++ b/packages/taler-util/src/taleruri.ts @@ -14,6 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { Codec, Context, DecodingError, renderContext } from "./codec.js"; import { canonicalizeBaseUrl } from "./helpers.js"; import { AmountString } from "./taler-types.js"; import { URLSearchParams, URL } from "./url.js"; @@ -32,6 +33,27 @@ export type TalerUri = | WithdrawExchangeUri | AuditorUri; +declare const __action_str: unique symbol; +export type TalerActionString = string & { [__action_str]: true }; + +export function codecForTalerActionString(): Codec<TalerActionString> { + return { + decode(x: any, c?: Context): TalerActionString { + if (typeof x !== "string") { + throw new DecodingError( + `expected string at ${renderContext(c)} but got ${typeof x}`, + ); + } + if (parseTalerUri(x) === undefined) { + throw new DecodingError( + `invalid taler action at ${renderContext(c)} but got "${x}"`, + ); + } + return x as TalerActionString; + }, + }; +} + export interface PayUriResult { type: TalerUriAction.Pay; merchantBaseUrl: string; |