Skip to content

Commit

Permalink
fix passing custom configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Mar 4, 2023
1 parent aa309a7 commit 5de447c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### [0.0.8](https://github.com/useElven/core/releases/tag/v0.0.8) (2023-03-04)
- bugfix for not passing the configuration setup in `useNetworkSync`

### [0.0.7](https://github.com/useElven/core/releases/tag/v0.0.7) (2023-03-01)
- export `TransactionArgs` type
- dependencies update
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@useelven/core",
"version": "0.0.7",
"version": "0.0.8",
"description": "Core hooks for MultiversX React DApps",
"license": "MIT",
"author": "Julian Ćwirko <julian.io>",
Expand Down
14 changes: 0 additions & 14 deletions src/hooks/common-helpers/useConfigurationSync.tsx

This file was deleted.

8 changes: 4 additions & 4 deletions src/hooks/useSyncNetwork.tsx → src/hooks/useNetworkSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { useLocalStorageSync } from './common-helpers/useLocalStorageSync';
import { useApiProviderSync } from './common-helpers/useApiProviderSync';
import { useDappProvidersSync } from './common-helpers/useDappProvidersSync';
import { useAccountNetworkSync } from './common-helpers/useAccountNetworkSync';
import { useConfigurationSync } from './common-helpers/useConfigurationSync';
import { initConfigState } from '../store/config';

export const useNetworkSync = (config?: NetworkType) => {
// Sync main configuration
initConfigState(config);

const [accountDone, setAccountDone] = useState(false);
const [loginInfoDone, setLoginInfoDone] = useState(false);

const apiNetworkProviderRef = useRef<ApiNetworkProvider>();

// Sync main configuration
useConfigurationSync(config);

// Sync data from local storage
useLocalStorageSync(setAccountDone, setLoginInfoDone);

Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Hooks
export * from './hooks/useSyncNetwork';
export * from './hooks/useNetworkSync';
export * from './hooks/useTransaction';
export * from './hooks/useLogout';
export * from './hooks/useLogin';
Expand Down
19 changes: 19 additions & 0 deletions src/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ export const setConfigState = (
configState[key] = value;
};

// When there is a custom configuration replace keys in defaults
// When there is only a change in the chainType replace the rest with defaults but by the chainType
export const initConfigState = (config: NetworkType | undefined) => {
const customConfig = { ...config };

Object.keys(initialState).forEach((key) => {
if (customConfig[key]) {
setConfigState(key, customConfig[key] as string | string[]);
} else if (customConfig.chainType) {
setConfigState(
key,
networkConfig[customConfig.chainType][key] as string | string[]
);
} else {
setConfigState(key, initialState[key] as string | string[]);
}
});
};

export const clearConfigState = () => {
const resetObj = cloneDeep(initialState);
Object.keys(resetObj).forEach((key) => {
Expand Down

0 comments on commit 5de447c

Please sign in to comment.