taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit a0e677863906ac7587fe065612da550751ba9a02
parent 706cbf7191e401a8794f4bde7b112b6a9019b7dc
Author: Florian Dold <florian@dold.me>
Date:   Wed,  4 Dec 2024 21:56:08 +0100

wallet-core: implement isInternal flag for balance notifications

Diffstat:
Mpackages/taler-util/src/notifications.ts | 40+++++++++++++++++++++++++---------------
Mpackages/taler-wallet-core/src/transactions.ts | 13++++++-------
2 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/packages/taler-util/src/notifications.ts b/packages/taler-util/src/notifications.ts @@ -34,10 +34,6 @@ export enum NotificationType { BalanceChange = "balance-change", BackupOperationError = "backup-error", TransactionStateTransition = "transaction-state-transition", - /** - * @deprecated - */ - WithdrawalOperationTransition = "withdrawal-operation-transition", ExchangeStateTransition = "exchange-state-transition", Idle = "idle", TaskObservabilityEvent = "task-observability-event", @@ -52,9 +48,25 @@ export interface ErrorInfoSummary { export interface TransactionStateTransitionNotification { type: NotificationType.TransactionStateTransition; + + /** + * Identifier of the affected transaction. + */ transactionId: string; + + /** + * State before the transition. + */ oldTxState: TransactionState; + + /** + * State after the transition. + */ newTxState: TransactionState; + + /** + * Short summary of the error for an error transition. + */ errorInfo?: ErrorInfoSummary; /** @@ -101,6 +113,15 @@ export interface BalanceChangeNotification { type: NotificationType.BalanceChange; /** + * If set to true, the balance change is internal + * to the wallet and not visible to the user. + * + * (For example when the material balance changes via a refresh, but + * the available balance stays the same.) + */ + isInternal?: boolean; + + /** * Transaction ID of the transaction that caused the balance update. * * Only used as a hint for debugging, should not be relied upon by clients. @@ -240,16 +261,6 @@ export interface BackupOperationErrorNotification { type: NotificationType.BackupOperationError; error: TalerErrorDetail; } -/** - * This notification is required to signal UI that - * the withdrawal operation changed the state. - * - * https://bugs.gnunet.org/view.php?id=8099 - */ -export interface WithdrawalOperationTransitionNotification { - type: NotificationType.WithdrawalOperationTransition; - uri: string; -} export interface IdleNotification { type: NotificationType.Idle; @@ -257,7 +268,6 @@ export interface IdleNotification { export type WalletNotification = | BalanceChangeNotification - | WithdrawalOperationTransitionNotification | BackupOperationErrorNotification | ExchangeStateTransitionNotification | TransactionStateTransitionNotification diff --git a/packages/taler-wallet-core/src/transactions.ts b/packages/taler-wallet-core/src/transactions.ts @@ -929,16 +929,15 @@ export function notifyTransition( experimentalUserData, }); - if (couldChangeBalance(transitionInfo)) { - wex.ws.notify({ - type: NotificationType.BalanceChange, - hintTransactionId: transactionId, - }); - } + wex.ws.notify({ + type: NotificationType.BalanceChange, + hintTransactionId: transactionId, + isInternal: !couldChangeVisibleBalance(transitionInfo), + }); } } -function couldChangeBalance(ti: TransitionInfo): boolean { +function couldChangeVisibleBalance(ti: TransitionInfo): boolean { // We emit a balance change notification unless we're sure that // the transition does not affect the balance. if (ti.newTxState.major == ti.oldTxState.major) {