/** * Token persistence utilities for CryptoAssetsStore * Handles extracting, saving, and restoring tokens from RTK Query cache */ import type { TokenCurrency } from "@ledgerhq/types-cryptoassets"; import { cryptoAssetsApi } from "./state-manager/api"; import type { ThunkDispatch } from "@reduxjs/toolkit"; /** * Current version of the persistence format * Increment this when making breaking changes to the format */ export declare const PERSISTENCE_VERSION = 2; /** * Serializable token format * This is TokenCurrency without the parentCurrency object (replaced by parentCurrencyId) */ export interface TokenCurrencyRaw { id: string; contractAddress: string; parentCurrencyId: string; tokenType: string; name: string; ticker: string; units: Array<{ name: string; code: string; magnitude: number; }>; delisted?: boolean; disableCountervalue?: boolean; ledgerSignature?: string; } /** * Persisted token entry with timestamp */ export interface PersistedTokenEntry { /** Serializable token data */ data: TokenCurrencyRaw; /** When this token was fetched (Unix timestamp in ms) */ timestamp: number; } /** * Root persistence format with versioning */ export interface PersistedCAL { /** Format version for migration handling */ version: number; /** Array of persisted tokens */ tokens: PersistedTokenEntry[]; /** Mapping of currencyId to X-Ledger-Commit hash */ hashes?: Record; } /** * Converts TokenCurrency to serializable Raw format */ export declare function toTokenCurrencyRaw(token: TokenCurrency): TokenCurrencyRaw; /** * Converts Raw format back to TokenCurrency * Returns undefined if parent currency is not found */ export declare function fromTokenCurrencyRaw(raw: TokenCurrencyRaw): TokenCurrency | undefined; /** * Redux state that includes the cryptoAssetsApi reducer */ export interface StateWithCryptoAssets { [cryptoAssetsApi.reducerPath]: ReturnType; } /** * Extracts all cached tokens from RTK Query state * Only includes fulfilled queries for findTokenById and findTokenByAddressInCurrency * Converts tokens to serializable format */ export declare function extractTokensFromState(state: StateWithCryptoAssets): PersistedTokenEntry[]; /** * Extracts hashes from getTokensSyncHash queries in RTK Query state * Returns a mapping of currencyId to hash */ export declare function extractHashesFromState(state: StateWithCryptoAssets): Record; /** * Extracts all persisted data (tokens and hashes) from RTK Query state * Returns a complete PersistedCAL object ready for serialization */ export declare function extractPersistedCALFromState(state: StateWithCryptoAssets): PersistedCAL; /** * Compares two PersistedCAL values by content (version, hashes, token data). * Ignores token timestamps so that refetches with identical cache content are considered equal. * Returns true only when both are null or both are content-equal. */ export declare function persistedCALContentEqual(a: PersistedCAL | null, b: PersistedCAL | null): boolean; /** * Filters out expired tokens based on TTL */ export declare function filterExpiredTokens(tokens: PersistedTokenEntry[], ttl: number): PersistedTokenEntry[]; /** * Restores tokens from persisted data to RTK Query cache. * Validates persisted hashes against current hashes and evicts cache if they differ. */ export declare function restoreTokensToCache(dispatch: ThunkDispatch, persistedData: PersistedCAL, ttl: number): Promise; //# sourceMappingURL=persistence.d.ts.map