From 6d52a3c119fde30787ac31e42a047c002c73b8a4 Mon Sep 17 00:00:00 2001 From: Will O'Beirne Date: Fri, 1 Sep 2023 11:47:19 -0500 Subject: [PATCH 1/4] refactor(guardian-ui): move all types into single directory for better sharing --- apps/guardian-ui/src/GuardianApi.ts | 4 +- .../src/components/ConnectGuardians.tsx | 2 +- .../src/components/RoleSelector.tsx | 2 +- .../src/components/SetConfiguration.tsx | 7 +-- .../src/components/SetupProgress.tsx | 2 +- .../src/components/VerifyGuardians.tsx | 2 +- .../guardian-ui/src/setup/FederationSetup.tsx | 2 +- apps/guardian-ui/src/setup/SetupContext.tsx | 4 +- .../src/{types.tsx => types/api.ts} | 55 ++++++------------- apps/guardian-ui/src/types/app.ts | 39 +++++++++++++ apps/guardian-ui/src/types/index.ts | 3 + .../src/{setup/types.tsx => types/setup.ts} | 22 +------- apps/guardian-ui/src/utils/api.ts | 2 +- 13 files changed, 71 insertions(+), 75 deletions(-) rename apps/guardian-ui/src/{types.tsx => types/api.ts} (75%) create mode 100644 apps/guardian-ui/src/types/app.ts create mode 100644 apps/guardian-ui/src/types/index.ts rename apps/guardian-ui/src/{setup/types.tsx => types/setup.ts} (88%) diff --git a/apps/guardian-ui/src/GuardianApi.ts b/apps/guardian-ui/src/GuardianApi.ts index f2d937706..353a09c82 100644 --- a/apps/guardian-ui/src/GuardianApi.ts +++ b/apps/guardian-ui/src/GuardianApi.ts @@ -1,5 +1,4 @@ import { JsonRpcError, JsonRpcWebsocket } from 'jsonrpc-client-websocket'; -import { ConfigGenParams, ConsensusState, PeerHashMap } from './setup/types'; import { AuditSummary, ConfigResponse, @@ -7,6 +6,9 @@ import { ServerStatus, StatusResponse, Versions, + ConfigGenParams, + ConsensusState, + PeerHashMap, } from './types'; export interface SocketAndAuthInterface { diff --git a/apps/guardian-ui/src/components/ConnectGuardians.tsx b/apps/guardian-ui/src/components/ConnectGuardians.tsx index a7c2081c1..1db5225a9 100644 --- a/apps/guardian-ui/src/components/ConnectGuardians.tsx +++ b/apps/guardian-ui/src/components/ConnectGuardians.tsx @@ -18,7 +18,7 @@ import { CopyInput, Table, TableRow } from '@fedimint/ui'; import { useTranslation } from '@fedimint/utils'; import { useConsensusPolling, useSetupContext } from '../hooks'; import { ModuleKind, ServerStatus } from '../types'; -import { GuardianRole } from '../setup/types'; +import { GuardianRole } from '../types'; import { getModuleParamsFromConfig } from '../utils/api'; import { ReactComponent as CopyIcon } from '../assets/svgs/copy.svg'; diff --git a/apps/guardian-ui/src/components/RoleSelector.tsx b/apps/guardian-ui/src/components/RoleSelector.tsx index fa18fc3b8..54a39504f 100644 --- a/apps/guardian-ui/src/components/RoleSelector.tsx +++ b/apps/guardian-ui/src/components/RoleSelector.tsx @@ -1,7 +1,7 @@ import React, { useCallback, useMemo, useState } from 'react'; import { Button, VStack, Icon } from '@chakra-ui/react'; import { RadioButtonGroup, RadioButtonOption } from '@fedimint/ui'; -import { GuardianRole, SETUP_ACTION_TYPE } from '../setup/types'; +import { GuardianRole, SETUP_ACTION_TYPE } from '../types'; import { ReactComponent as ArrowRightIcon } from '../assets/svgs/arrow-right.svg'; import { ReactComponent as CheckIcon } from '../assets/svgs/check.svg'; import { ReactComponent as StarsIcon } from '../assets/svgs/stars.svg'; diff --git a/apps/guardian-ui/src/components/SetConfiguration.tsx b/apps/guardian-ui/src/components/SetConfiguration.tsx index 82719d472..91559816b 100644 --- a/apps/guardian-ui/src/components/SetConfiguration.tsx +++ b/apps/guardian-ui/src/components/SetConfiguration.tsx @@ -14,12 +14,7 @@ import { import { useTranslation } from '@fedimint/utils'; import { FormGroup, FormGroupHeading } from '@fedimint/ui'; import { useSetupContext } from '../hooks'; -import { - BitcoinRpc, - ConfigGenParams, - GuardianRole, - Network, -} from '../setup/types'; +import { BitcoinRpc, ConfigGenParams, GuardianRole, Network } from '../types'; import { ReactComponent as FedimintLogo } from '../assets/svgs/fedimint.svg'; import { ReactComponent as BitcoinLogo } from '../assets/svgs/bitcoin.svg'; import { ReactComponent as ArrowRightIcon } from '../assets/svgs/arrow-right.svg'; diff --git a/apps/guardian-ui/src/components/SetupProgress.tsx b/apps/guardian-ui/src/components/SetupProgress.tsx index b79c70fc1..b1e7a16f8 100644 --- a/apps/guardian-ui/src/components/SetupProgress.tsx +++ b/apps/guardian-ui/src/components/SetupProgress.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { Box, Center, Flex, Text, useTheme } from '@chakra-ui/react'; import { ReactComponent as CheckIcon } from '../assets/svgs/white-check.svg'; -import { StepState } from '../setup/types'; +import { StepState } from '../types'; interface StepProps { text: string; diff --git a/apps/guardian-ui/src/components/VerifyGuardians.tsx b/apps/guardian-ui/src/components/VerifyGuardians.tsx index e960f66f6..d863edbb5 100644 --- a/apps/guardian-ui/src/components/VerifyGuardians.tsx +++ b/apps/guardian-ui/src/components/VerifyGuardians.tsx @@ -17,7 +17,7 @@ import { } from '@chakra-ui/react'; import { CopyInput, FormGroup, Table } from '@fedimint/ui'; import { useConsensusPolling, useSetupContext } from '../hooks'; -import { GuardianRole, Peer } from '../setup/types'; +import { GuardianRole, Peer } from '../types'; import { ReactComponent as ArrowRightIcon } from '../assets/svgs/arrow-right.svg'; import { ReactComponent as CopyIcon } from '../assets/svgs/copy.svg'; import { formatApiErrorMessage } from '../utils/api'; diff --git a/apps/guardian-ui/src/setup/FederationSetup.tsx b/apps/guardian-ui/src/setup/FederationSetup.tsx index bd1ac7ffd..32620ebe3 100644 --- a/apps/guardian-ui/src/setup/FederationSetup.tsx +++ b/apps/guardian-ui/src/setup/FederationSetup.tsx @@ -3,7 +3,7 @@ import { Box, Button, Text, Heading, Icon, VStack } from '@chakra-ui/react'; import { ReactComponent as ArrowLeftIcon } from '../assets/svgs/arrow-left.svg'; import { useTranslation } from '@fedimint/utils'; import { useSetupContext } from '../hooks'; -import { GuardianRole, SetupProgress, SETUP_ACTION_TYPE } from './types'; +import { GuardianRole, SetupProgress, SETUP_ACTION_TYPE } from '../types'; import { RoleSelector } from '../components/RoleSelector'; import { SetConfiguration } from '../components/SetConfiguration'; import { ConnectGuardians } from '../components/ConnectGuardians'; diff --git a/apps/guardian-ui/src/setup/SetupContext.tsx b/apps/guardian-ui/src/setup/SetupContext.tsx index ecb4ab0c6..8fd201f0a 100644 --- a/apps/guardian-ui/src/setup/SetupContext.tsx +++ b/apps/guardian-ui/src/setup/SetupContext.tsx @@ -13,8 +13,8 @@ import { SETUP_ACTION_TYPE, SetupProgress, ConfigGenParams, -} from './types'; -import { ServerStatus } from '../types'; + ServerStatus, +} from '../types'; import { GuardianApi } from '../GuardianApi'; const LOCAL_STORAGE_SETUP_KEY = 'setup-guardian-ui-state'; diff --git a/apps/guardian-ui/src/types.tsx b/apps/guardian-ui/src/types/api.ts similarity index 75% rename from apps/guardian-ui/src/types.tsx rename to apps/guardian-ui/src/types/api.ts index 498c3d84e..d33001059 100644 --- a/apps/guardian-ui/src/types.tsx +++ b/apps/guardian-ui/src/types/api.ts @@ -22,6 +22,14 @@ export interface PeerStatus { flagged: boolean; } +export interface Peer { + name: string; + cert: string; + api_url: string; + p2p_url: string; + status: ServerStatus; +} + export interface FederationStatus { session_count: number; peers_online: number; @@ -113,47 +121,16 @@ interface RouteHint { src_node_id: string; } -export enum Status { - Loading, - Setup, - Admin, +export enum Network { + Testnet = 'testnet', + Mainnet = 'bitcoin', + Regtest = 'regtest', + Signet = 'signet', } -export interface AppState { - status: Status; - needsAuth: boolean; - initServerStatus?: ServerStatus; - appError?: string; -} - -export enum APP_ACTION_TYPE { - SET_STATUS = 'SET_STATUS', - SET_NEEDS_AUTH = 'SET_NEEDS_AUTH', - SET_INIT_SERVER_STATUS = 'SET_INIT_SERVER_STATUS', - SET_ERROR = 'SET_ERROR', -} - -export type AppAction = - | { - type: APP_ACTION_TYPE.SET_STATUS; - payload: Status; - } - | { - type: APP_ACTION_TYPE.SET_NEEDS_AUTH; - payload: boolean; - } - | { - type: APP_ACTION_TYPE.SET_INIT_SERVER_STATUS; - payload: ServerStatus | undefined; - } - | { - type: APP_ACTION_TYPE.SET_ERROR; - payload: string | undefined; - }; - -export interface InitializationState { - needsAuth: boolean; - serverStatus: ServerStatus; +export interface BitcoinRpc { + kind: string; + url: string; } export interface ModuleSummary { diff --git a/apps/guardian-ui/src/types/app.ts b/apps/guardian-ui/src/types/app.ts new file mode 100644 index 000000000..904f6dae7 --- /dev/null +++ b/apps/guardian-ui/src/types/app.ts @@ -0,0 +1,39 @@ +import { ServerStatus } from './api'; + +export enum Status { + Loading, + Setup, + Admin, +} + +export interface AppState { + status: Status; + needsAuth: boolean; + initServerStatus?: ServerStatus; + appError?: string; +} + +export enum APP_ACTION_TYPE { + SET_STATUS = 'SET_STATUS', + SET_NEEDS_AUTH = 'SET_NEEDS_AUTH', + SET_INIT_SERVER_STATUS = 'SET_INIT_SERVER_STATUS', + SET_ERROR = 'SET_ERROR', +} + +export type AppAction = + | { + type: APP_ACTION_TYPE.SET_STATUS; + payload: Status; + } + | { + type: APP_ACTION_TYPE.SET_NEEDS_AUTH; + payload: boolean; + } + | { + type: APP_ACTION_TYPE.SET_INIT_SERVER_STATUS; + payload: ServerStatus | undefined; + } + | { + type: APP_ACTION_TYPE.SET_ERROR; + payload: string | undefined; + }; diff --git a/apps/guardian-ui/src/types/index.ts b/apps/guardian-ui/src/types/index.ts new file mode 100644 index 000000000..0897080f9 --- /dev/null +++ b/apps/guardian-ui/src/types/index.ts @@ -0,0 +1,3 @@ +export * from './app'; +export * from './api'; +export * from './setup'; diff --git a/apps/guardian-ui/src/setup/types.tsx b/apps/guardian-ui/src/types/setup.ts similarity index 88% rename from apps/guardian-ui/src/setup/types.tsx rename to apps/guardian-ui/src/types/setup.ts index 04b87fd37..372c1e47f 100644 --- a/apps/guardian-ui/src/setup/types.tsx +++ b/apps/guardian-ui/src/types/setup.ts @@ -1,4 +1,4 @@ -import { MetaConfig, ModuleKind, ServerStatus } from '../types'; +import { MetaConfig, ModuleKind, Peer, BitcoinRpc, Network } from './api'; export enum GuardianRole { Host = 'Host', @@ -20,26 +20,6 @@ export enum StepState { Completed = 'Completed', } -export enum Network { - Testnet = 'testnet', - Mainnet = 'bitcoin', - Regtest = 'regtest', - Signet = 'signet', -} - -export interface Peer { - name: string; - cert: string; - api_url: string; - p2p_url: string; - status: ServerStatus; -} - -export interface BitcoinRpc { - kind: string; - url: string; -} - export type PeerHashMap = Record; export type LnModuleParams = [ diff --git a/apps/guardian-ui/src/utils/api.ts b/apps/guardian-ui/src/utils/api.ts index 03609f259..2b0261d19 100644 --- a/apps/guardian-ui/src/utils/api.ts +++ b/apps/guardian-ui/src/utils/api.ts @@ -1,5 +1,5 @@ import { JsonRpcError } from 'jsonrpc-client-websocket'; -import { AnyModuleParams, ConfigGenParams } from '../setup/types'; +import { AnyModuleParams, ConfigGenParams } from '../types'; import { ModuleKind } from '../types'; /** From 5d249b145ca9c150bdaf431c87a9049a4490746c Mon Sep 17 00:00:00 2001 From: Will O'Beirne Date: Fri, 1 Sep 2023 13:43:52 -0500 Subject: [PATCH 2/4] feat(guardian-ui): add modules_config_json api method and types --- apps/guardian-ui/src/GuardianApi.ts | 7 ++++++ apps/guardian-ui/src/types/api.ts | 38 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/apps/guardian-ui/src/GuardianApi.ts b/apps/guardian-ui/src/GuardianApi.ts index 353a09c82..485391890 100644 --- a/apps/guardian-ui/src/GuardianApi.ts +++ b/apps/guardian-ui/src/GuardianApi.ts @@ -9,6 +9,7 @@ import { ConfigGenParams, ConsensusState, PeerHashMap, + ModulesConfigResponse, } from './types'; export interface SocketAndAuthInterface { @@ -210,6 +211,7 @@ enum AdminRpc { federationStatus = 'consensus_status', inviteCode = 'invite_code', config = 'config', + modulesConfig = 'modules_config_json', module = 'module', audit = 'audit', } @@ -226,6 +228,7 @@ export interface AdminApiInterface extends SharedApiInterface { inviteCode: () => Promise; config: (connection: string) => Promise; audit: () => Promise; + modulesConfig: () => Promise; moduleApiCall: (moduleId: number, rpc: ModuleRpc) => Promise; } @@ -375,6 +378,10 @@ export class GuardianApi return this.base.call(AdminRpc.audit); }; + modulesConfig = () => { + return this.base.call(AdminRpc.modulesConfig); + }; + moduleApiCall = (moduleId: number, rpc: ModuleRpc): Promise => { const method = `${AdminRpc.module}_${moduleId}_${rpc}`; return this.base.call_any_method(method); diff --git a/apps/guardian-ui/src/types/api.ts b/apps/guardian-ui/src/types/api.ts index d33001059..a49533d1e 100644 --- a/apps/guardian-ui/src/types/api.ts +++ b/apps/guardian-ui/src/types/api.ts @@ -141,3 +141,41 @@ export interface AuditSummary { net_assets: MSats; module_summaries: Record; } + +// Consider sharing these types with types/setup.ts *ModuleParams? Need to +// confirm that setup API returns identical types to the admin API. +interface ModuleConfigs { + [ModuleKind.Ln]: { + network: Network; + fee_consensus: { + contract_input: number; + contract_output: number; + }; + }; + [ModuleKind.Mint]: { + fee_consensus: { + note_issuance_abs: number; + note_spend_abs: number; + }; + max_notes_per_denomination: number; + peer_tbs_pks: Record>; + }; + [ModuleKind.Wallet]: { + client_default_bitcoin_rpc: BitcoinRpc; + default_fee: { sats_per_kvb: number }; + fee_consensus: { + peg_in_abs: number; + peg_out_abs: number; + }; + finality_delay: number; + network: Network; + peer_peg_in_keys: Record; + peg_in_descriptor: number; + }; +} + +export type ModuleConfig = { + kind: T; +} & ModuleConfigs[T]; + +export type ModulesConfigResponse = Record; From bd021679446d2f9480acbe9725c83b51b684b27b Mon Sep 17 00:00:00 2001 From: Will O'Beirne Date: Fri, 1 Sep 2023 13:45:30 -0500 Subject: [PATCH 3/4] feat(guardian-ui): hook up wallet module config to bitcoin node card --- .../guardian-ui/src/admin/FederationAdmin.tsx | 10 ++++-- .../src/components/BitcoinNodeCard.tsx | 31 ++++++++++++++----- apps/guardian-ui/src/languages/en.json | 2 +- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/apps/guardian-ui/src/admin/FederationAdmin.tsx b/apps/guardian-ui/src/admin/FederationAdmin.tsx index dba50199e..9c46a5054 100644 --- a/apps/guardian-ui/src/admin/FederationAdmin.tsx +++ b/apps/guardian-ui/src/admin/FederationAdmin.tsx @@ -3,7 +3,11 @@ import { Flex, Box, Icon, Text, useTheme, Heading } from '@chakra-ui/react'; import { CopyInput } from '@fedimint/ui'; import { useTranslation } from '@fedimint/utils'; import { useAdminContext } from '../hooks'; -import { ConfigResponse, StatusResponse } from '../types'; +import { + ConfigResponse, + ModulesConfigResponse, + StatusResponse, +} from '../types'; import { GatewaysCard } from '../components/GatewaysCard'; import { ReactComponent as CopyIcon } from '../assets/svgs/copy.svg'; import { GuardiansCard } from '../components/GuardiansCard'; @@ -17,12 +21,14 @@ export const FederationAdmin: React.FC = () => { const [status, setStatus] = useState(); const [inviteCode, setInviteCode] = useState(''); const [config, setConfig] = useState(); + const [modulesConfigs, setModulesConfigs] = useState(); const { t } = useTranslation(); useEffect(() => { // TODO: poll server status api.status().then(setStatus).catch(console.error); api.inviteCode().then(setInviteCode).catch(console.error); + api.modulesConfig().then(setModulesConfigs).catch(console.error); }, [api]); useEffect(() => { @@ -69,7 +75,7 @@ export const FederationAdmin: React.FC = () => { - + diff --git a/apps/guardian-ui/src/components/BitcoinNodeCard.tsx b/apps/guardian-ui/src/components/BitcoinNodeCard.tsx index c2c93a0ab..f19b0bac4 100644 --- a/apps/guardian-ui/src/components/BitcoinNodeCard.tsx +++ b/apps/guardian-ui/src/components/BitcoinNodeCard.tsx @@ -1,16 +1,23 @@ -import { Card, CardBody, CardHeader, Text } from '@chakra-ui/react'; +import { Card, CardBody, CardHeader, Skeleton, Text } from '@chakra-ui/react'; import { useTranslation } from '@fedimint/utils'; import React, { useMemo } from 'react'; -import { ConfigResponse } from '../types'; +import { ModuleConfig, ModuleKind, ModulesConfigResponse } from '../types'; import { KeyValues } from '@fedimint/ui'; interface Props { - config: ConfigResponse | undefined; + modulesConfigs: ModulesConfigResponse | undefined; } -export const BitcoinNodeCard: React.FC = () => { +export const BitcoinNodeCard: React.FC = ({ modulesConfigs }) => { const { t } = useTranslation(); + const walletConfig = modulesConfigs + ? Object.values(modulesConfigs).find( + (config): config is ModuleConfig => + config.kind === ModuleKind.Wallet + ) + : undefined; + // TODO: Populate values from config.client_config.modules.config // It's currently mysteriously hex encoded const keyValues = useMemo( @@ -18,15 +25,23 @@ export const BitcoinNodeCard: React.FC = () => { { key: 'url', label: t('federation-dashboard.bitcoin-node.url-label'), - value: t('common.unknown'), + value: walletConfig ? ( + walletConfig.client_default_bitcoin_rpc?.url + ) : ( + + ), }, { key: 'blockHeight', - label: t('federation-dashboard.bitcoin-node.block-height-label'), - value: t('common.unknown'), + label: t('federation-dashboard.bitcoin-node.network-label'), + value: walletConfig ? ( + walletConfig.network + ) : ( + + ), }, ], - [t] + [walletConfig, t] ); return ( diff --git a/apps/guardian-ui/src/languages/en.json b/apps/guardian-ui/src/languages/en.json index bf8381fcb..c72e58e6f 100644 --- a/apps/guardian-ui/src/languages/en.json +++ b/apps/guardian-ui/src/languages/en.json @@ -32,7 +32,7 @@ "bitcoin-node": { "label": "Bitcoin Node", "url-label": "URL", - "block-height-label": "Current block height" + "network-label": "Network" }, "guardians": { "label": "Guardians", From 6c0b911ce84bad6b93c4495cb82f0ffc41355af2 Mon Sep 17 00:00:00 2001 From: Ethan Tuttle <133234413+EthnTuttle@users.noreply.github.com> Date: Tue, 12 Sep 2023 15:05:41 -0500 Subject: [PATCH 4/4] fix: update key to accurate description --- apps/guardian-ui/src/components/BitcoinNodeCard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/guardian-ui/src/components/BitcoinNodeCard.tsx b/apps/guardian-ui/src/components/BitcoinNodeCard.tsx index f19b0bac4..aac648c85 100644 --- a/apps/guardian-ui/src/components/BitcoinNodeCard.tsx +++ b/apps/guardian-ui/src/components/BitcoinNodeCard.tsx @@ -32,7 +32,7 @@ export const BitcoinNodeCard: React.FC = ({ modulesConfigs }) => { ), }, { - key: 'blockHeight', + key: 'network', label: t('federation-dashboard.bitcoin-node.network-label'), value: walletConfig ? ( walletConfig.network