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

v0.4.4 #571

Merged
merged 13 commits into from
Oct 24, 2024
Merged
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);
};
Kodylow marked this conversation as resolved.
Show resolved Hide resolved

/*** Setup RPC methods ***/

public getPassword = (): string | null => {
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]);
Kodylow marked this conversation as resolved.
Show resolved Hide resolved

// If role in query params, set it
useEffect(() => {
Expand Down Expand Up @@ -90,17 +110,33 @@ export const RoleSelector = React.memo<Props>(function RoleSelector({
onChange={(value) => setRole(value)}
activeIcon={CheckIcon}
/>
<Alert status='warning'>
<AlertIcon>
<WarningIcon />
</AlertIcon>
<Box>
<AlertTitle>{t('role-selector.disclaimer-title')}</AlertTitle>
<AlertDescription>
{t('role-selector.disclaimer-text')}
</AlertDescription>
</Box>
</Alert>
{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: bitcoinStatus * 100,
})}
</AlertDescription>
</Box>
</Alert>
) : (
<Alert status='warning'>
<AlertIcon>
<WarningIcon />
</AlertIcon>
<Box>
<AlertTitle>{t('role-selector.disclaimer-title')}</AlertTitle>
<AlertDescription>
{t('role-selector.disclaimer-text')}
</AlertDescription>
</Box>
</Alert>
)}
Kodylow marked this conversation as resolved.
Show resolved Hide resolved
<div>
<Button
width={['100%', 'auto']}
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: bitcoinStatus * 100,
})}
Kodylow marked this conversation as resolved.
Show resolved Hide resolved
</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]);
Kodylow marked this conversation as resolved.
Show resolved Hide resolved

// Update password when updated from state
useEffect(() => {
setPassword(statePassword);
Expand Down Expand Up @@ -250,6 +266,7 @@ export const SetConfiguration: React.FC<Props> = ({ next }: Props) => {
blockConfirmations={blockConfirmations}
setBlockConfirmations={setBlockConfirmations}
isHostOrSolo={isHost || isSolo}
bitcoinStatus={bitcoinStatus}
/>
<BasicSettingsForm
myName={myName}
Expand Down
4 changes: 4 additions & 0 deletions apps/router/src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,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
1 change: 1 addition & 0 deletions apps/router/src/types/guardian.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export enum AdminRpc {
export enum SharedRpc {
auth = 'auth',
status = 'status',
checkBitcoinStatus = 'check_bitcoin_status',
getVerifyConfigHash = 'verify_config_hash',
}

Expand Down
Loading
Loading