Add periodic auto-sync with backend push events, remove refresh button

This commit is contained in:
2026-05-22 12:53:18 +08:00
parent cb55a6fc6b
commit c87e166468
5 changed files with 93 additions and 14 deletions
@@ -367,12 +367,6 @@
{/if}
<div class="flex gap-2 flex-wrap">
<Button onclick={() => w.refresh()} disabled={w.loading}>
{#if w.loading}
<Loader />
{/if}
Refresh
</Button>
<Button
variant="outline"
onclick={() => navigate('/settings')}>
+12 -2
View File
@@ -98,7 +98,7 @@ export type EvmWalletInfo = {
}
type RPC = {
bun: {
bun: {
requests: {
resetApp: {
params: {}
@@ -149,6 +149,10 @@ type RPC = {
params: {}
response: void
}
setAutoSync: {
params: { address: string; chainid: string } | null
response: void
}
fetchTokenBalances: {
params: {
address: string
@@ -260,7 +264,13 @@ type RPC = {
}
webview: {
requests: {}
messages: {}
messages: {
transfersUpdate: {
count: number
chainid: string
address: string
}
}
}
}
@@ -111,6 +111,18 @@ export const EvmWallet = () => {
const init = async () => {
if (!electrobun.rpc) return
electrobun.rpc.addMessageListener(
'transfersUpdate',
(payload: { chainid: string; address: string; count: number }) => {
if (
payload.address === address &&
payload.chainid === net().chainid
) {
fetchTxHistory()
}
},
)
const [walletList] = await tryCatch(
electrobun.rpc.request.evmListWallets({}),
)
@@ -166,6 +178,7 @@ export const EvmWallet = () => {
transactions = []
error = ''
currentPasswordHash = null
electrobun.rpc?.request.setAutoSync(null)
}
const unlockWallet = async (walletId: string) => {
@@ -181,6 +194,7 @@ export const EvmWallet = () => {
if (!vaultSeed) return false
seed = vaultSeed
await refresh()
await setAutoSync()
return true
}
@@ -221,6 +235,7 @@ export const EvmWallet = () => {
if (!vaultSeed) return false
seed = vaultSeed
await refresh()
await setAutoSync()
return true
}
@@ -360,6 +375,14 @@ export const EvmWallet = () => {
})
}
const setAutoSync = async () => {
if (!address || !electrobun.rpc) return
electrobun.rpc.request.setAutoSync({
address,
chainid: net().chainid,
})
}
const flushTxCache = async () => {
await electrobun.rpc?.request.flushTxCache({})
await fetchTxHistory()
@@ -513,6 +536,7 @@ export const EvmWallet = () => {
deleteWallet,
clearSelection,
syncTxHistory,
setAutoSync,
flushTxCache,
}
}