auto-detect existing wallets, show selectable list on startup

This commit is contained in:
2026-05-17 10:51:22 +08:00
parent 23b7447b92
commit 880199f096
5 changed files with 83 additions and 8 deletions
+7
View File
@@ -623,6 +623,13 @@ const rpc = BrowserView.defineRPC<RPC>({
console.log(`[rpc] moneroGetAccounts: ${accounts.length} accounts`)
return accounts
},
moneroListWallets: async () => {
console.log('[rpc] moneroListWallets')
if (!moneroManager) throw new Error('Monero wallet RPC not started')
const wallets = moneroManager.listWallets()
console.log(`[rpc] moneroListWallets: ${wallets.join(', ') || 'none'}`)
return wallets
},
},
messages: {},
},
+13 -1
View File
@@ -1,6 +1,7 @@
import { MoneroWalletRpc, MoneroRpcConnection, connectToWalletRpc, connectToDaemonRpc } from 'monero-ts'
import { getBinaryPath, getWalletDir } from './binary'
import { existsSync } from 'fs'
import { existsSync, readdirSync } from 'fs'
import { join } from 'path'
const DEFAULT_DAEMON = 'xmr-node.cakewallet.com:18081'
@@ -18,6 +19,17 @@ export class MoneroWalletManager {
this.rpcPassword = crypto.randomUUID()
}
listWallets(): string[] {
const dir = getWalletDir()
if (!existsSync(dir)) return []
const files = readdirSync(dir)
const wallets = files
.filter(f => f.endsWith('.keys'))
.map(f => f.replace(/\.keys$/, ''))
console.log(`[monero] wallets on disk: ${wallets.join(', ') || 'none'}`)
return wallets
}
private get rpcUrl() {
return `http://127.0.0.1:${this.rpcPort}`
}