From 8c219e297e1367bf835d078df05371bf313453e7 Mon Sep 17 00:00:00 2001 From: Gkirito Date: Thu, 9 Jan 2025 16:56:34 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(LndState.tsx):=20refactor?= =?UTF-8?q?=20ChooseLndDir=20function=20to=20use=20LndInfo.admMacaroon=20p?= =?UTF-8?q?ath=20and=20name=20for=20OpenFileSelector=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/LndState/LndState.tsx | 44 +++++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/frontend/src/pages/LndState/LndState.tsx b/frontend/src/pages/LndState/LndState.tsx index c5fabe4..217f635 100644 --- a/frontend/src/pages/LndState/LndState.tsx +++ b/frontend/src/pages/LndState/LndState.tsx @@ -8,8 +8,7 @@ import { GetLndRest, GetLndAdminMacaroonPath, GetLndChainInfo, - InitWallet, - GetDefaultLndDir, OpenFileSelector + OpenFileSelector } from '../../../wailsjs/go/main/App'; import { Input } from "@/components/ui/input" import { Button } from '@/components/ui/button'; @@ -165,7 +164,7 @@ function LndState() { progressRef.current = null } } - }, [isWalletRpcReady]) + }, [isWalletRpcReady]) useEffect(() => { if (!initState.current) { @@ -189,23 +188,26 @@ function LndState() { }, []) async function ChooseLndDir() { - try { - const chooseedLndDir = await OpenFileSelector(frontend.OpenDialogOptions.createFrom({ - 'DefaultDirectory': LndInfo.path, - 'DefaultFilename': 'admin', - 'Title': 'Select Lnd Data Directory', - 'ShowHiddenFiles': true, - 'CanCreateDirectories': true, - 'ResolvesAliases': true, - 'TreatPackagesAsDirectories': false, - })) - } catch (error) { - toast({ - variant: "destructive", - title: "Lnd Data File Error", - description: String(error), - }) - } + const lastSlashIndex = LndInfo.admMacaroon.lastIndexOf('/'); + const folderPath = LndInfo.admMacaroon.substring(0, lastSlashIndex); + const fileName = LndInfo.admMacaroon.substring(lastSlashIndex + 1); + await OpenFileSelector(frontend.OpenDialogOptions.createFrom({ + 'DefaultDirectory': folderPath, + 'DefaultFilename': fileName, + 'Title': 'Select Lnd Data Directory', + 'ShowHiddenFiles': true, + 'CanCreateDirectories': false, + 'ResolvesAliases': true, + 'TreatPackagesAsDirectories': false, + 'Filters': [ + frontend.FileFilter.createFrom( + { + 'DisplayName': fileName, + 'Pattern': '*.macaroon' + } + ) + ] + })) } return ( @@ -264,7 +266,7 @@ function LndState() {
- +