-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathsdkReduxInitialization.ts
More file actions
51 lines (45 loc) · 2.22 KB
/
sdkReduxInitialization.ts
File metadata and controls
51 lines (45 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {CreateApi} from '@reduxjs/toolkit/query';
import {coreModuleName} from '@reduxjs/toolkit/query';
import {Framework} from '@superfluid-finance/sdk-core';
import {createRpcApiSlice} from './reduxSlices/rtkQuery/rpcApiSlice/rpcApiSlice';
import {createSubgraphApiSlice} from './reduxSlices/rtkQuery/subgraphApiSlice/subgraphApiSlice';
import {createTransactionTrackerSlice} from './reduxSlices/transactionTrackerSlice/transactionTrackerSlice';
import {getConfig} from './sdkReduxConfig';
type ModuleName = typeof coreModuleName;
/**
* For initializing "rpcApiSlice" Redux slice.
*
* @param createApi Pass in either {@see createApiWithReactHooks} or {@see createApiWithoutReactHooks}.
* You can wrap the function with your own function to add even more configuration to the RTK-Query API (e.g. "redux-persist" support).
*/
export const initializeRpcApiSlice = <T extends ModuleName>(createApi: CreateApi<T>) => {
const rpcApiSlice = createRpcApiSlice(createApi);
getConfig().setRpcApiSlice(rpcApiSlice as any);
return rpcApiSlice;
};
/**
* For initializing "subgraphApiSlice" Redux slice.
*
* @param createApi Pass in either {@see createApiWithReactHooks} or {@see createApiWithoutReactHooks}.
* You can wrap the function with your own function to add even more configuration to the RTK-Query API (e.g. "redux-persist" support).
*/
export const initializeSubgraphApiSlice = <T extends ModuleName>(createApi: CreateApi<T>) => {
const subgraphApiSlice = createSubgraphApiSlice(createApi);
getConfig().setSubgraphApiSlice(subgraphApiSlice as any);
return subgraphApiSlice;
};
/**
* For initializing "sfTransaction" Redux slice.
*/
export const initializeTransactionTrackerSlice = () => {
const transactiontTrackerSlice = createTransactionTrackerSlice();
getConfig().setTransactionTrackerSlice(transactiontTrackerSlice);
return transactiontTrackerSlice;
};
/**
* SDK-Redux needs to know where to get SDK-Core's Framework for data querying.
* @param chainId The chain.
* @param framework The SDK-Framework getter. Can be either Promise or instance.
*/
export const setFrameworkForSdkRedux = (chainId: number, framework: (() => Promise<Framework>) | Framework) =>
getConfig().setFramework(chainId, framework);