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

Context Improvements + Hooks dir #570

Merged
merged 17 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion apps/router/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Flex, Text } from '@chakra-ui/react';
import { Logo } from './Logo';
import { ServiceMenu } from './ServiceMenu';
import { useActiveService } from '../hooks';
import { useAppContext } from '../context/hooks';
import { useAppContext } from '../hooks';

export const Header = React.memo(function Header() {
const { guardians, gateways } = useAppContext();
Expand Down
19 changes: 18 additions & 1 deletion apps/router/src/context/gateway/GatewayContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import React, {
useMemo,
useReducer,
} from 'react';
import { useGatewayConfig } from '../hooks';
import { useGatewayConfig } from '../../hooks';
import { GatewayApi } from '../../api/GatewayApi';
import {
GATEWAY_APP_ACTION_TYPE,
GatewayAppAction,
GatewayAppState,
GatewayStatus,
WalletModalAction,
WalletModalType,
} from '../../types/gateway';
import { useLocation } from 'react-router-dom';

Expand All @@ -29,6 +31,15 @@ const initialState: GatewayAppState = {
balances: null,
gatewayInfo: null,
unit: 'msats',
showConnectFed: false,
walletModalState: {
isOpen: false,
action: WalletModalAction.Receive,
type: WalletModalType.Onchain,
selectedFederation: null,
showSelector: true,
},
activeTab: 0,
};

const reducer = (
Expand All @@ -48,6 +59,12 @@ const reducer = (
return { ...state, gatewayInfo: action.payload };
case GATEWAY_APP_ACTION_TYPE.SET_UNIT:
return { ...state, unit: action.payload };
case GATEWAY_APP_ACTION_TYPE.SET_SHOW_CONNECT_FED:
return { ...state, showConnectFed: action.payload };
case GATEWAY_APP_ACTION_TYPE.SET_WALLET_MODAL_STATE:
return { ...state, walletModalState: { ...state.walletModalState, ...action.payload } };
case GATEWAY_APP_ACTION_TYPE.SET_ACTIVE_TAB:
return { ...state, activeTab: action.payload };
default:
return state;
}
Expand Down
3 changes: 1 addition & 2 deletions apps/router/src/context/guardian/AdminContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { createContext, ReactNode } from 'react';
// import { AdminApiInterface } from '../guardian-ui/GuardianApi';
import { useGuardianStatus } from '../hooks';
import { useGuardianStatus } from '../../hooks';
import { GuardianStatus } from '../../types/guardian';

// export interface AdminContextValue {}
Expand Down
2 changes: 1 addition & 1 deletion apps/router/src/context/guardian/GuardianContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
GuardianAppState,
GuardianStatus,
} from '../../types/guardian';
import { useGuardianConfig } from '../hooks';
import { useGuardianConfig } from '../../hooks';
import { useLocation } from 'react-router-dom';

export interface GuardianContextValue {
Expand Down
6 changes: 3 additions & 3 deletions apps/router/src/context/guardian/SetupContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { randomNames } from '../../guardian-ui/setup/randomNames';
import {
FollowerConfigs,
HostConfigs,
useGuardianContext,
useGuardianApi,
useHandleBackgroundGuardianSetupActions,
useHandleSetupServerStatus,
useUpdateLocalStorageOnSetupStateChange,
} from '../hooks';
} from '../../hooks';

export const LOCAL_STORAGE_SETUP_KEY = 'setup-guardian-ui-state';

Expand Down Expand Up @@ -123,7 +123,7 @@ export const SetupContextProvider: React.FC<SetupContextProviderProps> = ({
initServerStatus,
children,
}: SetupContextProviderProps) => {
const { api } = useGuardianContext();
const api = useGuardianApi();
const [state, dispatch] = useReducer(reducer, {
...initialState,
password: api.getPassword() || initialState.password,
Expand Down
Loading
Loading