import type { MutationEvent } from "../types.js"; import type { ChainId } from "@reactive-dot/core"; import { MutationError } from "@reactive-dot/core"; import type { Transaction, TxEvent } from "polkadot-api"; import { catchError, tap, type MonoTypeOperatorFunction, type Observable, } from "rxjs"; import { type Ref } from "vue"; export function tapTx( mutationEventRef: Ref, chainId: ChainId, transaction: Transaction, ): MonoTypeOperatorFunction { return (source: Observable) => { const eventProps = { id: globalThis.crypto.randomUUID(), chainId, call: transaction.decodedCall, }; mutationEventRef.value = { ...eventProps, status: "pending" }; return source.pipe( tap( (value) => (mutationEventRef.value = { ...eventProps, status: "success", data: value, }), ), catchError((error) => { mutationEventRef.value = { ...eventProps, status: "error", error: MutationError.from(error), }; throw error; }), ); }; }