Skip to content

Commit

Permalink
feat: next stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Sep 11, 2024
1 parent 8a018c2 commit 2531a8f
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 81 deletions.
4 changes: 2 additions & 2 deletions apps/router/src/gateway-ui/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Flex } from '@chakra-ui/react';
import { GatewayInfo, FederationInfo, GatewayBalances } from '@fedimint/types';
import { ConnectFederationModal, LightningCard } from './components';
import { ApiContext } from './ApiProvider';
import { Wrapper, Login } from '@fedimint/ui';
import { Login } from '@fedimint/ui';
import { FederationsTable } from './components/federations/FederationsTable';
import { Loading } from './components/Loading';
import { HeaderWithUnitSelector } from './components/HeaderWithUnitSelector';
Expand Down Expand Up @@ -165,5 +165,5 @@ export const Main = React.memo(function Admin(): JSX.Element {
gateway,
]);

return <Wrapper size='lg'>{content}</Wrapper>;
return content;
});
16 changes: 3 additions & 13 deletions apps/router/src/guardian-ui/App.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import React from 'react';
import { ColorModeScript } from '@chakra-ui/react';
import { Main } from './Main';
import { GuardianAppContextProvider } from './AppContext';
import { Fonts, SharedChakraProvider, theme } from '@fedimint/ui';
import spaceGroteskTtf from '@fedimint/ui/assets/fonts/SpaceGrotesk-Variable.ttf';
import interTtf from '@fedimint/ui/assets/fonts/Inter-Variable.ttf';

