# checkout-ui — result Item "checkout-ui" of batch "native-repair". Starting commit 28ff85f. No live payment was made: every wallet and Intake interaction in the new tests is simulated, offline. ## Defects mended ### (1) Pay was offered beside an unresolved order for the same selection — `web/src/checkout.tsx:100-101` (original lines) - **What happened:** `canPay` ignored `saved`. A saved native order (from `nativeOrdersOf`) with the same `slipId` as the current selection left "Pay … IMD and start research" enabled, plus "Your wallet will first ask you to approve…", right next to "Open request …". `submitNativePayment` would then have reopened that order, but the page was inviting a second payment. - **What happens now:** The checkout finds saved orders whose `slipId` equals `selection.slipId`. Such an order is *unresolved* unless its request transaction's receipt is known to have reverted, sent from this wallet. That is the same rule as `reconcile()` in `native/payment.ts`, whose "retry" case is the only one where the payment code pays again. The receipt is read with the existing `publicClient.getTransactionReceipt`. A missing receipt or a read error counts as unresolved (conservative), and Pay stays disabled until the read finishes. - While an unresolved order exists: - `canPay` is false. - The approval note is hidden. - A status line shows the existing strings "An earlier order exists for this selection." and an "Open request {x}" button. The button calls the existing `openEarlier` (`reopenNativePayment`, then `onSubmitted`). - A reverted request, or an order for a different selection, does not block Pay. ### (2) Stale approval note after a wallet error or approval — `web/src/checkout.tsx:63-75` (original lines) - **What happened:** The quote, and so `quote.allowance`, was re-read only when the price changed. Here is the sequence that went wrong: 1. The customer approved. 2. The approval was mined. 3. The customer then declined the Intake request. 4. The page still said "Your wallet will first ask you to approve the quoted IMD amount." because the old quote still had allowance 0. - **What happens now:** The `finally` block of `pay()` calls `reloadQuote` while the component is mounted. That covers every outcome: any thrown error (wallet declines included) and any return, which covers every path that went through an approval. The quote effect reads the price, allowance and balances again. While it does, Pay is disabled and the existing "Verifying the Swarm price on Ethereum…" is shown. ### (3) Limit errors with numbers were never translated — `web/src/native/body.ts:92`, `:97`; `web/src/checkout.tsx:51`, `:200` (original lines) - **What happened:** `nativeJobBody` threw `RangeError`s whose text already had the numbers filled in, e.g. "Research objective exceeds 8000 characters (8997); …". The checkout stored `errText(error)` and passed it to `t()` as a key. The catalogue key has placeholders (`{OBJECTIVE_MAX}`, `{objective_length}`, `{BODY_MAX_BYTES}`, `{bytes}`), so the lookup never matched and every language showed English. - **What happens now:** - `body.ts` exports a new `NativeBodyLimitError extends RangeError` with `template` (the catalogue key) and `values` (`{ OBJECTIVE_MAX, objective_length }` or `{ BODY_MAX_BYTES, bytes }`). - Its `message` is the template with the values filled in, so the English text is exactly what it was. `name` is still "RangeError". - The checkout keeps `selection.error` as `{ key, values }`: the template and values for these errors, and `errText(error)` for every other error, as before. It renders `t(key, values)`. - Storage errors are still shown in place of the selection error, as before. - Exported names and types are unchanged (one export was added). `web/src/i18n-ui` was not touched. ## Files changed - `web/src/checkout.tsx` - `web/src/native/body.ts` - `web/tests/native-body.test.mjs`: the bundle also exports `NativeBodyLimitError` and `CHECKOUT_KEYS`. One test was added: both limit errors carry the catalogue template and values, the English message is exactly unchanged, and the filled message is not a catalogue key. - No existing assertion stated the defect, so none was changed. - `web/tests/native-checkout-ui.test.mjs` (new): renders the real `NativeCheckout` with react-dom into a minimal in-memory DOM, using React `act`. It simulates: - the wallet hook and the wallet client's `writeContract` (approve is mined; the Intake request is declined with code 4001); - the quote, submit and reopen calls of `native/payment`; - schedule liveness; - `publicClient.getTransactionReceipt`. Everything else is real: `native/orders` over a localStorage double, `orders.jobBody`, `native/body`, `i18n` and its catalogues. There are 6 tests: - (1a) A same-selection order: Pay is disabled, the approval note is hidden, the "An earlier order exists…" and "Open request" offer is shown, and opening it hands the earlier hash to `onSubmitted` with no wallet call. - (1b) An order for another selection does not block Pay, a reverted request does not block Pay, and a mined successful request blocks Pay. - (2a) Approve, then a declined Intake request: "Request declined in the wallet." is shown, the approval note goes, and Pay is enabled again. - (2b) A non-wallet error after an approval refreshes the quote. A declined approval re-reads the quote and keeps the note. - (3) The objective-limit and byte-limit errors are each rendered in all 11 `LANGS`. The test checks that: - the alert equals `tr(template, values)`; - no `{}` is left; - both numbers are present; - the text equals the English message for en and en-NG, and differs from it in every other language; - each language has a catalogue entry. - No fixture files were changed or added (`tests/fixtures/native-body/games.mjs` is reused). ## Checked before and after The new tests were run against the original sources (`git show HEAD:…`): - Original `checkout.tsx` with the new `body.ts`: native-checkout-ui failed 6 of 6. - Both originals: native-checkout-ui failed 6 of 6, and the new native-body test failed (1 of 17). - With the change: all pass. ## Commands (from `web/`, TMPDIR inside `test/scratch/`) | Command | Exit | Result | |---|---|---| | `npm ci` | 0 | installed | | `npx tsc --noEmit` (baseline) | 0 | — | | `node --test tests/*.test.mjs` (baseline) | 0 | 216 tests, 214 pass, 0 fail, 2 todo | | `node --test tests/native-checkout-ui.test.mjs` (original sources) | 1 | 6 fail | | `node --test tests/native-body.test.mjs` (original sources) | 1 | 17 tests, 16 pass, 1 fail (the new test) | | `npx tsc --noEmit` (after) | 0 | — | | `node --test tests/*.test.mjs` (after) | 0 | 223 tests, 221 pass, 0 fail, 2 todo | | `node scripts/i18n-check.mjs` (after) | 0 | "605 translatable source strings checked in 9 non-English languages. PASS every string has an entry in every language, with its placeholders kept." | ## New English sentences a customer can see None. The new offer reuses the existing catalogue strings "An earlier order exists for this selection." and "Open request {x}". The limit errors use their existing catalogue templates, and their English text is unchanged. ## Defects seen outside my files (not changed) - The existing todo test `tests/native-merged.test.mjs:235` says `native/client.ts:226-232` loses the admitted job id while `/result` is still 404, so `native/view` cannot save it. It is still a todo, and that file belongs to another item. - `native/payment.ts` exposes no read-only "is this order unresolved?" helper. So the checkout repeats `reconcile()`'s "reverted from this payer, so retry" rule with one receipt read. If `reconcile()` changes, `checkout.tsx` should follow, or better, a helper exported from `payment.ts` should be used. ## What stays unproven - Nothing was run against Ethereum, a real wallet, IMD.fun or the Intake. Payment, approval mining and receipts are simulated. - The DOM is a minimal stand-in, not a browser. Layout, focus, the dialog hook (`useDialog`, simulated) and real wallet-extension behaviour were not exercised. - The receipt check only distinguishes "reverted from this wallet" from everything else. It does not recognise a replacement transaction that `reconcile()` would find by nonce for an order that has no `replacementHash` saved yet. Such an order stays "unresolved", so Pay stays disabled and the customer can open it. - The translations themselves are the catalogue's (`web/src/i18n-ui/checkout.ts`). Their wording was not reviewed.