Skip to content

Commit

Permalink
♻️ (LndState.tsx): refactor ChooseLndDir function to use LndInfo.admM…
Browse files Browse the repository at this point in the history
…acaroon path and name for OpenFileSelector options
  • Loading branch information
Gkirito committed Jan 9, 2025
1 parent f417ff8 commit 8c219e2
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions frontend/src/pages/LndState/LndState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -165,7 +164,7 @@ function LndState() {
progressRef.current = null
}
}
}, [isWalletRpcReady])
}, [isWalletRpcReady])

useEffect(() => {
if (!initState.current) {
Expand All @@ -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 (
Expand Down Expand Up @@ -264,7 +266,7 @@ function LndState() {
<Label className='w-full max-w-md'>Lnd Admin Macaroon</Label>
<div className="relative flex w-full max-w-md">
<Input className="pr-10" type="text" value={LndInfo.admMacaroon} disabled />
<Button onClick={ChooseLndDir} className="absolute right-2 top-1/2 -translate-y-1/2 h-7 w-7 p-0 flex items-center justify-center" variant="outline" size="icon"> <Folder/></Button>
<Button onClick={ChooseLndDir} className="absolute right-2 top-1/2 -translate-y-1/2 h-7 w-7 p-0 flex items-center justify-center" variant="outline" size="icon"> <Folder /></Button>
</div>
<Button variant="destructive" onClick={StopNode}>Stop</Button>
</div>
Expand Down

0 comments on commit 8c219e2

Please sign in to comment.