commit 8f86055c0cbaae66212341aae9319adb9f2a5f52
parent 06d79e42b9612f994216928635dac5e3238c544a
Author: Florian Dold <dold@taler.net>
Date: Tue, 10 Nov 2026 16:21:43 +0100
taler-util: define typed peer-credit snapshot observations
Diffstat:
5 files changed, 151 insertions(+), 1 deletion(-)
diff --git a/packages/taler-util/src/index.ts b/packages/taler-util/src/index.ts
@@ -51,6 +51,7 @@ export {
xsalsa20Poly1305Encrypt,
} from "./xsalsa20poly1305.js";
export * from "./notifications.js";
+export * from "./types-taler-wallet-observations.js";
export * from "./observability.js";
export * from "./operation.js";
export * from "./payto.js";
diff --git a/packages/taler-util/src/notifications.ts b/packages/taler-util/src/notifications.ts
@@ -34,8 +34,14 @@ import {
} from "./types-taler-wallet.js";
import { AmountString } from "./types-taler-common.js";
+import type {
+ ObservationType,
+ PeerPushCreditSnapshot,
+} from "./types-taler-wallet-observations.js";
export enum NotificationType {
+ ObservationSnapshot = "observation-snapshot",
+ ObservationError = "observation-error",
CoinRecoveryProgress = "coin-recovery-progress",
BalanceChange = "balance-change",
BankAccountChange = "bank-account-change",
@@ -60,6 +66,29 @@ export interface ErrorInfoSummary {
message?: string;
}
+export interface PeerPushCreditSnapshotNotification {
+ type: NotificationType.ObservationSnapshot;
+ observationType: ObservationType.PeerPushCredit;
+ observationId: string;
+ /** Starts at 1; increases within this observation when its value changes. */
+ revision: number;
+ transactionId: TransactionIdStr;
+ /** Null is the final snapshot after deletion. */
+ snapshot: PeerPushCreditSnapshot | null;
+}
+
+/** Extend this union with a discriminated variant for each observed domain. */
+export type ObservationSnapshotNotification =
+ PeerPushCreditSnapshotNotification;
+
+/** Ends the observation; does not describe the outcome of the transaction. */
+export interface ObservationErrorNotification {
+ type: NotificationType.ObservationError;
+ observationType: ObservationType;
+ observationId: string;
+ error: ErrorInfoSummary;
+}
+
export interface TransactionStateTransitionNotification {
type: NotificationType.TransactionStateTransition;
@@ -443,6 +472,8 @@ export interface CoinRecoveryProgressNotification {
}
export type WalletNotification =
+ | ObservationSnapshotNotification
+ | ObservationErrorNotification
| CoinRecoveryProgressNotification
| BalanceChangeNotification
| BankAccountChangeNotification
diff --git a/packages/taler-util/src/types-taler-wallet-observations.ts b/packages/taler-util/src/types-taler-wallet-observations.ts
@@ -0,0 +1,115 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2026 Taler Systems S.A.
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+import { buildCodecForObject, codecForString } from "./codec.js";
+import type { ErrorInfoSummary } from "./notifications.js";
+import type {
+ AmountString,
+ CurrencySpecification,
+} from "./types-taler-common.js";
+import type { TalerPreciseTimestamp } from "./time.js";
+import { codecForTransactionIdStr } from "./types-taler-wallet.js";
+import type {
+ ExchangeKeyChangeInfo,
+ ExchangeTosStatus,
+ ExchangeUpdateStatus,
+ ScopeInfo,
+ TransactionIdStr,
+} from "./types-taler-wallet.js";
+import type {
+ PeerInfoShort,
+ TransactionAction,
+ TransactionState,
+ TransactionType,
+ TransactionRetryInfo,
+} from "./types-taler-wallet-transactions.js";
+
+export enum ObservationType {
+ PeerPushCredit = "peer-push-credit",
+}
+
+export interface ObservePeerPushCreditRequest {
+ transactionId: TransactionIdStr;
+ /** Fresh caller-generated ID, unique within this wallet instance. */
+ observationId: string;
+}
+
+export interface StopObservationRequest {
+ observationId: string;
+}
+
+export const codecForObservePeerPushCreditRequest = () =>
+ buildCodecForObject<ObservePeerPushCreditRequest>()
+ .property("transactionId", codecForTransactionIdStr())
+ .property("observationId", codecForString())
+ .build("ObservePeerPushCreditRequest");
+
+export const codecForStopObservationRequest = () =>
+ buildCodecForObject<StopObservationRequest>()
+ .property("observationId", codecForString())
+ .build("StopObservationRequest");
+
+export type PeerPushCreditConfirmationUnavailableReason =
+ | "not-proposed"
+ | "expired"
+ | "exchange-not-ready"
+ | "exchange-keys-not-accepted"
+ | "exchange-tos-not-accepted"
+ | "kyc-hard-limit";
+
+/** The transaction view with diagnostic payloads and internal fields omitted. */
+export interface ObservedPeerPushCreditTransaction {
+ type: TransactionType.PeerPushCredit;
+ transactionId: TransactionIdStr;
+ localTransactionId?: string;
+ legacy?: boolean;
+ timestamp: TalerPreciseTimestamp;
+ scopes: ScopeInfo[];
+ txState: TransactionState;
+ txActions: TransactionAction[];
+ amountRaw: AmountString;
+ /** Initial estimate, including fees; preserved even after failure. */
+ amountEffective: AmountString;
+ /** Settled balance effect; absent until it can be established. */
+ amountEffectiveFinal?: AmountString;
+ info: PeerInfoShort;
+ exchangeBaseUrl: string;
+ kycUrl?: string;
+ /** Exchange-reported waiting-for-review hint for active KYC only.
+ * Absence means unknown/not applicable; false does not exclude undisclosed review.
+ */
+ kycAmlReview?: boolean;
+ retryInfo?: TransactionRetryInfo;
+ error?: ErrorInfoSummary;
+ abortReason?: ErrorInfoSummary;
+ failReason?: ErrorInfoSummary;
+}
+
+export interface PeerPushCreditExchangeSnapshot {
+ exchangeBaseUrl: string;
+ tosStatus: ExchangeTosStatus;
+ unconfirmedKeyChange?: ExchangeKeyChangeInfo;
+ exchangeUpdateStatus: ExchangeUpdateStatus;
+ currencySpec: CurrencySpecification;
+ /** Exchange-account request, not an independent transaction KYC status. */
+ walletKycRequestedThreshold?: string;
+ tosCurrentEtag?: string;
+ kycHardLimit?: AmountString;
+ kycSoftLimit?: AmountString;
+ lastUpdateError?: ErrorInfoSummary;
+}
+
+/** Complete replacement value, assembled from one committed database view. */
+export interface PeerPushCreditSnapshot {
+ transaction: ObservedPeerPushCreditTransaction;
+ exchange: PeerPushCreditExchangeSnapshot | null;
+ confirmation: {
+ /** Empty means confirmation is available based on local knowledge.
+ * Confirmation rechecks the prerequisites.
+ */
+ unavailableReasons: PeerPushCreditConfirmationUnavailableReason[];
+ };
+}
diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts
@@ -131,7 +131,7 @@ export type PendingIdStr = `pnd:${string}:${string}` & { [__pndId]: true };
declare const __tmbId: unique symbol;
export type TombstoneIdStr = `tmb:${string}:${string}` & { [__tmbId]: true };
-function codecForTransactionIdStr(): Codec<TransactionIdStr> {
+export function codecForTransactionIdStr(): Codec<TransactionIdStr> {
return {
decode(x: any, c?: Context): TransactionIdStr {
if (typeof x === "string" && x.startsWith("txn:")) {
diff --git a/packages/wallet-webui/src/api/notifications.ts b/packages/wallet-webui/src/api/notifications.ts
@@ -66,6 +66,9 @@ export function notificationFamilies(
case NotificationType.BackupOperationError:
return ["diagnostics"];
case NotificationType.Idle:
+ // Observations already carry their view; they must not trigger query reloads.
+ case NotificationType.ObservationSnapshot:
+ case NotificationType.ObservationError:
case NotificationType.TaskObservabilityEvent:
case NotificationType.RequestObservabilityEvent:
case NotificationType.RequestProgressError: