@tuwaio/pulsar-react 1.0.0-fix-orbit-integration-alpha.2.568e8f7 → 1.0.0-fix-orbit-integration-alpha.3.baecb80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -7,7 +7,17 @@ import { PersistOptions } from 'zustand/middleware';
7
7
 
8
8
  type PulsarStore<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;
9
9
  declare const PulsarStoreContext: react.Context<StoreApi<PulsarStore<Transaction>> | null>;
10
- declare function usePulsarStore<TTransaction extends Transaction, TSelected = unknown>(selector: (state: PulsarStore<TTransaction>) => TSelected): TSelected;
10
+ /**
11
+ * Hook to access the Pulsar Store.
12
+ * @template TTransaction The specific Transaction type used in the Store (e.g., EvmTransaction).
13
+ * @template TSelected The return type of the selector function.
14
+ * @param selector A function that takes the store state and returns a slice of data.
15
+ * @returns The selected state slice.
16
+ * @throws An error if not used within a PulsarProvider.
17
+ * * NOTE: The store type is manually inferred from the selector's parameter type.
18
+ * This pattern is necessary because React Context cannot be generic.
19
+ */
20
+ declare function usePulsarStore<TSelected, TTransaction extends Transaction = Transaction>(selector: (state: PulsarStore<TTransaction>) => TSelected): TSelected;
11
21
 
12
22
  /**
13
23
  * @file This file defines a React hook for initializing the transaction pool.
package/dist/index.d.ts CHANGED
@@ -7,7 +7,17 @@ import { PersistOptions } from 'zustand/middleware';
7
7
 
8
8
  type PulsarStore<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;
9
9
  declare const PulsarStoreContext: react.Context<StoreApi<PulsarStore<Transaction>> | null>;
10
- declare function usePulsarStore<TTransaction extends Transaction, TSelected = unknown>(selector: (state: PulsarStore<TTransaction>) => TSelected): TSelected;
10
+ /**
11
+ * Hook to access the Pulsar Store.
12
+ * @template TTransaction The specific Transaction type used in the Store (e.g., EvmTransaction).
13
+ * @template TSelected The return type of the selector function.
14
+ * @param selector A function that takes the store state and returns a slice of data.
15
+ * @returns The selected state slice.
16
+ * @throws An error if not used within a PulsarProvider.
17
+ * * NOTE: The store type is manually inferred from the selector's parameter type.
18
+ * This pattern is necessary because React Context cannot be generic.
19
+ */
20
+ declare function usePulsarStore<TSelected, TTransaction extends Transaction = Transaction>(selector: (state: PulsarStore<TTransaction>) => TSelected): TSelected;
11
21
 
