diff options
| -rw-r--r-- | src/app.js | 6 | ||||
| -rw-r--r-- | tools/offline-e2e.tmp.js | 51 |
2 files changed, 55 insertions, 2 deletions
@@ -1938,8 +1938,10 @@ function walletScreen() { return h('div', { class: 'col', style: 'gap:0' }, brandHeader(false), h('div', { class: 'mt16' }, ob)); } // Settings is a full page of its own — no balance, no tab strip; the hub's - // back button (or the logo / avatar menu) leads out. - if (ui.tab === 'settings') { + // back button (or the logo / avatar menu) leads out. Offline keeps the + // classic layout: settings is the forced tab there, and hiding the balance + // and tab strip would wall off the cached balance, history, and receive. + if (ui.tab === 'settings' && !wallet.offline) { return h( 'div', { class: 'col', style: 'gap:0' }, diff --git a/tools/offline-e2e.tmp.js b/tools/offline-e2e.tmp.js new file mode 100644 index 0000000..b917385 --- /dev/null +++ b/tools/offline-e2e.tmp.js @@ -0,0 +1,51 @@ +// Offline assessment: app loads, wallet opens, on-chain receive works, +// nothing crashes when every network call fails. +import puppeteer from 'puppeteer-core'; +import { generateMnemonic } from '@scure/bip39'; +import { wordlist } from '@scure/bip39/wordlists/english'; +import { buildHtml } from '../build.js'; +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +let ok = true; +const check = (n, c, d='') => { console.log(` ${c ? '✓' : '✗'} ${n}${d?' — '+d:''}`); if (!c) ok = false; }; +const html = await buildHtml({ minify: false, pwa: false }); +const server = Bun.serve({ port: 5199, fetch: () => new Response(html, { headers: { 'content-type': 'text/html' } }) }); +const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] }); + +// ---- scenario A: cold start fully offline (page already cached / file://) +const page = await browser.newPage(); +const errs = []; +page.on('pageerror', (e) => errs.push(e.message)); +await page.setViewport({ width: 480, height: 900 }); +await page.goto('http://localhost:5199', { waitUntil: 'domcontentloaded' }); +await sleep(300); +await page.setOfflineMode(true); +const bodyText = () => page.evaluate(() => document.body.innerText); +const waitText = async (t2, ms = 15000) => { for (let i = 0; i < ms/250; i++) { if ((await bodyText()).includes(t2)) return true; await sleep(250); } return false; }; +try { + console.log('[offline import]'); + await page.evaluate(() => [...document.querySelectorAll('button')].find(b => b.textContent.includes('Import existing'))?.click()); + await sleep(200); + await page.type('textarea', generateMnemonic(wordlist)); + await page.evaluate(() => [...document.querySelectorAll('button')].find(b => b.textContent.includes('Open wallet'))?.click()); + const opened = await waitText('Receive', 25000) || await waitText('Settings', 5000) || await waitText('offline', 5000); + check('wallet opens offline', opened, (await bodyText()).slice(0, 120).replaceAll('\n',' | ')); + await sleep(4000); + const body1 = await bodyText(); + console.log(' state:', body1.slice(0, 200).replaceAll('\n', ' | ')); + // try the receive tab + await page.evaluate(() => [...document.querySelectorAll('.tabs button')].find(b => b.textContent === 'Receive')?.click()); + await sleep(1500); + const body2 = await bodyText(); + check('on-chain address renders offline', /bc1[a-z0-9]{20,}/.test(body2)); + check('balance card present', await page.evaluate(() => !!document.querySelector('.balance'))); + // settings + advanced (offline transfer) + await page.evaluate(() => [...document.querySelectorAll('.tabs button')].find(b => b.textContent === 'Settings')?.click()); + await sleep(500); + await page.evaluate(() => [...document.querySelectorAll('.settings-nav')].find(b => b.textContent.trim() === 'Advanced')?.click()); + await sleep(500); + check('offline transfer reachable', (await bodyText()).includes('Offline transfer')); + const fatal = errs.filter((e) => !/net::|WebSocket|Failed to fetch|NetworkError|ERR_INTERNET/i.test(e)); + check('no fatal page errors', !fatal.length, fatal.slice(0, 3).join(' | ')); + console.log(' (network-shaped errors swallowed:', errs.length, ')'); +} finally { await browser.close(); server.stop(); } +process.exit(ok ? 0 : 1); |
