diff --git a/api.go b/api.go index 382ad767..9efb4bb9 100644 --- a/api.go +++ b/api.go @@ -233,6 +233,9 @@ func (svc *Service) Setup(setupRequest *api.SetupRequest) error { if setupRequest.LNBackendType != "" { dbConfig.LNBackendType = setupRequest.LNBackendType } + if setupRequest.BreezAPIKey != "" { + dbConfig.BreezAPIKey = setupRequest.BreezAPIKey + } if setupRequest.BreezMnemonic != "" { dbConfig.BreezMnemonic = setupRequest.BreezMnemonic } @@ -242,15 +245,9 @@ func (svc *Service) Setup(setupRequest *api.SetupRequest) error { if setupRequest.LNDAddress != "" { dbConfig.LNDAddress = setupRequest.LNDAddress } - if setupRequest.LNDCertFile != "" { - dbConfig.LNDCertFile = setupRequest.LNDCertFile - } if setupRequest.LNDCertHex != "" { dbConfig.LNDCertHex = setupRequest.LNDCertHex } - if setupRequest.LNDMacaroonFile != "" { - dbConfig.LNDMacaroonFile = setupRequest.LNDMacaroonFile - } if setupRequest.LNDMacaroonHex != "" { dbConfig.LNDMacaroonHex = setupRequest.LNDMacaroonHex } diff --git a/config.go b/config.go index f033b64c..2ae04410 100644 --- a/config.go +++ b/config.go @@ -22,7 +22,8 @@ type Config struct { ClientPubkey string `envconfig:"CLIENT_NOSTR_PUBKEY"` Relay string `envconfig:"RELAY" default:"wss://relay.getalby.com/v1"` PublicRelay string `envconfig:"PUBLIC_RELAY"` - BreezAPIKey string `envconfig:"BREEZ_API_KEY"` + LNDCertFile string `envconfig:"LND_CERT_FILE"` + LNDMacaroonFile string `envconfig:"LND_MACAROON_FILE"` BreezWorkdir string `envconfig:"BREEZ_WORK_DIR" default:".breez"` BasicAuthUser string `envconfig:"BASIC_AUTH_USER"` BasicAuthPassword string `envconfig:"BASIC_AUTH_PASSWORD"` diff --git a/frontend/src/screens/Setup.tsx b/frontend/src/screens/Setup.tsx index 64bf1818..4939f75d 100644 --- a/frontend/src/screens/Setup.tsx +++ b/frontend/src/screens/Setup.tsx @@ -1,5 +1,6 @@ import React from "react"; import { useNavigate } from "react-router-dom"; +import Loading from "src/components/Loading"; import { useCSRF } from "src/hooks/useCSRF"; import { useInfo } from "src/hooks/useInfo"; import { BackendType } from "src/types"; @@ -7,6 +8,7 @@ import { request, handleRequestError } from "src/utils/request"; export function Setup() { const [backendType, setBackendType] = React.useState("BREEZ"); + const [isConnecting, setConnecting] = React.useState(false); const navigate = useNavigate(); const { data: info } = useInfo(); @@ -14,6 +16,7 @@ export function Setup() { async function handleSubmit(data: object) { try { + setConnecting(true); if (!csrf) { throw new Error("info not loaded"); } @@ -32,6 +35,8 @@ export function Setup() { navigate("/apps"); } catch (error) { handleRequestError("Failed to connect", error); + } finally { + setConnecting(false); } } @@ -63,30 +68,49 @@ export function Setup() { - {backendType === "BREEZ" && } - {backendType === "LND" && } + {backendType === "BREEZ" && ( + + )} + {backendType === "LND" && ( + + )} ); } -function ConnectButton() { +type ConnectButtonProps = { + isConnecting: boolean; +}; + +function ConnectButton({ isConnecting }: ConnectButtonProps) { return ( ); } type SetupFormProps = { + isConnecting: boolean; handleSubmit(data: unknown): void; }; -function BreezForm({ handleSubmit }: SetupFormProps) { +function BreezForm({ isConnecting, handleSubmit }: SetupFormProps) { const [greenlightInviteCode, setGreenlightInviteCode] = React.useState(""); + const [breezApiKey, setBreezApiKey] = React.useState(""); const [breezMnemonic, setBreezMnemonic] = React.useState(""); function onSubmit(e: React.FormEvent) { @@ -97,6 +121,7 @@ function BreezForm({ handleSubmit }: SetupFormProps) { } handleSubmit({ greenlightInviteCode, + breezApiKey, breezMnemonic, }); } @@ -118,6 +143,20 @@ function BreezForm({ handleSubmit }: SetupFormProps) { id="greenlight-invite-code" className="bg-gray-50 border border-gray-300 text-gray-900 focus:ring-purple-700 dark:focus:ring-purple-600 dark:ring-offset-gray-800 focus:ring-2 text-sm rounded-lg block w-full p-2.5 dark:bg-surface-00dp dark:border-gray-700 dark:placeholder-gray-400 dark:text-white" /> + + setBreezApiKey(e.target.value)} + value={breezApiKey} + type="password" + id="breez-api-key" + className="bg-gray-50 border border-gray-300 text-gray-900 focus:ring-purple-700 dark:focus:ring-purple-600 dark:ring-offset-gray-800 focus:ring-2 text-sm rounded-lg block w-full p-2.5 dark:bg-surface-00dp dark:border-gray-700 dark:placeholder-gray-400 dark:text-white" + />