12
22
  /**
13
23
  * @file This file defines a React hook for initializing the transaction pool.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/pulsarHook.ts","../src/hooks/useInitializeTransactionsPool.tsx","../src/providers/PulsarCoreProvider.tsx"],"names":["PulsarStoreContext","createContext","usePulsarStore","selector","store","useContext","useStore","useInitializeTransactionsPool","initializeTransactionsPool","onError","useEffect","error","e","PulsarCoreProvider","children","params","storeRef","useRef","createPulsarStore","storeToProvide","jsx"],"mappings":"yJAMaA,CAAAA,CAAqBC,mBAAAA,CAAyD,IAAI,EAExF,SAASC,CAAAA,CACdC,CAAAA,CACW,CACX,IAAMC,EAAQC,gBAAAA,CAAWL,CAAkB,CAAA,CAC3C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,qDAAqD,CAAA,CAEvE,OAAOE,gBAAAA,CAASF,CAAAA,CAAyDD,CAAQ,CACnF,CCmBO,IAAMI,CAAAA,CAAgC,CAAC,CAC5C,0BAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAGM,CACJC,eAAAA,CAAU,IAAM,EACe,SAAY,CACvC,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EACOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,0CAA2CA,CAAC,CAAA,CAAA,EAC5FD,CAAc,EAC7B,CACF,CAAA,IAOF,CAAA,CAAG,CAACH,CAAAA,CAA4BC,CAAO,CAAC,EAC1C,EC7CO,SAASI,CAAAA,CAA0C,CAAE,SAAAC,CAAAA,CAAU,GAAGC,CAAO,CAAA,CAA+B,CAC7G,IAAMC,CAAAA,CAAWC,YAAAA,CAAwC,IAAI,EAExDD,CAAAA,CAAS,OAAA,GACZA,CAAAA,CAAS,OAAA,CAAUE,6BAAqB,CACtC,GAAGH,CAAAA,CACH,IAAA,CAAMA,CAAAA,CAAO,IAAA,EAAQ,cACvB,CAAC,GAGH,IAAMI,CAAAA,CAAiBH,CAAAA,CAAS,OAAA,CAEhC,OAAAT,CAAAA,CAA8B,CAC5B,0BAAA,CAA4BS,CAAAA,CAAS,QAAQ,QAAA,EAAS,CAAE,0BAAA,CACxD,OAAA,CAAUL,GAAU,OAAA,CAAQ,KAAA,CAAM,yCAAA,CAA2CA,CAAK,CACpF,CAAC,CAAA,CAEMS,cAAAA,CAACpB,CAAAA,CAAmB,SAAnB,CAA4B,KAAA,CAAOmB,CAAAA,CAAiB,QAAA,CAAAL,EAAS,CACvE","file":"index.js","sourcesContent":["import { ITxTrackingStore, Transaction } from '@tuwaio/pulsar-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\nexport type PulsarStore<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;\n\nexport const PulsarStoreContext = createContext<StoreApi<PulsarStore<Transaction>> | null>(null);\n\nexport function usePulsarStore<TTransaction extends Transaction, TSelected = unknown>(\n selector: (state: PulsarStore<TTransaction>) => TSelected,\n): TSelected {\n const store = useContext(PulsarStoreContext);\n if (!store) {\n throw new Error('usePulsarStore must be used within a PulsarProvider');\n }\n return useStore(store as unknown as StoreApi<PulsarStore<TTransaction>>, selector);\n}\n","/**\n * @file This file defines a React hook for initializing the transaction pool.\n * This hook is crucial for resuming the tracking of pending transactions after a page reload.\n */\n\nimport { useEffect } from 'react';\n\n/**\n * A React hook that triggers the initialization of the transaction pool when the component mounts.\n *\n * This should be used once in your application's layout or root component. It ensures that any\n * pending transactions from a previous session (stored in `localStorage`) are picked up and\n\n * their trackers are re-activated.\n *\n * @param {object} params - The parameters for the hook.\n * @param {() => Promise<void>} params.initializeTransactionsPool - The `initializeTransactionsPool` function from your Pulsar store instance.\n * @param {(error: Error) => void} [params.onError] - An optional custom function to handle any errors that occur during initialization. Defaults to `console.error`.\n *\n * @example\n * ```tsx\n * import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';\n * import { pulsarStore } from './path/to/your/store';\n *\n * function AppLayout({ children }) {\n * // This hook will run once when the layout mounts.\n * useInitializeTransactionsPool({\n * initializeTransactionsPool: pulsarStore.getState().initializeTransactionsPool,\n * onError: (err) => console.warn('Failed to re-initialize trackers:', err),\n * });\n *\n * return <div>{children}</div>;\n * }\n * ```\n */\nexport const useInitializeTransactionsPool = ({\n initializeTransactionsPool,\n onError,\n}: {\n initializeTransactionsPool: () => Promise<void>;\n onError?: (error: Error) => void;\n}) => {\n useEffect(() => {\n const reinitializeTrackers = async () => {\n try {\n await initializeTransactionsPool();\n } catch (error) {\n const errorHandler = onError ?? ((e: Error) => console.error('Failed to initialize transactions pool:', e));\n errorHandler(error as Error);\n }\n };\n\n // Run the initialization process.\n reinitializeTrackers();\n\n // The dependency array is empty to ensure this effect runs only once on mount.\n // The functions from a vanilla Zustand store are stable and do not need to be in the array.\n }, [initializeTransactionsPool, onError]);\n};\n","import { createPulsarStore, ITxTrackingStore, PulsarAdapter, Transaction } from '@tuwaio/pulsar-core';\nimport { PropsWithChildren, useRef } from 'react';\nimport { StoreApi } from 'zustand';\nimport { PersistOptions } from 'zustand/middleware';\n\nimport { PulsarStore, PulsarStoreContext } from '../hooks/pulsarHook';\nimport { useInitializeTransactionsPool } from '../hooks/useInitializeTransactionsPool';\n\ninterface PulsarCoreProviderProps<T extends Transaction>\n extends PropsWithChildren,\n PulsarAdapter<T>,\n Partial<PersistOptions<ITxTrackingStore<T>>> {}\n\nexport function PulsarCoreProvider<T extends Transaction>({ children, ...params }: PulsarCoreProviderProps<T>) {\n const storeRef = useRef<StoreApi<PulsarStore<T>> | null>(null);\n\n if (!storeRef.current) {\n storeRef.current = createPulsarStore<T>({\n ...params,\n name: params.name ?? 'pulsar-store',\n });\n }\n\n const storeToProvide = storeRef.current as unknown as StoreApi<PulsarStore<Transaction>>;\n\n useInitializeTransactionsPool({\n initializeTransactionsPool: storeRef.current.getState().initializeTransactionsPool,\n onError: (error) => console.error('Failed to initialize transactions pool:', error),\n });\n\n return <PulsarStoreContext.Provider value={storeToProvide}>{children}</PulsarStoreContext.Provider>;\n}\n"]}
1
+ {"version":3,"sources":["../src/hooks/pulsarHook.ts","../src/hooks/useInitializeTransactionsPool.tsx","../src/providers/PulsarCoreProvider.tsx"],"names":["PulsarStoreContext","createContext","usePulsarStore","selector","store","useContext","useStore","useInitializeTransactionsPool","initializeTransactionsPool","onError","useEffect","error","e","PulsarCoreProvider","children","params","storeRef","useRef","createPulsarStore","storeToProvide","jsx"],"mappings":"yJAQaA,CAAAA,CAAqBC,mBAAAA,CAAyD,IAAI,EAYxF,SAASC,CAAAA,CACdC,CAAAA,CACW,CACX,IAAMC,EAAQC,gBAAAA,CAAWL,CAAkB,CAAA,CAE3C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,qDAAqD,CAAA,CAMvE,OAAOE,gBAAAA,CAASF,CAAAA,CAAyDD,CAAQ,CACnF,CCEO,IAAMI,CAAAA,CAAgC,CAAC,CAC5C,0BAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAGM,CACJC,eAAAA,CAAU,IAAM,EACe,SAAY,CACvC,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EACOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,0CAA2CA,CAAC,CAAA,CAAA,EAC5FD,CAAc,EAC7B,CACF,CAAA,IAOF,CAAA,CAAG,CAACH,CAAAA,CAA4BC,CAAO,CAAC,EAC1C,EC7CO,SAASI,CAAAA,CAA0C,CAAE,SAAAC,CAAAA,CAAU,GAAGC,CAAO,CAAA,CAA+B,CAC7G,IAAMC,CAAAA,CAAWC,YAAAA,CAAwC,IAAI,EAExDD,CAAAA,CAAS,OAAA,GACZA,CAAAA,CAAS,OAAA,CAAUE,6BAAqB,CACtC,GAAGH,CAAAA,CACH,IAAA,CAAMA,CAAAA,CAAO,IAAA,EAAQ,cACvB,CAAC,GAGH,IAAMI,CAAAA,CAAiBH,CAAAA,CAAS,OAAA,CAEhC,OAAAT,CAAAA,CAA8B,CAC5B,0BAAA,CAA4BS,CAAAA,CAAS,QAAQ,QAAA,EAAS,CAAE,0BAAA,CACxD,OAAA,CAAUL,GAAU,OAAA,CAAQ,KAAA,CAAM,yCAAA,CAA2CA,CAAK,CACpF,CAAC,CAAA,CAEMS,cAAAA,CAACpB,CAAAA,CAAmB,SAAnB,CAA4B,KAAA,CAAOmB,CAAAA,CAAiB,QAAA,CAAAL,EAAS,CACvE","file":"index.js","sourcesContent":["import { ITxTrackingStore, Transaction } from '@tuwaio/pulsar-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\n// 1. Export PulsarStore type for easier use by consumers\nexport type PulsarStore<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;\n\n// 2. The Context holds the most general version of the store (PulsarStore<Transaction>)\nexport const PulsarStoreContext = createContext<StoreApi<PulsarStore<Transaction>> | null>(null);\n\n/**\n * Hook to access the Pulsar Store.\n * @template TTransaction The specific Transaction type used in the Store (e.g., EvmTransaction).\n * @template TSelected The return type of the selector function.\n * @param selector A function that takes the store state and returns a slice of data.\n * @returns The selected state slice.\n * @throws An error if not used within a PulsarProvider.\n * * NOTE: The store type is manually inferred from the selector's parameter type.\n * This pattern is necessary because React Context cannot be generic.\n */\nexport function usePulsarStore<TSelected, TTransaction extends Transaction = Transaction>(\n selector: (state: PulsarStore<TTransaction>) => TSelected,\n): TSelected {\n const store = useContext(PulsarStoreContext);\n\n if (!store) {\n throw new Error('usePulsarStore must be used within a PulsarProvider');\n }\n\n // Cast the context store (StoreApi<PulsarStore<Transaction>>)\n // to the required generic store type (StoreApi<PulsarStore<TTransaction>>)\n // for the selector function to work correctly.\n return useStore(store as unknown as StoreApi<PulsarStore<TTransaction>>, selector);\n}\n","/**\n * @file This file defines a React hook for initializing the transaction pool.\n * This hook is crucial for resuming the tracking of pending transactions after a page reload.\n */\n\nimport { useEffect } from 'react';\n\n/**\n * A React hook that triggers the initialization of the transaction pool when the component mounts.\n *\n * This should be used once in your application's layout or root component. It ensures that any\n * pending transactions from a previous session (stored in `localStorage`) are picked up and\n\n * their trackers are re-activated.\n *\n * @param {object} params - The parameters for the hook.\n * @param {() => Promise<void>} params.initializeTransactionsPool - The `initializeTransactionsPool` function from your Pulsar store instance.\n * @param {(error: Error) => void} [params.onError] - An optional custom function to handle any errors that occur during initialization. Defaults to `console.error`.\n *\n * @example\n * ```tsx\n * import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';\n * import { pulsarStore } from './path/to/your/store';\n *\n * function AppLayout({ children }) {\n * // This hook will run once when the layout mounts.\n * useInitializeTransactionsPool({\n * initializeTransactionsPool: pulsarStore.getState().initializeTransactionsPool,\n * onError: (err) => console.warn('Failed to re-initialize trackers:', err),\n * });\n *\n * return <div>{children}</div>;\n * }\n * ```\n */\nexport const useInitializeTransactionsPool = ({\n initializeTransactionsPool,\n onError,\n}: {\n initializeTransactionsPool: () => Promise<void>;\n onError?: (error: Error) => void;\n}) => {\n useEffect(() => {\n const reinitializeTrackers = async () => {\n try {\n await initializeTransactionsPool();\n } catch (error) {\n const errorHandler = onError ?? ((e: Error) => console.error('Failed to initialize transactions pool:', e));\n errorHandler(error as Error);\n }\n };\n\n // Run the initialization process.\n reinitializeTrackers();\n\n // The dependency array is empty to ensure this effect runs only once on mount.\n // The functions from a vanilla Zustand store are stable and do not need to be in the array.\n }, [initializeTransactionsPool, onError]);\n};\n","import { createPulsarStore, ITxTrackingStore, PulsarAdapter, Transaction } from '@tuwaio/pulsar-core';\nimport { PropsWithChildren, useRef } from 'react';\nimport { StoreApi } from 'zustand';\nimport { PersistOptions } from 'zustand/middleware';\n\nimport { PulsarStore, PulsarStoreContext } from '../hooks/pulsarHook';\nimport { useInitializeTransactionsPool } from '../hooks/useInitializeTransactionsPool';\n\ninterface PulsarCoreProviderProps<T extends Transaction>\n extends PropsWithChildren,\n PulsarAdapter<T>,\n Partial<PersistOptions<ITxTrackingStore<T>>> {}\n\nexport function PulsarCoreProvider<T extends Transaction>({ children, ...params }: PulsarCoreProviderProps<T>) {\n const storeRef = useRef<StoreApi<PulsarStore<T>> | null>(null);\n\n if (!storeRef.current) {\n storeRef.current = createPulsarStore<T>({\n ...params,\n name: params.name ?? 'pulsar-store',\n });\n }\n\n const storeToProvide = storeRef.current as unknown as StoreApi<PulsarStore<Transaction>>;\n\n useInitializeTransactionsPool({\n initializeTransactionsPool: storeRef.current.getState().initializeTransactionsPool,\n onError: (error) => console.error('Failed to initialize transactions pool:', error),\n });\n\n return <PulsarStoreContext.Provider value={storeToProvide}>{children}</PulsarStoreContext.Provider>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/pulsarHook.ts","../src/hooks/useInitializeTransactionsPool.tsx","../src/providers/PulsarCoreProvider.tsx"],"names":["PulsarStoreContext","createContext","usePulsarStore","selector","store","useContext","useStore","useInitializeTransactionsPool","initializeTransactionsPool","onError","useEffect","error","e","PulsarCoreProvider","children","params","storeRef","useRef","createPulsarStore","storeToProvide","jsx"],"mappings":"yLAMaA,CAAAA,CAAqBC,aAAAA,CAAyD,IAAI,EAExF,SAASC,CAAAA,CACdC,CAAAA,CACW,CACX,IAAMC,EAAQC,UAAAA,CAAWL,CAAkB,CAAA,CAC3C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,qDAAqD,CAAA,CAEvE,OAAOE,QAAAA,CAASF,CAAAA,CAAyDD,CAAQ,CACnF,CCmBO,IAAMI,CAAAA,CAAgC,CAAC,CAC5C,0BAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAGM,CACJC,SAAAA,CAAU,IAAM,EACe,SAAY,CACvC,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EACOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,0CAA2CA,CAAC,CAAA,CAAA,EAC5FD,CAAc,EAC7B,CACF,CAAA,IAOF,CAAA,CAAG,CAACH,CAAAA,CAA4BC,CAAO,CAAC,EAC1C,EC7CO,SAASI,CAAAA,CAA0C,CAAE,SAAAC,CAAAA,CAAU,GAAGC,CAAO,CAAA,CAA+B,CAC7G,IAAMC,CAAAA,CAAWC,MAAAA,CAAwC,IAAI,EAExDD,CAAAA,CAAS,OAAA,GACZA,CAAAA,CAAS,OAAA,CAAUE,kBAAqB,CACtC,GAAGH,CAAAA,CACH,IAAA,CAAMA,CAAAA,CAAO,IAAA,EAAQ,cACvB,CAAC,GAGH,IAAMI,CAAAA,CAAiBH,CAAAA,CAAS,OAAA,CAEhC,OAAAT,CAAAA,CAA8B,CAC5B,0BAAA,CAA4BS,CAAAA,CAAS,QAAQ,QAAA,EAAS,CAAE,0BAAA,CACxD,OAAA,CAAUL,GAAU,OAAA,CAAQ,KAAA,CAAM,yCAAA,CAA2CA,CAAK,CACpF,CAAC,CAAA,CAEMS,GAAAA,CAACpB,CAAAA,CAAmB,SAAnB,CAA4B,KAAA,CAAOmB,CAAAA,CAAiB,QAAA,CAAAL,EAAS,CACvE","file":"index.mjs","sourcesContent":["import { ITxTrackingStore, Transaction } from '@tuwaio/pulsar-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\nexport type PulsarStore<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;\n\nexport const PulsarStoreContext = createContext<StoreApi<PulsarStore<Transaction>> | null>(null);\n\nexport function usePulsarStore<TTransaction extends Transaction, TSelected = unknown>(\n selector: (state: PulsarStore<TTransaction>) => TSelected,\n): TSelected {\n const store = useContext(PulsarStoreContext);\n if (!store) {\n throw new Error('usePulsarStore must be used within a PulsarProvider');\n }\n return useStore(store as unknown as StoreApi<PulsarStore<TTransaction>>, selector);\n}\n","/**\n * @file This file defines a React hook for initializing the transaction pool.\n * This hook is crucial for resuming the tracking of pending transactions after a page reload.\n */\n\nimport { useEffect } from 'react';\n\n/**\n * A React hook that triggers the initialization of the transaction pool when the component mounts.\n *\n * This should be used once in your application's layout or root component. It ensures that any\n * pending transactions from a previous session (stored in `localStorage`) are picked up and\n\n * their trackers are re-activated.\n *\n * @param {object} params - The parameters for the hook.\n * @param {() => Promise<void>} params.initializeTransactionsPool - The `initializeTransactionsPool` function from your Pulsar store instance.\n * @param {(error: Error) => void} [params.onError] - An optional custom function to handle any errors that occur during initialization. Defaults to `console.error`.\n *\n * @example\n * ```tsx\n * import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';\n * import { pulsarStore } from './path/to/your/store';\n *\n * function AppLayout({ children }) {\n * // This hook will run once when the layout mounts.\n * useInitializeTransactionsPool({\n * initializeTransactionsPool: pulsarStore.getState().initializeTransactionsPool,\n * onError: (err) => console.warn('Failed to re-initialize trackers:', err),\n * });\n *\n * return <div>{children}</div>;\n * }\n * ```\n */\nexport const useInitializeTransactionsPool = ({\n initializeTransactionsPool,\n onError,\n}: {\n initializeTransactionsPool: () => Promise<void>;\n onError?: (error: Error) => void;\n}) => {\n useEffect(() => {\n const reinitializeTrackers = async () => {\n try {\n await initializeTransactionsPool();\n } catch (error) {\n const errorHandler = onError ?? ((e: Error) => console.error('Failed to initialize transactions pool:', e));\n errorHandler(error as Error);\n }\n };\n\n // Run the initialization process.\n reinitializeTrackers();\n\n // The dependency array is empty to ensure this effect runs only once on mount.\n // The functions from a vanilla Zustand store are stable and do not need to be in the array.\n }, [initializeTransactionsPool, onError]);\n};\n","import { createPulsarStore, ITxTrackingStore, PulsarAdapter, Transaction } from '@tuwaio/pulsar-core';\nimport { PropsWithChildren, useRef } from 'react';\nimport { StoreApi } from 'zustand';\nimport { PersistOptions } from 'zustand/middleware';\n\nimport { PulsarStore, PulsarStoreContext } from '../hooks/pulsarHook';\nimport { useInitializeTransactionsPool } from '../hooks/useInitializeTransactionsPool';\n\ninterface PulsarCoreProviderProps<T extends Transaction>\n extends PropsWithChildren,\n PulsarAdapter<T>,\n Partial<PersistOptions<ITxTrackingStore<T>>> {}\n\nexport function PulsarCoreProvider<T extends Transaction>({ children, ...params }: PulsarCoreProviderProps<T>) {\n const storeRef = useRef<StoreApi<PulsarStore<T>> | null>(null);\n\n if (!storeRef.current) {\n storeRef.current = createPulsarStore<T>({\n ...params,\n name: params.name ?? 'pulsar-store',\n });\n }\n\n const storeToProvide = storeRef.current as unknown as StoreApi<PulsarStore<Transaction>>;\n\n useInitializeTransactionsPool({\n initializeTransactionsPool: storeRef.current.getState().initializeTransactionsPool,\n onError: (error) => console.error('Failed to initialize transactions pool:', error),\n });\n\n return <PulsarStoreContext.Provider value={storeToProvide}>{children}</PulsarStoreContext.Provider>;\n}\n"]}
1
+ {"version":3,"sources":["../src/hooks/pulsarHook.ts","../src/hooks/useInitializeTransactionsPool.tsx","../src/providers/PulsarCoreProvider.tsx"],"names":["PulsarStoreContext","createContext","usePulsarStore","selector","store","useContext","useStore","useInitializeTransactionsPool","initializeTransactionsPool","onError","useEffect","error","e","PulsarCoreProvider","children","params","storeRef","useRef","createPulsarStore","storeToProvide","jsx"],"mappings":"yLAQaA,CAAAA,CAAqBC,aAAAA,CAAyD,IAAI,EAYxF,SAASC,CAAAA,CACdC,CAAAA,CACW,CACX,IAAMC,EAAQC,UAAAA,CAAWL,CAAkB,CAAA,CAE3C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,qDAAqD,CAAA,CAMvE,OAAOE,QAAAA,CAASF,CAAAA,CAAyDD,CAAQ,CACnF,CCEO,IAAMI,CAAAA,CAAgC,CAAC,CAC5C,0BAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAGM,CACJC,SAAAA,CAAU,IAAM,EACe,SAAY,CACvC,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EACOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,0CAA2CA,CAAC,CAAA,CAAA,EAC5FD,CAAc,EAC7B,CACF,CAAA,IAOF,CAAA,CAAG,CAACH,CAAAA,CAA4BC,CAAO,CAAC,EAC1C,EC7CO,SAASI,CAAAA,CAA0C,CAAE,SAAAC,CAAAA,CAAU,GAAGC,CAAO,CAAA,CAA+B,CAC7G,IAAMC,CAAAA,CAAWC,MAAAA,CAAwC,IAAI,EAExDD,CAAAA,CAAS,OAAA,GACZA,CAAAA,CAAS,OAAA,CAAUE,kBAAqB,CACtC,GAAGH,CAAAA,CACH,IAAA,CAAMA,CAAAA,CAAO,IAAA,EAAQ,cACvB,CAAC,GAGH,IAAMI,CAAAA,CAAiBH,CAAAA,CAAS,OAAA,CAEhC,OAAAT,CAAAA,CAA8B,CAC5B,0BAAA,CAA4BS,CAAAA,CAAS,QAAQ,QAAA,EAAS,CAAE,0BAAA,CACxD,OAAA,CAAUL,GAAU,OAAA,CAAQ,KAAA,CAAM,yCAAA,CAA2CA,CAAK,CACpF,CAAC,CAAA,CAEMS,GAAAA,CAACpB,CAAAA,CAAmB,SAAnB,CAA4B,KAAA,CAAOmB,CAAAA,CAAiB,QAAA,CAAAL,EAAS,CACvE","file":"index.mjs","sourcesContent":["import { ITxTrackingStore, Transaction } from '@tuwaio/pulsar-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\n// 1. Export PulsarStore type for easier use by consumers\nexport type PulsarStore<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;\n\n// 2. The Context holds the most general version of the store (PulsarStore<Transaction>)\nexport const PulsarStoreContext = createContext<StoreApi<PulsarStore<Transaction>> | null>(null);\n\n/**\n * Hook to access the Pulsar Store.\n * @template TTransaction The specific Transaction type used in the Store (e.g., EvmTransaction).\n * @template TSelected The return type of the selector function.\n * @param selector A function that takes the store state and returns a slice of data.\n * @returns The selected state slice.\n * @throws An error if not used within a PulsarProvider.\n * * NOTE: The store type is manually inferred from the selector's parameter type.\n * This pattern is necessary because React Context cannot be generic.\n */\nexport function usePulsarStore<TSelected, TTransaction extends Transaction = Transaction>(\n selector: (state: PulsarStore<TTransaction>) => TSelected,\n): TSelected {\n const store = useContext(PulsarStoreContext);\n\n if (!store) {\n throw new Error('usePulsarStore must be used within a PulsarProvider');\n }\n\n // Cast the context store (StoreApi<PulsarStore<Transaction>>)\n // to the required generic store type (StoreApi<PulsarStore<TTransaction>>)\n // for the selector function to work correctly.\n return useStore(store as unknown as StoreApi<PulsarStore<TTransaction>>, selector);\n}\n","/**\n * @file This file defines a React hook for initializing the transaction pool.\n * This hook is crucial for resuming the tracking of pending transactions after a page reload.\n */\n\nimport { useEffect } from 'react';\n\n/**\n * A React hook that triggers the initialization of the transaction pool when the component mounts.\n *\n * This should be used once in your application's layout or root component. It ensures that any\n * pending transactions from a previous session (stored in `localStorage`) are picked up and\n\n * their trackers are re-activated.\n *\n * @param {object} params - The parameters for the hook.\n * @param {() => Promise<void>} params.initializeTransactionsPool - The `initializeTransactionsPool` function from your Pulsar store instance.\n * @param {(error: Error) => void} [params.onError] - An optional custom function to handle any errors that occur during initialization. Defaults to `console.error`.\n *\n * @example\n * ```tsx\n * import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';\n * import { pulsarStore } from './path/to/your/store';\n *\n * function AppLayout({ children }) {\n * // This hook will run once when the layout mounts.\n * useInitializeTransactionsPool({\n * initializeTransactionsPool: pulsarStore.getState().initializeTransactionsPool,\n * onError: (err) => console.warn('Failed to re-initialize trackers:', err),\n * });\n *\n * return <div>{children}</div>;\n * }\n * ```\n */\nexport const useInitializeTransactionsPool = ({\n initializeTransactionsPool,\n onError,\n}: {\n initializeTransactionsPool: () => Promise<void>;\n onError?: (error: Error) => void;\n}) => {\n useEffect(() => {\n const reinitializeTrackers = async () => {\n try {\n await initializeTransactionsPool();\n } catch (error) {\n const errorHandler = onError ?? ((e: Error) => console.error('Failed to initialize transactions pool:', e));\n errorHandler(error as Error);\n }\n };\n\n // Run the initialization process.\n reinitializeTrackers();\n\n // The dependency array is empty to ensure this effect runs only once on mount.\n // The functions from a vanilla Zustand store are stable and do not need to be in the array.\n }, [initializeTransactionsPool, onError]);\n};\n","import { createPulsarStore, ITxTrackingStore, PulsarAdapter, Transaction } from '@tuwaio/pulsar-core';\nimport { PropsWithChildren, useRef } from 'react';\nimport { StoreApi } from 'zustand';\nimport { PersistOptions } from 'zustand/middleware';\n\nimport { PulsarStore, PulsarStoreContext } from '../hooks/pulsarHook';\nimport { useInitializeTransactionsPool } from '../hooks/useInitializeTransactionsPool';\n\ninterface PulsarCoreProviderProps<T extends Transaction>\n extends PropsWithChildren,\n PulsarAdapter<T>,\n Partial<PersistOptions<ITxTrackingStore<T>>> {}\n\nexport function PulsarCoreProvider<T extends Transaction>({ children, ...params }: PulsarCoreProviderProps<T>) {\n const storeRef = useRef<StoreApi<PulsarStore<T>> | null>(null);\n\n if (!storeRef.current) {\n storeRef.current = createPulsarStore<T>({\n ...params,\n name: params.name ?? 'pulsar-store',\n });\n }\n\n const storeToProvide = storeRef.current as unknown as StoreApi<PulsarStore<Transaction>>;\n\n useInitializeTransactionsPool({\n initializeTransactionsPool: storeRef.current.getState().initializeTransactionsPool,\n onError: (error) => console.error('Failed to initialize transactions pool:', error),\n });\n\n return <PulsarStoreContext.Provider value={storeToProvide}>{children}</PulsarStoreContext.Provider>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/pulsar-react",
3
- "version": "1.0.0-fix-orbit-integration-alpha.2.568e8f7",
3
+ "version": "1.0.0-fix-orbit-integration-alpha.3.baecb80",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -54,7 +54,7 @@
54
54
  "tsup": "^8.5.0",
55
55
  "typescript": "^5.9.2",
56
56
  "zustand": "^5.0.8",
57
- "@tuwaio/pulsar-core": "^1.0.0-fix-orbit-integration-alpha.2.568e8f7"
57
+ "@tuwaio/pulsar-core": "^1.0.0-fix-orbit-integration-alpha.3.baecb80"
58
58
  },
59
59
  "scripts": {
60
60
  "start": "tsup src/index.ts --watch",