export const App: React.FC = () => {
return (
<>
<ColorModeScript />
<GuardianAppContextProvider>
<Fonts spaceGroteskTtf={spaceGroteskTtf} interTtf={interTtf} />
<SharedChakraProvider theme={theme}>
<Main />
</SharedChakraProvider>
</GuardianAppContextProvider>
</>
<GuardianAppContextProvider>
<Main />
</GuardianAppContextProvider>
);
};
4 changes: 2 additions & 2 deletions apps/router/src/guardian-ui/GuardianApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
FederationStatus,
ModuleKind,
PeerHashMap,
ServerStatus,
GuardianServerStatus,
SignedApiAnnouncement,
StatusResponse,
Versions,
Expand Down Expand Up @@ -207,7 +207,7 @@ export class GuardianApi {
await this.connect(this.guardianConfig?.fm_config_api);
await this.shutdown_internal();
const status = await this.status();
if (status.server === ServerStatus.ConsensusRunning) {
if (status.server === GuardianServerStatus.ConsensusRunning) {
return;
} else {
throw new Error(
Expand Down
38 changes: 14 additions & 24 deletions apps/router/src/guardian-ui/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo } from 'react';
import { Box, Flex, Spinner, Heading, Text, Center } from '@chakra-ui/react';
import { Wrapper, Login } from '@fedimint/ui';
import { Login } from '@fedimint/ui';
import { SetupContextProvider } from './setup/SetupContext';
import { AdminContextProvider } from './admin/AdminContext';
import { FederationSetup } from './setup/FederationSetup';
Expand Down Expand Up @@ -37,27 +37,21 @@ export const Main = React.memo(function App() {
}

if (state.status === GuardianStatus.NotConfigured) {
return (
<Wrapper>
<NotConfigured api={api} dispatch={dispatch} />
</Wrapper>
);
return <NotConfigured api={api} dispatch={dispatch} />;
}

if (state.needsAuth) {
return (
<Wrapper>
<Login
checkAuth={(password) => api.testPassword(password || '')}
setAuthenticated={() =>
dispatch({
type: GUARDIAN_APP_ACTION_TYPE.SET_NEEDS_AUTH,
payload: false,
})
}
parseError={formatApiErrorMessage}
/>
</Wrapper>
<Login
checkAuth={(password) => api.testPassword(password || '')}
setAuthenticated={() =>
dispatch({
type: GUARDIAN_APP_ACTION_TYPE.SET_NEEDS_AUTH,
payload: false,
})
}
parseError={formatApiErrorMessage}
/>
);
}

Expand All @@ -67,19 +61,15 @@ export const Main = React.memo(function App() {
initServerStatus={state.initServerStatus}
api={api}
>
<Wrapper>
<FederationSetup />
</Wrapper>
<FederationSetup />
</SetupContextProvider>
);
}

if (state.status === GuardianStatus.Admin) {
return (
<AdminContextProvider api={api}>
<Wrapper size='lg'>
<FederationAdmin />
</Wrapper>
<FederationAdmin />
</AdminContextProvider>
);
}
Expand Down
12 changes: 6 additions & 6 deletions apps/router/src/guardian-ui/components/setup/RunDKG.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Flex,
useTheme,
} from '@chakra-ui/react';
import { ServerStatus } from '@fedimint/types';
import { GuardianServerStatus } from '@fedimint/types';
import { useTranslation } from '@fedimint/utils';
import { useConsensusPolling, useEllipsis, useSetupContext } from '../../hooks';
import { formatApiErrorMessage } from '../../utils/api';
Expand Down Expand Up @@ -40,20 +40,20 @@ export const RunDKG: React.FC<Props> = ({ next }) => {
const status = await api.status();
if (canceled) return;
switch (status.server) {
case ServerStatus.SharingConfigGenParams:
case GuardianServerStatus.SharingConfigGenParams:
await api.runDkg().catch((err) => {
// If we timed out, np just try again
if (err.code === -32002) return;
throw err;
});
break;
case ServerStatus.ReadyForConfigGen:
case GuardianServerStatus.ReadyForConfigGen:
setIsWaitingForOthers(true);
break;
case ServerStatus.VerifyingConfigs:
case GuardianServerStatus.VerifyingConfigs:
next();
break;
case ServerStatus.ConfigGenFailed:
case GuardianServerStatus.ConfigGenFailed:
setError(`${t('run-dkg.error-config')}`);
break;
default:
Expand All @@ -75,7 +75,7 @@ export const RunDKG: React.FC<Props> = ({ next }) => {
const progress = useMemo(() => {
if (!peers.length) return 0;
const peersWaiting = peers.filter(
(p) => p.status === ServerStatus.ReadyForConfigGen
(p) => p.status === GuardianServerStatus.ReadyForConfigGen
);
return Math.round((peersWaiting.length / peers.length) * 100);
}, [peers]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Icon,
} from '@chakra-ui/react';
import { CopyInput, Table, TableRow } from '@fedimint/ui';
import { ModuleKind, ServerStatus } from '@fedimint/types';
import { ModuleKind, GuardianServerStatus } from '@fedimint/types';
import { useTranslation } from '@fedimint/utils';
import { useConsensusPolling, useSetupContext } from '../../../../hooks';
import { GuardianRole } from '../../../../types';
Expand All @@ -40,8 +40,9 @@ export const ConnectGuardians: React.FC<Props> = ({ next }) => {
const isAllConnected = numPeers && numPeers == peers.length;
const isAllAccepted =
isAllConnected &&
peers.filter((peer) => peer.status === ServerStatus.ReadyForConfigGen)
.length >=
peers.filter(
(peer) => peer.status === GuardianServerStatus.ReadyForConfigGen
).length >=
numPeers - 1;

// For hosts, once all peers have connected, run DKG immediately.
Expand Down Expand Up @@ -169,7 +170,7 @@ export const ConnectGuardians: React.FC<Props> = ({ next }) => {
peers[i].name +
(ourCurrentId === i ? ` (${t('common.you')})` : ''),
status:
peers[i].status === ServerStatus.ReadyForConfigGen ||
peers[i].status === GuardianServerStatus.ReadyForConfigGen ||
ourCurrentId === i ? (
<Tag colorScheme='green'>{t('connect-guardians.approved')}</Tag>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
ModalBody,
ModalCloseButton,
} from '@chakra-ui/react';
import { ServerStatus, Peer } from '@fedimint/types';
import { GuardianServerStatus, Peer } from '@fedimint/types';
import { useTranslation } from '@fedimint/utils';
import { CopyInput, Table } from '@fedimint/ui';
import { useConsensusPolling, useSetupContext } from '../../../../hooks';
Expand Down Expand Up @@ -70,7 +70,11 @@ export const VerifyGuardians: React.FC<Props> = ({ next }) => {
useConsensusPolling();

useEffect(() => {
if (peers.every((peer) => peer.status === ServerStatus.VerifiedConfigs)) {
if (
peers.every(
(peer) => peer.status === GuardianServerStatus.VerifiedConfigs
)
) {
setVerifiedConfigs(true);
}

Expand Down Expand Up @@ -102,7 +106,9 @@ export const VerifyGuardians: React.FC<Props> = ({ next }) => {
);

// If we're already at the VerifiedConfigs state, prefill all the other hashes with the correct values
if (peers[ourCurrentId].status === ServerStatus.VerifiedConfigs) {
if (
peers[ourCurrentId].status === GuardianServerStatus.VerifiedConfigs
) {
const otherPeers = Object.entries(peers).filter(
([id]) => id !== ourCurrentId.toString()
);
Expand Down
4 changes: 2 additions & 2 deletions apps/router/src/guardian-ui/setup/FederationSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TermsOfService } from '../components/TermsOfService';

import { ReactComponent as ArrowLeftIcon } from '../assets/svgs/arrow-left.svg';
import { ReactComponent as CancelIcon } from '../assets/svgs/x-circle.svg';
import { ServerStatus } from '@fedimint/types';
import { GuardianServerStatus } from '@fedimint/types';
import { RestartModals } from './RestartModals';

const PROGRESS_ORDER: SetupProgress[] = [
Expand Down Expand Up @@ -155,7 +155,7 @@ export const FederationSetup: React.FC = () => {
const isPeerRestarted =
canRestart &&
peers &&
peers.some((peer) => peer.status === ServerStatus.SetupRestarted);
peers.some((peer) => peer.status === GuardianServerStatus.SetupRestarted);

return (
<Flex
Expand Down
14 changes: 7 additions & 7 deletions apps/router/src/guardian-ui/setup/SetupContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, {
useReducer,
useState,
} from 'react';
import { ConfigGenParams, ServerStatus } from '@fedimint/types';
import { ConfigGenParams, GuardianServerStatus } from '@fedimint/types';
import {
SetupState,
SetupAction,
Expand Down Expand Up @@ -139,7 +139,7 @@ export const SetupContext = createContext<SetupContextValue>({

export interface SetupContextProviderProps {
api: GuardianApi;
initServerStatus: ServerStatus;
initServerStatus: GuardianServerStatus;
children: ReactNode;
}

Expand All @@ -157,29 +157,29 @@ export const SetupContextProvider: React.FC<SetupContextProviderProps> = ({

useEffect(() => {
switch (initServerStatus) {
case ServerStatus.AwaitingPassword:
case GuardianServerStatus.AwaitingPassword:
// If we're still waiting for a password, restart the whole thing.
dispatch({
type: SETUP_ACTION_TYPE.SET_INITIAL_STATE,
payload: null,
});
break;
case ServerStatus.ReadyForConfigGen:
case GuardianServerStatus.ReadyForConfigGen:
// If we're ready for DKG, move them to approve the config to start.
dispatch({
type: SETUP_ACTION_TYPE.SET_PROGRESS,
payload: SetupProgress.ConnectGuardians,
});
break;
case ServerStatus.VerifyingConfigs:
case ServerStatus.VerifiedConfigs:
case GuardianServerStatus.VerifyingConfigs:
case GuardianServerStatus.VerifiedConfigs:
// If we're supposed to be verifying, or have verified, jump to peer validation screen
dispatch({
type: SETUP_ACTION_TYPE.SET_PROGRESS,
payload: SetupProgress.VerifyGuardians,
});
break;
case ServerStatus.ConsensusRunning:
case GuardianServerStatus.ConsensusRunning:
default:
// We should never boot into these states with the setup UI. We probably should show error
// For now, skip past all setup, and transition to admin.
Expand Down
Loading

0 comments on commit 2531a8f

Please sign in to comment.