Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update use-app-config.ts #3214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 29 additions & 54 deletions app/hooks/use-app-config.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,41 @@
import { useCallback, useMemo } from "react"

import { GaloyInstance, resolveGaloyInstanceOrDefault } from "@app/config"
import { usePersistentStateContext } from "@app/store/persistent-state"
import { useCallback, useMemo } from "react";
import { GaloyInstance, resolveGaloyInstanceOrDefault } from "@app/config";
import { usePersistentStateContext } from "@app/store/persistent-state";

export const useAppConfig = () => {
const { persistentState, updateState } = usePersistentStateContext()
const { persistentState, updateState } = usePersistentStateContext();

const appConfig = useMemo(
() => ({
token: persistentState.galoyAuthToken,
galoyInstance: resolveGaloyInstanceOrDefault(persistentState.galoyInstance),
}),
[persistentState.galoyAuthToken, persistentState.galoyInstance],
)
const appConfig = useMemo(() => ({
token: persistentState.galoyAuthToken,
galoyInstance: resolveGaloyInstanceOrDefault(persistentState.galoyInstance),
}), [persistentState.galoyAuthToken, persistentState.galoyInstance]);

const setGaloyInstance = useCallback(
(newInstance: GaloyInstance) => {
updateState((state) => {
if (state)
return {
...state,
galoyInstance: newInstance,
}
return undefined
})
},
[updateState],
)
const setGaloyInstance = useCallback((newInstance: GaloyInstance) => {
updateState((state) => ({

Check failure on line 14 in app/hooks/use-app-config.ts

View workflow job for this annotation

GitHub Actions / Check Code

Type '{ galoyInstance: GaloyInstance; schemaVersion?: 6 | undefined; galoyAuthToken?: string | undefined; }' is not assignable to type 'PersistentState_6'.
...state,
galoyInstance: newInstance,
}));
}, [updateState]);

const saveToken = useCallback(
(token: string) => {
updateState((state) => {
if (state)
return {
...state,
galoyAuthToken: token,
}
return undefined
})
},
[updateState],
)
const saveToken = useCallback((token: string) => {
updateState((state) => ({

Check failure on line 21 in app/hooks/use-app-config.ts

View workflow job for this annotation

GitHub Actions / Check Code

Type '{ galoyAuthToken: string; schemaVersion?: 6 | undefined; galoyInstance?: GaloyInstanceInput | undefined; }' is not assignable to type 'PersistentState_6'.
...state,
galoyAuthToken: token,
}));
}, [updateState]);

const saveTokenAndInstance = useCallback(
({ token, instance }: { token: string; instance: GaloyInstance }) => {
updateState((state) => {
if (state)
return {
...state,
galoyInstance: instance,
galoyAuthToken: token,
}
return undefined
})
},
[updateState],
)
const saveTokenAndInstance = useCallback(({ token, instance }: { token: string; instance: GaloyInstance }) => {
updateState((state) => ({

Check failure on line 28 in app/hooks/use-app-config.ts

View workflow job for this annotation

GitHub Actions / Check Code

Type '{ galoyInstance: GaloyInstance; galoyAuthToken: string; schemaVersion?: 6 | undefined; }' is not assignable to type 'PersistentState_6'.
...state,
galoyInstance: instance,
galoyAuthToken: token,
}));
}, [updateState]);

return {
appConfig,
setGaloyInstance,
saveToken,
saveTokenAndInstance,
}
}
};
};
Loading