Skip to content

Commit

Permalink
Merge pull request fedimint#571 from Kodylow/v0.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow authored Oct 24, 2024
2 parents 3af06a8 + 4e8fb7a commit 1ee9f74
Show file tree
Hide file tree
Showing 24 changed files with 266 additions and 439 deletions.
5 changes: 5 additions & 0 deletions apps/router/src/api/GuardianApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { JsonRpcError, JsonRpcWebsocket } from 'jsonrpc-client-websocket';
import {
AuditSummary,
BitcoinRpcConnectionStatus,
ClientConfig,
ConfigGenParams,
ConsensusState,
Expand Down Expand Up @@ -112,6 +113,10 @@ export class GuardianApi {
return this.call(SharedRpc.status);
};

checkBitcoinStatus = (): Promise<BitcoinRpcConnectionStatus> => {
return this.call(SharedRpc.checkBitcoinStatus);
};

/*** Setup RPC methods ***/

public getPassword = (): string | null => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@fedimint/types';
import { useTranslation } from '@fedimint/utils';
import { KeyValues, NetworkIndicator } from '@fedimint/ui';
import { useGuardianAdminApi } from '../../../../../context/hooks';
import { useGuardianApi } from '../../../../../context/hooks';
import { BftInfo } from '../../../BftInfo';

interface Props {
Expand All @@ -26,7 +26,7 @@ export const FederationInfo: React.FC<Props> = ({
modulesConfigs,
}) => {
const { t } = useTranslation();
const api = useGuardianAdminApi();
const api = useGuardianApi();
const [versions, setVersions] = useState<Versions>();
const [blockCount, setBlockCount] = useState<number>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const MetaManager = React.memo(function MetaManager({
}
)
.then(() => {
setActiveTab(3);
setActiveTab(0);
})
.catch((error) => {
console.error(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ import { ReactComponent as WarningIcon } from '../../../../assets/svgs/warning.s
import { ReactComponent as SoloIcon } from '../../../../assets/svgs/solo.svg';
import { useTranslation } from '@fedimint/utils';
import { WarningModal } from './WarningModal';
import { useGuardianSetupContext } from '../../../../../context/hooks';
import {
useGuardianApi,
useGuardianSetupContext,
} from '../../../../../context/hooks';
import { GuardianRole, SETUP_ACTION_TYPE } from '../../../../../types/guardian';
import { BitcoinRpcConnectionStatus } from '@fedimint/types';

interface Props {
next: () => void;
Expand All @@ -29,9 +33,25 @@ export const RoleSelector = React.memo<Props>(function RoleSelector({
next,
}: Props) {
const { t } = useTranslation();
const api = useGuardianApi();
const { dispatch } = useGuardianSetupContext();
const [role, setRole] = useState<GuardianRole>();
const [isModalOpen, setIsModalOpen] = useState(false);
const [bitcoinStatus, setBitcoinStatus] =
useState<BitcoinRpcConnectionStatus>();

useEffect(() => {
const fetchBitcoinStatus = async () => {
try {
const status = await api.checkBitcoinStatus();
setBitcoinStatus(status);
} catch (error) {
console.error('Failed to fetch Bitcoin status:', error);
}
};

fetchBitcoinStatus();
}, [api]);

// If role in query params, set it
useEffect(() => {
Expand Down Expand Up @@ -91,21 +111,47 @@ export const RoleSelector = React.memo<Props>(function RoleSelector({
activeIcon={CheckIcon}
/>
<Alert status='warning'>
<AlertIcon>
<WarningIcon />
</AlertIcon>
<Box>
<AlertTitle>{t('role-selector.disclaimer-title')}</AlertTitle>
<AlertDescription>
{t('role-selector.disclaimer-text')}
</AlertDescription>
</Box>
{bitcoinStatus === undefined ? (
// Error state
<>
<AlertIcon />
<Box>
<AlertTitle>{t('role-selector.bitcoin-node.error')}</AlertTitle>
</Box>
</>
) : bitcoinStatus !== 'Synced' ? (
// Not synced state
<>
<AlertIcon />
<Box>
<AlertTitle>{t('role-selector.bitcoin-node.not-synced')}</AlertTitle>
<AlertDescription>
{t('role-selector.bitcoin-node.not-synced-description', {
progress: Math.round(Number(bitcoinStatus) * 100),
})}
</AlertDescription>
</Box>
</>
) : (
// Default warning
<>
<AlertIcon>
<WarningIcon />
</AlertIcon>
<Box>
<AlertTitle>{t('role-selector.disclaimer-title')}</AlertTitle>
<AlertDescription>
{t('role-selector.disclaimer-text')}
</AlertDescription>
</Box>
</>
)}
</Alert>
<div>
<Button
width={['100%', 'auto']}
leftIcon={<Icon as={ArrowRightIcon} />}
isDisabled={!role}
isDisabled={!role || (bitcoinStatus !== undefined && bitcoinStatus !== 'Synced')}
onClick={() => {
role === GuardianRole.Solo ? handleConfirm() : setIsModalOpen(true);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ import {
Input,
Select,
FormHelperText,
Alert,
AlertIcon,
Box,
AlertTitle,
AlertDescription,
} from '@chakra-ui/react';
import { useTranslation } from '@fedimint/utils';
import { FormGroup, NetworkIndicator } from '@fedimint/ui';
import { ReactComponent as BitcoinLogo } from '../../../../assets/svgs/bitcoin.svg';
import { Network, BitcoinRpc, BitcoinRpcKind } from '@fedimint/types';
import {
Network,
BitcoinRpc,
BitcoinRpcKind,
BitcoinRpcConnectionStatus,
} from '@fedimint/types';
import { NumberFormControl } from '../../../NumberFormControl';

interface BitcoinSettingsFormProps {
Expand All @@ -22,6 +32,7 @@ interface BitcoinSettingsFormProps {
blockConfirmations: string;
setBlockConfirmations: (value: string) => void;
isHostOrSolo: boolean;
bitcoinStatus: BitcoinRpcConnectionStatus | undefined;
}

export const BitcoinSettingsForm: React.FC<BitcoinSettingsFormProps> = ({
Expand All @@ -34,6 +45,7 @@ export const BitcoinSettingsForm: React.FC<BitcoinSettingsFormProps> = ({
blockConfirmations,
setBlockConfirmations,
isHostOrSolo,
bitcoinStatus,
}) => {
const { t } = useTranslation();

Expand All @@ -48,6 +60,21 @@ export const BitcoinSettingsForm: React.FC<BitcoinSettingsFormProps> = ({
}
isOpen={true}
>
{bitcoinStatus && bitcoinStatus !== 'Synced' && (
<Alert status='warning'>
<AlertIcon />
<Box>
<AlertTitle>
{t('role-selector.bitcoin-node.not-synced')}
</AlertTitle>
<AlertDescription>
{t('role-selector.bitcoin-node.not-synced-description', {
progress: typeof bitcoinStatus === 'number' ? bitcoinStatus * 100 : 0,
})}
</AlertDescription>
</Box>
</Alert>
)}
{isHostOrSolo && (
<NumberFormControl
isDisabled={bitcoinSetFromParams}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ConfigGenParams,
ModuleKind,
Network,
BitcoinRpcConnectionStatus,
} from '@fedimint/types';
import { useTranslation } from '@fedimint/utils';
import { GuardianRole } from '../../../../../types/guardian';
Expand Down Expand Up @@ -67,6 +68,8 @@ export const SetConfiguration: React.FC<Props> = ({ next }: Props) => {
url: '',
});
const [bitcoinSetFromParams, setBitcoinSetFromParams] = useState(false);
const [bitcoinStatus, setBitcoinStatus] =
useState<BitcoinRpcConnectionStatus>();
const [mintAmounts, setMintAmounts] = useState<number[]>([]);
const [error, setError] = useState<string>();
const [numPeers, setNumPeers] = useState(
Expand Down Expand Up @@ -115,6 +118,19 @@ export const SetConfiguration: React.FC<Props> = ({ next }: Props) => {
}
}, [configGenParams, api]);

useEffect(() => {
const fetchBitcoinStatus = async () => {
try {
const status = await api.checkBitcoinStatus();
setBitcoinStatus(status);
} catch (error) {
console.error('Failed to fetch Bitcoin status:', error);
}
};

fetchBitcoinStatus();
}, [api]);

// Update password when updated from state
useEffect(() => {
setPassword(statePassword);
Expand Down Expand Up @@ -229,6 +245,7 @@ export const SetConfiguration: React.FC<Props> = ({ next }: Props) => {
justify='flex-start'
align='flex-start'
width='auto'
minWidth='90%'
>
<FederationSettingsForm
federationName={federationName}
Expand All @@ -250,6 +267,7 @@ export const SetConfiguration: React.FC<Props> = ({ next }: Props) => {
blockConfirmations={blockConfirmations}
setBlockConfirmations={setBlockConfirmations}
isHostOrSolo={isHost || isSolo}
bitcoinStatus={bitcoinStatus}
/>
<BasicSettingsForm
myName={myName}
Expand All @@ -264,14 +282,14 @@ export const SetConfiguration: React.FC<Props> = ({ next }: Props) => {
width='60%'
alignSelf='center'
>
{t('common.next')}
{t('common.continue')}
</Button>
{error && (
<Text color={theme.colors.red[500]} mt={4}>
{error}
</Text>
)}
{password !== null && (
{password !== null && bitcoinStatus === 'Synced' && (
<ConfirmPasswordModal
password={password}
submitConfig={submitConfig}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export const VerifyGuardians: React.FC<Props> = ({ next }) => {
return <Spinner />;
} else if (numPeers === 1) {
return (
<Flex direction='column' gap={10} justify='center' align='center'>
<Flex direction='column' gap={6} justify='center' align='center'>
<CircularProgress
isIndeterminate
color={theme.colors.blue[400]}
Expand All @@ -270,7 +270,7 @@ export const VerifyGuardians: React.FC<Props> = ({ next }) => {
);
} else {
return (
<Flex direction='column' gap={10} justify='start' align='start'>
<Flex direction='column' gap={6} justify='start' align='start'>
<FormControl
bg={theme.colors.blue[50]}
p={4}
Expand Down
11 changes: 10 additions & 1 deletion apps/router/src/guardian-ui/setup/FederationSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,16 @@ export const FederationSetup: React.FC = () => {
</Text>
)}
</Flex>
<Box width={['100%', '90%']} justifyItems='center'>
<Box
width={['100%', '90%']}
justifyItems={
(progress === SetupProgress.Start ||
progress === SetupProgress.VerifyGuardians) &&
!tosConfig?.showTos
? 'left'
: 'center'
}
>
{content}
</Box>
<RestartModals
Expand Down
7 changes: 6 additions & 1 deletion apps/router/src/languages/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"latest-session": "Última sessió"
},
"version-label": "Versió (consens / api)",
"consensus-block-height-label": "Consens de l'altura del bloc Bitcoin"
"consensus-block-height-label": "Consens de l'altura del bloc Bitcoin",
"bitcoin-status-label": "Estat de sincronització de Bitcoin"
},
"balance": {
"label": "Balanç general"
Expand Down Expand Up @@ -219,6 +220,10 @@
"warning-modal": {
"title": "Tothom està a punt?",
"description": "Sortir de la cerimònia de configuració pot provocar que la configuració falli i requereixi que reinicieu el vostre guardià. Assegureu-vos que tothom està preparat per executar la configuració completa abans de continuar!"
},
"bitcoin-node": {
"not-synced": "Node de Bitcoin no està completament sincronitzat",
"not-synced-description": "El vostre node de Bitcoin està actualment sincronitzat al {{progress}}%. Heu d'esperar a la sincronització completa abans de continuar."
}
},
"run-dkg": {
Expand Down
7 changes: 6 additions & 1 deletion apps/router/src/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"latest-session": "Letzte Sitzung"
},
"version-label": "Version (Konsens / API)",
"consensus-block-height-label": "Konsens Bitcoin Blockhöhe"
"consensus-block-height-label": "Konsens Bitcoin Blockhöhe",
"bitcoin-status-label": "Bitcoin-Synchronisierungsstatus"
},
"balance": {
"label": "Bilanz"
Expand Down Expand Up @@ -219,6 +220,10 @@
"warning-modal": {
"title": "Ist jeder bereit?",
"description": "Das Verlassen der Einrichtungszeremonie kann dazu führen, dass die Einrichtung fehlschlägt und Sie Ihren Wächter neu starten müssen. Stellen Sie sicher, dass jeder bereit ist, die vollständige Einrichtung durchzuführen, bevor Sie fortfahren!"
},
"bitcoin-node": {
"not-synced": "Bitcoin-Knoten nicht vollständig synchronisiert",
"not-synced-description": "Ihr Bitcoin-Knotenpunkt ist derzeit zu {{progress}}% synchronisiert. Sie müssen auf die vollständige Synchronisation warten, bevor Sie fortfahren können."
}
},
"run-dkg": {
Expand Down
7 changes: 6 additions & 1 deletion apps/router/src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"latest-session": "Latest Session"
},
"version-label": "Version (consensus / api)",
"consensus-block-height-label": "Consensus Bitcoin Block Height"
"consensus-block-height-label": "Consensus Bitcoin Block Height",
"bitcoin-status-label": "Bitcoin Sync Status"
},
"status": {
"label": "Status"
Expand Down Expand Up @@ -246,6 +247,10 @@
"warning-modal": {
"title": "Is everyone ready?",
"description": "Exiting the setup ceremony may cause the setup to fail and require you to restart your guardian. Make sure everyone is ready to run the full setup before continuing!"
},
"bitcoin-node": {
"not-synced": "Bitcoin Node Not Fully Synced",
"not-synced-description": "Your Bitcoin node is currently {{progress}}% synced. You must wait for full synchronization before proceeding."
}
},
"run-dkg": {
Expand Down
7 changes: 6 additions & 1 deletion apps/router/src/languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"latest-session": "Última Sesión"
},
"version-label": "Versión (consenso / api)",
"consensus-block-height-label": "Altura de Bloque de Consenso de Bitcoin"
"consensus-block-height-label": "Altura de Bloque de Consenso de Bitcoin",
"bitcoin-status-label": "Estado de Sincronización de Bitcoin"
},
"balance": {
"label": "Hoja de Balance"
Expand Down Expand Up @@ -219,6 +220,10 @@
"warning-modal": {
"title": "¿Están todos listos?",
"description": "Salir de la ceremonia de configuración puede causar que la configuración falle y requiera que reinicies tu guardián. ¡Asegúrate de que todos estén listos para ejecutar la configuración completa antes de continuar!"
},
"bitcoin-node": {
"not-synced": "Nodo de Bitcoin no completamente sincronizado",
"not-synced-description": "Tu nodo de Bitcoin está actualmente sincronizado al {{progress}}%. Debes esperar a la sincronización completa antes de continuar."
}
},
"run-dkg": {
Expand Down
Loading

0 comments on commit 1ee9f74

Please sign in to comment.