Skip to content

Commit

Permalink
Add indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
arhtudormorar committed Jul 12, 2024
1 parent 58046ea commit 22f69c0
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/apiCalls/configuration/getCleanApiAddress.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { networkSelector } from 'store/selectors/networkSelectors';
import { store } from 'store/store';
import { getState } from 'store/store';

export const getCleanApiAddress = (customApiAddress?: string) => {
const network = networkSelector(store.getState());
const network = networkSelector(getState());
const apiAddress = customApiAddress ?? network.apiAddress;
return apiAddress.endsWith('/') ? apiAddress.slice(0, -1) : apiAddress;
};
File renamed without changes.
1 change: 1 addition & 0 deletions src/store/actions/account/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './accountActions';
3 changes: 3 additions & 0 deletions src/store/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './account';
export * from './network';
export * from './sharedActions';
1 change: 1 addition & 0 deletions src/store/actions/network/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './networkActions';
46 changes: 46 additions & 0 deletions src/store/actions/network/initializeNetwork.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { getServerConfiguration } from 'apiCalls/configuration/getServerConfiguration';
import { fallbackNetworkConfigurations } from 'constants/network';
import { EnvironmentsEnum } from 'types/enums.types';
import { CustomNetworkType, NetworkType } from 'types/network.types';
import { initializeNetworkConfig } from './networkActions';

export type InitializeNetworkPropsType = {
customNetworkConfig?: CustomNetworkType;
environment: EnvironmentsEnum;
};

export const initializeNetwork = async ({
customNetworkConfig = {},
environment
}: InitializeNetworkPropsType): Promise<NetworkType> => {
const fetchConfigFromServer = !customNetworkConfig?.skipFetchFromServer;
const customNetworkApiAddress = customNetworkConfig?.apiAddress;
const fallbackConfig = fallbackNetworkConfigurations[environment] || {};

const localConfig = {
...fallbackConfig,
...customNetworkConfig
};

if (fetchConfigFromServer) {
const fallbackApiAddress = fallbackConfig?.apiAddress;

const serverConfig = await getServerConfiguration(
customNetworkApiAddress || fallbackApiAddress
);

if (serverConfig != null) {
const apiConfig = {
...fallbackConfig,
...serverConfig,
...customNetworkConfig
};

initializeNetworkConfig(apiConfig);
return apiConfig;
}
}

initializeNetworkConfig(localConfig);
return localConfig;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NetworkType } from 'types/network.types';
import { store } from '../store';
import { store } from '../../store';

export const initializeNetwork = (newNetwork: NetworkType) =>
export const initializeNetworkConfig = (newNetwork: NetworkType) =>
store.setState(({ network: state }) => {
const walletConnectV2RelayAddress =
newNetwork.walletConnectV2RelayAddresses[
Expand All @@ -22,3 +22,5 @@ export const setCustomWalletAddress = (customWalletAddress: string) =>
store.setState(({ network: state }) => {
state.network.customWalletAddress = customWalletAddress;
});

export { initializeNetwork } from './initializeNetwork';
1 change: 1 addition & 0 deletions src/store/actions/sharedActions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './sharedActions';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address } from '@multiversx/sdk-core/out';
import { initialState as initialAccountState } from 'store/slices/account/accountSlice';
import { store } from '../store';
import { store } from '../../store';

export const logout = () =>
store.setState((state) => {
Expand Down
1 change: 1 addition & 0 deletions src/store/selectors/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useSelector';
3 changes: 3 additions & 0 deletions src/store/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './accountSelectors';
export * from './networkSelectors';
export * from './storeSelector';
4 changes: 2 additions & 2 deletions src/store/slices/account/accountSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const initialState: AccountSliceType = {
walletConnectAccount: null
};

function getAccountConfigSlice(): StateCreator<
function getAccountSlice(): StateCreator<
DAppStoreState,
MutatorsIn,
[],
Expand All @@ -22,4 +22,4 @@ function getAccountConfigSlice(): StateCreator<
return () => initialState;
}

export const accountConfigSlice = getAccountConfigSlice();
export const accountSlice = getAccountSlice();
1 change: 1 addition & 0 deletions src/store/slices/account/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './accountSlice';
2 changes: 2 additions & 0 deletions src/store/slices/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './account';
export * from './network';
1 change: 1 addition & 0 deletions src/store/slices/network/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './networkSlice';
4 changes: 2 additions & 2 deletions src/store/slices/network/networkSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const initialState: NetworkSliceType = {
network: emptyNetwork
};

function getNetworkConfigSlice(): StateCreator<
function getNetworkSlice(): StateCreator<
DAppStoreState,
MutatorsIn,
[],
Expand All @@ -16,4 +16,4 @@ function getNetworkConfigSlice(): StateCreator<
return () => initialState;
}

export const networkConfigSlice = getNetworkConfigSlice();
export const networkSlice = getNetworkSlice();
8 changes: 4 additions & 4 deletions src/store/store.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createStore } from 'zustand/vanilla';
import { createJSONStorage, devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import { networkConfigSlice } from './slices/network/networkSlice';
import { networkSlice } from './slices/network/networkSlice';
import { NetworkSliceType } from './slices/network/networkSlice.types';
import { AccountSliceType } from './slices/account/account.types';
import { accountConfigSlice } from './slices/account/accountSlice';
import { accountSlice } from './slices/account/accountSlice';
import { createBoundedUseStore } from './createBoundedStore';

export type StoreType = {
Expand All @@ -28,8 +28,8 @@ export const store = createStore<StoreType, MutatorsOut>(
devtools(
persist(
immer((...args) => ({
network: networkConfigSlice(...args),
account: accountConfigSlice(...args)
network: networkSlice(...args),
account: accountSlice(...args)
})),
{
name: 'sdk-dapp-store',
Expand Down

0 comments on commit 22f69c0

Please sign in to comment.