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

feat: disable when env vars detected + BitcoinRpcKind #492

Merged
merged 2 commits into from
Aug 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import {
import { useTranslation } from '@fedimint/utils';
import { FormGroup, NetworkIndicator } from '@fedimint/ui';
import { ReactComponent as BitcoinLogo } from '../../../../assets/svgs/bitcoin.svg';
import { Network, BitcoinRpc } from '@fedimint/types';
import { Network, BitcoinRpc, BitcoinRpcKind } from '@fedimint/types';
import { NumberFormControl } from '../../../NumberFormControl';

interface BitcoinSettingsFormProps {
network: Network;
setNetwork: (network: Network) => void;
networkSetFromParams: boolean;
bitcoinRpc: BitcoinRpc;
setBitcoinRpc: (rpc: BitcoinRpc) => void;
bitcoinSetFromParams: boolean;
blockConfirmations: string;
setBlockConfirmations: (value: string) => void;
isHostOrSolo: boolean;
Expand All @@ -25,8 +27,10 @@ interface BitcoinSettingsFormProps {
export const BitcoinSettingsForm: React.FC<BitcoinSettingsFormProps> = ({
network,
setNetwork,
networkSetFromParams,
bitcoinRpc,
setBitcoinRpc,
bitcoinSetFromParams,
blockConfirmations,
setBlockConfirmations,
isHostOrSolo,
Expand All @@ -46,6 +50,7 @@ export const BitcoinSettingsForm: React.FC<BitcoinSettingsFormProps> = ({
>
{isHostOrSolo && (
<NumberFormControl
isDisabled={bitcoinSetFromParams}
labelText={t('set-config.block-confirmations')}
helperText={t('set-config.block-confirmations-help')}
warningText={t('set-config.block-confirmations-warning')}
Expand All @@ -58,8 +63,11 @@ export const BitcoinSettingsForm: React.FC<BitcoinSettingsFormProps> = ({
}}
/>
)}
<FormControl>
<FormLabel>{t('set-config.bitcoin-network')}</FormLabel>
<FormControl isDisabled={networkSetFromParams}>
<FormLabel>
{t('set-config.bitcoin-network')}{' '}
{networkSetFromParams && t('set-config.read-from-env')}
</FormLabel>
<Select
placeholder={`${t('set-config.select-network')}`}
value={network !== null ? network : ''}
Expand All @@ -75,15 +83,41 @@ export const BitcoinSettingsForm: React.FC<BitcoinSettingsFormProps> = ({
))}
</Select>
</FormControl>
<FormControl>
<FormLabel>{t('set-config.bitcoin-rpc')}</FormLabel>
<FormControl isDisabled={bitcoinSetFromParams}>
<FormLabel>
{t('set-config.bitcoin-rpc-kind')}{' '}
{bitcoinSetFromParams && t('set-config.read-from-env')}
</FormLabel>
<Select
value={bitcoinRpc.kind}
onChange={(ev) => {
setBitcoinRpc({
...bitcoinRpc,
kind: ev.target.value as BitcoinRpcKind,
});
}}
>
{Object.entries(BitcoinRpcKind).map(([label, value]) => (
<option key={value} value={value}>
{label}
</option>
))}
</Select>
</FormControl>
<FormControl isDisabled={bitcoinSetFromParams}>
<FormLabel>
{t('set-config.bitcoin-rpc')}{' '}
{bitcoinSetFromParams && t('set-config.read-from-env')}
</FormLabel>
<Input
value={bitcoinRpc.url}
onChange={(ev) => {
setBitcoinRpc({ ...bitcoinRpc, url: ev.currentTarget.value });
}}
/>
<FormHelperText>{t('set-config.set-rpc-help')}</FormHelperText>
{!bitcoinSetFromParams && (
<FormHelperText>{t('set-config.set-rpc-help')}</FormHelperText>
)}
</FormControl>
</FormGroup>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ export const SetConfiguration: React.FC<Props> = ({ next }: Props) => {
const [metaFields, setMetaFields] = useState<[string, string][]>([['', '']]);
const [blockConfirmations, setBlockConfirmations] = useState('');
const [network, setNetwork] = useState('');
const [networkSetFromParams, setNetworkSetFromParams] = useState(false);
const [bitcoinRpc, setBitcoinRpc] = useState<BitcoinRpc>({
kind: '',
url: '',
});
const [bitcoinSetFromParams, setBitcoinSetFromParams] = useState(false);
const [mintAmounts, setMintAmounts] = useState<number[]>([]);
const [error, setError] = useState<string>();
const [numPeers, setNumPeers] = useState(
Expand Down Expand Up @@ -90,9 +92,11 @@ export const SetConfiguration: React.FC<Props> = ({ next }: Props) => {
}
if (walletConsensus?.network) {
setNetwork(walletConsensus.network);
setNetworkSetFromParams(true);
}
if (walletModule?.local?.bitcoin_rpc) {
setBitcoinRpc(walletModule.local.bitcoin_rpc);
setBitcoinSetFromParams(true);
}
};

Expand Down Expand Up @@ -236,8 +240,10 @@ export const SetConfiguration: React.FC<Props> = ({ next }: Props) => {
<BitcoinSettingsForm
network={network as Network}
setNetwork={setNetwork}
networkSetFromParams={networkSetFromParams}
bitcoinRpc={bitcoinRpc}
setBitcoinRpc={setBitcoinRpc}
bitcoinSetFromParams={bitcoinSetFromParams}
blockConfirmations={blockConfirmations}
setBlockConfirmations={setBlockConfirmations}
isHostOrSolo={isHost || isSolo}
Expand Down
6 changes: 4 additions & 2 deletions apps/guardian-ui/src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@
"block-confirmations-warning": "Running Fedimint with less than 5 additional block confirmations is extremely risky! Fedimint CANNOT handle blockchain reorganizations.",
"bitcoin-network": "Bitcoin Network",
"select-network": "Select a network",
"set-rpc-help": "Locally configured Bitcoin RPC address",
"bitcoin-rpc": "Bitcoin RPC",
"bitcoin-rpc-kind": "Bitcoin RPC kind",
"set-rpc-help": "Source of bitcoin block data for your guardian node",
"bitcoin-rpc": "Bitcoin RPC URL",
"read-from-env": "(Detected from environment variables)",
"error-valid-number": "Please input a valid number.",
"error-valid-min": "Please input a number of at least {{min}}.",
"error-valid-max": "Please input a number of at most {{max}}.",
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export enum Network {
Regtest = 'regtest',
}

export enum BitcoinRpcKind {
Bitcoind = 'bitcoind',
Esplora = 'esplora',
// Electrum = 'electrum', TODO: needs testing fedimint side
}

export class Bip21Uri {
constructor(public address: string, public amountSats?: Sats) {}

Expand Down
Loading