From 09804cda2230dcd2023e4ab1cda91fb3c5412e43 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 8 Sep 2026 10:14:23 -0500 Subject: [PATCH] Fix wallet add/switch-network: use a clean RPC, not the WC proxy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AppKit's built-in networks advertise rpc.walletconnect.org/v1/?chainId=…&projectId=… as the chain RPC. Wallets reject that query-string URL as "Invalid URL" when adding/switching the network — Trust showed "Invalid URL", desktop MetaMask looped on Switch Network, and the mobile buy failed because the switch to Amoy never completed. Clone the chain with our clean public RPC before handing it to AppKit/Wagmi. Co-Authored-By: Claude Opus 4.8 --- public/assets/wallet.js | 10 +++++++++- public/index.html | 2 +- public/my.html | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/public/assets/wallet.js b/public/assets/wallet.js index ab982b6..4b2cafc 100644 --- a/public/assets/wallet.js +++ b/public/assets/wallet.js @@ -17,7 +17,15 @@ window.IAPWallet = (function () { const mod = await import(APPKIT_URL); const { createAppKit, WagmiAdapter, networks } = mod; const netMap = { 80002: networks.polygonAmoy, 137: networks.polygon }; - const net = netMap[Number(c.chainId)] || networks.polygonAmoy; + const base = netMap[Number(c.chainId)] || networks.polygonAmoy; + // Override the chain's RPC with our clean public endpoint. AppKit's built-in + // networks advertise the WalletConnect RPC proxy + // (rpc.walletconnect.org/v1/?chainId=…&projectId=…) as the chain RPC, and + // wallets reject that query-string URL as "Invalid URL" when adding/switching + // the network — the cause of Trust's "Invalid URL", MetaMask's switch loop, + // and the failed mobile buy (the chain switch never completed). + const rpc = String(c.rpc || '').trim(); + const net = rpc ? Object.assign({}, base, { rpcUrls: { default: { http: [rpc] }, public: { http: [rpc] } } }) : base; const projectId = String(c.walletConnectProjectId || '').trim(); const wagmiAdapter = new WagmiAdapter({ networks: [net], projectId }); modal = createAppKit({ diff --git a/public/index.html b/public/index.html index d4e9802..1368b15 100644 --- a/public/index.html +++ b/public/index.html @@ -439,7 +439,7 @@ - + diff --git a/public/my.html b/public/my.html index bd48373..2aba520 100644 --- a/public/my.html +++ b/public/my.html @@ -696,7 +696,7 @@ - +