Gas floor fix, chain guard, and dashboard footer
- wallet.js: fetch correct EIP-1559 fees from the network (Amoy/Polygon Bor enforce a ~25-30 gwei priority floor MetaMask's estimate misses) via new /api/gas; hard chain-guard before signing so a tx never lands on the wrong network; accept the wallet's usual networks in AppKit so its modal stops looping and drive add+switch ourselves. - chain.js: suggestedFees() from eth_maxPriorityFeePerGas + base fee. - Dashboard: move the Site links (Ad packages / Live ledger / The contract) out of the sidebar into a page footer; hide the sidebar scrollbar. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -227,7 +227,7 @@ textarea{resize:vertical;font:inherit}
|
||||
/* ── member back-office shell ─────────────────────────── */
|
||||
.bo-body{background:var(--ground)}
|
||||
.bo{display:grid;grid-template-columns:236px 1fr;min-height:100vh}
|
||||
.bo-side{position:sticky;top:0;height:100vh;overflow-y:auto;display:flex;flex-direction:column;gap:22px;
|
||||
.bo-side{position:sticky;top:0;height:100vh;overflow-y:auto;scrollbar-width:none;-ms-overflow-style:none;display:flex;flex-direction:column;gap:22px;
|
||||
padding:22px 16px;background:rgba(10,18,15,.92);border-right:1px solid var(--line)}
|
||||
.bo-side .logo{font-size:19px;padding:0 8px}
|
||||
.bo-menu{display:flex;flex-direction:column;gap:4px}
|
||||
@@ -243,6 +243,10 @@ textarea{resize:vertical;font:inherit}
|
||||
.bo-links a:hover{color:var(--ink);text-decoration:none}
|
||||
.bo-foot{margin-top:auto;padding:14px 12px 0;border-top:1px solid var(--line);display:flex;flex-direction:column;gap:6px;overflow-wrap:anywhere}
|
||||
.bo-main{min-width:0;display:flex;flex-direction:column}
|
||||
.bo-side::-webkit-scrollbar{width:0;height:0;display:none}
|
||||
.bo-pagefoot{margin-top:auto;padding:22px 26px;border-top:1px solid var(--line);display:flex;gap:20px;flex-wrap:wrap;justify-content:center;font-size:13px}
|
||||
.bo-pagefoot a{color:var(--muted)}
|
||||
.bo-pagefoot a:hover{color:var(--ink);text-decoration:none}
|
||||
.bo-top{display:flex;align-items:center;gap:16px;padding:16px 26px;border-bottom:1px solid var(--line);
|
||||
background:rgba(6,10,8,.75);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);position:sticky;top:0;z-index:5}
|
||||
.bo-top h2{font-size:20px}
|
||||
|
||||
+35
-4
@@ -26,10 +26,18 @@ window.IAPWallet = (function () {
|
||||
// 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;
|
||||
// Accept the wallet's usual networks too, so AppKit doesn't trap the user in
|
||||
// its own "Switch Network" modal — that modal loops on a testnet the wallet
|
||||
// can't auto-add. We switch to `net` ourselves (wallet_addEthereumChain adds
|
||||
// + switches in one step) and sendTx hard-guards the chain before signing.
|
||||
const allNets = [net];
|
||||
for (const k of ['polygon', 'mainnet']) {
|
||||
try { const n = networks[k]; if (n && n.id !== net.id) allNets.push(n); } catch (e) {}
|
||||
}
|
||||
const projectId = String(c.walletConnectProjectId || '').trim();
|
||||
const wagmiAdapter = new WagmiAdapter({ networks: [net], projectId });
|
||||
const wagmiAdapter = new WagmiAdapter({ networks: allNets, projectId });
|
||||
modal = createAppKit({
|
||||
adapters: [wagmiAdapter], networks: [net], projectId, defaultNetwork: net,
|
||||
adapters: [wagmiAdapter], networks: allNets, projectId, defaultNetwork: net,
|
||||
metadata: { name: c.siteName || 'InstantAdPay', description: c.tagline || 'Advertise and earn, paid on-chain.',
|
||||
url: location.origin, icons: [location.origin + '/logo-icon.png'] },
|
||||
features: { analytics: false, email: false, socials: [] }
|
||||
@@ -85,7 +93,9 @@ window.IAPWallet = (function () {
|
||||
try {
|
||||
await eth().request({ method: 'wallet_switchEthereumChain', params: [{ chainId: want }] });
|
||||
} catch (e) {
|
||||
if (e && e.code !== 4902) return; // don't hard-fail; AppKit/wallet usually handles the network
|
||||
// any failure (not just 4902): try to add the chain — wallet_addEthereumChain
|
||||
// adds AND switches in one step, which is what unblocks wallets that can't
|
||||
// otherwise reach a chain they don't already have (e.g. a testnet).
|
||||
const addParams = { chainId: want, chainName: c.chainName, nativeCurrency: { name: 'POL', symbol: 'POL', decimals: 18 }, rpcUrls: [c.rpc] };
|
||||
if (c.explorer && /^https?:\/\//i.test(c.explorer)) addParams.blockExplorerUrls = [c.explorer];
|
||||
try { await eth().request({ method: 'wallet_addEthereumChain', params: [addParams] }); } catch (e2) {}
|
||||
@@ -110,9 +120,30 @@ window.IAPWallet = (function () {
|
||||
async function sendTx(data, valueWei) {
|
||||
const c = await IAP.getConfig();
|
||||
const addr = await connect();
|
||||
// Hard chain guard: connect()'s switch is best-effort and some wallets (or
|
||||
// AppKit's own modal) don't complete it. Never sign on the wrong chain —
|
||||
// a value tx to a contract that doesn't exist on that chain would look like
|
||||
// it "succeeded" while doing nothing.
|
||||
const want = '0x' + Number(c.chainId).toString(16);
|
||||
let cur; try { cur = await eth().request({ method: 'eth_chainId' }); } catch (e) {}
|
||||
if (cur && cur.toLowerCase() !== want.toLowerCase()) {
|
||||
await ensureChain(c);
|
||||
try { cur = await eth().request({ method: 'eth_chainId' }); } catch (e) {}
|
||||
if (cur && cur.toLowerCase() !== want.toLowerCase())
|
||||
throw new Error('Your wallet is on the wrong network. Switch it to ' + (c.chainName || 'the correct network') + ', then try again.');
|
||||
}
|
||||
const tx = { from: addr, to: c.contract, data };
|
||||
if (valueWei) tx.value = '0x' + BigInt(valueWei).toString(16);
|
||||
// let the wallet set gas/fees (its estimate meets the chain's minimums)
|
||||
// Amoy's Bor nodes enforce a ~25 gwei minimum priority fee that MetaMask's
|
||||
// own estimate misses ("gas tip below minimum"). Pull the network's correct
|
||||
// fees from the server and set them so the tx clears the floor.
|
||||
try {
|
||||
const g = await (await fetch('/api/gas')).json();
|
||||
if (g && g.maxPriorityFeePerGas && g.maxFeePerGas) {
|
||||
tx.maxPriorityFeePerGas = g.maxPriorityFeePerGas;
|
||||
tx.maxFeePerGas = g.maxFeePerGas;
|
||||
}
|
||||
} catch (e) {}
|
||||
return eth().request({ method: 'eth_sendTransaction', params: [tx] });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user