fix: add missing walletGetAddress import and update MoneroWalletManager -> MoneroWalletState type

This commit is contained in:
2026-05-26 03:17:10 +08:00
parent 6fe9e6306b
commit 2993df29cb
4 changed files with 155 additions and 55 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ ApplicationMenu.setApplicationMenu([
const url = await getMainViewUrl() const url = await getMainViewUrl()
const moneroState = { const moneroState = {
manager: null as MoneroWalletManager | null, manager: null as MoneroWalletState | null,
downloading: false, downloading: false,
} }
const syncState = { const syncState = {
+140 -32
View File
@@ -8,6 +8,7 @@ import {
restoreWallet as walletRestore, restoreWallet as walletRestore,
openWallet as walletOpen, openWallet as walletOpen,
getBalance as walletGetBalance, getBalance as walletGetBalance,
getAddress as walletGetAddress,
getTransactions as walletGetTransactions, getTransactions as walletGetTransactions,
getAccounts as walletGetAccounts, getAccounts as walletGetAccounts,
listWallets, listWallets,
@@ -21,10 +22,16 @@ import {
} from '../../lib/monero' } from '../../lib/monero'
import type { MoneroWalletState } from '../../lib/monero' import type { MoneroWalletState } from '../../lib/monero'
export function createMoneroHandlers(state: { manager: MoneroWalletState | null; downloading: boolean }) { export function createMoneroHandlers(state: {
manager: MoneroWalletState | null
downloading: boolean
}) {
return { return {
moneroBinaryStatus: async () => { moneroBinaryStatus: async () => {
const status = { installed: isBinaryInstalled(), downloading: state.downloading } const status = {
installed: isBinaryInstalled(),
downloading: state.downloading,
}
console.log('[rpc] moneroBinaryStatus:', status) console.log('[rpc] moneroBinaryStatus:', status)
return status return status
}, },
@@ -41,7 +48,11 @@ export function createMoneroHandlers(state: { manager: MoneroWalletState | null;
state.downloading = false state.downloading = false
} }
}, },
moneroStart: async ({ daemonAddress }: { daemonAddress?: string }) => { moneroStart: async ({
daemonAddress,
}: {
daemonAddress?: string
}) => {
console.log('[rpc] moneroStart:', { daemonAddress }) console.log('[rpc] moneroStart:', { daemonAddress })
if (!state.manager) { if (!state.manager) {
state.manager = createMoneroWalletState() state.manager = createMoneroWalletState()
@@ -63,40 +74,97 @@ export function createMoneroHandlers(state: { manager: MoneroWalletState | null;
state.manager = null state.manager = null
} }
}, },
moneroCreateWallet: async ({ name, password }: { name: string; password: string }) => { moneroCreateWallet: async ({
name,
password,
}: {
name: string
password: string
}) => {
console.log('[rpc] moneroCreateWallet:', name) console.log('[rpc] moneroCreateWallet:', name)
if (!state.manager) throw new Error('Monero wallet RPC not started') if (!state.manager)
throw new Error('Monero wallet RPC not started')
const result = await walletCreate(state.manager, name, password) const result = await walletCreate(state.manager, name, password)
console.log('[rpc] moneroCreateWallet complete') console.log('[rpc] moneroCreateWallet complete')
return result return result
}, },
moneroRestoreWallet: async ({ name, password, mnemonic, restoreHeight }: { name: string; password: string; mnemonic: string; restoreHeight?: number }) => { moneroRestoreWallet: async ({
name,
password,
mnemonic,
restoreHeight,
}: {
name: string
password: string
mnemonic: string
restoreHeight?: number
}) => {
console.log('[rpc] moneroRestoreWallet:', name) console.log('[rpc] moneroRestoreWallet:', name)
if (!state.manager) throw new Error('Monero wallet RPC not started') if (!state.manager)
await walletRestore(state.manager, name, password, mnemonic, restoreHeight) throw new Error('Monero wallet RPC not started')
await walletRestore(
state.manager,
name,
password,
mnemonic,
restoreHeight,
)
const address = await walletGetAddress(state.manager) const address = await walletGetAddress(state.manager)
console.log('[rpc] moneroRestoreWallet complete, address:', address) console.log(
'[rpc] moneroRestoreWallet complete, address:',
address,
)
return { address } return { address }
}, },
moneroOpenWallet: async ({ name, password }: { name: string; password: string }) => { moneroOpenWallet: async ({
name,
password,
}: {
name: string
password: string
}) => {
console.log('[rpc] moneroOpenWallet:', name) console.log('[rpc] moneroOpenWallet:', name)
if (!state.manager) throw new Error('Monero wallet RPC not started') if (!state.manager)
throw new Error('Monero wallet RPC not started')
await walletOpen(state.manager, name, password) await walletOpen(state.manager, name, password)
}, },
moneroGetBalance: async () => { moneroGetBalance: async () => {
console.log('[rpc] moneroGetBalance') console.log('[rpc] moneroGetBalance')
if (!state.manager) throw new Error('Monero wallet RPC not started') if (!state.manager)
const { balance, unlocked } = await walletGetBalance(state.manager) throw new Error('Monero wallet RPC not started')
const { balance, unlocked } = await walletGetBalance(
state.manager,
)
const address = await walletGetAddress(state.manager) const address = await walletGetAddress(state.manager)
const height = await walletGetHeight(state.manager) const height = await walletGetHeight(state.manager)
const daemonHeight = await walletGetDaemonHeight(state.manager) const daemonHeight = await walletGetDaemonHeight(state.manager)
console.log('[rpc] balance:', { balance: balance.toString(), unlocked: unlocked.toString(), address, height, daemonHeight }) console.log('[rpc] balance:', {
return { balance: balance.toString(), unlocked: unlocked.toString(), address, height, daemonHeight } balance: balance.toString(),
unlocked: unlocked.toString(),
address,
height,
daemonHeight,
})
return {
balance: balance.toString(),
unlocked: unlocked.toString(),
address,
height,
daemonHeight,
}
}, },
moneroGetTransactions: async ({ accountIndex }: { accountIndex?: number }) => { moneroGetTransactions: async ({
accountIndex,
}: {
accountIndex?: number
}) => {
console.log('[rpc] moneroGetTransactions', { accountIndex }) console.log('[rpc] moneroGetTransactions', { accountIndex })
if (!state.manager) throw new Error('Monero wallet RPC not started') if (!state.manager)
const txs = await walletGetTransactions(state.manager, accountIndex) throw new Error('Monero wallet RPC not started')
const txs = await walletGetTransactions(
state.manager,
accountIndex,
)
console.log(`[rpc] moneroGetTransactions: ${txs.length} txs`) console.log(`[rpc] moneroGetTransactions: ${txs.length} txs`)
return txs return txs
}, },
@@ -107,47 +175,87 @@ export function createMoneroHandlers(state: { manager: MoneroWalletState | null;
} }
const connected = await isConnected(state.manager) const connected = await isConnected(state.manager)
const walletOpen = await isWalletOpen(state.manager) const walletOpen = await isWalletOpen(state.manager)
console.log('[rpc] moneroWalletStatus: running, walletOpen:', walletOpen, 'connected:', connected) console.log(
'[rpc] moneroWalletStatus: running, walletOpen:',
walletOpen,
'connected:',
connected,
)
return { running: true, walletOpen, connected } return { running: true, walletOpen, connected }
}, },
moneroGetAccounts: async () => { moneroGetAccounts: async () => {
console.log('[rpc] moneroGetAccounts') console.log('[rpc] moneroGetAccounts')
if (!state.manager) throw new Error('Monero wallet RPC not started') if (!state.manager)
throw new Error('Monero wallet RPC not started')
const accounts = await walletGetAccounts(state.manager) const accounts = await walletGetAccounts(state.manager)
console.log(`[rpc] moneroGetAccounts: ${accounts.length} accounts`) console.log(
`[rpc] moneroGetAccounts: ${accounts.length} accounts`,
)
return accounts return accounts
}, },
moneroListWallets: async () => { moneroListWallets: async () => {
console.log('[rpc] moneroListWallets') console.log('[rpc] moneroListWallets')
if (!state.manager) throw new Error('Monero wallet RPC not started') if (!state.manager)
throw new Error('Monero wallet RPC not started')
const wallets = listWallets() const wallets = listWallets()
console.log(`[rpc] moneroListWallets: ${wallets.join(', ') || 'none'}`) console.log(
`[rpc] moneroListWallets: ${wallets.join(', ') || 'none'}`,
)
return wallets return wallets
}, },
moneroTransfer: async ({ address, amount, priority, accountIndex }: { address: string; amount: string; priority?: number; accountIndex?: number }) => { moneroTransfer: async ({
console.log('[rpc] moneroTransfer:', { address, amount, priority }) address,
if (!state.manager) throw new Error('Monero wallet RPC not started') amount,
const result = await walletTransfer(state.manager, address, BigInt(amount), priority ?? 0, accountIndex ?? 0) priority,
accountIndex,
}: {
address: string
amount: string
priority?: number
accountIndex?: number
}) => {
console.log('[rpc] moneroTransfer:', {
address,
amount,
priority,
})
if (!state.manager)
throw new Error('Monero wallet RPC not started')
const result = await walletTransfer(
state.manager,
address,
BigInt(amount),
priority ?? 0,
accountIndex ?? 0,
)
console.log('[rpc] moneroTransfer complete:', result.txHash) console.log('[rpc] moneroTransfer complete:', result.txHash)
return result return result
}, },
moneroGetTransferDetails: async ({ txid }: { txid: string }) => { moneroGetTransferDetails: async ({ txid }: { txid: string }) => {
console.log('[rpc] moneroGetTransferDetails:', txid) console.log('[rpc] moneroGetTransferDetails:', txid)
if (!state.manager) throw new Error('Monero wallet RPC not started') if (!state.manager)
const details = await walletGetTransferDetails(state.manager, txid) throw new Error('Monero wallet RPC not started')
console.log('[rpc] moneroGetTransferDetails complete:', details?.hash) const details = await walletGetTransferDetails(
state.manager,
txid,
)
console.log(
'[rpc] moneroGetTransferDetails complete:',
details?.hash,
)
return details return details
}, },
moneroGetFeeEstimate: async () => { moneroGetFeeEstimate: async () => {
console.log('[rpc] moneroGetFeeEstimate') console.log('[rpc] moneroGetFeeEstimate')
if (!state.manager) throw new Error('Monero wallet RPC not started') if (!state.manager)
throw new Error('Monero wallet RPC not started')
try { try {
const fee = await walletGetFeeEstimate(state.manager) const fee = await walletGetFeeEstimate(state.manager)
console.log('[monero][gas][fee]', fee) console.log('[monero][gas][fee]', fee)
return fee return fee
} catch (error) { } catch (error) {
console.log('[monero][gas][error]', error) console.log('[monero][gas][error]', error)
return return null
} }
}, },
} }
@@ -113,7 +113,11 @@ export const EvmWallet = () => {
electrobun.rpc.addMessageListener( electrobun.rpc.addMessageListener(
'transfersUpdate', 'transfersUpdate',
(payload: { chainid: string; address: string; count: number }) => { (payload: {
chainid: string
address: string
count: number
}) => {
if ( if (
payload.address === address && payload.address === address &&
payload.chainid === net().chainid payload.chainid === net().chainid
@@ -151,21 +155,12 @@ export const EvmWallet = () => {
ready = true ready = true
} }
const login = async (type: AccountType) => { const login = async () => {
accountType = type accountType = 'multi'
if (type === 'multi') {
if (seed) await switchNetwork(network) if (seed) await switchNetwork(network)
} else if (type === 'monero') {
if (moneroWallet.installed && !moneroWallet.running) {
await moneroWallet.start()
await moneroWallet.checkStatus()
}
await moneroWallet.listWallets()
}
} }
const logout = async () => { const logout = async () => {
await moneroWallet.stop()
accountType = null accountType = null
clearWallet() clearWallet()
} }
+4 -7
View File
@@ -10,16 +10,13 @@
CardTitle, CardTitle,
} from '$lib/components/ui/card/index.js' } from '$lib/components/ui/card/index.js'
import { navigate } from 'sv-router/generated' import { navigate } from 'sv-router/generated'
import { onMount } from 'svelte'
const w = wallet const w = wallet
let initStarted = false onMount(() => {
$effect(() => {
if (!initStarted) {
initStarted = true
w.init() w.init()
moneroWallet.init() moneroWallet.init()
}
}) })
</script> </script>
@@ -46,7 +43,7 @@
<div class="flex flex-col gap-3"> <div class="flex flex-col gap-3">
<Button <Button
onclick={async () => { onclick={async () => {
await w.login('multi') await w.login()
navigate('/multicoin') navigate('/multicoin')
}} }}
class="w-full"> class="w-full">
@@ -67,7 +64,7 @@
</Button> </Button>
<Button <Button
onclick={async () => { onclick={async () => {
await w.login('monero') await moneroWallet.login()
navigate('/monero') navigate('/monero')
}} }}
variant="outline" variant="outline"