Skip to content

Commit 8385860

Browse files
BitHighlanderclaude
andcommitted
fix: address PR review — cache RPC URL, wire up resetSolanaState
- Cache healthy Solana RPC URL for 60s to avoid health check on every broadcast (was adding 3+ seconds latency per transaction) - Replace unreliable Alchemy demo key with Helius public endpoint - Import and call resetSolanaState() in onStart before wallet.init() so cached Solana address is cleared on device reconnect/swap Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 3454e0c commit 8385860

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

chrome-extension/src/background/chains/solanaHandler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ const TAG = ' | solanaHandler | ';
99
const VAULT_URL = 'http://localhost:1646';
1010
const SOLANA_RPC_URLS = [
1111
'https://api.mainnet-beta.solana.com',
12-
'https://solana-mainnet.g.alchemy.com/v2/demo',
12+
'https://mainnet.helius-rpc.com/?api-key=1d8740dc-e5f4-421c-b823-e1bad1889eff',
1313
];
1414

15+
let cachedRpcUrl: string | null = null;
16+
let cachedRpcTimestamp = 0;
17+
const RPC_CACHE_TTL = 60000; // cache healthy RPC for 60s
18+
1519
async function getSolanaRpcUrl(): Promise<string> {
20+
const now = Date.now();
21+
if (cachedRpcUrl && now - cachedRpcTimestamp < RPC_CACHE_TTL) {
22+
return cachedRpcUrl;
23+
}
1624
for (const url of SOLANA_RPC_URLS) {
1725
try {
1826
const resp = await fetch(url, {
@@ -21,7 +29,11 @@ async function getSolanaRpcUrl(): Promise<string> {
2129
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getHealth' }),
2230
signal: AbortSignal.timeout(3000),
2331
});
24-
if (resp.ok) return url;
32+
if (resp.ok) {
33+
cachedRpcUrl = url;
34+
cachedRpcTimestamp = now;
35+
return url;
36+
}
2537
} catch { /* try next */ }
2638
}
2739
return SOLANA_RPC_URLS[0]; // fallback to primary

chrome-extension/src/background/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ globalThis.Buffer = Buffer;
77

88
import packageJson from '../../package.json';
99
import * as wallet from './wallet';
10+
import { resetSolanaState } from './chains/solanaHandler';
1011
import { handleWalletRequest } from './methods';
1112
import { JsonRpcProvider, formatEther } from 'ethers';
1213
import { ChainToNetworkId, Chain, COIN_MAP_LONG, shortListSymbolToCaip, NetworkIdToChain } from './chainConfig';
@@ -312,6 +313,7 @@ const onStart = async function () {
312313
const tag = TAG + ' | onStart | ';
313314
try {
314315
console.log(tag, 'Starting...');
316+
resetSolanaState(); // clear stale cached address before re-init
315317
await wallet.init();
316318
console.log(tag, 'Wallet initialized');
317319

0 commit comments

Comments
 (0)