Extract shared RPC types into src/lib/rpc-schema.ts, remove duplicate type declarations

This commit is contained in:
2026-05-22 12:58:04 +08:00
parent c87e166468
commit a3e609ea8f
3 changed files with 154 additions and 499 deletions
+1 -225
View File
@@ -5,8 +5,6 @@ import {
PATHS,
Updater,
Utils,
defineElectrobunRPC,
type RPCSchema,
} from 'electrobun/bun'
import { getTokenMetadata } from './lib/tokens'
import { getTokensBalances, type Transaction } from './lib/alchemy'
@@ -40,6 +38,7 @@ import {
evmWallets,
} from './lib/db/schema'
import { syncTxDetails } from './lib/sync/sync-tx-details'
import type { RPC, TokenBalanceResult, TxEntry } from '../lib/rpc-schema'
const env = getENV()
@@ -105,230 +104,7 @@ const ALCHEMY_NETWORKS: Record<string, string> = {
'56': 'bnb-mainnet',
}
type TokenBalanceResult = {
symbol: string
balance: string
contractAddress: string
logo?: string
}
type TxDetailsResult = {
hash: string
from: string
to: string | null
value: string
blockNumber: string | null
fee: string
gasPrice: string
status: 'success' | 'reverted'
type: string
nonce: number
input: string
}
type TxEntry = {
hash: string
timeStamp: string
from: string
to: string
value: string
tokenSymbol?: string
tokenDecimal?: string
contractAddress?: string
logo?: string
pairedValue?: string
pairedSymbol?: string
pairedDecimals?: string
pairedContractAddress?: string
pairedLogo?: string
}
type RPC = {
bun: RPCSchema<{
requests: {
resetApp: {
params: {}
response: boolean
}
biometricCanAuth: {
params: {}
response: boolean
}
biometricAuth: {
params: { reason: string }
response: boolean
}
getSecret: {
params: {
service: string
name: string
}
response: string | null
}
setSecret: {
params: {
service: string
name: string
value: string
}
response: void
}
fetchTxHistory: {
params: {
address: string
chainid: string
}
response: TxEntry[]
}
fetchCachedTxHistory: {
params: {
address: string
chainid: string
}
response: TxEntry[]
}
syncTxHistory: {
params: { address: string; chainid: string }
response: void
}
flushTxCache: {
params: {}
response: void
}
setAutoSync: {
params: { address: string; chainid: string } | null
response: void
}
fetchTokenBalances: {
params: {
address: string
chainid: string
}
response: TokenBalanceResult[]
}
fetchTransactionDetails: {
params: {
hash: string
chainid: string
}
response: ReturnType<typeof getTransactionDetails>
}
openExternal: {
params: {
url: string
}
response: void
}
moneroBinaryStatus: {
params: {}
response: {
installed: boolean
downloading: boolean
error?: string
}
}
moneroDownloadBinary: {
params: {}
response: void
}
moneroStart: {
params: { daemonAddress?: string }
response: {
running: boolean
walletOpen: boolean
walletName?: string
connected: boolean
}
}
moneroStop: {
params: {}
response: void
}
moneroCreateWallet: {
params: { name: string; password: string }
response: { mnemonic: string; address: string }
}
moneroRestoreWallet: {
params: {
name: string
password: string
mnemonic: string
restoreHeight?: number
}
response: { address: string }
}
moneroOpenWallet: {
params: { name: string; password: string }
response: void
}
moneroGetBalance: {
params: {}
response: {
balance: string
unlocked: string
address: string
height: number
}
}
moneroGetTransactions: {
params: {}
response: Array<{
hash: string
amount: string
timestamp: string
direction: 'in' | 'out'
height: number
}>
}
moneroWalletStatus: {
params: {}
response: {
running: boolean
walletOpen: boolean
walletName?: string
connected: boolean
}
}
evmCreateWallet: {
params: {
name: string
phrase: string
passwordHash?: string
}
response: { id: string; name: string; createdAt: string }
}
evmListWallets: {
params: {}
response: Array<{
id: string
name: string
hasPassword: boolean
vaultKey: string
createdAt: string
}>
}
evmGetSeed: {
params: { vaultKey: string }
response: string
}
evmDeleteWallet: {
params: { id: string }
response: void
}
}
messages: {}
}>
webview: RPCSchema<{
requests: {}
messages: {
transfersUpdate: {
count: number
chainid: string
address: string
}
}
}>
}
async function fetchAlchemyTransfers(
key: string,