diff --git a/apps/desktop/src/bun/index.ts b/apps/desktop/src/bun/index.ts index 11e1201..77475d1 100644 --- a/apps/desktop/src/bun/index.ts +++ b/apps/desktop/src/bun/index.ts @@ -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 = { '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 - } - 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, diff --git a/apps/desktop/src/lib/electrobun.ts b/apps/desktop/src/lib/electrobun.ts index 7a6b6ab..be80181 100644 --- a/apps/desktop/src/lib/electrobun.ts +++ b/apps/desktop/src/lib/electrobun.ts @@ -1,278 +1,17 @@ import { Electroview } from 'electrobun/view' - -export type MoneroBalance = { - balance: string - unlocked: string - address: string - height: number - daemonHeight: number -} - -export type MoneroTxEntry = { - hash: string - amount: string - timestamp: string - direction: 'in' | 'out' - height: number - note?: string -} - -export type MoneroBinaryStatus = { - installed: boolean - downloading: boolean - error?: string -} - -export type MoneroWalletStatus = { - running: boolean - walletOpen: boolean - walletName?: string - connected: boolean -} - -export type MoneroSubaddressEntry = { - accountIndex: number - index: number - address: string - label: string - balance: string - unlockedBalance: string - numUnspentOutputs: number - isUsed: boolean - numBlocksToUnlock: number -} - -export type MoneroAccountEntry = { - index: number - primaryAddress: string - label: string - balance: string - unlockedBalance: string - tag?: string - subaddresses: MoneroSubaddressEntry[] -} - -export 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 - pairedLogo?: string -} - -export type TransactionDetails = { - 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 -} - -export type TokenBalanceResult = { - symbol: string - balance: string - contractAddress: string - logo?: string -} - -export type EvmWalletInfo = { - id: string - name: string - hasPassword: boolean - vaultKey: string - createdAt: string -} - -type RPC = { - bun: { - 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: TransactionDetails | null - } - openExternal: { - params: { - url: string - } - response: void - } - moneroBinaryStatus: { - params: {} - response: MoneroBinaryStatus - } - moneroDownloadBinary: { - params: {} - response: void - } - moneroStart: { - params: { - daemonAddress?: string - } - response: MoneroWalletStatus - } - 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: MoneroBalance - } - moneroGetTransactions: { - params: {} - response: MoneroTxEntry[] - } - moneroWalletStatus: { - params: {} - response: MoneroWalletStatus - } - moneroGetAccounts: { - params: {} - response: MoneroAccountEntry[] - } - moneroListWallets: { - params: {} - response: string[] - } - evmCreateWallet: { - params: { - name: string - phrase: string - passwordHash?: string - } - response: { id: string; name: string; createdAt: string } - } - evmListWallets: { - params: {} - response: EvmWalletInfo[] - } - evmGetSeed: { - params: { vaultKey: string } - response: string - } - evmDeleteWallet: { - params: { id: string } - response: void - } - } - messages: {} - } - webview: { - requests: {} - messages: { - transfersUpdate: { - count: number - chainid: string - address: string - } - } - } -} +import type { RPC } from './rpc-schema' +export type { + MoneroBalance, + MoneroTxEntry, + MoneroBinaryStatus, + MoneroWalletStatus, + MoneroSubaddressEntry, + MoneroAccountEntry, + TxEntry, + TransactionDetails, + TokenBalanceResult, + EvmWalletInfo, +} from './rpc-schema' const rpc = Electroview.defineRPC({ maxRequestTime: 10000, diff --git a/apps/desktop/src/lib/rpc-schema.ts b/apps/desktop/src/lib/rpc-schema.ts new file mode 100644 index 0000000..b50fb9b --- /dev/null +++ b/apps/desktop/src/lib/rpc-schema.ts @@ -0,0 +1,140 @@ +export type MoneroBalance = { + balance: string + unlocked: string + address: string + height: number + daemonHeight: number +} + +export type MoneroTxEntry = { + hash: string + amount: string + timestamp: string + direction: 'in' | 'out' + height: number + note?: string +} + +export type MoneroBinaryStatus = { + installed: boolean + downloading: boolean + error?: string +} + +export type MoneroWalletStatus = { + running: boolean + walletOpen: boolean + walletName?: string + connected: boolean +} + +export type MoneroSubaddressEntry = { + accountIndex: number + index: number + address: string + label: string + balance: string + unlockedBalance: string + numUnspentOutputs: number + isUsed: boolean + numBlocksToUnlock: number +} + +export type MoneroAccountEntry = { + index: number + primaryAddress: string + label: string + balance: string + unlockedBalance: string + tag?: string + subaddresses: MoneroSubaddressEntry[] +} + +export 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 +} + +export type TransactionDetails = { + 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 +} + +export type TokenBalanceResult = { + symbol: string + balance: string + contractAddress: string + logo?: string +} + +export type EvmWalletInfo = { + id: string + name: string + hasPassword: boolean + vaultKey: string + createdAt: string +} + +export type RPC = { + bun: { + 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: TransactionDetails | null } + openExternal: { params: { url: string }; response: void } + moneroBinaryStatus: { params: {}; response: MoneroBinaryStatus } + moneroDownloadBinary: { params: {}; response: void } + moneroStart: { params: { daemonAddress?: string }; response: MoneroWalletStatus } + 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: MoneroBalance } + moneroGetTransactions: { params: {}; response: MoneroTxEntry[] } + moneroWalletStatus: { params: {}; response: MoneroWalletStatus } + moneroGetAccounts: { params: {}; response: MoneroAccountEntry[] } + moneroListWallets: { params: {}; response: string[] } + evmCreateWallet: { params: { name: string; phrase: string; passwordHash?: string }; response: { id: string; name: string; createdAt: string } } + evmListWallets: { params: {}; response: EvmWalletInfo[] } + evmGetSeed: { params: { vaultKey: string }; response: string } + evmDeleteWallet: { params: { id: string }; response: void } + } + messages: {} + } + webview: { + requests: {} + messages: { + transfersUpdate: { count: number; chainid: string; address: string } + } + } +}