remove multiple wallets + monero auto-open + agents rules

This commit is contained in:
2026-08-01 19:12:32 +08:00
parent bd8ba8e3e5
commit 5ac8c93027
7 changed files with 114 additions and 352 deletions
+65 -158
View File
@@ -1,6 +1,5 @@
<script lang="ts">
import { moneroWallet } from '$lib/states/monero-wallet.svelte.js'
import { session } from '$lib/states/session.svelte.js'
import { Button } from '$lib/components/ui/button/index.js'
import { Textarea } from '$lib/components/ui/textarea/index.js'
import { Input } from '$lib/components/ui/input/index.js'
@@ -11,28 +10,21 @@
CardHeader,
CardTitle,
} from '$lib/components/ui/card/index.js'
import Fingerprint from '@lucide/svelte/icons/fingerprint'
import Loader from '$lib/components/loader.svelte'
import { navigate } from 'sv-router/generated'
const w = moneroWallet
let moneroWalletName = $state('')
let moneroWalletPass = $state('')
let moneroMnemonic = $state('')
let moneroRestoreHeight = $state<number | undefined>(undefined)
let moneroSelectedWallet = $state('')
let moneroSelectedWalletPass = $state('')
let moneroUseBiometric = $state(false)
let initStarted = false
$effect(() => {
if (w.walletOpen && w.walletName) {
navigate('/monero/wallet/:name', {
params: {
name: w.walletName,
},
params: { name: w.walletName },
})
}
})
@@ -46,6 +38,12 @@
})
}
})
$effect(() => {
if (w.running && !w.walletOpen && w.wallets.length > 0 && !w.loading) {
w.autoUnlock(w.wallets[0])
}
})
</script>
<div class="mx-auto max-w-xl">
@@ -101,162 +99,71 @@
</CardContent>
</Card>
{:else if !w.walletOpen}
<Card>
<CardHeader>
<CardTitle>Monero Wallet</CardTitle>
<CardDescription>
{w.wallets.length > 0
? `${w.wallets.length} wallet${w.wallets.length > 1 ? 's' : ''} found on disk`
: 'No existing wallets found'}
</CardDescription>
</CardHeader>
<CardContent>
<div class="flex flex-col gap-3">
{#if w.wallets.length > 0}
<p class="text-xs font-medium">
Select a wallet to open:
{#if w.wallets.length > 0}
<Card>
<CardContent class="flex items-center justify-center py-8">
<Loader />
<span class="ml-2 text-sm text-muted-foreground">
Opening wallet...
</span>
</CardContent>
</Card>
{:else}
<Card>
<CardHeader>
<CardTitle>Monero Wallet</CardTitle>
<CardDescription>
Create a new wallet or restore from seed
</CardDescription>
</CardHeader>
<CardContent>
<div class="flex flex-col gap-3">
<p class="text-xs text-muted-foreground">
Create a new wallet:
</p>
<div class="flex flex-wrap gap-2">
{#each w.wallets as name}
<Button
variant={moneroSelectedWallet === name
? 'default'
: 'outline'}
onclick={() => {
moneroSelectedWallet = name
moneroSelectedWalletPass = ''
}}>
{name}
</Button>
{/each}
</div>
{#if moneroSelectedWallet}
<div class="flex flex-col gap-2">
{#if session.unlocked}
<Button
onclick={() =>
w.autoUnlock(
moneroSelectedWallet,
)}
disabled={w.loading}>
{#if w.loading}
<Loader />
{/if}
Open
</Button>
{:else if w.biometricAvailable}
<Button
onclick={async () => {
const ok = await w.biometricAuth()
if (ok) {
await w.openExistingWallet(
moneroSelectedWallet,
)
}
}}
disabled={w.loading}>
<Fingerprint size={14} />
Open with Touch ID
</Button>
{/if}
<div class="flex gap-2 items-end">
<Input
type="password"
placeholder="Enter password"
bind:value={moneroSelectedWalletPass} />
<Button
onclick={() =>
w.openExistingWallet(
moneroSelectedWallet,
moneroSelectedWalletPass,
)}
disabled={w.loading ||
!moneroSelectedWalletPass}>
Open
</Button>
</div>
</div>
{/if}
<hr class="border-muted" />
{/if}
<p class="text-xs text-muted-foreground">
Or create a new wallet:
</p>
<Input
placeholder="Wallet name"
bind:value={moneroWalletName} />
{#if w.biometricAvailable}
<label
class="flex items-center gap-2 text-xs cursor-pointer">
<input
type="checkbox"
bind:checked={moneroUseBiometric} />
Save password with Touch ID
</label>
{/if}
{#if !moneroUseBiometric}
<Input
type="password"
placeholder="Password"
bind:value={moneroWalletPass} />
{/if}
<div class="flex gap-2">
placeholder="Wallet name"
bind:value={moneroWalletName} />
<Button
onclick={async () => {
const pw = moneroUseBiometric
? crypto.randomUUID()
: moneroWalletPass
await w.createWallet(
onclick={() =>
w.createWallet(
moneroWalletName,
pw,
moneroUseBiometric,
)
}}
disabled={w.loading ||
!moneroWalletName ||
(!moneroUseBiometric && !moneroWalletPass)}>
crypto.randomUUID(),
true,
)}
disabled={w.loading || !moneroWalletName}>
Create Wallet
</Button>
</div>
<hr class="border-muted" />
<p class="text-xs text-muted-foreground">
Restore from seed
</p>
<Textarea
placeholder="Enter your Monero seed phrase (16 or 25 words)"
bind:value={moneroMnemonic} />
<Input
type="number"
placeholder="Restore height (optional)"
bind:value={moneroRestoreHeight} />
{#if !moneroUseBiometric}
<hr class="border-muted" />
<p class="text-xs text-muted-foreground">
Restore from seed
</p>
<Textarea
placeholder="Enter your Monero seed phrase (16 or 25 words)"
bind:value={moneroMnemonic} />
<Input
type="password"
placeholder="Password"
bind:value={moneroWalletPass} />
{/if}
<Button
onclick={async () => {
await w.restoreWallet(
moneroWalletName,
moneroUseBiometric
? crypto.randomUUID()
: moneroWalletPass,
moneroMnemonic,
moneroRestoreHeight,
moneroUseBiometric,
)
}}
disabled={w.loading ||
!moneroWalletName ||
(!moneroUseBiometric && !moneroWalletPass) ||
!moneroMnemonic.trim()}>
Restore Wallet
</Button>
</div>
</CardContent>
</Card>
type="number"
placeholder="Restore height (optional)"
bind:value={moneroRestoreHeight} />
<Button
onclick={() =>
w.restoreWallet(
moneroWalletName,
crypto.randomUUID(),
moneroMnemonic,
moneroRestoreHeight,
true,
)}
disabled={w.loading ||
!moneroWalletName ||
!moneroMnemonic.trim()}>
Restore Wallet
</Button>
</div>
</CardContent>
</Card>
{/if}
{/if}
{/if}
</div>
</div>
</div>