Skip to content

Commit

Permalink
Merge pull request #422 from Kodylow/0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow authored May 10, 2024
2 parents 027d30e + 88dc497 commit 1fc0cc6
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 71 deletions.
26 changes: 16 additions & 10 deletions apps/guardian-ui/src/admin/FederationAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { BalanceCard } from '../components/BalanceCard';
import { InviteCode } from '../components/InviteCode';
import { ConfigViewer } from '../components/ConfigViewer';
import { DangerZone } from '../components/DangerZone';
import { BftInfo } from '../components/BftInfo';

export const FederationAdmin: React.FC = () => {
const { api } = useAdminContext();
Expand Down Expand Up @@ -58,16 +59,21 @@ export const FederationAdmin: React.FC = () => {
return (
<Flex gap='32px' flexDirection='row'>
<Flex gap={6} flexDirection='column' w='100%'>
<Box maxWidth='440px'>
<Heading size='xs' mt='12px'>
{config ? (
config.meta.federation_name
) : (
<Skeleton height='32px' width='180px' />
)}
</Heading>
<InviteCode inviteCode={inviteCode} />
</Box>
<Heading size='xs' mt='12px'>
{config ? (
config.meta.federation_name
) : (
<Skeleton height='32px' width='180px' />
)}
</Heading>
<Flex flexDirection='row' justifyContent='space-between'>
<Box maxWidth='480px'>
<InviteCode inviteCode={inviteCode} />
</Box>
{config ? (
<BftInfo numPeers={Object.keys(config.api_endpoints).length} />
) : null}
</Flex>
<Flex
gap={6}
alignItems='flex-start'
Expand Down
39 changes: 39 additions & 0 deletions apps/guardian-ui/src/components/BftInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import { Box, Text, Flex, theme } from '@chakra-ui/react';
import { useTranslation } from '@fedimint/utils';
import { bftHonest, bftFaulty } from '../utils';

interface BftInfoProps {
numPeers: number;
}

export const BftInfo: React.FC<BftInfoProps> = ({ numPeers }) => {
const { t } = useTranslation();

return (
<Box bg='blue.50' p={4} borderRadius='md' w={['100%', '50%']}>
<Text
mb='6px'
fontSize='16px'
fontWeight='500'
color={theme.colors.gray[700]}
>
{t('set-config.bft-explanation-title', { total: numPeers })}
</Text>
<Flex direction='column' gap='6px'>
<Text fontSize='sm'>
{t('set-config.bft-explanation', {
total: numPeers,
honest: bftHonest(numPeers),
faulty: bftFaulty(numPeers),
})}
</Text>
<Text fontSize='sm'>
{t('set-config.bft-faulty', {
faulty: bftFaulty(numPeers),
})}
</Text>
</Flex>
</Box>
);
};
28 changes: 16 additions & 12 deletions apps/guardian-ui/src/components/ConnectGuardians.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useConsensusPolling, useSetupContext } from '../hooks';
import { GuardianRole } from '../types';
import { getModuleParamsFromConfig } from '../utils/api';
import { ReactComponent as CopyIcon } from '../assets/svgs/copy.svg';
import { BftInfo } from './BftInfo';

interface Props {
next(): void;
Expand Down Expand Up @@ -59,17 +60,20 @@ export const ConnectGuardians: React.FC<Props> = ({ next }) => {
content = <Spinner />;
} else if (role === GuardianRole.Host) {
content = (
<FormControl maxWidth={400} bg='blue.50' p={2} borderRadius='md'>
<FormLabel>{t('connect-guardians.invite-guardians')}</FormLabel>
<CopyInput
value={guardianLink}
size='sm'
buttonLeftIcon={<Icon as={CopyIcon} />}
/>
<FormHelperText>
{t('connect-guardians.invite-guardians-help')}
</FormHelperText>
</FormControl>
<Flex direction={['column', 'row']} gap={4} align='start'>
<FormControl maxW={400} bg='blue.50' p={2} borderRadius='md'>
<FormLabel>{t('connect-guardians.invite-guardians')}</FormLabel>
<CopyInput
value={guardianLink}
size='sm'
buttonLeftIcon={<Icon as={CopyIcon} />}
/>
<FormHelperText>
{t('connect-guardians.invite-guardians-help')}
</FormHelperText>
</FormControl>
<BftInfo numPeers={numPeers} />
</Flex>
);
} else {
// TODO: Consider making this more dynamic, work with unknown modules etc.
Expand Down Expand Up @@ -190,7 +194,7 @@ export const ConnectGuardians: React.FC<Props> = ({ next }) => {
width='100%'
justify='start'
align='start'
gap={10}
gap={[8, 4]}
>
{content}
{peerTableRows.length > 1 && (
Expand Down
2 changes: 1 addition & 1 deletion apps/guardian-ui/src/components/DangerZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const DangerZone: React.FC<DangerZoneProps> = ({ config, ourPeer }) => {
const { t } = useTranslation();

return (
<Box mt={['12px']} bg='red.50' p={2} borderRadius='md'>
<Box mt='12px' bg='red.50' p={2} borderRadius='md' maxW='480px'>
<Text
mb='6px'
fontSize='14px'
Expand Down
5 changes: 4 additions & 1 deletion apps/guardian-ui/src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"network-label": "Network"
},
"guardians": {
"label": "Guardians",
"label": "Other Guardians",
"name-label": "Name",
"status-label": "Connection Status",
"health-label": "Health",
Expand Down Expand Up @@ -108,6 +108,9 @@
"generating-header": "Generating codes..."
},
"set-config": {
"bft-explanation-title": "Byzantine Fault Tolerance of Your Federation",
"bft-explanation": "A {{total}} Guardian Federation creates a {{honest}}/{{total}} Threshold.",
"bft-faulty": "Your Federation will be able to tolerate {{faulty}} faulty, offline, or malicious Guardians without impacting the Federation's operations.",
"guardian-name": "Guardian name",
"guardian-name-help": "This random name will be shown to other Guardians",
"admin-password": "Admin password",
Expand Down
1 change: 1 addition & 0 deletions apps/guardian-ui/src/setup/FederationSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export const FederationSetup: React.FC = () => {

const isPeerRestarted =
canRestart &&
peers &&
peers.some((peer) => peer.status === ServerStatus.SetupRestarted);

return (
Expand Down
34 changes: 3 additions & 31 deletions apps/guardian-ui/src/setup/SetupContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,19 @@ import {
} from '../types';
import { GuardianApi } from '../GuardianApi';
import { isConsensusparams } from '../utils/validators';
import { randomNames } from './randomNames';

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

/**
* Creates the initial state using loaded state from local storage.
*/
function makeInitialState(loadFromStorage = true): SetupState {
const randomNames = [
'Alice',
'Bob',
'Charlie',
'David',
'Eve',
'Frank',
'Grace',
'Harry',
'Iris',
'Jack',
'John',
'Kim',
'Lisa',
'Maggie',
'Mike',
'Naomi',
'Olivia',
'Paul',
'Queen',
'Robert',
'Sarah',
'Taylor',
'Victoria',
'William',
'Xavier',
'Yvonne',
'Zoe',
];
const randomName =
randomNames[Math.floor(Math.random() * randomNames.length)] +
Math.floor(Math.random() * 100)
Math.floor(Math.random() * 10000)
.toString()
.padStart(2, '0');
.padStart(4, '0');
let state: SetupState = {
role: null,
progress: SetupProgress.Start,
Expand Down
56 changes: 56 additions & 0 deletions apps/guardian-ui/src/setup/randomNames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export const randomNames = [
'Alice',
'Andy',
'Bob',
'Bella',
'Charlie',
'Cara',
'David',
'Diana',
'Eve',
'Ethan',
'Frank',
'Fiona',
'Grace',
'George',
'Harry',
'Helen',
'Iris',
'Ian',
'Jack',
'Jill',
'John',
'Julia',
'Kim',
'Kyle',
'Lisa',
'Leo',
'Maggie',
'Max',
'Mike',
'Molly',
'Naomi',
'Nate',
'Olivia',
'Oscar',
'Paul',
'Penny',
'Queen',
'Quinn',
'Robert',
'Rachel',
'Sarah',
'Sam',
'Taylor',
'Thomas',
'Victoria',
'Vincent',
'William',
'Wendy',
'Xavier',
'Xena',
'Yvonne',
'Yuri',
'Zoe',
'Zack',
];
7 changes: 7 additions & 0 deletions apps/guardian-ui/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function bftHonest(totalGuardians: number): number {
return totalGuardians - bftFaulty(totalGuardians);
}

export function bftFaulty(totalGuardians: number): number {
return Math.floor((totalGuardians - 1) / 3);
}
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
flake-utils.url = "github:numtide/flake-utils";
fedimint = {
url =
"github:fedimint/fedimint?rev=446f967f3f4c4ce9fba3d439c3544f80379d376e";
"github:fedimint/fedimint?rev=dbabb5f44de5401d24ca9414534a36a22e89c6df"; # v0.3.1
};
};
outputs = { self, flake-utils, fedimint }:
Expand Down Expand Up @@ -43,25 +43,25 @@
src = ./.;

nativeBuildInputs = with pkgs; [
nodejs
yarn
yarn2nix-moretea.fixup_yarn_lock
nodejs
yarn
yarn2nix-moretea.fixup_yarn_lock
];

configurePhase = ''
export HOME=$(mktemp -d)
export HOME=$(mktemp -d)
'';

buildPhase = ''
yarn config --offline set yarn-offline-mirror ${yarnOfflineCache}
fixup_yarn_lock yarn.lock
yarn config --offline set yarn-offline-mirror ${yarnOfflineCache}
fixup_yarn_lock yarn.lock
yarn install --offline \
--frozen-lockfile \
--ignore-engines --ignore-scripts
patchShebangs .
yarn install --offline \
--frozen-lockfile \
--ignore-engines --ignore-scripts
patchShebangs .
yarn build:guardian-ui
yarn build:guardian-ui
'';

installPhase = ''
Expand Down

0 comments on commit 1fc0cc6

Please sign in to comment.