From c677ad2488f018cc1e9e305ad1dbbe920b51d038 Mon Sep 17 00:00:00 2001 From: Christian Baroni <7061887+christianbaroni@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:10:13 +0000 Subject: [PATCH] Organize types, skip string conversion if unneeded in getOrCreateAttachValue --- src/state/internal/createQueryStore.ts | 34 ++++++++++----------- src/state/internal/signal.ts | 3 +- src/state/internal/tests/QueryStoreTest.tsx | 8 ++--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/state/internal/createQueryStore.ts b/src/state/internal/createQueryStore.ts index 6d7bf4dfa2a..41ad4ad0980 100644 --- a/src/state/internal/createQueryStore.ts +++ b/src/state/internal/createQueryStore.ts @@ -174,17 +174,6 @@ export type RainbowQueryStoreConfig TQueryFnData | Promise; - /** - * The maximum number of times to retry a failed fetch operation. - * @default 3 - */ - maxRetries?: number; - /** - * The delay between retries after a fetch error occurs, in milliseconds, defined as a number or a function that - * receives the error and current retry count and returns a number. - * @default time.seconds(5) - */ - retryDelay?: number | ((retryCount: number, error: Error) => number); /** * A callback invoked whenever a fetch operation fails. * Receives the error and the current retry count. @@ -199,7 +188,7 @@ export type RainbowQueryStoreConfig | ((state: S) => S | Partial)) => void; }) => void; - /** - * Suppresses warnings in the event a `staleTime` under the minimum is desired. - * @default false - */ - suppressStaleTimeWarning?: boolean; /** * A function to transform the raw fetched data (`TQueryFnData`) into another form (`TData`). * If not provided, the raw data returned by `fetcher` is used. @@ -245,6 +229,11 @@ export type RainbowQueryStoreConfig; }; + /** + * The delay between retries after a fetch error occurs, in milliseconds, defined as a number or a function that + * receives the error and current retry count and returns a number. + * @default time.seconds(5) + */ + retryDelay?: number | ((retryCount: number, error: Error) => number); /** * The duration, in milliseconds, that data is considered fresh after fetching. * After becoming stale, the store may automatically refetch data in the background if there are active subscribers. @@ -260,6 +255,11 @@ export type RainbowQueryStoreConfig(store: StoreApi, selector: (state: T) = } return v; } - const pathKey = fullPath ? `${fullPath}.${key.toString()}` : key.toString(); + const keyString = typeof key === 'string' ? key : key.toString(); + const pathKey = fullPath ? `${fullPath}.${keyString}` : keyString; const cached = localCache.get(pathKey); if (cached) { if (ENABLE_LOGS) console.log('[🌀 AttachValue 🌀] Cache hit for:', pathKey); diff --git a/src/state/internal/tests/QueryStoreTest.tsx b/src/state/internal/tests/QueryStoreTest.tsx index 7df6f19623a..6041d131a0b 100644 --- a/src/state/internal/tests/QueryStoreTest.tsx +++ b/src/state/internal/tests/QueryStoreTest.tsx @@ -96,7 +96,7 @@ export const UserAssetsTest = memo(function UserAssetsTest() { ) )} - + {data ? `Number of assets: ${Object.values(data).reduce((acc, chainAssets) => acc + Object.keys(chainAssets).length, 0)}` : 'Loading…'} @@ -119,7 +119,7 @@ export const UserAssetsTest = memo(function UserAssetsTest() { }} style={styles.button} > - + Shuffle Address @@ -129,7 +129,7 @@ export const UserAssetsTest = memo(function UserAssetsTest() { }} style={styles.button} > - + {useUserAssetsTestStore.getState().enabled ? 'Disable Fetching' : 'Enable Fetching'} @@ -194,7 +194,7 @@ export async function simpleUserAssetsQuery({ address, currency }: FetchUserAsse } return {}; } catch (e) { - logger.error(new RainbowError('[userAssetsQueryFunction]: Failed to fetch user assets'), { + logger.error(new RainbowError('[simpleUserAssetsQuery]: Failed to fetch user assets'), { message: (e as Error)?.message, }); return {};