diff --git a/webapp/README.md b/webapp/README.md index 8ca02a8a..2a1010be 100644 --- a/webapp/README.md +++ b/webapp/README.md @@ -17,7 +17,7 @@ The page talks only to the names service under `/api`. In development that servi - `dev/`: the local chain deployment, the server of its terms' texts, the mock service and `start.sh`. - `test/`: unit tests (vitest). `e2e/`: browser tests (Playwright) against the dev backend. -The window holds the header, the screen and the invest note; the footer is below the fold, as on the badges store. The purchase steps (search, Links, name code, Community terms for a community name, Check your order, payment) follow one another. Each step, and each screen like one (an order's outcome, Check your code, Edit links), is a frame of one height, 540 px on a laptop and 640 px on a phone, as the mockup draws it, so Back, the heading, the main button and the link under it stand at the same place on every step, for a name of any length; a step without a main button keeps its link at the link's place, and on a laptop a step's last link stays at least 48 px above the invest note. The content runs down from under the heading, so nothing above a change moves. The home keeps its answer's room from the start, so its headline and field never move. A plain name's order waits for its buyer to agree to the general terms on Check your order, whose words link the terms' page at the commit the name policy links; a community name's order waits for its buyer to accept its community terms, which include the general terms, on their own step, which shows their text as the service fetches it by the name policy's link and, for a link to git.simplex.chat or GitHub, links that commit's page. While the terms of a name's kind cannot be read, its search answer says that names can't be ordered right now. A community name is registered for 2 years, even with a code for more, which Check your order then says. On Check your order, I have a code, under the payment choices, opens a code field in their place: a prepaid code that covers the name makes the order free, as the tab's code does, and Remove code, under the main button, brings the payment choices back. A pay page checks its name as it opens and every 5 minutes; when someone has registered it meanwhile, its note turns red and the payment's details are turned off. A prepaid code entered in Check your code registers the names the tab finds for free until it is taken off in the header; a name code entered there finds its order and adds it to Your names, or, reached from an order's page, opens the order it found. Every screen replaces the whole page between the header and the invest note and rises into place (220 ms); the old screen goes at once, so two never show together. What a step adds, such as a search's answer, a notice or a link's profile, fades in (180 ms); a change of theme eases its colours (200 ms). A reader who asks for reduced motion gets none of it. +The window holds the header, the screen and the invest note; the footer is below the fold, as on the badges store. The purchase steps (search, Links, name code, Community terms for a community name, Check your order, payment) follow one another. Each step, and each screen like one (an order's outcome, Check your code, Edit links), is a frame of one height, 540 px on a laptop and 640 px on a phone, as the mockup draws it, so Back, the heading, the main button and the link under it stand at the same place on every step, for a name of any length; a step without a main button keeps its link at the link's place, and on a laptop a step's last link stays at least 48 px above the invest note. The content runs down from under the heading, so nothing above a change moves. The home keeps its answer's room from the start, so its headline and field never move. A plain name's order waits for its buyer to agree to the general terms on Check your order, whose words link the terms' page at the commit the name policy links; a community name's order waits for its buyer to accept its community terms, which include the general terms, on their own step, which shows their text as the service fetches it by the name policy's link and, for a link to git.simplex.chat or GitHub, links that commit's page. While the terms of a name's kind cannot be read, its search answer says that names can't be ordered right now. A community name is registered for 2 years, even with a code for more, which Check your order then says. On Check your order, I have a code, under the payment choices, opens a code field in their place: a prepaid code that covers the name makes the order free, as the tab's code does, and Remove code, under the main button, brings the payment choices back. A pay page checks its name as it opens and every 5 minutes; when someone has registered it meanwhile, its note turns red and the payment's details are turned off. A registered name's page writes a name of more than 25 letters in its Use in the app card as its first 12 letters, "..." and its last 3, so that the page fits a phone's frame; its heading keeps the whole name. On Check your order such a name is written so too, in the card, so that the review with its Dispute period row fits a laptop's frame; screen readers read the whole name in each. Check your order contains a Dispute period row: the number of days after registration during which the registration can be ended if a payment for it is disputed, reversed or refunded in full. Its hint, shown on hover, focus or tap, is the same rule in one sentence. The number is 120 for a card, and 14 for Bitcoin, Monero or a prepaid code; a name selected for a taken order has the number of the order's payment. The page signs each order's registration over these days when it places the order, and signs no registration later over more days than are allowed for its payment, and says so. The payment is taken from this browser's record of the order. Until a registered name's dispute end, its order's page says that the registration can be ended if a payment for it is disputed, reversed or refunded in full. Once the order is ended in the service's view, which the service sets at its hourly check of the chain, the order's page says so when it is next opened, as an open page stops reading a registered order, Your names marks its row Ended, and Edit links edits nothing for it. Until that check, Your names offers no Edit links for a name that the chain has unregistered, and Edit links reads it again every 5 seconds. A prepaid code entered in Check your code registers the names the tab finds for free until it is taken off in the header; a name code entered there finds its order and adds it to Your names, or, reached from an order's page, opens the order it found. Every screen replaces the whole page between the header and the invest note and rises into place (220 ms); the old screen goes at once, so two never show together. What a step adds, such as a search's answer, a notice or a link's profile, fades in (180 ms); a change of theme eases its colours (200 ms). A reader who asks for reduced motion gets none of it. ## Run everything with Docker @@ -44,12 +44,13 @@ npx playwright install chromium firefox webkit The backend needs two things outside this repo: -1. The contracts: ens-contracts at PR #47 (6ccb5c5, whose name policy links the terms of each kind), the submodule of [simplex-namespace-contract](https://github.com/brenzi/simplex-namespace-contract) at its main (e3ba0a5, PR #10), whose `test/fixtures/terms/` holds the terms' texts, compiled: +1. The contracts: ens-contracts at ebf7698 (PR #51, in which each sponsored registration has a dispute period), the submodule of [simplex-namespace-contract](https://github.com/brenzi/simplex-namespace-contract) at its main (e3ba0a5, PR #10), whose `test/fixtures/terms/` holds the terms' texts, compiled: ``` git clone https://github.com/brenzi/simplex-namespace-contract.git && cd simplex-namespace-contract git fetch origin e3ba0a50d9475dab8336b5a4026ab0fc5f79ebd4 && git checkout e3ba0a5 git submodule update --init ens-contracts && cd ens-contracts + git checkout ebf7698 npx pnpm@9 install --frozen-lockfile --ignore-scripts npx hardhat compile ``` @@ -67,6 +68,8 @@ npm run dev `MIN_COMMITMENT_AGE` is the seconds a registration waits after its commit; the contracts' deploy scripts use 60. +Each order's view in the mock contains the dispute days that the owner signs in its reveal, those of its payment: 120 for a card, 14 for Bitcoin, Monero or a prepaid code; a name selected for a taken order keeps its order's. Once the name is registered, the view's `registered` phase contains the registrar's dispute end. + Without a Stripe key the dev server shows a stand-in card form, labelled as a test, whose Pay button acts as a submitted card; the production build never has the stand-in, and shows that the card form did not load. The page reads the key from `GET /api/config`, which the mock answers with none. To see Stripe's own form in development, make the mock's answer carry a test publishable key (`pk_test_…`, from the Stripe dashboard in test mode) and keep it out of commits; the mock's client secrets are not Stripe's, so no card can be confirmed against it: that needs the service, with the account's test secret key (`sk_test_…`). ### Mock controls @@ -82,6 +85,7 @@ Tests and manual checks advance orders with `POST` requests to the mock: | `/control/overdue/` | the invoice's rate window ends now; the next request that meets it expires it, unless money reached it | | `/control/fail/` | the next commit fails | | `/control/lapse/` | a committed order not signed yet runs out of time for its reveal and fails | +| `/control/unregister/` | the contracts' owner unregisters a registered order's name in its dispute period, as the guardian or the admin does for a disputed, reversed or refunded payment: the name is available to anyone at once, and the order is `ended` from then on | | `/control/take` `{"label"}` | a rival registers the name before the waiting order, whose name is then not selected: a paid order keeps its price as its balance, and a code order keeps its code reserved, until a name is selected for the order, with a new order's checks, and paid from the balance or registered with the code; the code is accepted past its expiry until a calendar month after the take, and refused once revoked | | `/control/refund/` `{"cents"}` | support refunds the order's whole balance, the cents given or all of it, answering the refund, or why not: `no_balance` or `balance_changed` | | `/control/credit/` `{"cents"}` | the order's balance grows by the cents, as a later credit (a late payment) grows it | diff --git a/webapp/dev/Dockerfile b/webapp/dev/Dockerfile index cd79654b..0ffe24a4 100644 --- a/webapp/dev/Dockerfile +++ b/webapp/dev/Dockerfile @@ -1,10 +1,10 @@ # syntax=docker/dockerfile:1 -# The names webapp with its whole dev backend: a local chain with the PR #47 contracts and the mock names service. +# The names webapp with its whole dev backend: a local chain with the PR #51 contracts and the mock names service. # Built from the simplex.domains repository root, as compose.yaml does: the page's fonts and images live there. FROM node:24-bookworm AS contracts ARG NAMESPACE_COMMIT=e3ba0a50d9475dab8336b5a4026ab0fc5f79ebd4 -ARG ENS_CONTRACTS_COMMIT=6ccb5c52c80619493db32a4128ee5067f4274ac2 +ARG ENS_CONTRACTS_COMMIT=ebf76989ec5cab1c7dd49085b4c18faf303657d0 WORKDIR /src RUN git clone https://github.com/brenzi/simplex-namespace-contract.git . \ && git fetch origin "$NAMESPACE_COMMIT" \ diff --git a/webapp/dev/deploy.ts b/webapp/dev/deploy.ts index 5cc59c94..bf6c7d49 100644 --- a/webapp/dev/deploy.ts +++ b/webapp/dev/deploy.ts @@ -1,5 +1,5 @@ -// Deploys the .simplex contracts (ens-contracts PR #47) to a running local node for the names webapp, -// wired as the PR's test fixture wires them, and seeds names in every state search can answer. +// Deploys the .simplex contracts (ens-contracts PR #51) to a running local node for the names webapp, +// with the controller and the name policy behind their proxies and the other contracts deployed directly, and seeds names in every state search can answer. import { readFileSync, writeFileSync } from "node:fs" import { join } from "node:path" import { @@ -10,6 +10,7 @@ import { mnemonicToAccount, privateKeyToAccount } from "viem/accounts" import { foundry } from "viem/chains" import { durationFor } from "../src/crypto/registration.ts" import { BLOCK_POLL_MS, TERM_START_S, untilChainTime } from "./chain-time.ts" +import { registerNameTypedData } from "./register-name.ts" import { savedTerms } from "./serve-terms.ts" const RPC_URL = process.env.RPC_URL ?? "http://127.0.0.1:8545" @@ -30,6 +31,7 @@ const PRICE_BASE = 5000n const PRICE_EXCEPTIONS = [{ labelLength: 7n, priceCentsPerYear: 10000n }, { labelLength: 6n, priceCentsPerYear: 20000n }] // the seeded names are registered as a paid order is, for paid years from the term start const SEED_YEARS = 2 +const SEED_DISPUTE_DAYS = 120n // the registrar's credit in USD with 18 decimals, more than any number of test runs spends const ALLOWANCE = 1_000_000n * 10n ** 18n // SimplexNamePolicy.Reason.Internal @@ -118,14 +120,6 @@ await write(owner, namePolicy, "addCommunityNames", [COMMUNITY_NAMES]) const chainId = await publicClient.getChainId() const holderAccount = privateKeyToAccount(holderKey) -const REGISTER_TYPES = { - RegisterName: [ - { name: "label", type: "string" }, { name: "owner", type: "address" }, { name: "duration", type: "uint256" }, - { name: "resolver", type: "address" }, { name: "data", type: "bytes[]" }, { name: "nonce", type: "uint256" }, - { name: "deadline", type: "uint256" }, - ], -} as const - // A name registered to the holder through the sponsor, as the store's service registers names. function seedRegistration(label: string, records: Record, now: number) { const node = namehash(`${label}.${TLD}`) @@ -164,12 +158,10 @@ for (const registration of seeds) { const nonce = await publicClient.readContract({ ...sponsor, functionName: "nonces", args: [holder.address] }) as bigint const deadline = (await publicClient.getBlock()).timestamp + 3600n const signature = await holderAccount.signTypedData({ - domain: { name: "SimplexSponsor", version: "1", chainId, verifyingContract: sponsor.address }, - types: REGISTER_TYPES, - primaryType: "RegisterName", - message: { ...registration, nonce, deadline }, + ...registerNameTypedData(chainId, sponsor.address), + message: { ...registration, disputeDays: SEED_DISPUTE_DAYS, nonce, deadline }, }) - await write(registrar, sponsor, "registerWithCredit", [registration, nonce, deadline, signature]) + await write(registrar, sponsor, "registerWithCredit", [registration, SEED_DISPUTE_DAYS, nonce, deadline, signature]) } const deployment = { diff --git a/webapp/dev/mock.ts b/webapp/dev/mock.ts index 8035f309..95602116 100644 --- a/webapp/dev/mock.ts +++ b/webapp/dev/mock.ts @@ -3,7 +3,7 @@ import { createServer, type IncomingMessage, type ServerResponse } from "node:ht import { isIP } from "node:net" import { takeCodeToken } from "./mock/limits.ts" import { - cancelInvoice, checkCode, controlClock, controlCommunity, controlCommunityTerms, controlCredit, controlEdits, controlGeneralTerms, controlInvoice, controlLate, controlMode, controlRate, controlRefund, controlRegistration, controlSearch, controlSeed, controlTake, createInvoice, currentTerms, dump, editRecords, find, findLimited, + cancelInvoice, checkCode, controlClock, controlCommunity, controlCommunityTerms, controlCredit, controlEdits, controlGeneralTerms, controlInvoice, controlLate, controlMode, controlRate, controlRefund, controlRegistration, controlSearch, controlSeed, controlTake, controlUnregister, createInvoice, currentTerms, dump, editRecords, find, findLimited, HttpError, issueCode, modeNow, oneOrderAtATime, setCodeState, previewLink, readInvoice, readRegistration, registerWithCode, retry, reveal, search, selectName, signFor, siteConfig, } from "./mock/service.ts" @@ -49,6 +49,7 @@ const routes: [string, RegExp, Handler, Limit?][] = [ ["POST", /^\/api\/registration\/([^/]+)\/retry$/, (m) => retry(m[1])], ["POST", /^\/control\/(settle|partial|confirming|expire|overdue)\/([^/]+)$/, (m, b) => controlInvoice(m[1], m[2], b)], ["POST", /^\/control\/(fail|stale|unread|lapse)\/([^/]+)$/, (m) => controlRegistration(m[1], m[2])], + ["POST", /^\/control\/unregister\/([^/]+)$/, (m) => controlUnregister(m[1])], ["POST", /^\/control\/late\/([^/]+)$/, (m, b) => controlLate(m[1], b.waiting ?? null)], ["POST", /^\/control\/credit\/([^/]+)$/, (m, b) => controlCredit(m[1], b.cents)], ["POST", /^\/control\/take$/, (_, b) => controlTake(b.label)], diff --git a/webapp/dev/mock/service.ts b/webapp/dev/mock/service.ts index 4d32caf3..adc71e71 100644 --- a/webapp/dev/mock/service.ts +++ b/webapp/dev/mock/service.ts @@ -15,6 +15,7 @@ import { baseRegistrar, chainNow, contractsOwner, controller, deployment, holder, mined, moveChainTo, namePolicy, NotSent, ownerOf, read, registry, resolver, Reverted, send, sponsor, } from "./chain.ts" import { TERM_START_S, untilChainTime } from "../chain-time.ts" +import { registerNameTypedData } from "../register-name.ts" import { savedTerms } from "../serve-terms.ts" import { addressFor } from "./addresses.ts" import { setClock } from "./clock.ts" @@ -68,7 +69,7 @@ const SIGN_AGAIN = ["InvalidNonce", "TermsNotAccepted", "TermsMismatch"] const COMMUNITY_TEXT_MAX = 200 const SECP256K1_HALF_N = 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0n -export type Phase = "unpaid" | "queued" | "committing" | "committed" | "registering" | "registered" | "taken" | "failed" +export type Phase = "unpaid" | "queued" | "committing" | "committed" | "registering" | "registered" | "ended" | "taken" | "failed" type Method = "card" | "btc" | "xmr" type Coin = Exclude const isMethod = (v: unknown): v is Method => v === "card" || v === "btc" || v === "xmr" @@ -113,6 +114,8 @@ interface Registration { terms: string paidAt: number | null takenAt: number | null + disputeDays: number + disputeUntil: number | null } interface Invoice { @@ -480,7 +483,7 @@ async function phaseView(reg: Registration): Promise> { case "unpaid": return closedBy ? { type: "closed", closedBy } : { type: "unpaid" } case "committed": return { type: "committed", revealAfter: reg.revealAfter, revealBefore: reg.revealBefore, signature: reg.label !== null ? { type: "signed" } : lapsed(reg) ? { type: "lapsed" } : { type: "awaiting", toSign: await toSignOf(reg) } } - case "registered": return { type: "registered", expiresAt: reg.expiresAt } + case "registered": return { type: "registered", expiresAt: reg.expiresAt, ...reg.disputeUntil === null ? {} : { disputeUntil: reg.disputeUntil } } case "failed": return { type: "failed", reason: reg.error, ...reg.error !== "monthEnded" && reg.paidAt !== null ? { heldUntil: iso(monthAfter(reg.paidAt)) } : {} } default: return { type: reg.phase } } @@ -495,7 +498,7 @@ async function registrationView(reg: Registration): Promise): Pr const freshTimestamp = (timestamp: unknown) => { if (Math.abs(nowSeconds() - (timestamp as number)) > SIGNED_REQUEST_SECONDS) throw badRequest() } -// A registration is live while its invoice is open, or once paid until it is taken. -// a registered order is not live either, so its wallet can order the name again once it lapses function live(reg: Registration): boolean { if (reg.phase === "unpaid") return reg.invoiceId !== null && invoices.get(reg.invoiceId)!.status === "open" - return reg.phase !== "taken" && reg.phase !== "registered" + return reg.phase !== "taken" && reg.phase !== "registered" && reg.phase !== "ended" } // The answer to an exact resend, or nothing; an overdue order of the same wallet and name with nothing received is closed @@ -715,7 +716,7 @@ export async function createInvoice(body: Record): Promise +const DISPUTE_DAYS: Record = { card: 120, btc: 14, xmr: 14, code: 14 } + function newRegistration(order: OrderBody, extra: NewRegistration, rv: Reveal): Registration { const reg: Registration = { id: id(), invoiceId: null, ...order, ...extra, ...rv, commitTx: null, registerTx: null, revealAfter: null, revealBefore: null, expiresAt: null, error: null, createdAt: iso(nowSeconds()), failNext: false, staleNext: false, resends: 0, version: 1, - paidAt: extra.phase === "queued" ? nowSeconds() : null, takenAt: null, + paidAt: extra.phase === "queued" ? nowSeconds() : null, takenAt: null, disputeDays: DISPUTE_DAYS[extra.method], disputeUntil: null, } registrations.set(reg.id, reg) return reg @@ -817,7 +820,7 @@ export async function registerWithCode(body: Record): Promise { if (!(e instanceof Reverted) || await accepted() !== acceptance.termsHash) throw e }) } - reg.registerTx = await sendTx(sponsor, "registerWithCredit", [registrationTuple(reg), nonce, deadline, signature], sending) + reg.registerTx = await sendTx(sponsor, "registerWithCredit", [registrationTuple(reg), BigInt(reg.disputeDays), nonce, deadline, signature], sending) } catch (e) { if (e instanceof NotSent) throw e // a register with no answer may still be mined, so the order waits for the chain; a relay with no answer fails the order @@ -1009,6 +1012,8 @@ async function registered(reg: Registration): Promise { for (let i = 0; ; i++) { try { reg.expiresAt = Number(await read(baseRegistrar, "nameExpires", [BigInt(reg.labelHash)])) + const disputeUntil = await read(baseRegistrar, "disputeUntil", [BigInt(reg.labelHash)]) + reg.disputeUntil = disputeUntil === 0n ? null : Number(disputeUntil) break } catch (e) { if (i + 1 >= EXPIRY_READS) throw e @@ -1051,7 +1056,7 @@ function linksOf(records: unknown): RevealLinks { const refusedLink = (records: RevealLinks): LinkKind | null => (["contact", "channel"] as const).find((kind) => { const link = records[kind]; return link !== null && (linkProblem(kind, link) !== null || deepLinkOf(link) === null) }) ?? null -type Ordered = Pick +type Ordered = Pick type Reveal = { label: string; secret: Hex; records: RevealLinks; intent: NonNullable; acceptance: NonNullable } // A reveal includes the owner's signature of the acceptance its view returns, of the terms of the name's kind on chain now. @@ -1084,15 +1089,8 @@ async function checkReveal(o: Ordered, body: Record, earliest: if ((await read(controller, "makeCommitment", [tuple]).catch(unread)) !== o.commitment) throw badRequest() if (deadline < earliest || deadline > nowSeconds() + SIGNATURE_SECONDS + SIGNED_REQUEST_SECONDS) throw badRequest() const signer = await recoverTypedDataAddress({ - domain: { name: "SimplexSponsor", version: "1", chainId: deployment.chainId, verifyingContract: deployment.sponsor }, - types: { - RegisterName: [ - { name: "label", type: "string" }, { name: "owner", type: "address" }, { name: "duration", type: "uint256" }, - { name: "resolver", type: "address" }, { name: "data", type: "bytes[]" }, { name: "nonce", type: "uint256" }, { name: "deadline", type: "uint256" }, - ], - }, - primaryType: "RegisterName", - message: { label, owner: o.owner, duration: tuple.duration, resolver: deployment.resolver, data: tuple.data, nonce: BigInt(nonce), deadline: BigInt(deadline) }, + ...registerNameTypedData(deployment.chainId, deployment.sponsor), + message: { label, owner: o.owner, duration: tuple.duration, resolver: deployment.resolver, data: tuple.data, disputeDays: BigInt(o.disputeDays), nonce: BigInt(nonce), deadline: BigInt(deadline) }, signature, }) if (signer !== o.owner) throw badRequest() @@ -1165,7 +1163,7 @@ export async function selectName(registrationId: string, body: Record> { + const reg = registrations.get(registrationId) + if (!reg) throw new HttpError(404, "not_found") + if (reg.phase !== "registered" || reg.disputeUntil === null) throw badRequest() + await send(controller, "unregister", [reg.label, BigInt(reg.disputeUntil)], undefined, contractsOwner) + reg.phase = "ended" + reg.expiresAt = null + reg.disputeUntil = null + changed(reg) + return { ok: true } +} + // A refund support records, by the order's invoice id or registration id, of the whole balance: the cents given, else all of it. export function controlRefund(reference: string, cents: unknown): Record { const reg = registrations.get(reference) ?? registrations.get(invoices.get(reference)?.registrationId ?? "") @@ -1517,16 +1527,9 @@ let holderTurn: Promise = Promise.resolve() async function registerForHolder(tuple: { label: string; owner: Address; duration: bigint; secret: Hex; resolver: Address; data: Hex[]; reverseRecord: number; referrer: Hex }): Promise { const nonce = await read(sponsor, "nonces", [holder.address]) const deadline = BigInt(nowSeconds() + 3600) - const signature = await holder.signTypedData({ - domain: { name: "SimplexSponsor", version: "1", chainId: deployment.chainId, verifyingContract: deployment.sponsor }, - types: { RegisterName: [ - { name: "label", type: "string" }, { name: "owner", type: "address" }, { name: "duration", type: "uint256" }, - { name: "resolver", type: "address" }, { name: "data", type: "bytes[]" }, { name: "nonce", type: "uint256" }, { name: "deadline", type: "uint256" }, - ] }, - primaryType: "RegisterName", - message: { ...tuple, nonce, deadline }, - }) - await send(sponsor, "registerWithCredit", [tuple, nonce, deadline, signature]) + const disputeDays = BigInt(DISPUTE_DAYS.card) + const signature = await holder.signTypedData({ ...registerNameTypedData(deployment.chainId, deployment.sponsor), message: { ...tuple, disputeDays, nonce, deadline } }) + await send(sponsor, "registerWithCredit", [tuple, disputeDays, nonce, deadline, signature]) } export function controlSearch(body: Record): Record { diff --git a/webapp/dev/register-name.ts b/webapp/dev/register-name.ts new file mode 100644 index 00000000..9d678950 --- /dev/null +++ b/webapp/dev/register-name.ts @@ -0,0 +1,13 @@ +import type { Address } from "viem" + +export const registerNameTypedData = (chainId: number, sponsor: Address) => ({ + domain: { name: "SimplexSponsor", version: "1", chainId, verifyingContract: sponsor }, + types: { + RegisterName: [ + { name: "label", type: "string" }, { name: "owner", type: "address" }, { name: "duration", type: "uint256" }, + { name: "resolver", type: "address" }, { name: "data", type: "bytes[]" }, { name: "disputeDays", type: "uint256" }, { name: "nonce", type: "uint256" }, + { name: "deadline", type: "uint256" }, + ], + }, + primaryType: "RegisterName", +} as const) diff --git a/webapp/dev/start.sh b/webapp/dev/start.sh index 30ad39e6..2115a1ea 100755 --- a/webapp/dev/start.sh +++ b/webapp/dev/start.sh @@ -1,8 +1,8 @@ #!/bin/bash -# Starts the local backend for the names webapp: a chain with the PR #47 contracts, the server of their terms' texts on +# Starts the local backend for the names webapp: a chain with the PR #51 contracts, the server of their terms' texts on # 127.0.0.1:8098 and the mock names service. Then run `npm run dev` for the page. Ctrl-C stops everything. # -# ENS_CONTRACTS_DIR the compiled ens-contracts submodule (PR #47) of a simplex-namespace-contract checkout, whose +# ENS_CONTRACTS_DIR the compiled ens-contracts submodule (PR #51) of a simplex-namespace-contract checkout, whose # test/fixtures/terms/ the chain links as its terms # TERMS_HOST the address the terms' texts are served on (default: 127.0.0.1) # ANVIL Foundry's anvil (default: anvil) diff --git a/webapp/e2e/codes-only.spec.ts b/webapp/e2e/codes-only.spec.ts index 04310c86..a5866f3f 100644 --- a/webapp/e2e/codes-only.spec.ts +++ b/webapp/e2e/codes-only.spec.ts @@ -2,7 +2,7 @@ import { type APIRequestContext, expect, type Page } from "@playwright/test" import { labelHash } from "../src/crypto/registration.ts" import { hex } from "../src/crypto/wallet.ts" import { - AGREE, agreeToTerms, CHECKOUT_KEY, codeField, control, MOCK, onStep, payButton, recordedFrames, recordFrames, savedToReview, search, shot, startOrder, takenOrder, test, toCodeStep, toFullReview, toReview, + AGREE, agreeToTerms, CHECKOUT_KEY, codeField, control, keepOrder, MOCK, onStep, payButton, recordedFrames, recordFrames, registrationView, savedToReview, search, shot, startOrder, takenOrder, test, toCodeStep, toFullReview, toReview, uniqueLabel, useCode, waitRegistered, } from "./helpers.ts" @@ -199,6 +199,7 @@ test("a valid prepaid code opens the search for the names it covers and register await shot(page, "C4-codes-only-covered") await toReview(page) await expect(page.locator(".card.order .trow.total")).toHaveText("Free SimpleX name") + await expect(onStep(page).locator(".card.order .trow", { hasText: "Dispute period" }).getByRole("button")).toHaveText("14 days") await noPaymentUi(page) await expect(onStep(page).getByText("I have a code")).toHaveCount(0) await expect(onStep(page).getByText("Remove code")).toHaveCount(0) @@ -264,6 +265,18 @@ test("an order paid before codes only shows no new invoice or other name, only R await shot(page, "C8-codes-only-names") }) +test("a registration ended in its dispute period offers only Register with code, as the other endings do", async ({ page, request }) => { + await setMode(request, "codes") + const label = uniqueLabel("endc") + const order = await keepOrder(page, `reg-${label}`, null, label) + await page.route(`**/api/registration/${order.registrationId}*`, (route) => route.fulfill({ json: registrationView(order, { phase: { type: "ended" }, commitTx: "0x02", registerTx: "0x03" }) })) + await page.goto(`/?registration=${order.registrationId}`) + await expect(onStep(page).getByRole("heading", { name: "Registration ended" })).toBeVisible() + await expect(onStep(page).getByRole("button", { name: "Search a name" })).toHaveCount(0) + await onStep(page).getByRole("button", { name: REGISTER_WITH_CODE }).click() + await expect(onStep(page).getByRole("heading", { name: "Check your code" })).toBeVisible() +}) + test("a page opened before codes only, refused as it pays, says registration is by code and leads to a code", async ({ page, request }) => { await search(page, uniqueLabel("stale")) await toCodeStep(page) diff --git a/webapp/e2e/codes.spec.ts b/webapp/e2e/codes.spec.ts index f6e05d28..2b14b53b 100644 --- a/webapp/e2e/codes.spec.ts +++ b/webapp/e2e/codes.spec.ts @@ -8,7 +8,7 @@ import { walletOf } from "../src/flow.ts" import { dateOf } from "../src/format.ts" import { agreeToTerms, answersReserved, blockTimeOf, chainExpiry, channelLink, CHECKOUT_KEY, checkoutOwnerCode, CODE_HEADING, codeField, contactLink, control, fakeRegisteredName, fillLinks, FIT_SIZES, keepOrder, LINKS_HEADING, MOCK, offCentre, onStep, - payButton, previewsShown, qrText, registrationView, savedToReview, search, searchName, selectedToReview, sevenLetters, shot, shownCode, SLOW_FETCH_MS, startOrder, takenHeading, test, textChangesOf, toCodeStep, restoreOrder, toReview, uniqueLabel, + payButton, previewsShown, qrText, registeredPhase, registrationView, savedToReview, search, searchName, selectedToReview, sevenLetters, shot, shownCode, SLOW_FETCH_MS, startOrder, takenHeading, test, textChangesOf, toCodeStep, restoreOrder, toReview, uniqueLabel, useCode, waitRegistered, acceptedOnChain, COMMUNITY_TERMS_HASH, contractsOwnerLists, GENERAL_TERMS_HASH, } from "./helpers.ts" @@ -101,7 +101,7 @@ test("a prepaid code from Check your code shows a name as Free and registers it await toReview(page) await expect(total(page)).toHaveText(FREE_TOTAL) // no row nor note words the code as a payment - await expect(page.locator(".card.order .trow")).toHaveText([/^Term5 years and (\d{2,} days|1 day)Early adopter bonus: your 5 years start on 1\u00a0January 2027\.$/, /^Registered until/, FREE_TOTAL]) + await expect(page.locator(".card.order .trow")).toHaveText([/^Term5 years and (\d{2,} days|1 day)Early adopter bonus: your 5 years start on 1\u00a0January 2027\.$/, /^Registered until/, /^Dispute period14 days/, FREE_TOTAL]) await expect(onStep(page).locator(".notes")).toHaveCount(0) await expect(page.getByRole("radio")).toHaveCount(0) await shot(page, "K3-checkout-covered") @@ -114,12 +114,14 @@ test("a prepaid code from Check your code shows a name as Free and registers it await waitRegistered(page, label) const registered = await searchName(request, label) expect(registered.type).toBe("registered") - await expect(page.locator("body > main .lead")).toHaveText(`Registered until ${dateOf(registered.expiresAt as number)}.`) + const view = await (await request.get(`${MOCK}/api/registration/${new URL(page.url()).searchParams.get("registration")}`)).json() as + { years: number; duration: number; registerTx: string; disputeDays: number; phase: { disputeUntil: number } } + await expect(page.locator("body > main .lead")).toHaveText(`Registered until ${dateOf(registered.expiresAt as number)}. It can be ended until ${dateOf(view.phase.disputeUntil)} if a payment for it is disputed, reversed or refunded in full.`) // the code's term, its 5 years and the free days, sent as the duration, counted on chain from the register's block - const view = await (await request.get(`${MOCK}/api/registration/${new URL(page.url()).searchParams.get("registration")}`)).json() as { years: number; duration: number; registerTx: string } expect(view.years).toBe(5) expect(await chainExpiry(label)).toBe(await blockTimeOf(view.registerTx) + view.duration) expect(registered.expiresAt).toBe(await chainExpiry(label)) + expect(view.phase.disputeUntil, "the dispute days signed in the reveal, counted on chain from the register's block").toBe(await blockTimeOf(view.registerTx) + view.disputeDays * 86400) await shot(page, "K8-registered-with-code") await page.goto("/#/names") const row = page.locator(".list-row", { hasText: `${label}.simplex` }) @@ -148,6 +150,51 @@ test("a prepaid code from Check your code shows a name as Free and registers it await shot(page, "K5-code-used") }) +test("a registration ended in its dispute period says so on its order's page, is marked Ended in Your names, has no links to edit, and leaves the name available", async ({ page, request }) => { + const { registrationId, label } = await registerWithCode(page, request, "ended") + await waitRegistered(page, label) + await control(request, `unregister/${registrationId}`) + expect((await (await request.get(`${MOCK}/api/registration/${registrationId}`)).json()).phase, "the view the service gives an ended order").toEqual({ type: "ended" }) + await page.reload() + await expect(onStep(page).getByRole("heading", { name: "Registration ended" })).toBeVisible() + await expect(onStep(page).locator(".notice")).toHaveText(`The registration of ${label}.simplex was ended because a payment for it was disputed, reversed or refunded in full.`) + expect((await searchName(request, label)).type).toBe("available") + await page.goto("/#/names") + const row = page.locator(".list-row", { hasText: `${label}.simplex` }) + await expect(row.locator(".chip")).toHaveText("Ended") + await expect(row.getByRole("button", { name: /links$/ })).toHaveCount(0) + await page.goto(`/#/edit/${registrationId}`) + await expect(onStep(page).getByText("The registration was ended")).toBeVisible() + await expect(onStep(page).getByRole("button", { name: "Save links" })).toHaveCount(0) +}) + +test("a registered name's page takes its dispute end away as it passes, and is drawn once while that end is further off than a timer's longest delay", async ({ page }) => { + const label = uniqueLabel("until") + const order = await keepOrder(page, `reg-${label}`, null, label) + const now = Math.floor(Date.now() / 1000) + const expiresAt = now + YEAR_S + let disputeUntil = now + 10 + await page.route(`**/api/registration/${order.registrationId}*`, (route) => route.fulfill({ json: registrationView(order, { phase: registeredPhase(expiresAt, disputeUntil), commitTx: "0x02", registerTx: "0x03" }) })) + const lead = page.locator("body > main .lead") + const disputed = () => `Registered until ${dateOf(expiresAt)}. It can be ended until ${dateOf(disputeUntil)} if a payment for it is disputed, reversed or refunded in full.` + await page.goto(`/?registration=${order.registrationId}`) + await expect(lead).toHaveText(disputed()) + await expect(lead, "the lead once the dispute end has passed").toHaveText(`Registered until ${dateOf(expiresAt)}.`, { timeout: 20_000 }) + disputeUntil = now + 30 * 86400 + await page.reload() + await expect(lead).toHaveText(disputed()) + const draws = await page.evaluate(() => new Promise((done) => { + let count = 0 + const watch = new MutationObserver(() => { count++ }) + watch.observe(document.querySelector("body > main")!, { childList: true }) + setTimeout(() => { + watch.disconnect() + done(count) + }, 2000) + })) + expect(draws, "the screens drawn in two seconds after the first").toBe(0) +}) + // These cases need a prepaid code alone, from /control/code, so they run against the service as well as the mock. test("a prepaid code registers a name with its links, which its records on chain then hold, its register recording the owner's acceptance of the general terms", async ({ page, request }) => { const links = { contact: contactLink("CL"), channel: channelLink("CL") } diff --git a/webapp/e2e/community.spec.ts b/webapp/e2e/community.spec.ts index d904580f..bb174df8 100644 --- a/webapp/e2e/community.spec.ts +++ b/webapp/e2e/community.spec.ts @@ -514,6 +514,11 @@ test("the marker stands where the mockup draws it on Check your order", async ({ // the order's name is drawn smaller on a phone's review that holds a line under the order await expectMarkerPlaces(page, "review", label, onStep(page).locator(".order .row .name"), false) } + await expect(onStep(page).locator(".order > .row .name"), "the name drawn abbreviated").toContainText(`${long.slice(0, 12)}...${long.slice(-3)}.simplex`) + const read = await onStep(page).locator(".order > .row").ariaSnapshot() + expect(read.split(`${long}.simplex`).length - 1, `the whole name read once: ${read}`).toBe(1) + expect(read, "the abbreviation not read").not.toContain("...") + expect(read, "the marker reachable").toContain(MARKER) }) }) diff --git a/webapp/e2e/contract.spec.ts b/webapp/e2e/contract.spec.ts index 2d7422b2..a684943b 100644 --- a/webapp/e2e/contract.spec.ts +++ b/webapp/e2e/contract.spec.ts @@ -56,16 +56,16 @@ async function quote(label: string): Promise { return q! } -async function draftOf(label: string, links = { contact: "", channel: "" }): Promise { +async function draftOf(label: string, links = { contact: "", channel: "" }, disputeDays = api.DISPUTE_DAYS.btc): Promise { const q = await quote(label) - return { label, links, chain: flow.chainOf(readSite()), years: q.years, termStart: readSite().termStart, ownerCode: flow.newOwnerCode(), terms: api.currentTerms(q) } + return { label, links, chain: flow.chainOf(readSite()), years: q.years, termStart: readSite().termStart, ownerCode: flow.newOwnerCode(), terms: api.currentTerms(q), disputeDays } } // a name selected for the order, under the terms the service has for that name now or `terms` async function selectionOf(record: store.OrderRecord, to: string, terms?: string): Promise { const q = await quote(to) const draft: flow.Draft = { label: to, links: NO_LINKS, chain: flow.chainOf(readSite()), years: api.termYears(q.community, record.years), termStart: readSite().termStart, ownerCode: record.ownerCode, - terms: terms ?? api.currentTerms(q) } + terms: terms ?? api.currentTerms(q), disputeDays: api.DISPUTE_DAYS[record.method] } return flow.selectName(record, draft, await flow.orderRequest(draft)) } @@ -278,7 +278,7 @@ test("a cancelled or expired order gives way to a new one of the same wallet, an await control(request, `settle/${second.json.invoiceId}`) const late = await call("GET", `/api/invoice/${second.json.invoiceId}`) expect([late.json.status, late.json.paidInFull, (late.json.registration as Json).phase]).toEqual(["expired", true, { type: "closed", closedBy: "expired" }]) - expect((await call("POST", "/api/invoice", invoiceBody((await flow.orderRequest(draft)).request, "card", q.price))).status).toBe(200) + expect((await call("POST", "/api/invoice", invoiceBody((await flow.orderRequest({ ...draft, disputeDays: api.DISPUTE_DAYS.card })).request, "card", q.price))).status).toBe(200) }) // an invoice's status as the mock holds it, which a read of the invoice would mark expired once due @@ -466,7 +466,7 @@ test("a name selected for a code order taken first is one its code allows, its c const label = uniqueLabel("cc") const { id, code, view: taken } = await takenCode(request, label, 10) expect(Object.keys(taken).sort(), "the fields of the service's view of a taken code order (registration-taken-code.json)").toEqual([ - "balance", "commitTx", "commitment", "community", "duration", "id", "label", "labelHash", "latePayment", "owner", "payment", "phase", "price", + "balance", "commitTx", "commitment", "community", "disputeDays", "duration", "id", "label", "labelHash", "latePayment", "owner", "payment", "phase", "price", "registerTx", "sealed", "terms", "version", "years", ]) expect([taken.phase, taken.payment, taken.balance, taken.price, taken.label], "a code order has no balance").toEqual([{ type: "taken" }, { type: "code" }, null, 0, label]) @@ -492,7 +492,7 @@ async function nameBody(record: store.OrderRecord, view: api.RegistrationView, t const sealedHash = hex(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(view.sealed)))) const length = record.label.length const message = `simplex.domains name ${view.id} ${view.labelHash} ${length} ${view.duration} ${view.commitment} ${sealedHash} ${terms} ${timestamp}` - const reveal = await flow.revealFor(record, view.duration, await api.signFor(view.labelHash, view.owner)) + const reveal = await flow.revealFor(record, view, await api.signFor(view.labelHash, view.owner)) return { ...api.signedFields({ labelHash: view.labelHash, length, duration: view.duration, commitment: view.commitment, sealed: view.sealed, terms, timestamp, signature: hex(signDigest(flow.walletOf(record.ownerCode)!.privateKey, personalDigest(message))) }), reveal } as unknown as Json } @@ -623,7 +623,7 @@ type Paying = { draft: flow.Draft; record: store.OrderRecord; id: string; invoic // An order of a new code whose invoice closed with nothing received, then got its money: a closed order holding a balance of its price. async function lateBalance(request: APIRequestContext, label = uniqueLabel("lb"), method: api.Method = "btc"): Promise { - const draft = await draftOf(label) + const draft = await draftOf(label, undefined, api.DISPUTE_DAYS[method]) const built = await flow.orderRequest(draft) const { price } = await quote(label) const opened = await call("POST", "/api/invoice", invoiceBody(built.request, method, price)) @@ -669,7 +669,7 @@ test("a late payment is credited once settled, each confirmed figure once, at th // an order whose invoice closed with nothing received const closed = async (method: api.Method) => { const label = uniqueLabel("lp") - const res = await call("POST", "/api/invoice", invoiceBody((await flow.orderRequest(await draftOf(label))).request, method, (await quote(label)).price)) + const res = await call("POST", "/api/invoice", invoiceBody((await flow.orderRequest(await draftOf(label, undefined, api.DISPUTE_DAYS[method]))).request, method, (await quote(label)).price)) await control(request, `expire/${res.json.invoiceId}`) return { invoiceId: res.json.invoiceId as string, id: (res.json.registration as Json).id as string, cryptoAmount: res.json.cryptoAmount } } @@ -963,6 +963,15 @@ test("a plain name's committed view asks for the owner's acceptance of the gener expect(await acceptedOnChain(done.registerTx!)).toEqual({ kind: "general", name: label, holder: record.owner, termsHash: GENERAL_TERMS_HASH }) }) +test("a code order whose reveal is signed over other dispute days than a code's is bad_request, and one over a code's registers the name with them", async ({ request }) => { + const { code } = await control(request, "code", { minLength: 6 }) as { code: string } + const over = await flow.orderRequest({ ...await draftOf(uniqueLabel("tu")), disputeDays: api.DISPUTE_DAYS.card }) + expect(await call("POST", "/api/name/register", codeBody(over.request, code))).toEqual({ status: 400, json: { type: "bad_request" } }) + const { id } = await codeOrder(request, uniqueLabel("tu")) + expect((await viewOf(id)).disputeDays).toBe(api.DISPUTE_DAYS.code) + await untilPhase(id, ["registered"]) +}) + test("a selection repeat is answered however old its signature, while a selection signed too long ago is bad_request", async ({ request }) => { const { id, view } = await takenPaid(request, uniqueLabel("th")) const record = store.orderByRegistration(id)! diff --git a/webapp/e2e/helpers.ts b/webapp/e2e/helpers.ts index ef923cc9..b3384274 100644 --- a/webapp/e2e/helpers.ts +++ b/webapp/e2e/helpers.ts @@ -584,17 +584,18 @@ export async function keepOrder(page: Page, registrationId: string, invoiceId: s export const registrationView = (o: KeptOrder, change: Record = {}) => ({ id: o.registrationId, version: 1, phase: { type: "unpaid" }, labelHash: o.request.labelHash, label: o.label, owner: o.owner, commitment: o.request.commitment, sealed: "sealed", years: 2, duration: 2 * YEAR_S, price: 10000, payment: { type: "invoice", method: "btc" }, balance: null, commitTx: null, registerTx: null, latePayment: null, - community: null, terms: { communityName: false, termsHash: GENERAL_TERMS_HASH }, ...change, + disputeDays: 14, community: null, terms: { communityName: false, termsHash: GENERAL_TERMS_HASH }, ...change, }) -export const registeredPhase = (expiresAt: number) => ({ type: "registered", expiresAt }) +export const registeredPhase = (expiresAt: number, disputeUntil?: number) => ({ type: "registered", expiresAt, disputeUntil }) // A registered name of this browser's code, as the service answers it, holding `links` until `records` answers otherwise. export async function fakeRegisteredName(page: Page, label: string, links: { contact: string; channel: string }, records: () => { links: { contact: string; channel: string }; nonce: number } = () => ({ links, nonce: 0 })): Promise { const order = await keepOrder(page, `reg-${label.slice(0, 12)}`, null, label, links) const expiresAt = Math.floor(Date.now() / 1000) + YEAR_S - await page.route(`**/api/registration/${order.registrationId}*`, (route) => route.fulfill({ json: registrationView(order, { phase: registeredPhase(expiresAt), commitTx: "0x02", registerTx: "0x03" }) })) + const disputeUntil = Math.floor(Date.now() / 1000) + 120 * 86400 + await page.route(`**/api/registration/${order.registrationId}*`, (route) => route.fulfill({ json: registrationView(order, { phase: registeredPhase(expiresAt, disputeUntil), commitTx: "0x02", registerTx: "0x03" }) })) await page.route("**/api/name/**", (route) => { const now = records() return route.fulfill({ json: registeredAnswer(order.owner, expiresAt, now.links, [], now.nonce) }) diff --git a/webapp/e2e/paid.spec.ts b/webapp/e2e/paid.spec.ts index 479cd1b7..038d8e70 100644 --- a/webapp/e2e/paid.spec.ts +++ b/webapp/e2e/paid.spec.ts @@ -306,7 +306,8 @@ test("a purchase walks the steps a buyer expects, and the links set before payin await expect(step.locator(".screen-body > .review + [role=status] + .mid")).toHaveCount(1) await expect(step.locator(".card.order .name")).toHaveText(`${label}.simplex`) // the term holds the free days until the paid years start, which are folded into it - await expect(step.locator(".card.order .trow")).toHaveText([/^Term2 years and (\d{2,} days|1 day)Early adopter bonus: your 2 years start on 1\u00a0January 2027\.$/, /^Registered until31\u00a0December 2028$/, /^Total\$\d+$/]) + await expect(step.locator(".card.order .trow")).toHaveText([/^Term2 years and (\d{2,} days|1 day)Early adopter bonus: your 2 years start on 1\u00a0January 2027\.$/, /^Registered until31\u00a0December 2028$/, + `Dispute period14 days${disputeLine(14)}`, /^Total\$\d+$/]) // each link as the chat it opens, read only await expect(step.locator(".card.order .chat")).toHaveCount(2) await expect(step.getByRole("button", { name: "Contact F1Y8m3, contact address" })).toBeVisible() @@ -350,13 +351,15 @@ test("a purchase walks the steps a buyer expects, and the links set before payin await waitRegistered(page, label) const main = page.locator("body > main") - await expect(main.locator(".lead")).toHaveText(`Registered until ${dateOf((await searchName(request, label)).expiresAt as number)}.`) + const paidInvoice = await (await request.get(`${MOCK}/api/invoice/${invoiceId}`)).json() as { amount: number; registration: { years: number; duration: number; registerTx: string; phase: { disputeUntil: number } } } + await expect(main.locator(".lead")).toHaveText(`Registered until ${dateOf((await searchName(request, label)).expiresAt as number)}. It can be ended until ${dateOf(paidInvoice.registration.phase.disputeUntil)} if a payment for it is disputed, reversed or refunded in full.`) // on chain: the price charged is the oracle's quote for the paid years, and the name expires the sent duration after the register's block - const paidInvoice = await (await request.get(`${MOCK}/api/invoice/${invoiceId}`)).json() as { amount: number; registration: { years: number; duration: number; registerTx: string } } expect(paidInvoice.amount).toBe(await oracleQuote(label, paidInvoice.registration.years)) expect(await chainExpiry(label)).toBe(await blockTimeOf(paidInvoice.registration.registerTx) + paidInvoice.registration.duration) + expect(paidInvoice.registration.phase.disputeUntil, "a Bitcoin payment's dispute end, 14 days after the register's block").toBe(await blockTimeOf(paidInvoice.registration.registerTx) + 14 * 86400) // how to use the name in the app, with its code, and no buttons to go elsewhere await expect(main.locator(".card.use").getByRole("heading", { name: "Use in the app" })).toBeVisible() + await expect(main.locator(".card.use :is(.sr-only, [aria-hidden=true])"), "a name of up to 25 letters drawn and read as it is").toHaveCount(0) await expect(await shownCode(page)).toHaveText(ownerCode) await expect(main.getByRole("button", { name: "Copy code" })).toBeVisible() await expect(main.getByRole("checkbox")).toHaveCount(0) @@ -432,6 +435,46 @@ const inWindow = async (page: Page, node: Locator) => { const termLines = (page: Page) => onStep(page).locator(".trow").first().locator("> span").last() .evaluate((value) => new Set([...value.getClientRects()].map((r) => Math.round(r.top))).size) +const disputeLine = (days: number) => `For ${days} days after it is registered, the registration can be ended if a payment for it is disputed, reversed or refunded in full.` +const disputeRow = (page: Page) => onStep(page).locator(".card.order .trow", { hasText: "Dispute period" }) + +test("Check your order says for how many days the registration can be ended, by the way it is paid, explained on hover", async ({ page }) => { + await search(page, uniqueLabel("days")) + await toReview(page) + for (const [method, days] of [["Card", 120], ["Bitcoin", 14], ["Monero", 14]] as const) { + await page.getByRole("radio", { name: method }).click() + await expect(disputeRow(page).getByRole("button")).toHaveText(`${days} days`) + await expect(disputeRow(page).getByRole("button")).toHaveAccessibleDescription(disputeLine(days)) + } + await expect(disputeRow(page).getByRole("tooltip")).toBeHidden() + await disputeRow(page).getByRole("button").hover() + await expect(disputeRow(page).getByRole("tooltip")).toBeVisible() + await page.mouse.move(0, 0) + await page.getByRole("radio", { name: "Card" }).click() + await onStep(page).getByRole("button", { name: "I have a code" }).click() + await expect(disputeRow(page).getByRole("button")).toHaveText("14 days") +}) + +test("a reveal over more dispute days than the order's payment allows is not signed, and the page says so", async ({ page, request }) => { + const { invoiceId } = await startOrder(page, uniqueLabel("over"), { method: "btc" }) + const reveals: string[] = [] + page.on("request", (r) => { if (r.method() === "POST" && new URL(r.url()).pathname.endsWith("/reveal")) reveals.push(r.url()) }) + await page.route(`**/api/invoice/${invoiceId}*`, async (route) => { + const res = await route.fetch() + const json = await res.json() + await route.fulfill({ response: res, json: { ...json, registration: { ...json.registration, disputeDays: 120 } } }) + }) + await control(request, `stale/${await registrationOf(request, invoiceId)}`) + await control(request, `settle/${invoiceId}`) + const notice = onStep(page).locator(".notice", { hasText: "This order cannot be signed" }) + await expect(notice).toHaveText("This order cannot be signedIts registration could be ended for 120 days, longer than the 14 days its payment allows. Write to chat@simplex.chat with the reference below.", + { timeout: REGISTRATION_MS }) + await expect(page.locator("body > .sr-only[role=status]")).toHaveText("This order cannot be signed. Its registration could be ended for 120 days, longer than the 14 days its payment allows. Write to chat@simplex.chat with the reference below.") + await expect(onStep(page).locator(".screen-head .lead"), "no lead to keep the page open").toHaveCount(0) + expect(reveals, "no reveal sent").toEqual([]) + await page.unrouteAll({ behavior: "ignoreErrors" }) +}) + test("the term's free days are the early adopter bonus, explained on hover, focus and tap, with nothing moving", async ({ page, browser, baseURL }) => { await search(page, uniqueLabel("bonus")) await toReview(page, false) @@ -488,6 +531,23 @@ test("the term's free days are the early adopter bonus, explained on hover, focu await context.close() }) +test("on a touch screen, I have a code takes its taps under the payment methods, none of theirs", async ({ page, browser, baseURL, browserName }) => { + test.skip(browserName !== "chromium", "Chromium's touch emulation gives the page a coarse pointer") + await search(page, uniqueLabel("tap")) + await toReview(page) + const checkout = await page.evaluate((key) => sessionStorage.getItem(key)!, CHECKOUT_KEY) + const context = await browser.newContext({ baseURL, viewport: FIT_SIZES[1], hasTouch: true, reducedMotion: "reduce" }) + await context.addInitScript(([key, value]) => sessionStorage.setItem(key, value), [CHECKOUT_KEY, checkout]) + const phone = await context.newPage() + await phone.goto("/#/checkout") + await expect(onStep(phone).getByRole("heading", { name: "Check your order" })).toBeVisible() + expect(await phone.evaluate(() => matchMedia("(pointer: coarse)").matches), "a coarse pointer").toBe(true) + const methods = (await onStep(phone).locator(".methods").boundingBox())! + const link = (await onStep(phone).getByRole("button", { name: "I have a code" }).boundingBox())! + expect(Math.round(link.y), "the top of the link's tap area").toBeGreaterThanOrEqual(Math.round(methods.y + methods.height)) + await context.close() +}) + test("a term that has started has no free days, so no bonus or hint, which come back with the days", async ({ page }) => { await search(page, uniqueLabel("nobonus")) await toReview(page, false) @@ -497,7 +557,7 @@ test("a term that has started has no free days, so no bonus or hint, which come await page.reload() await expect(onStep(page).locator(".trow").first()).toHaveText("Term2 years") await expect(bonusOf(page)).toHaveCount(0) - await expect(onStep(page).locator("[role=tooltip]")).toHaveCount(0) + await expect(onStep(page).locator(".trow").first().locator("[role=tooltip]")).toHaveCount(0) await startAt(termStart) await page.reload() await expect(bonusOf(page)).toHaveAccessibleDescription(/^Early adopter bonus/) @@ -1378,15 +1438,23 @@ test("once a name is registered, Back to its search never offers it again, and Y expect(await page.evaluate(() => (window as unknown as { __chips: string[] }).__chips), "the row's chips from its first draw").toEqual([]) }) -test("on a phone, a long name wraps beside its chats on Check your order, the chats at the row's right", async ({ page }) => { - await page.setViewportSize({ width: 390, height: 844 }) - await toFullReview(page, `${uniqueLabel("wrap")}${"w".repeat(63)}`.slice(0, 63)) +const orderRow = async (page: Page) => { const row = onStep(page).locator(".card.order > .row") const [box, name, chats] = await Promise.all([row, row.locator(".name"), row.locator(".chats")].map(async (l) => (await l.boundingBox())!)) const padding = await row.evaluate((r) => parseFloat(getComputedStyle(r).paddingRight)) + return { name, chats, right: Math.round(box.x + box.width - padding) } +} + +test("on a phone, a long name wraps beside its chats on Check your order, the chats at the row's right, as they are for a name abbreviated", async ({ page }) => { + await page.setViewportSize({ width: 390, height: 844 }) + await toFullReview(page, `${uniqueLabel("wrap")}${"w".repeat(25)}`.slice(0, 25)) + const { name, chats, right } = await orderRow(page) expect(chats.x, "the chats after the name").toBeGreaterThanOrEqual(name.x + name.width) - expect(Math.round(chats.x + chats.width), "the chats at the row's right").toBe(Math.round(box.x + box.width - padding)) + expect(Math.round(chats.x + chats.width), "the chats at the row's right").toBe(right) expect(name.height, "the name on more than one line").toBeGreaterThan(40) + await toFullReview(page, `${uniqueLabel("wrap")}${"w".repeat(63)}`.slice(0, 63)) + const abbreviated = await orderRow(page) + expect(Math.round(abbreviated.chats.x + abbreviated.chats.width), "the chats of a name abbreviated at the row's right").toBe(abbreviated.right) }) // how often a pay page checks its name again (NAME_CHECK_MS in src/views/order.ts) diff --git a/webapp/e2e/robustness.spec.ts b/webapp/e2e/robustness.spec.ts index 75ecabc4..021d60d1 100644 --- a/webapp/e2e/robustness.spec.ts +++ b/webapp/e2e/robustness.spec.ts @@ -163,7 +163,7 @@ test("a registered order opened in a browser without its code offers restore", a const other = await browser.newContext() const page2 = await other.newPage() await page2.goto(`/?order=${invoiceId}`) - await expect(page2.getByText("Its name code is not in this browser.")).toBeVisible() + await expect(page2.locator("body > main .lead")).toHaveText(/^Registered until .+ to .+\. It can be ended until .+ if a payment for it is disputed, reversed or refunded in full\. Its name code is not in this browser\.$/) await page2.getByRole("button", { name: "Restore with your name code" }).click() await codeField(page2).fill(ownerCode) await page2.getByRole("button", { name: "Add to Your names" }).click() diff --git a/webapp/e2e/screens.spec.ts b/webapp/e2e/screens.spec.ts index 184d6348..6b57af03 100644 --- a/webapp/e2e/screens.spec.ts +++ b/webapp/e2e/screens.spec.ts @@ -1674,6 +1674,17 @@ screen(2176, "order-registered-no-links", async (r) => { await control(r.request, `settle/${invoiceId}`) await waitRegistered(r.page, r.id) }) +screen(2177, "order-registering-days-refused", async (r) => { + const { invoiceId, registrationId } = await ordered(r, r.id) + await r.page.route(`**/api/invoice/${invoiceId}*`, async (route) => { + const res = await route.fetch() + const json = await res.json() + await route.fulfill({ response: res, json: { ...json, registration: { ...json.registration, disputeDays: 120 } } }) + }) + await control(r.request, `stale/${registrationId}`) + await control(r.request, `settle/${invoiceId}`) + await shown(r.page, "This order cannot be signed") +}) screen(2178, "order-registered-no-record", async (r) => { const { invoiceId } = await ordered(r, r.id) await control(r.request, `settle/${invoiceId}`) @@ -1682,6 +1693,14 @@ screen(2178, "order-registered-no-record", async (r) => { await heading(other, `${r.id}.simplex is yours`) return other }) +screen(2179, "order-ended", async (r) => { + const { invoiceId, registrationId } = await ordered(r, r.id) + await control(r.request, `settle/${invoiceId}`) + await waitRegistered(r.page, r.id) + await control(r.request, `unregister/${registrationId}`) + await r.page.reload() + await heading(r.page, "Registration ended") +}) screen(2180, "order-taken-chain", async (r) => { await takenOrder(r.page, r.request, r.id) }) screen(2182, "order-taken-reserved", async (r) => { const { invoiceId } = await startOrder(r.page, r.id, { method: "btc" }) @@ -1934,6 +1953,13 @@ screen(3012, "names-list-config-unread-fresh", async (r) => { await r.page.goto("/#/names") await expect(r.page.locator(".list-row", { hasText: r.id })).toContainText("Until") }) +screen(3013, "names-row-ended", async (r) => { + const { registrationId } = await codeOrder(r, r.id) + await waitRegistered(r.page, r.id) + await control(r.request, `unregister/${registrationId}`) + await r.page.goto("/#/names") + await expect(r.page.locator(".list-row", { hasText: r.id }).locator(".chip")).toHaveText("Ended") +}) const seenListReloaded = async (r: Reach, unread: (page: Page) => Promise) => { await codeOrder(r, r.id) await waitRegistered(r.page, r.id) @@ -2434,6 +2460,13 @@ screen(3132, "names-edit-expired-taken", async (r) => { await editFaked(r, { phase: registeredPhase(r.now - 100 * 86400) }, (order) => registeredFor(order, r.now + YEAR_S, OTHER_OWNER)) await shown(r.page, "This name has expired") }) +screen(3133, "names-edit-ended", async (r) => { + const { registrationId } = await codeOrder(r, r.id) + await waitRegistered(r.page, r.id) + await control(r.request, `unregister/${registrationId}`) + await r.page.goto(`/#/edit/${registrationId}`) + await shown(r.page, "The registration was ended") +}) screen(3134, "names-edit-other-owner", async (r) => { const expiresAt = START_S + 2 * YEAR_S await editFaked(r, { phase: registeredPhase(expiresAt) }, (order) => registeredFor(order, expiresAt, OTHER_OWNER)) diff --git a/webapp/e2e/screens/checkout-review-bonus-tip-desktop.png b/webapp/e2e/screens/checkout-review-bonus-tip-desktop.png index 4a281087..fa6de542 100644 Binary files a/webapp/e2e/screens/checkout-review-bonus-tip-desktop.png and b/webapp/e2e/screens/checkout-review-bonus-tip-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-bonus-tip-phone.png b/webapp/e2e/screens/checkout-review-bonus-tip-phone.png index a74ade6a..06154073 100644 Binary files a/webapp/e2e/screens/checkout-review-bonus-tip-phone.png and b/webapp/e2e/screens/checkout-review-bonus-tip-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-btc-desktop.png b/webapp/e2e/screens/checkout-review-btc-desktop.png index 80dd9991..b4419492 100644 Binary files a/webapp/e2e/screens/checkout-review-btc-desktop.png and b/webapp/e2e/screens/checkout-review-btc-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-btc-phone.png b/webapp/e2e/screens/checkout-review-btc-phone.png index 126dd091..8b5dd636 100644 Binary files a/webapp/e2e/screens/checkout-review-btc-phone.png and b/webapp/e2e/screens/checkout-review-btc-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-busy-desktop.png b/webapp/e2e/screens/checkout-review-busy-desktop.png index d9204efe..a5d0ccdd 100644 Binary files a/webapp/e2e/screens/checkout-review-busy-desktop.png and b/webapp/e2e/screens/checkout-review-busy-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-busy-phone.png b/webapp/e2e/screens/checkout-review-busy-phone.png index 35eb847e..b57c3382 100644 Binary files a/webapp/e2e/screens/checkout-review-busy-phone.png and b/webapp/e2e/screens/checkout-review-busy-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-card-desktop.png b/webapp/e2e/screens/checkout-review-card-desktop.png index 50c1f5bf..bdef978e 100644 Binary files a/webapp/e2e/screens/checkout-review-card-desktop.png and b/webapp/e2e/screens/checkout-review-card-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-card-phone.png b/webapp/e2e/screens/checkout-review-card-phone.png index f11627bf..a9e47cae 100644 Binary files a/webapp/e2e/screens/checkout-review-card-phone.png and b/webapp/e2e/screens/checkout-review-card-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-chat-popup-desktop.png b/webapp/e2e/screens/checkout-review-chat-popup-desktop.png index cdf83703..f1ef5d37 100644 Binary files a/webapp/e2e/screens/checkout-review-chat-popup-desktop.png and b/webapp/e2e/screens/checkout-review-chat-popup-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-chat-popup-phone.png b/webapp/e2e/screens/checkout-review-chat-popup-phone.png index 247f168f..edc42dea 100644 Binary files a/webapp/e2e/screens/checkout-review-chat-popup-phone.png and b/webapp/e2e/screens/checkout-review-chat-popup-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-field-covering-desktop.png b/webapp/e2e/screens/checkout-review-code-field-covering-desktop.png index 7a2f2a7f..6c86cc7c 100644 Binary files a/webapp/e2e/screens/checkout-review-code-field-covering-desktop.png and b/webapp/e2e/screens/checkout-review-code-field-covering-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-field-covering-phone.png b/webapp/e2e/screens/checkout-review-code-field-covering-phone.png index 290a2794..1f5a2bd7 100644 Binary files a/webapp/e2e/screens/checkout-review-code-field-covering-phone.png and b/webapp/e2e/screens/checkout-review-code-field-covering-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-field-empty-desktop.png b/webapp/e2e/screens/checkout-review-code-field-empty-desktop.png index 0c5b96bb..6e9ebf6c 100644 Binary files a/webapp/e2e/screens/checkout-review-code-field-empty-desktop.png and b/webapp/e2e/screens/checkout-review-code-field-empty-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-field-empty-phone.png b/webapp/e2e/screens/checkout-review-code-field-empty-phone.png index 15f78f5a..25778d92 100644 Binary files a/webapp/e2e/screens/checkout-review-code-field-empty-phone.png and b/webapp/e2e/screens/checkout-review-code-field-empty-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-expired-desktop.png b/webapp/e2e/screens/checkout-review-code-refused-expired-desktop.png index 8d6d4789..9cc16784 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-expired-desktop.png and b/webapp/e2e/screens/checkout-review-code-refused-expired-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-expired-phone.png b/webapp/e2e/screens/checkout-review-code-refused-expired-phone.png index 7235c6dd..5b6116df 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-expired-phone.png and b/webapp/e2e/screens/checkout-review-code-refused-expired-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-invalid-desktop.png b/webapp/e2e/screens/checkout-review-code-refused-invalid-desktop.png index 879aab2e..d11d77f5 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-invalid-desktop.png and b/webapp/e2e/screens/checkout-review-code-refused-invalid-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-invalid-phone.png b/webapp/e2e/screens/checkout-review-code-refused-invalid-phone.png index fd11761c..5e168528 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-invalid-phone.png and b/webapp/e2e/screens/checkout-review-code-refused-invalid-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-not-covering-desktop.png b/webapp/e2e/screens/checkout-review-code-refused-not-covering-desktop.png index 0ac24c8b..61db9bd8 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-not-covering-desktop.png and b/webapp/e2e/screens/checkout-review-code-refused-not-covering-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-not-covering-phone.png b/webapp/e2e/screens/checkout-review-code-refused-not-covering-phone.png index 9ce1a99d..7c5d6716 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-not-covering-phone.png and b/webapp/e2e/screens/checkout-review-code-refused-not-covering-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-reserved-desktop.png b/webapp/e2e/screens/checkout-review-code-refused-reserved-desktop.png index d62583e9..c888b5c2 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-reserved-desktop.png and b/webapp/e2e/screens/checkout-review-code-refused-reserved-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-reserved-phone.png b/webapp/e2e/screens/checkout-review-code-refused-reserved-phone.png index 3e077c42..c539087b 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-reserved-phone.png and b/webapp/e2e/screens/checkout-review-code-refused-reserved-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-unpaid-desktop.png b/webapp/e2e/screens/checkout-review-code-refused-unpaid-desktop.png index 0347b8b3..0764e706 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-unpaid-desktop.png and b/webapp/e2e/screens/checkout-review-code-refused-unpaid-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-unpaid-phone.png b/webapp/e2e/screens/checkout-review-code-refused-unpaid-phone.png index d04a613c..7c43c056 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-unpaid-phone.png and b/webapp/e2e/screens/checkout-review-code-refused-unpaid-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-used-desktop.png b/webapp/e2e/screens/checkout-review-code-refused-used-desktop.png index 0b809622..2c48ee74 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-used-desktop.png and b/webapp/e2e/screens/checkout-review-code-refused-used-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-refused-used-phone.png b/webapp/e2e/screens/checkout-review-code-refused-used-phone.png index aa13b84d..bd5c6d1e 100644 Binary files a/webapp/e2e/screens/checkout-review-code-refused-used-phone.png and b/webapp/e2e/screens/checkout-review-code-refused-used-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-scan-dialog-phone.png b/webapp/e2e/screens/checkout-review-code-scan-dialog-phone.png index da64db1c..ae23941c 100644 Binary files a/webapp/e2e/screens/checkout-review-code-scan-dialog-phone.png and b/webapp/e2e/screens/checkout-review-code-scan-dialog-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-expired-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-expired-desktop.png index 50b98bec..af35bf89 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-expired-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-expired-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-expired-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-expired-phone.png index 422b1ac0..a6768fcf 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-expired-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-expired-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-mistyped-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-mistyped-desktop.png index 0d8e8283..4223ccec 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-mistyped-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-mistyped-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-mistyped-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-mistyped-phone.png index 959d17e5..7243b5ee 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-mistyped-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-mistyped-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-name-code-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-name-code-desktop.png index 49cea6c3..982c2d3c 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-name-code-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-name-code-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-name-code-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-name-code-phone.png index 9c93178f..d2ff0ce9 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-name-code-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-name-code-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-no-camera-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-no-camera-phone.png index 37defca2..a321d729 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-no-camera-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-no-camera-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-not-checked-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-not-checked-desktop.png index bcab5bd1..07e13859 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-not-checked-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-not-checked-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-not-checked-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-not-checked-phone.png index ad740453..ca6fab2a 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-not-checked-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-not-checked-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-not-covering-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-not-covering-desktop.png index b01fe222..3b3f4f79 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-not-covering-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-not-covering-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-not-covering-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-not-covering-phone.png index d64e7e16..68df1011 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-not-covering-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-not-covering-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-not-issued-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-not-issued-desktop.png index 486660a6..7512a768 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-not-issued-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-not-issued-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-not-issued-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-not-issued-phone.png index ace58b44..9cf1fe48 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-not-issued-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-not-issued-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-rate-limited-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-rate-limited-desktop.png index 0677aa51..34bfc080 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-rate-limited-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-rate-limited-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-rate-limited-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-rate-limited-phone.png index b8a4ec3a..41570aad 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-rate-limited-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-rate-limited-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-reserved-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-reserved-desktop.png index 86a4b150..069553b4 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-reserved-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-reserved-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-reserved-own-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-reserved-own-desktop.png index 1ab31dca..54614814 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-reserved-own-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-reserved-own-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-reserved-own-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-reserved-own-phone.png index b96fd407..5d0e84f3 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-reserved-own-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-reserved-own-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-reserved-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-reserved-phone.png index ff1a1b10..386ae1b4 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-reserved-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-reserved-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-revoked-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-revoked-desktop.png index 135955f1..50832036 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-revoked-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-revoked-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-revoked-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-revoked-phone.png index 4281eeaf..98433bc9 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-revoked-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-revoked-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-unfinished-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-unfinished-desktop.png index 0655366e..e8442d8c 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-unfinished-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-unfinished-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-unfinished-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-unfinished-phone.png index 3228b10d..ffe4a044 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-unfinished-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-unfinished-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-unpaid-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-unpaid-desktop.png index ea00bc89..ea7f0756 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-unpaid-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-unpaid-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-unpaid-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-unpaid-phone.png index d6ece1a8..97c9e1a5 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-unpaid-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-unpaid-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-used-desktop.png b/webapp/e2e/screens/checkout-review-code-verdict-used-desktop.png index 7fdda7c5..7a8ec898 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-used-desktop.png and b/webapp/e2e/screens/checkout-review-code-verdict-used-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-code-verdict-used-phone.png b/webapp/e2e/screens/checkout-review-code-verdict-used-phone.png index 4ffc2e3a..811b9408 100644 Binary files a/webapp/e2e/screens/checkout-review-code-verdict-used-phone.png and b/webapp/e2e/screens/checkout-review-code-verdict-used-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-codes-only-code-desktop.png b/webapp/e2e/screens/checkout-review-codes-only-code-desktop.png index 9cbc3a5e..86799c56 100644 Binary files a/webapp/e2e/screens/checkout-review-codes-only-code-desktop.png and b/webapp/e2e/screens/checkout-review-codes-only-code-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-codes-only-code-phone.png b/webapp/e2e/screens/checkout-review-codes-only-code-phone.png index f241717d..b40cd1f0 100644 Binary files a/webapp/e2e/screens/checkout-review-codes-only-code-phone.png and b/webapp/e2e/screens/checkout-review-codes-only-code-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-codes-only-field-desktop.png b/webapp/e2e/screens/checkout-review-codes-only-field-desktop.png index 3a197ed9..56ac8b71 100644 Binary files a/webapp/e2e/screens/checkout-review-codes-only-field-desktop.png and b/webapp/e2e/screens/checkout-review-codes-only-field-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-codes-only-field-phone.png b/webapp/e2e/screens/checkout-review-codes-only-field-phone.png index 9bc381e9..ed076e1c 100644 Binary files a/webapp/e2e/screens/checkout-review-codes-only-field-phone.png and b/webapp/e2e/screens/checkout-review-codes-only-field-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-codes-only-refused-desktop.png b/webapp/e2e/screens/checkout-review-codes-only-refused-desktop.png index 09250603..2fb392fd 100644 Binary files a/webapp/e2e/screens/checkout-review-codes-only-refused-desktop.png and b/webapp/e2e/screens/checkout-review-codes-only-refused-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-codes-only-refused-phone.png b/webapp/e2e/screens/checkout-review-codes-only-refused-phone.png index 40761db3..d5f28fb2 100644 Binary files a/webapp/e2e/screens/checkout-review-codes-only-refused-phone.png and b/webapp/e2e/screens/checkout-review-codes-only-refused-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-community-code-hint-desktop.png b/webapp/e2e/screens/checkout-review-community-code-hint-desktop.png index 56f8bee0..9eaf8200 100644 Binary files a/webapp/e2e/screens/checkout-review-community-code-hint-desktop.png and b/webapp/e2e/screens/checkout-review-community-code-hint-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-community-code-hint-phone.png b/webapp/e2e/screens/checkout-review-community-code-hint-phone.png index e7839c37..6917dd92 100644 Binary files a/webapp/e2e/screens/checkout-review-community-code-hint-phone.png and b/webapp/e2e/screens/checkout-review-community-code-hint-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-community-desktop.png b/webapp/e2e/screens/checkout-review-community-desktop.png index 20cff9e6..552d7a1f 100644 Binary files a/webapp/e2e/screens/checkout-review-community-desktop.png and b/webapp/e2e/screens/checkout-review-community-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-community-phone.png b/webapp/e2e/screens/checkout-review-community-phone.png index 17f15c9d..d63d067b 100644 Binary files a/webapp/e2e/screens/checkout-review-community-phone.png and b/webapp/e2e/screens/checkout-review-community-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-community-popup-desktop.png b/webapp/e2e/screens/checkout-review-community-popup-desktop.png index 0a941f8e..281916ed 100644 Binary files a/webapp/e2e/screens/checkout-review-community-popup-desktop.png and b/webapp/e2e/screens/checkout-review-community-popup-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-community-popup-phone.png b/webapp/e2e/screens/checkout-review-community-popup-phone.png index c10c7888..0c6f0eed 100644 Binary files a/webapp/e2e/screens/checkout-review-community-popup-phone.png and b/webapp/e2e/screens/checkout-review-community-popup-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-hold-desktop.png b/webapp/e2e/screens/checkout-review-hold-desktop.png index 56673f08..8af815ea 100644 Binary files a/webapp/e2e/screens/checkout-review-hold-desktop.png and b/webapp/e2e/screens/checkout-review-hold-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-hold-phone.png b/webapp/e2e/screens/checkout-review-hold-phone.png index 55c410ff..a8afa71f 100644 Binary files a/webapp/e2e/screens/checkout-review-hold-phone.png and b/webapp/e2e/screens/checkout-review-hold-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-links-desktop.png b/webapp/e2e/screens/checkout-review-links-desktop.png index 2aecdbb3..4ddbd023 100644 Binary files a/webapp/e2e/screens/checkout-review-links-desktop.png and b/webapp/e2e/screens/checkout-review-links-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-links-phone.png b/webapp/e2e/screens/checkout-review-links-phone.png index a426cdbb..aec552ce 100644 Binary files a/webapp/e2e/screens/checkout-review-links-phone.png and b/webapp/e2e/screens/checkout-review-links-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-links-unread-desktop.png b/webapp/e2e/screens/checkout-review-links-unread-desktop.png index abbceac8..17221fe5 100644 Binary files a/webapp/e2e/screens/checkout-review-links-unread-desktop.png and b/webapp/e2e/screens/checkout-review-links-unread-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-links-unread-phone.png b/webapp/e2e/screens/checkout-review-links-unread-phone.png index f7a5f732..4806b73e 100644 Binary files a/webapp/e2e/screens/checkout-review-links-unread-phone.png and b/webapp/e2e/screens/checkout-review-links-unread-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-method-unavailable-desktop.png b/webapp/e2e/screens/checkout-review-method-unavailable-desktop.png index b646e3da..dc1e9e5a 100644 Binary files a/webapp/e2e/screens/checkout-review-method-unavailable-desktop.png and b/webapp/e2e/screens/checkout-review-method-unavailable-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-method-unavailable-phone.png b/webapp/e2e/screens/checkout-review-method-unavailable-phone.png index bcf6d613..94c44100 100644 Binary files a/webapp/e2e/screens/checkout-review-method-unavailable-phone.png and b/webapp/e2e/screens/checkout-review-method-unavailable-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-open-order-confirming-desktop.png b/webapp/e2e/screens/checkout-review-open-order-confirming-desktop.png index a23ab87d..46549e9e 100644 Binary files a/webapp/e2e/screens/checkout-review-open-order-confirming-desktop.png and b/webapp/e2e/screens/checkout-review-open-order-confirming-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-open-order-confirming-phone.png b/webapp/e2e/screens/checkout-review-open-order-confirming-phone.png index 3193f51a..32b2d3b3 100644 Binary files a/webapp/e2e/screens/checkout-review-open-order-confirming-phone.png and b/webapp/e2e/screens/checkout-review-open-order-confirming-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-open-order-desktop.png b/webapp/e2e/screens/checkout-review-open-order-desktop.png index 480c25af..3274469f 100644 Binary files a/webapp/e2e/screens/checkout-review-open-order-desktop.png and b/webapp/e2e/screens/checkout-review-open-order-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-open-order-phone.png b/webapp/e2e/screens/checkout-review-open-order-phone.png index 787b0453..6553669e 100644 Binary files a/webapp/e2e/screens/checkout-review-open-order-phone.png and b/webapp/e2e/screens/checkout-review-open-order-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-sending-desktop.png b/webapp/e2e/screens/checkout-review-sending-desktop.png index 196e890b..331322a2 100644 Binary files a/webapp/e2e/screens/checkout-review-sending-desktop.png and b/webapp/e2e/screens/checkout-review-sending-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-sending-phone.png b/webapp/e2e/screens/checkout-review-sending-phone.png index 028f0619..e52b93b0 100644 Binary files a/webapp/e2e/screens/checkout-review-sending-phone.png and b/webapp/e2e/screens/checkout-review-sending-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-tab-code-desktop.png b/webapp/e2e/screens/checkout-review-tab-code-desktop.png index 8992eaed..526db3d7 100644 Binary files a/webapp/e2e/screens/checkout-review-tab-code-desktop.png and b/webapp/e2e/screens/checkout-review-tab-code-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-tab-code-phone.png b/webapp/e2e/screens/checkout-review-tab-code-phone.png index 8d9f06cc..aab9e1e1 100644 Binary files a/webapp/e2e/screens/checkout-review-tab-code-phone.png and b/webapp/e2e/screens/checkout-review-tab-code-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-term-started-desktop.png b/webapp/e2e/screens/checkout-review-term-started-desktop.png index 058214a5..0d206031 100644 Binary files a/webapp/e2e/screens/checkout-review-term-started-desktop.png and b/webapp/e2e/screens/checkout-review-term-started-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-term-started-phone.png b/webapp/e2e/screens/checkout-review-term-started-phone.png index 0a88d7d2..abf1faba 100644 Binary files a/webapp/e2e/screens/checkout-review-term-started-phone.png and b/webapp/e2e/screens/checkout-review-term-started-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-terms-changed-desktop.png b/webapp/e2e/screens/checkout-review-terms-changed-desktop.png index 0901ea8b..390a4bb9 100644 Binary files a/webapp/e2e/screens/checkout-review-terms-changed-desktop.png and b/webapp/e2e/screens/checkout-review-terms-changed-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-terms-changed-phone.png b/webapp/e2e/screens/checkout-review-terms-changed-phone.png index 278cfe2d..4fff0c65 100644 Binary files a/webapp/e2e/screens/checkout-review-terms-changed-phone.png and b/webapp/e2e/screens/checkout-review-terms-changed-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-unticked-desktop.png b/webapp/e2e/screens/checkout-review-unticked-desktop.png index 34cfa45b..ac7ea84c 100644 Binary files a/webapp/e2e/screens/checkout-review-unticked-desktop.png and b/webapp/e2e/screens/checkout-review-unticked-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-unticked-phone.png b/webapp/e2e/screens/checkout-review-unticked-phone.png index 6c269635..dd730873 100644 Binary files a/webapp/e2e/screens/checkout-review-unticked-phone.png and b/webapp/e2e/screens/checkout-review-unticked-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-waiting-card-desktop.png b/webapp/e2e/screens/checkout-review-waiting-card-desktop.png index 9e3641a4..872fe891 100644 Binary files a/webapp/e2e/screens/checkout-review-waiting-card-desktop.png and b/webapp/e2e/screens/checkout-review-waiting-card-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-waiting-card-phone.png b/webapp/e2e/screens/checkout-review-waiting-card-phone.png index 51792266..de22c997 100644 Binary files a/webapp/e2e/screens/checkout-review-waiting-card-phone.png and b/webapp/e2e/screens/checkout-review-waiting-card-phone.png differ diff --git a/webapp/e2e/screens/checkout-review-xmr-desktop.png b/webapp/e2e/screens/checkout-review-xmr-desktop.png index 74e4966b..d544cc43 100644 Binary files a/webapp/e2e/screens/checkout-review-xmr-desktop.png and b/webapp/e2e/screens/checkout-review-xmr-desktop.png differ diff --git a/webapp/e2e/screens/checkout-review-xmr-phone.png b/webapp/e2e/screens/checkout-review-xmr-phone.png index 8f40dab3..a20d21cf 100644 Binary files a/webapp/e2e/screens/checkout-review-xmr-phone.png and b/webapp/e2e/screens/checkout-review-xmr-phone.png differ diff --git a/webapp/e2e/screens/checkout-select-busy-desktop.png b/webapp/e2e/screens/checkout-select-busy-desktop.png index e535ce8a..b3a1ba09 100644 Binary files a/webapp/e2e/screens/checkout-select-busy-desktop.png and b/webapp/e2e/screens/checkout-select-busy-desktop.png differ diff --git a/webapp/e2e/screens/checkout-select-busy-phone.png b/webapp/e2e/screens/checkout-select-busy-phone.png index 96efbc2c..153490d6 100644 Binary files a/webapp/e2e/screens/checkout-select-busy-phone.png and b/webapp/e2e/screens/checkout-select-busy-phone.png differ diff --git a/webapp/e2e/screens/checkout-select-code-desktop.png b/webapp/e2e/screens/checkout-select-code-desktop.png index 6df15646..93270774 100644 Binary files a/webapp/e2e/screens/checkout-select-code-desktop.png and b/webapp/e2e/screens/checkout-select-code-desktop.png differ diff --git a/webapp/e2e/screens/checkout-select-code-phone.png b/webapp/e2e/screens/checkout-select-code-phone.png index def0afe8..cb26f832 100644 Binary files a/webapp/e2e/screens/checkout-select-code-phone.png and b/webapp/e2e/screens/checkout-select-code-phone.png differ diff --git a/webapp/e2e/screens/checkout-select-paid-desktop.png b/webapp/e2e/screens/checkout-select-paid-desktop.png index 85d66a17..5ff27bf6 100644 Binary files a/webapp/e2e/screens/checkout-select-paid-desktop.png and b/webapp/e2e/screens/checkout-select-paid-desktop.png differ diff --git a/webapp/e2e/screens/checkout-select-paid-phone.png b/webapp/e2e/screens/checkout-select-paid-phone.png index 40a19069..98323914 100644 Binary files a/webapp/e2e/screens/checkout-select-paid-phone.png and b/webapp/e2e/screens/checkout-select-paid-phone.png differ diff --git a/webapp/e2e/screens/checkout-select-refused-code-expired-desktop.png b/webapp/e2e/screens/checkout-select-refused-code-expired-desktop.png index 7cf2d267..6da952b2 100644 Binary files a/webapp/e2e/screens/checkout-select-refused-code-expired-desktop.png and b/webapp/e2e/screens/checkout-select-refused-code-expired-desktop.png differ diff --git a/webapp/e2e/screens/checkout-select-refused-code-expired-phone.png b/webapp/e2e/screens/checkout-select-refused-code-expired-phone.png index 41574188..6ab15683 100644 Binary files a/webapp/e2e/screens/checkout-select-refused-code-expired-phone.png and b/webapp/e2e/screens/checkout-select-refused-code-expired-phone.png differ diff --git a/webapp/e2e/screens/checkout-select-refused-code-revoked-desktop.png b/webapp/e2e/screens/checkout-select-refused-code-revoked-desktop.png index dab120cb..06988813 100644 Binary files a/webapp/e2e/screens/checkout-select-refused-code-revoked-desktop.png and b/webapp/e2e/screens/checkout-select-refused-code-revoked-desktop.png differ diff --git a/webapp/e2e/screens/checkout-select-refused-code-revoked-phone.png b/webapp/e2e/screens/checkout-select-refused-code-revoked-phone.png index 6e02a2a7..c8a9e196 100644 Binary files a/webapp/e2e/screens/checkout-select-refused-code-revoked-phone.png and b/webapp/e2e/screens/checkout-select-refused-code-revoked-phone.png differ diff --git a/webapp/e2e/screens/checkout-select-refused-uncovered-desktop.png b/webapp/e2e/screens/checkout-select-refused-uncovered-desktop.png index fba3eff1..2bb7668a 100644 Binary files a/webapp/e2e/screens/checkout-select-refused-uncovered-desktop.png and b/webapp/e2e/screens/checkout-select-refused-uncovered-desktop.png differ diff --git a/webapp/e2e/screens/checkout-select-refused-uncovered-phone.png b/webapp/e2e/screens/checkout-select-refused-uncovered-phone.png index 27ca7489..ed40d47d 100644 Binary files a/webapp/e2e/screens/checkout-select-refused-uncovered-phone.png and b/webapp/e2e/screens/checkout-select-refused-uncovered-phone.png differ diff --git a/webapp/e2e/screens/checkout-select-terms-changed-desktop.png b/webapp/e2e/screens/checkout-select-terms-changed-desktop.png index 458902bb..b31d0d9f 100644 Binary files a/webapp/e2e/screens/checkout-select-terms-changed-desktop.png and b/webapp/e2e/screens/checkout-select-terms-changed-desktop.png differ diff --git a/webapp/e2e/screens/checkout-select-terms-changed-phone.png b/webapp/e2e/screens/checkout-select-terms-changed-phone.png index 2ae348fb..f6c76434 100644 Binary files a/webapp/e2e/screens/checkout-select-terms-changed-phone.png and b/webapp/e2e/screens/checkout-select-terms-changed-phone.png differ diff --git a/webapp/e2e/screens/names-edit-ended-desktop.png b/webapp/e2e/screens/names-edit-ended-desktop.png new file mode 100644 index 00000000..8661c2fb Binary files /dev/null and b/webapp/e2e/screens/names-edit-ended-desktop.png differ diff --git a/webapp/e2e/screens/names-edit-ended-phone.png b/webapp/e2e/screens/names-edit-ended-phone.png new file mode 100644 index 00000000..21010ca2 Binary files /dev/null and b/webapp/e2e/screens/names-edit-ended-phone.png differ diff --git a/webapp/e2e/screens/names-row-ended-desktop.png b/webapp/e2e/screens/names-row-ended-desktop.png new file mode 100644 index 00000000..5fbe003f Binary files /dev/null and b/webapp/e2e/screens/names-row-ended-desktop.png differ diff --git a/webapp/e2e/screens/names-row-ended-phone.png b/webapp/e2e/screens/names-row-ended-phone.png new file mode 100644 index 00000000..bb1d99a7 Binary files /dev/null and b/webapp/e2e/screens/names-row-ended-phone.png differ diff --git a/webapp/e2e/screens/order-ended-desktop.png b/webapp/e2e/screens/order-ended-desktop.png new file mode 100644 index 00000000..aa868567 Binary files /dev/null and b/webapp/e2e/screens/order-ended-desktop.png differ diff --git a/webapp/e2e/screens/order-ended-phone.png b/webapp/e2e/screens/order-ended-phone.png new file mode 100644 index 00000000..63b3b6e9 Binary files /dev/null and b/webapp/e2e/screens/order-ended-phone.png differ diff --git a/webapp/e2e/screens/order-registered-links-desktop.png b/webapp/e2e/screens/order-registered-links-desktop.png index 69c72911..37028042 100644 Binary files a/webapp/e2e/screens/order-registered-links-desktop.png and b/webapp/e2e/screens/order-registered-links-desktop.png differ diff --git a/webapp/e2e/screens/order-registered-links-phone.png b/webapp/e2e/screens/order-registered-links-phone.png index 69c6bdb0..6033af1b 100644 Binary files a/webapp/e2e/screens/order-registered-links-phone.png and b/webapp/e2e/screens/order-registered-links-phone.png differ diff --git a/webapp/e2e/screens/order-registered-no-links-desktop.png b/webapp/e2e/screens/order-registered-no-links-desktop.png index 6447dd40..902c17bb 100644 Binary files a/webapp/e2e/screens/order-registered-no-links-desktop.png and b/webapp/e2e/screens/order-registered-no-links-desktop.png differ diff --git a/webapp/e2e/screens/order-registered-no-links-phone.png b/webapp/e2e/screens/order-registered-no-links-phone.png index 932498a9..686bd0c7 100644 Binary files a/webapp/e2e/screens/order-registered-no-links-phone.png and b/webapp/e2e/screens/order-registered-no-links-phone.png differ diff --git a/webapp/e2e/screens/order-registered-no-record-desktop.png b/webapp/e2e/screens/order-registered-no-record-desktop.png index 4e807a68..949035da 100644 Binary files a/webapp/e2e/screens/order-registered-no-record-desktop.png and b/webapp/e2e/screens/order-registered-no-record-desktop.png differ diff --git a/webapp/e2e/screens/order-registered-no-record-phone.png b/webapp/e2e/screens/order-registered-no-record-phone.png index 209d56c7..01ecb3de 100644 Binary files a/webapp/e2e/screens/order-registered-no-record-phone.png and b/webapp/e2e/screens/order-registered-no-record-phone.png differ diff --git a/webapp/e2e/screens/order-registering-days-refused-desktop.png b/webapp/e2e/screens/order-registering-days-refused-desktop.png new file mode 100644 index 00000000..f7c8052c Binary files /dev/null and b/webapp/e2e/screens/order-registering-days-refused-desktop.png differ diff --git a/webapp/e2e/screens/order-registering-days-refused-phone.png b/webapp/e2e/screens/order-registering-days-refused-phone.png new file mode 100644 index 00000000..f8a1c8e7 Binary files /dev/null and b/webapp/e2e/screens/order-registering-days-refused-phone.png differ diff --git a/webapp/e2e/track.spec.ts b/webapp/e2e/track.spec.ts index e77ad140..f3e7f9c2 100644 --- a/webapp/e2e/track.spec.ts +++ b/webapp/e2e/track.spec.ts @@ -769,6 +769,13 @@ for (const length of [15, 25, MAX_LABEL_LENGTH]) { await fitsWindow(page, `${shots}-3-code`, frames) await savedToReview(page) await fitsWindow(page, `${shots}-4-review`, frames) + if (length > 25) { + await expect(step.locator(".card.order .row .name"), "the name abbreviated in the card").toHaveText(new RegExp(`^${label.slice(0, 12)}\\.\\.\\.${label.slice(-3)}\\.simplex$`)) + await expect(step.locator(".card.order .row .sr-only"), "the whole name, for a screen reader").toHaveText(`${label}.simplex`) + const read = await step.locator(".card.order > .row").ariaSnapshot() + expect(read.split(`${label}.simplex`).length - 1, `the whole name read once: ${read}`).toBe(1) + expect(read, "the abbreviation not read").not.toContain("...") + } await payButton(page).click() await page.waitForURL(/\?order=/) await expect(page.getByRole("heading", { name: "Pay with Bitcoin" })).toBeVisible() @@ -793,6 +800,9 @@ test(`the name-is-yours screen fits both windows for a name of ${MAX_LABEL_LENGT await page.goto(`/?registration=${registrationId}`) await expect(page.getByRole("heading", { name: `${label}.simplex is yours` })).toBeVisible() await expect(onStep(page).getByRole("button", { name: "Edit links" })).toBeVisible() + const instruction = onStep(page).locator(".card.use p") + await expect(instruction.locator(".sr-only"), "the whole name, for a screen reader").toHaveText(`${label}.simplex.`) + await expect(instruction.locator("[aria-hidden=true]"), "the name as drawn").toHaveText(/^m+\.\.\.m+\.simplex\.$/) await fitsWindow(page, `long-${MAX_LABEL_LENGTH}-m-registered`) }) diff --git a/webapp/src/api.ts b/webapp/src/api.ts index bc58175b..8a7a2b8c 100644 --- a/webapp/src/api.ts +++ b/webapp/src/api.ts @@ -55,7 +55,7 @@ export function retryDelay(e: unknown, usual: number): number | null { return e.status >= 400 && e.status < 500 ? null : usual } -export type Phase = "unpaid" | "closed" | "queued" | "committing" | "committed" | "registering" | "registered" | "taken" | "failed" +export type Phase = "unpaid" | "closed" | "queued" | "committing" | "committed" | "registering" | "registered" | "ended" | "taken" | "failed" export type Method = "card" | "btc" | "xmr" export interface ChainInfo { @@ -192,7 +192,8 @@ export type PhaseView = | { type: "committing" } | { type: "committed"; revealAfter: number; revealBefore: number; signature: Signing } | { type: "registering" } - | { type: "registered"; expiresAt: number } + | { type: "registered"; expiresAt: number; disputeUntil?: number } + | { type: "ended" } | { type: "taken" } | { type: "failed"; reason: FailReason; heldUntil?: string } @@ -219,6 +220,7 @@ export interface RegistrationView { latePayment: LateWait | null commitTx: string | null registerTx: string | null + disputeDays: number community: Community | null terms: AgreedTerms } @@ -233,6 +235,7 @@ export const toSignOf = (view: RegistrationView): ToSign | null => { } export const lapsedOf = (view: RegistrationView) => committedOf(view)?.signature.type === "lapsed" export const expiresAtOf = (view: RegistrationView) => view.phase.type === "registered" ? view.phase.expiresAt : null +export const disputeUntilOf = (view: RegistrationView) => view.phase.type === "registered" ? view.phase.disputeUntil ?? null : null export const signedTermsOf = (terms: AgreedTerms) => `${terms.communityName ? COMMUNITY_TERMS : ""}${terms.termsHash.slice(2)}` const LATE_WAITS = ["confirming", "crediting", "support"] as const @@ -413,7 +416,7 @@ const isLinkProfile = (p: unknown) => isObject(p) && CHAT_KINDS.includes(p.kind const isPreview = (p: unknown) => isObject(p) && LINK_KINDS.includes(p.kind as Preview["kind"]) && isObject(p.profile) && (p.profile.type === "ok" ? isLinkProfile(p.profile.linkProfile) : PROFILE_STATES.includes(p.profile.type as Profile["profile"])) const isEntity = (e: unknown) => isObject(e) && isPreview(e.preview) && isText(e.link) && isText(e.deepLink) -const PHASES: Phase[] = ["unpaid", "closed", "queued", "committing", "committed", "registering", "registered", "taken", "failed"] +const PHASES: Phase[] = ["unpaid", "closed", "queued", "committing", "committed", "registering", "registered", "ended", "taken", "failed"] const METHODS: Method[] = ["card", "btc", "xmr"] const isBalance = (v: unknown) => isObject(v) && isAmount(v.amount) && isAmount(v.refunded) const isPayment = (v: unknown) => isObject(v) && ((v.type === "invoice" && METHODS.includes(v.method as Method)) || v.type === "code") @@ -422,15 +425,19 @@ const isAgreedTerms = (v: unknown) => isObject(v) && typeof v.communityName === const isTerms = (v: unknown, chainId: number) => isObject(v) && isHash(v.hash) && typeof v.link === "string" && termsLink(v.link, chainId) !== null && keccakOf(v.link) === v.hash const isCommunity = (v: unknown) => v === null || (isObject(v) && optional(v.for, (f) => typeof f === "string" && f !== "") && isCount(v.years)) const isAcceptance = (v: unknown) => isObject(v) && typeof v.community === "boolean" && isText(v.policy) && isHash(v.termsHash) && Number.isInteger(v.nonce) && (v.nonce as number) >= 0 +const MIN_DISPUTE_DAYS = 14 +const MAX_DISPUTE_DAYS = 120 +export const DISPUTE_DAYS: Record = { card: 120, btc: 14, xmr: 14, code: 14 } +const isDisputeDays = (v: unknown) => Number.isInteger(v) && (v as number) >= MIN_DISPUTE_DAYS && (v as number) <= MAX_DISPUTE_DAYS const isToSign = (v: unknown) => isObject(v) && (v.type === "unread" || (v.type === "read" && isAmount(v.intentNonce) && isAcceptance(v.acceptance))) const isSigning = (v: unknown) => isObject(v) && ((v.type === "awaiting" && isToSign(v.toSign)) || v.type === "signed" || v.type === "lapsed") const isPhase = (v: unknown) => isObject(v) && PHASES.includes(v.type as Phase) && (v.type !== "closed" || v.closedBy === "expired" || v.closedBy === "cancelled" || v.closedBy === "reversed") && (v.type !== "committed" || (isAmount(v.revealAfter) && isAmount(v.revealBefore) && isSigning(v.signature))) - && (v.type !== "registered" || isAmount(v.expiresAt)) && (v.type !== "failed" || (FAIL_REASONS.includes(v.reason as FailReason) && optional(v.heldUntil, isTime))) + && (v.type !== "registered" || (isAmount(v.expiresAt) && optional(v.disputeUntil, isAmount))) && (v.type !== "failed" || (FAIL_REASONS.includes(v.reason as FailReason) && optional(v.heldUntil, isTime))) const isRegistration = (v: unknown) => isObject(v) && isText(v.id) && Number.isInteger(v.version) && isPhase(v.phase) && isText(v.labelHash) && nullable(v.label, isText) && isText(v.owner) && isText(v.commitment) && isText(v.sealed) && isCount(v.years) && isCount(v.duration) && isAmount(v.price) && isPayment(v.payment) && nullable(v.balance, isBalance) && nullable(v.latePayment, (l) => LATE_WAITS.includes(l as LateWait)) - && nullable(v.commitTx, isText) && nullable(v.registerTx, isText) && isCommunity(v.community) && isAgreedTerms(v.terms) + && nullable(v.commitTx, isText) && nullable(v.registerTx, isText) && isDisputeDays(v.disputeDays) && isCommunity(v.community) && isAgreedTerms(v.terms) const isInvoice = (v: unknown) => isObject(v) && isText(v.invoiceId) && ["open", "paid", "expired"].includes(v.status as string) && isAmount(v.amount) && isText(v.currency) && isText(v.expiresAt) && isRegistration(v.registration) && optional(v.amountPaid, isAmount) && optional(v.cryptoAmountPaid, isDecimal) && optional(v.cryptoAmountDue, isDue) && optional(v.cryptoAmount, isDecimal) diff --git a/webapp/src/crypto/registration.ts b/webapp/src/crypto/registration.ts index 06804b0b..3f202169 100644 --- a/webapp/src/crypto/registration.ts +++ b/webapp/src/crypto/registration.ts @@ -1,5 +1,5 @@ // The registration, its commitment and the signed intents, from simplexmq PR #1942's names-web (which mirrors -// simplex-chat PR #7693's Registration.hs), with the record edits and the store's derived secret added. +// simplex-chat PR #7693's Registration.hs), with the record edits, the store's derived secret and the dispute days added. import { concatBytes, numberToBytesBE, utf8ToBytes } from "@noble/curves/utils" import { hmac } from "@noble/hashes/hmac" import { sha256 } from "@noble/hashes/sha2" @@ -57,13 +57,14 @@ export function recordCalls(r: Registration): Uint8Array[] { ) } -export function registerIntentDigest(chainId: bigint, sponsor: Uint8Array, r: Registration, nonce: bigint, deadline: bigint): Uint8Array { - const intent = hashStruct("RegisterName(string label,address owner,uint256 duration,address resolver,bytes[] data,uint256 nonce,uint256 deadline)", [ +export function registerIntentDigest(chainId: bigint, sponsor: Uint8Array, r: Registration, disputeDays: bigint, nonce: bigint, deadline: bigint): Uint8Array { + const intent = hashStruct("RegisterName(string label,address owner,uint256 duration,address resolver,bytes[] data,uint256 disputeDays,uint256 nonce,uint256 deadline)", [ keccak_256(utf8ToBytes(r.label)), addressWord(r.owner), uint256(r.duration), addressWord(r.resolver), keccak_256(concatBytes(...recordCalls(r).map((c) => keccak_256(c)))), + uint256(disputeDays), uint256(nonce), uint256(deadline), ]) diff --git a/webapp/src/dom.ts b/webapp/src/dom.ts index 196f309f..2a0ed9a2 100644 --- a/webapp/src/dom.ts +++ b/webapp/src/dom.ts @@ -1,5 +1,5 @@ // Building blocks for the views, as the mockups (plans/names-codes/mockups/domains.js) draw them. -import { seconds } from "./format.ts" +import { seconds, shortLabel } from "./format.ts" import { icon, type IconName } from "./icons.ts" import { qrSvg } from "./qr.ts" @@ -100,9 +100,27 @@ export function nameText(label: string, tld: string, after = ""): HTMLSpanElemen return el("span", { class: "nt" }, nameHead(label), el("span", { class: "nowrap" }, `${nameTail(label)}.${tld}${after}`)) } +type Drawn = (...text: Kid[]) => Kid +const asIs: Drawn = (...text) => text +const unread: Drawn = (...text) => el("span", { "aria-hidden": "true" }, ...text) + // `after` is a label that belongs to the name, kept with its last letters, so it never starts a line alone -export function nameTitle(label: string, cls = "name", tld = "simplex", ...after: Kid[]): HTMLDivElement { - return el("div", { class: cls }, nameHead(label), el("span", { class: "nowrap" }, nameTail(label), el("span", { class: "tld" }, `.${tld}`), ...after)) +export function nameTitle(label: string, cls = "name", tld = "simplex", drawn = asIs, ...after: Kid[]): HTMLDivElement { + return el("div", { class: cls }, drawn(nameHead(label)), el("span", { class: "nowrap" }, drawn(nameTail(label), el("span", { class: "tld" }, `.${tld}`)), ...after)) +} + +export interface ShortName { shown: string; whole: HTMLElement | null } + +export function shortName(label: string, tld: string, after = ""): ShortName { + const shown = shortLabel(label) + return { shown, whole: shown === label ? null : el("span", { class: "sr-only" }, `${label}.${tld}${after}`) } +} + +export const drawnOf = ({ whole }: ShortName): Drawn => whole ? unread : asIs + +export function shortNameText(label: string, tld: string, after = ""): Kid { + const name = shortName(label, tld, after) + return [drawnOf(name)(nameText(name.shown, tld, after)), name.whole] } export function gradName(label: string, tld = "simplex"): HTMLSpanElement { diff --git a/webapp/src/flow.ts b/webapp/src/flow.ts index acadc262..61ef17ed 100644 --- a/webapp/src/flow.ts +++ b/webapp/src/flow.ts @@ -38,6 +38,7 @@ export interface Draft { termStart: number ownerCode: string terms: string + disputeDays: number } export type Available = Extract & { community: api.Community | null } @@ -55,8 +56,8 @@ export async function quoteOf(label: string): Promise { } // An order of a record's name and links again, as a new order of its code: a new commitment for the term from now. -export const draftAgain = (record: store.OrderRecord, quote: Quote, terms: string): Draft => - ({ label: record.label, links: { contact: record.contact, channel: record.channel }, chain: chainOf(readSite()), years: api.termYears(quote.community, quote.years), termStart: readSite().termStart, ownerCode: record.ownerCode, terms }) +export const draftAgain = (record: store.OrderRecord, quote: Quote, terms: string, disputeDays: number): Draft => + ({ label: record.label, links: { contact: record.contact, channel: record.channel }, chain: chainOf(readSite()), years: api.termYears(quote.community, quote.years), termStart: readSite().termStart, ownerCode: record.ownerCode, terms, disputeDays }) export type BuiltOrder = { request: api.SignedOrder; owner: string } @@ -71,14 +72,14 @@ export async function orderRequest(draft: Draft): Promise { const sealed = await seal(wallet.seed, { label: draft.label, ...draft.links }) const owner = checksumAddress(wallet.address) const order = { labelHash: hex(labelHash(draft.label)), length: draft.label.length, duration: Number(duration), owner, commitment: hex(commitment), sealed, terms: draft.terms } - const reveal = signedReveal(wallet, r, commitment, await api.signFor(order.labelHash, owner), draft.chain) + const reveal = signedReveal(wallet, r, commitment, await api.signFor(order.labelHash, owner), draft.chain, draft.disputeDays) const message = `simplex.domains order ${order.labelHash} ${order.length} ${order.duration} ${order.commitment} ${await sha256Hex(sealed)} ${order.terms} ${timestamp}` return { request: { ...order, timestamp, signature: hex(signDigest(wallet.privateKey, personalDigest(message))), reveal }, owner } } -function signedReveal(wallet: Wallet, r: Registration, commitment: Uint8Array, toSign: api.ToSignRead, chain: Pick): api.RevealBody { +function signedReveal(wallet: Wallet, r: Registration, commitment: Uint8Array, toSign: api.ToSignRead, chain: Pick, disputeDays: number): api.RevealBody { const deadline = now() + REVEAL_DEADLINE_SECONDS - const digest = registerIntentDigest(BigInt(chain.chainId), fromHex(chain.sponsor), r, BigInt(toSign.intentNonce), BigInt(deadline)) + const digest = registerIntentDigest(BigInt(chain.chainId), fromHex(chain.sponsor), r, BigInt(disputeDays), BigInt(toSign.intentNonce), BigInt(deadline)) const a = toSign.acceptance const acceptance = { termsHash: a.termsHash, nonce: a.nonce, @@ -100,17 +101,30 @@ export function recordFor(draft: Draft, built: BuiltOrder, method: store.OrderRe } } -export async function revealFor(record: Pick, duration: number, toSign: api.ToSignRead): Promise { +export class DisputeDaysDeclined extends Error { + readonly days: number + readonly allowed: number + constructor(days: number, allowed: number) { + super("dispute_days") + this.days = days + this.allowed = allowed + } +} + +export async function revealFor(record: Pick, view: Pick, + toSign: api.ToSignRead): Promise { + const allowed = api.DISPUTE_DAYS[record.method] + if (view.disputeDays > allowed) throw new DisputeDaysDeclined(view.disputeDays, allowed) const wallet = walletOf(record.ownerCode)! const site = await namesSite() - const r = registrationOf(record.label, wallet.address, commitmentSecret(wallet.seed, record.label), record, site, BigInt(duration)) - return signedReveal(wallet, r, makeCommitment(r), toSign, site) + const r = registrationOf(record.label, wallet.address, commitmentSecret(wallet.seed, record.label), record, site, BigInt(view.duration)) + return signedReveal(wallet, r, makeCommitment(r), toSign, site, view.disputeDays) } export async function revealOrder(view: api.RegistrationView, record: store.OrderRecord): Promise { const toSign = api.toSignOf(view) if (toSign?.type !== "read") throw new Error("the order's view has nothing read to sign") - await api.reveal(view.id, await revealFor(record, view.duration, toSign)) + await api.reveal(view.id, await revealFor(record, view, toSign)) } async function sha256Hex(text: string): Promise { @@ -219,7 +233,7 @@ export async function restore(text: string): Promise { export async function ownOrderFor(ownerCode: string, nameHash: string): Promise { const wallet = walletOf(ownerCode)! const found = (await findOrders(wallet)).filter((r) => r.labelHash === nameHash) - const chosen = found.find((r) => !["unpaid", "closed", "taken"].includes(r.phase)) ?? found.find((r) => r.phase === "unpaid") + const chosen = found.find((r) => !["unpaid", "closed", "ended", "taken"].includes(r.phase)) ?? found.find((r) => r.phase === "unpaid") return chosen ? (await reopen(wallet, ownerCode, chosen)).record : null } diff --git a/webapp/src/format.ts b/webapp/src/format.ts index 2f5ef0d9..8dab0d8f 100644 --- a/webapp/src/format.ts +++ b/webapp/src/format.ts @@ -12,6 +12,13 @@ export function shortAddress(address: string): string { return `${address.slice(0, 6)}\u2060…\u2060${address.slice(-4)}` } +const WHOLE_LABEL_MAX = 25 +const SHORT_LABEL_HEAD = 12 +const SHORT_LABEL_TAIL = 3 + +export const shortLabel = (label: string) => + label.length > WHOLE_LABEL_MAX ? `${label.slice(0, SHORT_LABEL_HEAD)}...${label.slice(-SHORT_LABEL_TAIL)}` : label + export function letters(n: number): string { return n === 1 ? "1 letter" : `${n} letters` } diff --git a/webapp/src/screens/checkout.ts b/webapp/src/screens/checkout.ts index 6abe6ad5..4f569127 100644 --- a/webapp/src/screens/checkout.ts +++ b/webapp/src/screens/checkout.ts @@ -1,4 +1,4 @@ -import type { Community, Method, Terms } from "../api.ts" +import { type Community, DISPUTE_DAYS, type Method, type Terms } from "../api.ts" import type { LinkKind } from "../names.ts" import type { AppliedCode, Checkout } from "../session.ts" import { type Hold, NO_LEAD } from "./hold.ts" @@ -114,6 +114,9 @@ export function codeEntry(c: Checkout, codesOnly: boolean): "field" | "link" | n // the open code field takes the payment choices' place, and the order waits for a code there that covers the name export const awaitsCode = (c: Checkout, codesOnly: boolean) => codeEntry(c, codesOnly) === "field" && c.code === null +export const disputeDaysOf = (c: Checkout, codesOnly: boolean) => + DISPUTE_DAYS[c.order ? c.order.method : c.code || codeEntry(c, codesOnly) === "field" ? "code" : c.method] + // the review opens once the name code is saved and a community name's terms are accepted on their own step, which only a // community name has export function stepFor(c: Checkout, asked: CheckoutStep): CheckoutStep { diff --git a/webapp/src/screens/names.ts b/webapp/src/screens/names.ts index 59c1a51d..496faa84 100644 --- a/webapp/src/screens/names.ts +++ b/webapp/src/screens/names.ts @@ -161,8 +161,8 @@ export function nameRows(s: ListState): OrderRecord[] { // A registered name past its expiry: there are no renewals, so the page takes it as over, though the chain keeps it its // holder's through the grace period, and whether or not someone has registered it again since. -export const lapsed = ({ view, answer }: Pick, now: number) => - view.phase.type === "registered" && (view.phase.expiresAt < now / 1000 || answer?.found.type === "available") +export const lapsed = ({ view }: Pick, now: number) => + view.phase.type === "registered" && view.phase.expiresAt < now / 1000 export const waitsToSign = (view: RegistrationView, now: number) => view.phase.type === "committed" && view.label === null && now / 1000 >= view.phase.revealAfter @@ -170,7 +170,7 @@ export const waitsToSign = (view: RegistrationView, now: number) => const PHASE_CHIPS: Record, [string, string]> = { unpaid: ["Waiting for payment", "warn"], queued: ["Registering", "brand"], committing: ["Registering", "brand"], committed: ["Registering", "brand"], registering: ["Registering", "brand"], - registered: ["Registered", "ok"], taken: ["Taken first", "warn"], failed: ["Not registered", "bad"], + registered: ["Registered", "ok"], ended: ["Ended", "bad"], taken: ["Taken first", "warn"], failed: ["Not registered", "bad"], } const CHIPS = { @@ -221,7 +221,7 @@ export const CODE_CHIPS: Record = { } export function editable({ found }: SearchAnswer, owner: string): boolean { - if (found.type !== "registered") return true + if (found.type !== "registered") return false return found.owner.toLowerCase() === owner.toLowerCase() && found.records.type === "own" } @@ -259,7 +259,7 @@ export function reduceRestore(s: RestoreState, e: RestoreEvent): RestoreState { } export const EDIT_RETRY_MS = 5000 -export type EditKind = "edit" | "edit-unreadable" | "edit-no-code" | "edit-expired" | "edit-in-app" | "edit-elsewhere" | "edit-not-registered" +export type EditKind = "edit" | "edit-unreadable" | "edit-no-code" | "edit-expired" | "edit-ended" | "edit-in-app" | "edit-elsewhere" | "edit-not-registered" interface EditRead { view: RegistrationView; answer: SearchAnswer; now: number } type EditResult = "sending" | "nothing" | "saved" | "unanswered" | "moved" | "refused" @@ -347,7 +347,9 @@ export function screenOfEdit(s: EditState): EditKind { if (!s.read) return "edit-unreadable" const { view, answer, now } = s.read const { found } = answer + if (view.phase.type === "ended") return "edit-ended" if (lapsed({ view, answer }, now)) return "edit-expired" + if (view.phase.type === "registered" && found.type !== "registered") return "edit-unreadable" if (found.type === "registered" && !owns(found, s.record.owner)) return "edit-in-app" if (found.type === "registered" && found.records.type === "other") return "edit-elsewhere" if (view.phase.type !== "registered" || found.type !== "registered") return "edit-not-registered" diff --git a/webapp/src/screens/order.ts b/webapp/src/screens/order.ts index 0cc3b051..6561d6c1 100644 --- a/webapp/src/screens/order.ts +++ b/webapp/src/screens/order.ts @@ -1,4 +1,4 @@ -import { committedOf, type Community, type FailReason, type Found, holdsPayment, type InvoiceView, lapsedOf, paidLate, type RegistrationView, reversedOrder, type Terms, toSignOf } from "../api.ts" +import { committedOf, type Community, disputeUntilOf, type FailReason, type Found, holdsPayment, type InvoiceView, lapsedOf, paidLate, type RegistrationView, reversedOrder, type Terms, toSignOf } from "../api.ts" import type { IconName } from "../icons.ts" import type { CodeRefusal, OrderRecord } from "../store.ts" import { type Hold, NO_LEAD } from "./hold.ts" @@ -17,7 +17,7 @@ export const TX_STALL_MS = 180_000 const UNREAD_PACING_MS = [5_000, 15_000, 30_000] export const unreadDelay = (reads: number) => UNREAD_PACING_MS[Math.min(reads, UNREAD_PACING_MS.length - 1)] -export type OrderKind = "pay-crypto" | "pay-card" | "confirming" | "registering" | "registered" | "taken" | "failed" | "not-on-device" +export type OrderKind = "pay-crypto" | "pay-card" | "confirming" | "registering" | "registered" | "ended" | "taken" | "failed" | "not-on-device" | "status:closed" | "status:card-unconfirmed" | "status:paid-by-invoice" | "status:unreadable" | "status:unknown-link" | "status:price-changed" export type ClosedCase = "paid-late" | "cancelled" | "received" | "expired" | "reversed" @@ -53,6 +53,7 @@ export interface OrderState { nameStatus: Found["type"] | null // when this page first saw the stage, or the buyer ticked changed terms in it, on the service's clock since: { stage: string; at: number } | null + declined: { key: string; days: number; allowed: number } | null } export type OrderEvent = @@ -69,6 +70,7 @@ export type OrderEvent = | { type: "reveal-refused"; key: string } | { type: "reveal-failed"; key: string } | { type: "reveal-retried" } + | { type: "reveal-declined"; key: string; days: number; allowed: number } | { type: "cancel-started" } | { type: "cancel-answered" } | { type: "cancel-failed"; note: Note } @@ -88,7 +90,7 @@ export type OrderEvent = | { type: "hold-ended" } export function initialState(reference: string, hold: Hold | null, reveal: Reveal | null = null): OrderState { - return { reference, seq: 0, now: 0, invoice: null, view: null, record: null, cardSubmittedAt: null, cardFailed: false, reveal, busy: null, note: null, hold, price: null, gone: false, codeRefused: false, codeKept: false, codeCheckAt: null, ask: null, nameStatus: null, since: null } + return { reference, seq: 0, now: 0, invoice: null, view: null, record: null, cardSubmittedAt: null, cardFailed: false, reveal, busy: null, note: null, hold, price: null, gone: false, codeRefused: false, codeKept: false, codeCheckAt: null, ask: null, nameStatus: null, since: null, declined: null } } const stageOf = (view: RegistrationView) => `${view.id} ${view.phase.type}${view.phase.type === "committed" && view.label !== null ? " signed" : ""}` @@ -119,6 +121,7 @@ function apply(s: OrderState, e: OrderEvent): OrderState { case "reveal-refused": return s.reveal?.key === e.key ? { ...s, reveal: { ...s.reveal, sending: false, refusals: s.reveal.refusals + 1 } } : s case "reveal-failed": return s.reveal?.key === e.key ? { ...s, reveal: { ...s.reveal, sending: false } } : s case "reveal-retried": return s.reveal ? { ...s, reveal: { ...s.reveal, refusals: 0 } } : s + case "reveal-declined": return { ...s, declined: { key: e.key, days: e.days, allowed: e.allowed }, reveal: s.reveal?.key === e.key ? { ...s.reveal, sending: false } : s.reveal } case "cancel-started": return start(s, "cancel") case "cancel-answered": return end(s, "cancel", {}) case "cancel-failed": return end(s, "cancel", { note: e.note }) @@ -198,6 +201,11 @@ export const coinOf = (invoice: InvoiceView) => invoice.cryptoCurrency === "btc" // What the order's name costs; null for a code, which costs nothing. export const costOf = (view: RegistrationView, invoice: InvoiceView | null): number | null => invoice ? view.price : null +export function disputeEndAhead({ view, now }: OrderState): number | null { + const until = view && disputeUntilOf(view) + return until && until * 1000 > now ? until : null +} + export function screenOf(s: OrderState): OrderKind { if (s.gone) return "status:unknown-link" if (s.price !== null) return "status:price-changed" @@ -207,6 +215,7 @@ export function screenOf(s: OrderState): OrderKind { if (invoice && unpaidOrClosed(view)) return paymentKind(s, invoice) if (unpaidOrClosed(view)) return "status:paid-by-invoice" if (view.phase.type === "registered") return "registered" + if (view.phase.type === "ended") return "ended" if (view.phase.type === "taken") return "taken" if (view.phase.type === "failed") return "failed" if (view.phase.type !== "registering" && view.label === null && !record) return "not-on-device" @@ -225,7 +234,7 @@ export function closedBalance(s: OrderState): "offer" | "replaced" | null { // A taken or failed order is followed too, since another tab or browser can select a name for it or retry it. Money paid after the close // is followed until it is all in the order's balance, or until the service says only support can credit it. export function finished(invoice: InvoiceView | null, view: RegistrationView): boolean { - if (view.phase.type === "registered" || reversedOrder(view)) return true + if (view.phase.type === "registered" || view.phase.type === "ended" || reversedOrder(view)) return true if (!unpaidOrClosed(view) || !invoice || invoice.status === "open") return false if (view.latePayment) return view.latePayment === "support" return paidLate(invoice) && view.balance !== null @@ -255,7 +264,7 @@ export const readToSign = (view: RegistrationView) => { export const revealKey = (view: RegistrationView) => { const read = readToSign(view) - return `${view.id} ${view.commitment} ${read?.intentNonce ?? null} ${committedOf(view)?.revealBefore ?? null}${read ? ` ${read.acceptance.policy} ${read.acceptance.termsHash} ${read.acceptance.nonce}` : ""}` + return `${view.id} ${view.commitment} ${read?.intentNonce ?? null} ${committedOf(view)?.revealBefore ?? null} ${view.disputeDays}${read ? ` ${read.acceptance.policy} ${read.acceptance.termsHash} ${read.acceptance.nonce}` : ""}` } // The terms of the name's kind on chain are not the ones the order signed, so the buyer agrees to them again before the reveal. @@ -273,13 +282,15 @@ export const termsToAgree = (s: OrderState) => termsChanged(s) && !(termsAskedAg // The changed terms are asked for once the order is committed and they are not asked for yet. export const askAgainDue = (s: OrderState) => !!s.record && termsChanged(s) && !termsAskedAgain(s) +export const declinedNow = ({ view, declined }: OrderState) => view && declined?.key === revealKey(view) ? declined : null + export function refusalsOf({ view, reveal }: OrderState): number { return view?.phase.type === "committed" && reveal?.key === revealKey(view) ? reveal.refusals : 0 } export function revealDue(s: OrderState): boolean { const { view, record, reveal } = s - if (view?.phase.type !== "committed" || view.label !== null || !readToSign(view) || !record) return false + if (view?.phase.type !== "committed" || view.label !== null || !readToSign(view) || !record || declinedNow(s)) return false if (termsToAgree(s)) return false if (view.phase.revealAfter * 1000 > s.now) return false return !(reveal?.key === revealKey(view) && reveal.sending) && refusalsOf(s) < REVEAL_ATTEMPTS @@ -287,7 +298,7 @@ export function revealDue(s: OrderState): boolean { export function stalledAt(s: OrderState): number | null { const { view, since } = s - if (!view || !since || screenOf(s) !== "registering" || refusalsOf(s) >= REVEAL_ATTEMPTS || (termsAskedAgain(s) && !ticked(s.ask!))) return null + if (!view || !since || screenOf(s) !== "registering" || refusalsOf(s) >= REVEAL_ATTEMPTS || (termsAskedAgain(s) && !ticked(s.ask!)) || declinedNow(s)) return null if (view.phase.type !== "committed" || view.label !== null) return since.at + TX_STALL_MS return Math.max(since.at, view.phase.revealAfter * 1000) + REVEAL_ATTEMPTS * RETRY_MS + STALL_MARGIN_MS } @@ -296,6 +307,7 @@ export function stalledAt(s: OrderState): number | null { export function wakeAt(s: OrderState): number | null { const { invoice, view, record, cardSubmittedAt, now } = s const moments = [ + view?.phase.type === "registered" && view.phase.disputeUntil !== undefined ? view.phase.disputeUntil * 1000 : null, invoice?.status === "open" && !coinOf(invoice) && record && cardSubmittedAt ? Date.parse(cardSubmittedAt) + CARD_SLOW_MS : null, view?.phase.type === "committed" ? view.phase.revealAfter * 1000 : null, ].filter((at): at is number => at !== null && at > now) diff --git a/webapp/src/screens/search.ts b/webapp/src/screens/search.ts index c3d0f565..0dbd0dcc 100644 --- a/webapp/src/screens/search.ts +++ b/webapp/src/screens/search.ts @@ -102,7 +102,7 @@ export function reduce(s: SearchState, e: SearchEvent): SearchState { export interface OrderRead { phase: Phase; failure: FailReason | null; invoice: InvoiceView["status"] | null } export interface OwnOrders { open: OrderRecord | null; closed: OrderRecord | null } -const ENDED: Phase[] = ["closed", "registered", "taken"] +const ENDED: Phase[] = ["closed", "registered", "ended", "taken"] const ended = (r: OrderRead) => ENDED.includes(r.phase) || r.failure === "monthEnded" // This browser's orders for a name, newest first: the first that can still register it, and the newest that closed diff --git a/webapp/src/styles.css b/webapp/src/styles.css index b79fcb7d..1e545a9f 100644 --- a/webapp/src/styles.css +++ b/webapp/src/styles.css @@ -361,13 +361,14 @@ html.framed body > main:empty { min-height: calc(var(--step-h) + var(--screen-to .trow.total { margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--surface-line); font-size: 17px; } .trow.total span { color: var(--ink); font-weight: 700; } /* the term's free days, whose hint shows over the rows under it, so nothing moves */ -.bonus { position: relative; } -.bonus > .days { all: unset; border-radius: 4px; color: var(--ok-fg); cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; } -.bonus > .days:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } -.bonus > .tip { position: absolute; top: calc(100% + 6px); right: 0; z-index: 1; width: max-content; max-width: min(300px, calc(100vw - 48px)); padding: 8px 12px; +:is(.bonus, .period) { position: relative; } +:is(.bonus, .period) > .days { all: unset; border-radius: 4px; color: var(--ok-fg); cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; } +.period > .days { color: inherit; } +:is(.bonus, .period) > .days:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +:is(.bonus, .period) > .tip { position: absolute; top: calc(100% + 6px); right: 0; z-index: 1; width: max-content; max-width: min(300px, calc(100vw - 48px)); padding: 8px 12px; border-radius: 10px; background: var(--ink); color: var(--surface); font-size: var(--fs-small); font-weight: 500; line-height: 1.4; text-align: left; white-space: normal; visibility: hidden; opacity: 0; transition: opacity var(--fast), visibility var(--fast); } -.bonus:is(:hover, :focus-within):not(.hushed) > .tip { visibility: visible; opacity: 1; } +:is(.bonus, .period):is(:hover, :focus-within):not(.hushed) > .tip { visibility: visible; opacity: 1; } .pay-with, .code-entry, .link-fields, .forget { --block-gap: 12px; display: grid; gap: var(--block-gap); } /* an empty verdict or note stays in the accessibility tree, so its next words are announced; in a column, unlike a grid, its negative margin takes back the gap */ @@ -408,16 +409,13 @@ html.framed body > main:empty { min-height: calc(var(--step-h) + var(--screen-to .preview .entity { flex: 1; } /* while the field is focused its link shows alone, from its start, at the field's whole width */ .link-field .field:focus-within .preview { display: none; } -.review { display: grid; gap: 14px; } -/* a review holding a refusal's line is drawn tighter, so its fullest state, with a name of 63 wide letters, fits the frame */ -.review:has(.line) { gap: 8px; } -.review:has(.line) .pay-with { --block-gap: 8px; } -.review:has(.line) .trow { padding-block: 4px; } -/* a name that breaks over lines takes room, so the review draws as tight as with a line */ -.review:has(.order .name:not(.whole)) { gap: 8px; } -.review:has(.order .name:not(.whole)) .trow { padding-block: 4px; } -.screen-body:has(> .review .line) { --body-gap: 8px; } -.screen-body:has(> .review .line) > [role="status"]:empty { margin-top: -8px; } +.review { display: grid; gap: 8px; } +.review .pay-with { --block-gap: 8px; } +.review .trow { padding-block: 4px; } +.review:has(.line) .order > .row { min-height: 0; } +.review:has(.line) .trow { line-height: 1.3; } +.screen-body:has(> .review) { --body-gap: 8px; } +.screen-body:has(> .review) > [role="status"]:empty { margin-top: -8px; } /* the link to a code just under the payment choices, and the field it opens in their place */ .have-code { display: grid; justify-items: center; font-size: var(--fs-small); } .have-code:has(> a) { margin-block: -8px; line-height: 1.2; } @@ -641,6 +639,7 @@ html.dark .monero-base { fill: #fff; } .check:hover .box { border-color: var(--primary); } .cinfo:hover { background: var(--chip); } .bonus > .days:hover { background: var(--ok-bg); } + .period > .days:hover { background: var(--chip); } } /* after the hover rules and as specific as the quiet one, as a button pressed with a mouse still matches them */ :is(.btn, .btn.quiet):not([disabled], [aria-busy="true"]):active { filter: brightness(.94); } @@ -664,6 +663,7 @@ a[aria-disabled="true"] { opacity: .6; cursor: default; } .field-copy { position: relative; } .field-copy::before { content: ""; position: absolute; inset: -6px; } .row > a, .alt a, .acts a, .end-links a, .have-code > a { padding-block: 12px; margin-block: -12px; } + .have-code:has(> a) { margin-top: 4px; } } /* a phone: its heading smaller, Back above it on a line kept on every screen, and the main button across the column with diff --git a/webapp/src/views/checkout.ts b/webapp/src/views/checkout.ts index 554fdb50..5bf4110f 100644 --- a/webapp/src/views/checkout.ts +++ b/webapp/src/views/checkout.ts @@ -8,7 +8,7 @@ import { type Method, methodMark } from "../icons.ts" import type { LinkKind } from "../names.ts" import { RETRY_MS } from "../screens/order.ts" import { - awaitsCode, changeOf, codeEntry, type CheckoutEvent, type CheckoutKind, type CheckoutState, initialState, METHODS, reduce, screenOf, stepFor, type WaitingOrder, + awaitsCode, changeOf, codeEntry, disputeDaysOf, type CheckoutEvent, type CheckoutKind, type CheckoutState, initialState, METHODS, reduce, screenOf, stepFor, type WaitingOrder, } from "../screens/checkout.ts" import { CODES_ONLY, codesOnly } from "../mode.ts" import { type CheckoutStep, checkoutUrl, CODE_URL } from "../screens/routes.ts" @@ -24,7 +24,7 @@ import { holdEnd, holdEnder, holdFrom, holding, holdNotice, tabHold } from "./ho import { openedInstead, REFUSED_LINK, REPLACE_LINK } from "./order.ts" import { readOrder } from "./search.ts" import { loadNextRouteAfresh } from "./served-mode.ts" -import { CANT_SHOW, commitLink, communityCheck, NO_ORDERS, rowName, termsBox, termsChangedLine, termsText } from "./terms.ts" +import { CANT_SHOW, commitLink, communityCheck, NO_ORDERS, shortRowName, termsBox, termsChangedLine, termsText } from "./terms.ts" const CHECKOUT_NOTE = "checkout-note" const SAVED_LABEL = "I have saved my name code" @@ -157,35 +157,42 @@ async function showOpenOrder(signal: AbortSignal): Promise { const row = (what: string, value: Kid, cls?: string) => el("div", { class: `trow${cls ? ` ${cls}` : ""}` }, el("span", {}, what), el("span", {}, value)) -const BONUS_HINT = "bonus-hint" const HUSHED = "hushed" +function hinted(cls: string, shown: string, hint: string): HTMLElement { + const days = el("button", { class: "days", type: "button", "aria-describedby": `${cls}-hint`, "data-focus": cls }, shown) + const holder = el("span", { class: cls }, days, el("span", { class: "tip", id: `${cls}-hint`, role: "tooltip" }, hint)) + days.addEventListener("keydown", (e) => { if (e.key === "Escape") holder.classList.add(HUSHED) }) + days.addEventListener("blur", () => holder.classList.remove(HUSHED)) + holder.addEventListener("mouseleave", () => holder.classList.remove(HUSHED)) + return holder +} + // The free days before the paid years start, with a hint saying why, which shows over the page on hover, focus or tap // and Escape hides. function term(years: number, termStart: number, now: number): Kid { const free = freeDays(termStart, now) if (free === 0) return `${years} years` - const days = el("button", { class: "days", type: "button", "aria-describedby": BONUS_HINT, "data-focus": "bonus" }, bonusDays(free)) - const bonus = el("span", { class: "bonus" }, days, el("span", { class: "tip", id: BONUS_HINT, role: "tooltip" }, bonusHint(years, termStart))) - days.addEventListener("keydown", (e) => { if (e.key === "Escape") bonus.classList.add(HUSHED) }) - days.addEventListener("blur", () => bonus.classList.remove(HUSHED)) - bonus.addEventListener("mouseleave", () => bonus.classList.remove(HUSHED)) - return [`${years} years `, bonus] + return [`${years} years `, hinted("bonus", bonusDays(free), bonusHint(years, termStart))] } +const disputeLine = (days: number) => `For ${days} days after it is registered, the registration can be ended if a payment for it is disputed, reversed or refunded in full.` + // The order as the search answered it, with the chats its links open, over its term, with the free days before it // starts, its end, and what it costs; a name registered with a code costs nothing. In codes-only mode every order is registered with a code. function orderCard(c: session.Checkout, codesOnly: boolean): HTMLElement { const y = years(c) + const disputeDays = disputeDaysOf(c, codesOnly) const now = api.serviceNow() / 1000 const name = `${c.label}.${c.chain.tld}` const chats = api.LINK_KINDS.filter((kind) => c[kind]).map((kind) => linkChat(c[kind], kind, name, `chat-${kind}`)) const side = chats.length ? el("span", { class: "chats" }, chats) : null return el("section", { class: "card order" }, - el("div", { class: "row" }, rowName(c.label, c.chain.tld, c.community, "community"), side), + el("div", { class: "row" }, shortRowName(c.label, c.chain.tld, c.community, "community"), side), el("div", { class: "table" }, row("Term", term(y, c.termStart, now)), row("Registered until", dateOf(termEnd(y, c.termStart, now))), + row("Dispute period", hinted("period", `${disputeDays} days`, disputeLine(disputeDays))), c.code || codesOnly || c.order?.method === "code" ? el("div", { class: "trow total" }, el("span", {}, "Free SimpleX name")) : row("Total", c.order?.paid === c.price ? "Paid" : dollars(c.price), "total"), c.code && y < c.code.years ? el("p", { class: "hint" }, `A community name is registered for ${y} years, not your code's ${c.code.years}.`) : null)) @@ -454,7 +461,7 @@ async function sendOrder(): Promise { dispatch({ type: "send-started" }) const links = { contact: c.contact, channel: c.channel } const terms = api.termsFor(c.terms, c.community) - const draft: flow.Draft = { label: c.label, links, chain: c.chain, years: years(c), termStart: c.termStart, ownerCode: c.ownerCode!, terms } + const draft: flow.Draft = { label: c.label, links, chain: c.chain, years: years(c), termStart: c.termStart, ownerCode: c.ownerCode!, terms, disputeDays: disputeDaysOf(c, state.codesOnly) } // The order is kept whatever the buyer did meanwhile. Its checkout ends, and the order opens, only while this checkout // is still the tab's: the buyer may have started another name, by Back and Forward too. const mine = currentRoute() diff --git a/webapp/src/views/names.ts b/webapp/src/views/names.ts index 28a31eff..12ebb627 100644 --- a/webapp/src/views/names.ts +++ b/webapp/src/views/names.ts @@ -650,6 +650,7 @@ const EDIT_BUILDERS: Record> = { "edit-no-code": (s) => editNotice(s, alertBox("info", "key", "The name code is not in this browser", "Add it in Check your code to edit this name's links.")), "edit-unreadable": buildUnreadable, "edit-expired": buildExpired, + "edit-ended": notice("alert", "The registration was ended", "A payment for it was disputed, reversed or refunded in full, so this page no longer edits its links."), "edit-in-app": notice("key", "This name has another owner", "Its owner changed, so this browser can no longer edit its links."), "edit-elsewhere": notice("link", "This name's links are kept elsewhere", "It points at another resolver, so its links are not edited here."), "edit-not-registered": notice("clock", "The name is not registered yet", "Its links can be edited once the registration is final."), diff --git a/webapp/src/views/order.ts b/webapp/src/views/order.ts index 2b90f9f8..17939efd 100644 --- a/webapp/src/views/order.ts +++ b/webapp/src/views/order.ts @@ -1,12 +1,12 @@ // An order's page (?order=) or a code registration's (?registration=): payment, registration, and every ending. import * as api from "../api.ts" import { namesSite, readSite } from "../config.ts" -import { alertBox, announce, btn, codeDisplay, copyButton, el, gradName, icon, type Kid, link, nameCodeQr, nameText, refill, setAction, type Tone, waitOut } from "../dom.ts" +import { alertBox, announce, btn, codeDisplay, copyButton, el, gradName, icon, type Kid, link, nameCodeQr, nameText, refill, setAction, shortNameText, type Tone, waitOut } from "../dom.ts" import * as flow from "../flow.ts" import { clock, dateOf, dollars, methodName, SEP, shortAddress, timeOf } from "../format.ts" import { paymentUri, qrSvg } from "../qr.ts" import { - closedBalance, type ClosedCase, closedCase, coinOf, costOf, failedAlert, failedLead, finished, supportCase, type SupportCase, initialState, type Note, type OrderEvent, type OrderKind, + closedBalance, type ClosedCase, closedCase, coinOf, costOf, declinedNow, disputeEndAhead, failedAlert, failedLead, finished, supportCase, type SupportCase, initialState, type Note, type OrderEvent, type OrderKind, type OrderState, readToSign, reduce, refusalsOf, RETRY_MS, retryDue, REVEAL_ATTEMPTS, revealDue, revealKey, screenOf, stalledAt, unpaidOrClosed, unreadDelay, wakeAt, askAgainDue, termsAskedAgain, termsToAgree, } from "../screens/order.ts" import { termsToSign, ticked } from "../screens/terms.ts" @@ -23,7 +23,7 @@ import { holdEnd, holdEnder, holdFrom, holdNotice, tabHold } from "./hold.ts" import { loadNextRouteAfresh, UNKEPT_TICKS } from "./served-mode.ts" import { NO_ORDERS, termsBox } from "./terms.ts" import { - asStep, type Builder, contactSupport, currentRoute, draw, drawLoading, focusOn, go, historyPlace, isRedraw, isRoute, kept, keptLive, outcome, pageTheme, redirect, referenceLine, refresh, screen, + asStep, type Builder, CONTACT_EMAIL, contactSupport, currentRoute, draw, drawLoading, focusOn, go, historyPlace, isRedraw, isRoute, kept, keptLive, outcome, pageTheme, redirect, referenceLine, refresh, screen, searchLink, showRefund, whenDropped, whenLeaving, } from "./shell.ts" @@ -87,10 +87,12 @@ function dispatch(event: OrderEvent): void { wakeOnTime() } +const LONGEST_TIMEOUT_MS = 2 ** 31 - 1 + function wakeOnTime(): void { clearTimeout(wakes) const at = wakeAt(state) - if (at !== null) wakes = setTimeout(() => dispatch({ type: "tick", now: api.serviceNow() }), at - api.serviceNow()) + if (at !== null) wakes = setTimeout(() => dispatch({ type: "tick", now: api.serviceNow() }), Math.min(at - api.serviceNow(), LONGEST_TIMEOUT_MS)) } const isOpen = (gen: number) => gen === opened && isRoute(pageRoute) @@ -312,6 +314,11 @@ function reveal(view: api.RegistrationView, record: store.OrderRecord): void { const reference = state.reference dispatch({ type: "reveal-sent", key }) flow.revealOrder(view, record).catch((e) => { + if (e instanceof flow.DisputeDaysDeclined) { + dispatch({ type: "reveal-declined", key, days: e.days, allowed: e.allowed }) + if (isRoute(pageRoute) && state.reference === reference) announce(`${NOT_SIGNABLE}. ${overDays(e)} Write to ${CONTACT_EMAIL} with the reference below.`) + return + } const refused = e instanceof api.ApiError && e.code === "bad_request" setTimeout(() => { dispatch({ type: refused ? "reveal-refused" : "reveal-failed", key }) @@ -960,7 +967,7 @@ async function newInvoice(invoice: api.InvoiceView, record: store.OrderRecord | const signed = api.signedTermsOf(now.registration.terms) const terms = termsOrAsk(gen, record, signed, quote) if (terms === null) return - const built = await flow.orderRequest(flow.draftAgain(record, quote, terms)) + const built = await flow.orderRequest(flow.draftAgain(record, quote, terms, api.DISPUTE_DAYS[method])) const res = await api.createOrder(built.request, method, invoice.amount, readSite().chainId) const next = store.orderUrl({ invoiceId: res.invoiceId, registrationId: res.registration.id }) // the old record is the stored owner code until the new one is stored too @@ -1029,6 +1036,9 @@ function leadOf(s: OrderState): Kid { return "Keep this page open until the name is registered." } +const NOT_SIGNABLE = "This order cannot be signed" +const overDays = ({ days, allowed }: { days: number; allowed: number }) => `Its registration could be ended for ${days} days, longer than the ${allowed} days its payment allows.` + const WAIT_NOTE = "Every new name waits a little, so nobody who sees your order can take the name first." const COMMIT_NOTE = "Placing your order. The wait starts once it is in." const LAPSED_NOTE = "The name was not signed in time" @@ -1040,6 +1050,7 @@ function buildRegistering(s: OrderState, signal: AbortSignal): HTMLElement { const states = stagesOf(view) sayStage(view, states) const refused = refusalsOf(s) >= REVEAL_ATTEMPTS + const declined = declinedNow(s) const steps = stages(states) const stalled = stalledAt(s) const lapsed = api.lapsedOf(view) @@ -1063,14 +1074,15 @@ function buildRegistering(s: OrderState, signal: AbortSignal): HTMLElement { if (stalled !== null && api.serviceNow() >= stalled) return say(note, STALL_NOTE) if (view.phase.type !== "committed") return say(note, view.phase.type === "registering" ? REGISTERING_NOTE : COMMIT_NOTE) waitsSeen.delete(view.id) - if (view.label === null && (refused || termsToAgree(s))) say(note, "The registration is not signed yet.") + if (view.label === null && (refused || declined || termsToAgree(s))) say(note, "The registration is not signed yet.") else say(note, REGISTERING_NOTE) } onTheSecond(() => waitLeft(view), tick, signal) - return screen({ title: headingOf(s), lead: leadOf(s), action: refused ? btn("Try again", "", tryAgain) : null }, + return screen({ title: headingOf(s), lead: declined ? null : leadOf(s), action: refused ? btn("Try again", "", tryAgain) : null }, steps, // the note keeps the height of its longest words, so the page keeps still as they change el("div", { class: "countdown" }, clockNode, el("p", {}, note, el("span", { class: "sizer", "aria-hidden": "true" }, WAIT_NOTE))), + declined ? alertBox("danger", "alert", NOT_SIGNABLE, [`${overDays(declined)} Write to `, el("a", { href: `mailto:${CONTACT_EMAIL}` }, CONTACT_EMAIL), " with the reference below."]) : null, refused ? alertBox("danger", "alert", "The name could not be signed", "The service refused the signed registration.") : null, referenceLine(s.invoice?.invoiceId ?? view.id), termsAskedAgain(s) ? agreement(s, "reveal") : null) @@ -1126,19 +1138,27 @@ function buildRegistered(s: OrderState): HTMLElement { // the code's QR is under everything, there only while the code is shown const qr = el("div", { class: "code-qr" }) const { tld } = readSite() - return screen({ title: [label ? gradName(label, tld) : "The name", " is\u00a0yours"], lead: registeredLead(view, s.record), action: registeredAction(s.record) }, + return screen({ title: [label ? gradName(label, tld) : "The name", " is\u00a0yours"], lead: registeredLead(view, s.record, disputeEndAhead(s)), action: registeredAction(s.record) }, code ? [el("div", { class: "card use" }, el("h2", {}, "Use in the app"), - el("p", {}, "In SimpleX, open Your SimpleX address, tap Set SimpleX name and enter ", nameText(label ?? "", tld, "."), " For a channel, set it in the channel's profile.")), + el("p", {}, "In SimpleX, open Your SimpleX address, tap Set SimpleX name and enter ", shortNameText(label ?? "", tld, "."), " For a channel, set it in the channel's profile.")), el("p", { class: "note center" }, "Keep your name code: it owns the name and edits its links."), codeDisplay(code, "owner-code", true, (shown) => refill(qr, shown && nameCodeQr(code))), // under the code and over its QR, so showing the code moves it and nothing above it el("div", { class: "yours-edit center" }, btn(linksAction(hasLinks(s.record!, null)), "quiet small", () => go(editUrl(view.id)))), qr] : null) } -function registeredLead(view: api.RegistrationView, record: store.OrderRecord | null): string { +function registeredLead(view: api.RegistrationView, record: store.OrderRecord | null, disputeUntil: number | null): string { const expiresAt = api.expiresAtOf(view) const until = expiresAt ? dateOf(expiresAt) : "" - return record ? `Registered until ${until}.` : `Registered until ${until} to ${shortAddress(view.owner)}. Its name code is not in this browser.` + const dispute = disputeUntil === null ? "" : ` It can be ended until ${dateOf(disputeUntil)} if a payment for it is disputed, reversed or refunded in full.` + return record ? `Registered until ${until}.${dispute}` : `Registered until ${until} to ${shortAddress(view.owner)}.${dispute} Its name code is not in this browser.` +} + +function buildEnded({ view, record, invoice }: OrderState): HTMLElement { + const label = labelOf(view!, record) + return outcome({ tone: "warn", icon: "alert", title: "Registration ended", + text: ["The registration of ", label ? nameText(label, readSite().tld) : "the name", " was ended because a payment for it was disputed, reversed or refunded in full."], + action: codesOnly() ? codeAction() : btn("Search a name", "", () => go(searchLink(""))), reference: invoice?.invoiceId ?? view!.id }) } // An order taken first keeps its payment or its code: a name is selected for the order, or support refunds the payment; @@ -1216,11 +1236,13 @@ async function continueOrder(): Promise { const view = state.view! dispatch({ type: "continue-started" }) try { - await api.reveal(view.id, await flow.revealFor(record, view.duration, await api.signFor(view.labelHash, view.owner))) + await api.reveal(view.id, await flow.revealFor(record, view, await api.signFor(view.labelHash, view.owner))) reread(gen) } catch (e) { if (holdOn(e, "Nothing changed. ", gen)) return - answer(gen, { type: "continue-failed", note: warning("That did not go through. Nothing changed. Try again in a moment.") }) + const note: Note = e instanceof flow.DisputeDaysDeclined ? { tone: "danger", icon: "alert", title: NOT_SIGNABLE, text: `${overDays(e)} Write to ${CONTACT_EMAIL} with the reference below.` } + : warning("That did not go through. Nothing changed. Try again in a moment.") + answer(gen, { type: "continue-failed", note }) reread(gen) } } @@ -1245,6 +1267,7 @@ const BUILDERS: Record> = { confirming: buildConfirming, registering: buildRegistering, registered: buildRegistered, + ended: buildEnded, taken: buildTaken, failed: buildFailed, "not-on-device": buildNotOnDevice, diff --git a/webapp/src/views/terms.ts b/webapp/src/views/terms.ts index 176c6c4c..1c7d086e 100644 --- a/webapp/src/views/terms.ts +++ b/webapp/src/views/terms.ts @@ -1,5 +1,5 @@ import * as api from "../api.ts" -import { el, icon, line, nameText, nameTitle } from "../dom.ts" +import { drawnOf, el, icon, type Kid, line, nameText, nameTitle, shortName, type ShortName } from "../dom.ts" import { blocksOf, spansOf } from "../markdown.ts" import { POPUP_TITLE, showPopup } from "./shell.ts" @@ -42,11 +42,16 @@ function showTerms(terms: api.Terms, chainId: number, key: string): void { } // `listed` marks a community name whose entry is not read yet, so the marker takes its place before the entry comes -export function rowName(label: string, tld: string, community: api.Community | null, key: string, listed = community !== null): HTMLDivElement { - if (!listed) return nameTitle(label, "name", tld) +export function rowName(label: string, tld: string, community: api.Community | null, key: string, listed = community !== null, name: ShortName = { shown: label, whole: null }): HTMLDivElement { + if (!listed) return nameTitle(name.shown, "name", tld, drawnOf(name)) const marker = el("button", { class: "cmark", type: "button", "aria-label": "Community name: about it", "aria-haspopup": "dialog", "data-focus": key, onclick: () => showCommunity(label, tld, community, key) }, "Community", icon("info")) - return nameTitle(label, "name comm", tld, " ", marker) + return nameTitle(name.shown, "name comm", tld, drawnOf(name), " ", marker) +} + +export function shortRowName(label: string, tld: string, community: api.Community | null, key: string): Kid { + const name = shortName(label, tld) + return [name.whole, rowName(label, tld, community, key, community !== null, name)] } export interface Agreement { diff --git a/webapp/test/api.test.ts b/webapp/test/api.test.ts index 40472c29..e8a856f5 100644 --- a/webapp/test/api.test.ts +++ b/webapp/test/api.test.ts @@ -1,7 +1,7 @@ import { afterEach, describe, expect, it, vi } from "vitest" import { keccak256, sha256, toHex, zeroHash } from "viem" import { - ApiError, cancelInvoice, checkCode, createOrder, currentTerms, editRecords, EditLimited, previewLink, readInvoice, readRegistration, registerWithCode, retryDelay, searchName, seenOf, selectName, TermsChanged, + ApiError, cancelInvoice, checkCode, createOrder, currentTerms, DISPUTE_DAYS, editRecords, EditLimited, previewLink, readInvoice, readRegistration, registerWithCode, retryDelay, searchName, seenOf, selectName, TermsChanged, communityAgreed, readerUrl, type RegistrationView, selectable, signedHash, termsFor, termsLink, termsText, termYears, } from "../src/api.ts" @@ -131,6 +131,12 @@ describe("retryDelay", () => { }) }) +describe("DISPUTE_DAYS", () => { + it("is 120 days for a card and 14 for Bitcoin, Monero or a code", () => { + expect([DISPUTE_DAYS.card, DISPUTE_DAYS.btc, DISPUTE_DAYS.xmr, DISPUTE_DAYS.code]).toEqual([120, 14, 14, 14]) + }) +}) + describe("service errors", () => { it("reads the service's own refusal, tagged by type on the names endpoints and by error on the others, whatever the status", async () => { answerWith(503, JSON.stringify({ type: "provider_unavailable" })) @@ -285,7 +291,7 @@ describe("service errors", () => { const REGISTRATION = { id: "r1", version: 4, phase: { type: "unpaid" }, labelHash: `0x${"ab".repeat(32)}`, label: null, owner: "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed", commitment: `0x${"cd".repeat(32)}`, sealed: "sealed", years: 2, duration: 2 * 365 * 86400, price: 10000, payment: { type: "invoice", method: "btc" }, balance: null, commitTx: null, registerTx: null, latePayment: null, - community: null, terms: { communityName: false, termsHash: TERMS.hash }, + disputeDays: 14, community: null, terms: { communityName: false, termsHash: TERMS.hash }, } const INVOICE = { invoiceId: "inv1", status: "open", amount: 10000, currency: "usd", expiresAt: "2026-10-16T12:00:00Z", kind: "name", registration: REGISTRATION, cryptoCurrency: "btc", cryptoAmount: "0.00156", address: "bc1q" } @@ -334,7 +340,8 @@ describe("service errors", () => { for (const phase of [ { type: "unpaid" }, { type: "closed", closedBy: "expired" }, { type: "closed", closedBy: "cancelled" }, { type: "closed", closedBy: "reversed" }, { type: "queued" }, { type: "committing" }, committed({ type: "awaiting", toSign: { type: "unread" } }), committed({ type: "awaiting", toSign: { type: "read", intentNonce: 4, acceptance } }), committed({ type: "signed" }), - committed({ type: "lapsed" }), { type: "registering" }, { type: "registered", expiresAt: 3 }, { type: "taken" }, + committed({ type: "lapsed" }), { type: "registering" }, { type: "registered", expiresAt: 3 }, { type: "registered", expiresAt: 3, disputeUntil: 2 }, + { type: "ended" }, { type: "taken" }, { type: "failed", reason: "registryRefused" }, { type: "failed", reason: "signatureRefused" }, { type: "failed", reason: "monthEnded" }, { type: "failed", reason: "unread" }, ]) { @@ -344,7 +351,7 @@ describe("service errors", () => { for (const phase of [ { type: "closed" }, { type: "closed", closedBy: "paid" }, { type: "committed", revealAfter: 1, revealBefore: 2 }, committed({ type: "awaiting" }), committed({ type: "awaiting", toSign: { type: "read", intentNonce: 4 } }), committed({ type: "awaiting", toSign: { type: "read", intentNonce: -1, acceptance } }), - { ...committed({ type: "signed" }), revealAfter: null }, { type: "registered" }, { type: "failed" }, { type: "failed", reason: "not_registered" }, { type: "failed", reason: "linksRefused" }, + { ...committed({ type: "signed" }), revealAfter: null }, { type: "registered" }, { type: "registered", expiresAt: 3, disputeUntil: null }, { type: "failed" }, { type: "failed", reason: "not_registered" }, { type: "failed", reason: "linksRefused" }, ]) { answerWith(200, JSON.stringify({ ...REGISTRATION, phase })) const e = await readRegistration("r1").then(() => null, (e: unknown) => e) @@ -369,6 +376,28 @@ describe("service errors", () => { } }) + const registered = (disputeUntil?: unknown) => ({ phase: { type: "registered", expiresAt: 1870000000, ...disputeUntil === undefined ? {} : { disputeUntil } } }) + + it("passes an order's dispute days, 14 to 120, and a registered order's dispute end, and takes a view without them or with values that cannot be so as no answer", async () => { + for (const change of [{ disputeDays: 14 }, { disputeDays: 120, ...registered(1810000000) }, registered()]) { + answerWith(200, JSON.stringify({ ...REGISTRATION, ...change })) + expect(await readRegistration("r1"), JSON.stringify(change)).toMatchObject(change) + } + for (const change of [ + { disputeDays: undefined }, { disputeDays: null }, { disputeDays: 13 }, { disputeDays: 121 }, { disputeDays: 14.5 }, { disputeDays: "14" }, + registered(null), registered(-1), registered("1810000000"), + ]) { + answerWith(200, JSON.stringify({ ...REGISTRATION, ...change })) + const e = await readRegistration("r1").then(() => null, (e: unknown) => e) + expect((e as ApiError).code, JSON.stringify(change)).toBe("network") + } + }) + + it("passes an order whose registration was ended in its dispute period", async () => { + answerWith(200, JSON.stringify({ ...REGISTRATION, phase: { type: "ended" }, label: "alice" })) + expect(await readRegistration("r1")).toMatchObject({ phase: { type: "ended" } }) + }) + it("holds a poll on the registration's version and the payment marks it has seen", async () => { const fetched = vi.fn(async () => new Response(JSON.stringify(INVOICE), { status: 200 })) vi.stubGlobal("fetch", fetched) diff --git a/webapp/test/contract/store.test.ts b/webapp/test/contract/store.test.ts index f3037ce8..b5f84211 100644 --- a/webapp/test/contract/store.test.ts +++ b/webapp/test/contract/store.test.ts @@ -27,7 +27,7 @@ async function refusal(name: string, send: () => Promise): Promise { @@ -176,6 +176,20 @@ describe.skipIf(!DIR)("the names page reads the service's recorded answers", () expect(api.selectable(view)).toBe(true) }) + it("reads a registered order's dispute days and its dispute end, and one registered without a dispute end as having none", async () => { + answering("registration-registered") + const disputed = await api.readRegistration("registration") + expect([disputed.disputeDays, disputed.phase.type, api.disputeUntilOf(disputed)]).toEqual([14, "registered", expect.any(Number)]) + answering("registration-registered-no-dispute") + const undisputed = await api.readRegistration("registration") + expect([undisputed.phase.type, api.disputeUntilOf(undisputed)]).toEqual(["registered", null]) + }) + + it("reads an order whose registration was ended", async () => { + answering("registration-ended") + expect((await api.readRegistration("registration")).phase).toEqual({ type: "ended" }) + }) + it("reads a selection of a name at another price with that name's price", async () => { const e = await refusal("select-catalog-changed", () => api.selectName("r1", order, chainId())) expect([e.code, e.body.price]).toEqual(["catalog_changed", 20000]) diff --git a/webapp/test/contract/vectors.test.ts b/webapp/test/contract/vectors.test.ts index 4ecb7345..4293fe8b 100644 --- a/webapp/test/contract/vectors.test.ts +++ b/webapp/test/contract/vectors.test.ts @@ -13,14 +13,17 @@ const read = (name: string): T => JSON.parse(readFileSync(join(DIR!, `${name} const fromHex = (h: string) => Uint8Array.from(Buffer.from(h.replace(/^0x/, ""), "hex")) const ENTROPY = fromHex("6f2d1c9a4b7e3f80d15a2c6e9b04f7a3") +interface RegisterName { + chainId: number; sponsor: string; label: string; owner: string; duration: number; secret: string; resolver: string + contact: string | null; channel: string | null; commitment: string; disputeDays: number; nonce: number; deadline: number; digest: string +} + interface Signatures { owner: string findTimestamp: number messages: { kind: string; terms: string | null; text: string; digest: Hex; signature: Hex }[] - registerName: { - chainId: number; sponsor: string; label: string; owner: string; duration: number; secret: string; resolver: string - contact: string | null; channel: string | null; commitment: string; nonce: number; deadline: number; digest: string - } + registerName: RegisterName + registerNameCode: RegisterName setText: { chainId: number; resolver: string; label: string; key: string; value: string; nonce: number; deadline: number; digest: string } } @@ -44,14 +47,17 @@ describe.skipIf(!DIR)("the names page reproduces the service's recorded vectors" expect(await recoverMessageAddress({ message: find.text, signature: find.signature })).toBe(v.owner) }) - it("commits to a registration and hashes RegisterName and SetText as the service does", () => { - const { registerName: r, setText: s } = read("vectors-signatures") - const registration = { - label: r.label, tld: "simplex", owner: fromHex(r.owner), duration: BigInt(r.duration), secret: fromHex(r.secret), resolver: fromHex(r.resolver), - contactLink: r.contact, channelLink: r.channel, + it("commits to a registration and hashes RegisterName over a card's and a code's dispute days, and SetText, as the service does", () => { + const { registerName, registerNameCode, setText: s } = read("vectors-signatures") + expect([registerName.disputeDays, registerNameCode.disputeDays]).toEqual([120, 14]) + for (const r of [registerName, registerNameCode]) { + const registration = { + label: r.label, tld: "simplex", owner: fromHex(r.owner), duration: BigInt(r.duration), secret: fromHex(r.secret), resolver: fromHex(r.resolver), + contactLink: r.contact, channelLink: r.channel, + } + expect(hex(makeCommitment(registration))).toBe(r.commitment) + expect(hex(registerIntentDigest(BigInt(r.chainId), fromHex(r.sponsor), registration, BigInt(r.disputeDays), BigInt(r.nonce), BigInt(r.deadline))), `${r.disputeDays} days`).toBe(r.digest) } - expect(hex(makeCommitment(registration))).toBe(r.commitment) - expect(hex(registerIntentDigest(BigInt(r.chainId), fromHex(r.sponsor), registration, BigInt(r.nonce), BigInt(r.deadline)))).toBe(r.digest) expect(hex(setTextDigest(BigInt(s.chainId), fromHex(s.resolver), namehash("simplex", s.label), s.key, s.value, BigInt(s.nonce), BigInt(s.deadline)))).toBe(s.digest) }) diff --git a/webapp/test/crypto.test.ts b/webapp/test/crypto.test.ts index a8ef40bc..31588c36 100644 --- a/webapp/test/crypto.test.ts +++ b/webapp/test/crypto.test.ts @@ -128,19 +128,19 @@ describe("registration", () => { expect(hex(commitmentSecret(seed, "dynamis"))).not.toBe(hex(commitmentSecret(seed, "dynamos"))) }) - it("signs RegisterName as viem's typed data, recoverable to the owner", async () => { + it("signs RegisterName with the dispute days as viem's typed data, recoverable to the owner", async () => { const wallet = walletFromEntropy(ENTROPY) const r = registration(wallet.address, "https://smp8.simplex.im/a#Y8m3qT0vLw2Ab7cD9eF1gH3jK5mN7pQ9rSAAAAAAAAA") const typed = { domain: { name: "SimplexSponsor", version: "1", chainId: Number(CHAIN_ID), verifyingContract: hex(SPONSOR) }, types: { RegisterName: [ { name: "label", type: "string" }, { name: "owner", type: "address" }, { name: "duration", type: "uint256" }, - { name: "resolver", type: "address" }, { name: "data", type: "bytes[]" }, { name: "nonce", type: "uint256" }, { name: "deadline", type: "uint256" }, + { name: "resolver", type: "address" }, { name: "data", type: "bytes[]" }, { name: "disputeDays", type: "uint256" }, { name: "nonce", type: "uint256" }, { name: "deadline", type: "uint256" }, ] }, primaryType: "RegisterName" as const, - message: { label: r.label, owner: hex(r.owner), duration: r.duration, resolver: hex(RESOLVER), data: recordCalls(r).map(hex), nonce: 0n, deadline: 1800000000n }, + message: { label: r.label, owner: hex(r.owner), duration: r.duration, resolver: hex(RESOLVER), data: recordCalls(r).map(hex), disputeDays: 37n, nonce: 0n, deadline: 1800000000n }, } - const digest = registerIntentDigest(CHAIN_ID, SPONSOR, r, 0n, 1800000000n) + const digest = registerIntentDigest(CHAIN_ID, SPONSOR, r, 37n, 0n, 1800000000n) expect(hex(digest)).toBe(hashTypedData(typed)) const signature = hex(signDigest(wallet.privateKey, digest)) expect(await recoverTypedDataAddress({ ...typed, signature })).toBe(OWNER_ADDRESS) diff --git a/webapp/test/flow.test.ts b/webapp/test/flow.test.ts index cd6185a8..59689f53 100644 --- a/webapp/test/flow.test.ts +++ b/webapp/test/flow.test.ts @@ -76,7 +76,7 @@ beforeEach(() => { }) afterEach(() => vi.unstubAllGlobals()) -const draft = (label = "dynamis", terms = SIGNED) => ({ label, links: LINKS, chain: CHAIN, years: 2, termStart: TERM_START, ownerCode: OWNER_CODE, terms }) +const draft = (label = "dynamis", terms = SIGNED) => ({ label, links: LINKS, chain: CHAIN, years: 2, termStart: TERM_START, ownerCode: OWNER_CODE, terms, disputeDays: 120 }) const view = (request: { labelHash: string; duration: number; commitment: string; sealed: string }, extra: ShortView = {}) => viewOf({ id: "reg1", version: 1, labelHash: request.labelHash, label: null, owner: OWNER, commitment: request.commitment, sealed: request.sealed, @@ -118,7 +118,7 @@ describe("orderRequest", () => { expect(flow.recordFor(draft("dynamis", COMMUNITY_SIGNED), built, "btc", 20000, { registrationId: "reg1", invoiceId: "inv1" }).terms).toBe(COMMUNITY_SIGNED) }) - it("includes the RegisterName and the terms acceptance the code's key signs at what the service reads for the name and owner, a week ahead of the service's clock", async () => { + it("includes the RegisterName, over the order's dispute days, and the terms acceptance the code's key signs at what the service reads for the name and owner, a week ahead of the service's clock", async () => { const { flow } = await modules() const { request } = await flow.orderRequest(draft()) expect(signReads).toEqual([`/api/name/${request.labelHash}/sign?owner=${OWNER}`]) @@ -129,7 +129,7 @@ describe("orderRequest", () => { label: "dynamis", tld: "simplex", owner: WALLET.address, duration: BigInt(request.duration), secret: fromHex(reveal.secret), resolver: fromHex(CHAIN.resolver), contactLink: LINKS.contact, channelLink: null, } - const intent = registerIntentDigest(31337n, fromHex(CHAIN.sponsor), r, 5n, BigInt(reveal.deadline)) + const intent = registerIntentDigest(31337n, fromHex(CHAIN.sponsor), r, 120n, 5n, BigInt(reveal.deadline)) expect(await recoverAddress({ hash: hex(intent) as Hex, signature: reveal.signature as Hex })).toBe(OWNER) const a = TO_SIGN.acceptance expect(reveal.acceptance).toMatchObject({ termsHash: a.termsHash, nonce: 1 }) @@ -141,12 +141,12 @@ describe("orderRequest", () => { describe("revealOrder", () => { const general = { community: false, policy: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", termsHash: `0x${"c7".repeat(32)}`, nonce: 0 } - it("sends the label, secret and links with a RegisterName signature from the code's key, a week ahead of the service's clock", async () => { + it("sends the label, secret and links with a RegisterName signature from the code's key, of the order's dispute days, a week ahead of the service's clock", async () => { const { flow } = await modules() const built = await flow.orderRequest(draft()) - const record = flow.recordFor(draft(), built, "btc", 20000, { registrationId: "reg1", invoiceId: "inv1" }) + const record = flow.recordFor(draft(), built, "card", 20000, { registrationId: "reg1", invoiceId: "inv1" }) answers["POST /api/registration/reg1/reveal"] = {} - await flow.revealOrder(view(built.request, { acceptance: general }), record) + await flow.revealOrder(view(built.request, { acceptance: general, disputeDays: 37 }), record) const body = calls[0].body as { label: string; secret: string; records: unknown; nonce: number; deadline: number; signature: Hex } expect(body).toMatchObject({ label: "dynamis", secret: hex(commitmentSecret(WALLET.seed, "dynamis")), records: { contact: LINKS.contact, channel: null }, nonce: 3 }) expect(Math.abs(body.deadline - (Date.now() / 1000 + 7 * 86400)), "the deadline's distance from a week ahead").toBeLessThan(2) @@ -154,7 +154,7 @@ describe("revealOrder", () => { label: "dynamis", tld: "simplex", owner: WALLET.address, duration: BigInt(built.request.duration), secret: fromHex(body.secret), resolver: fromHex(CHAIN.resolver), contactLink: LINKS.contact, channelLink: null, } - const digest = registerIntentDigest(31337n, fromHex(CHAIN.sponsor), r, 3n, BigInt(body.deadline)) + const digest = registerIntentDigest(31337n, fromHex(CHAIN.sponsor), r, 37n, 3n, BigInt(body.deadline)) expect(await recoverAddress({ hash: hex(digest) as Hex, signature: body.signature })).toBe(OWNER) }) @@ -172,6 +172,15 @@ describe("revealOrder", () => { expect(await recoverAddress({ hash: hex(digest) as Hex, signature: sent.acceptance.signature })).toBe(OWNER) expect(await recoverAddress({ hash: hex(other) as Hex, signature: sent.acceptance.signature })).not.toBe(OWNER) }) + + it.each([["btc", 15, 14], ["xmr", 15, 14], ["code", 15, 14], ["card", 121, 120]] as const)("signs no reveal of an order paid by %s over %i dispute days, more than its %i", async (method, days, allowed) => { + const { flow } = await modules() + const built = await flow.orderRequest(draft()) + const record = flow.recordFor(draft(), built, method, 20000, { registrationId: "reg1", invoiceId: method === "code" ? null : "inv1" }) + answers["POST /api/registration/reg1/reveal"] = {} + await expect(flow.revealOrder(view(built.request, { acceptance: general, disputeDays: days }), record)).rejects.toMatchObject({ days, allowed }) + expect(calls, "nothing sent").toEqual([]) + }) }) describe("selectName", () => { @@ -207,13 +216,14 @@ describe("selectName", () => { expect(store.orderByRegistration("reg1")?.years).toBe(5) }) - it("drafts a new invoice for the answer's years, or a community name's own", async () => { + it("drafts a new invoice for the answer's years, or a community name's own, over the dispute days of its way to pay", async () => { const { flow } = await modules() await (await import("../src/config.ts")).namesSite() const record = flow.recordFor(draft(), await flow.orderRequest(draft()), "btc", 20000, { registrationId: "reg1", invoiceId: "inv1" }) const community = { years: 2 } - expect(flow.draftAgain(record, { ...QUOTE, years: 3 }, SIGNED).years).toBe(3) - expect(flow.draftAgain(record, { ...QUOTE, years: 3, community }, SIGNED).years).toBe(2) + expect(flow.draftAgain(record, { ...QUOTE, years: 3 }, SIGNED, 14).years).toBe(3) + expect(flow.draftAgain(record, { ...QUOTE, years: 3, community }, SIGNED, 14).years).toBe(2) + expect(flow.draftAgain(record, QUOTE, SIGNED, 120).disputeDays).toBe(120) }) }) diff --git a/webapp/test/registration-view.ts b/webapp/test/registration-view.ts index 5ae494fa..5eff58ae 100644 --- a/webapp/test/registration-view.ts +++ b/webapp/test/registration-view.ts @@ -1,6 +1,6 @@ import type { Acceptance, FailReason, Payment, Phase, PhaseView, RegistrationView, ToSign } from "../src/api.ts" -export type ViewBase = Omit +export type ViewBase = Omit export interface ShortView extends Partial> { phase?: Phase @@ -11,6 +11,7 @@ export interface ShortView extends Partial> { unread?: boolean lapsed?: boolean expiresAt?: number + disputeUntil?: number reason?: FailReason closedBy?: ClosedBy } @@ -18,11 +19,11 @@ export interface ShortView extends Partial> { type ClosedBy = Extract["closedBy"] export function viewOf(base: ViewBase, change: ShortView): RegistrationView { - const { phase = "unpaid", revealAfter = 0, revealBefore = 0, intentNonce = null, acceptance = null, unread = false, lapsed = false, expiresAt = 0, reason = "registryRefused", closedBy = "expired", ...rest } = change + const { phase = "unpaid", revealAfter = 0, revealBefore = 0, intentNonce = null, acceptance = null, unread = false, lapsed = false, expiresAt = 0, disputeUntil, reason = "registryRefused", closedBy = "expired", ...rest } = change const view = { ...base, ...rest } const payment: Payment = { type: "invoice", method: "btc" } const toSign: ToSign = unread || intentNonce === null || acceptance === null ? { type: "unread" } : { type: "read", intentNonce, acceptance } const phaseView: PhaseView = phase === "committed" ? { type: phase, revealAfter, revealBefore, signature: view.label !== null ? { type: "signed" } : lapsed ? { type: "lapsed" } : { type: "awaiting", toSign } } - : phase === "registered" ? { type: phase, expiresAt } : phase === "failed" ? { type: phase, reason } : phase === "closed" ? { type: phase, closedBy } : { type: phase } - return { payment, ...view, phase: phaseView } + : phase === "registered" ? { type: phase, expiresAt, disputeUntil } : phase === "failed" ? { type: phase, reason } : phase === "closed" ? { type: phase, closedBy } : { type: phase } + return { payment, disputeDays: 14, ...view, phase: phaseView } } diff --git a/webapp/test/rules.test.ts b/webapp/test/rules.test.ts index a9fab418..27cb6b24 100644 --- a/webapp/test/rules.test.ts +++ b/webapp/test/rules.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest" -import { bonusDays, bonusHint, clock, dateOf, dollars, freeDays, letters, methodName, seconds, shortAddress, termEnd, timeOf } from "../src/format.ts" +import { bonusDays, bonusHint, clock, dateOf, dollars, freeDays, letters, methodName, seconds, shortAddress, shortLabel, termEnd, timeOf } from "../src/format.ts" import { coreLink, deepLinkOf } from "../dev/mock/links.ts" import { foldLabel, labelProblem, linkKind, linkProblem, LINK_MAX_BYTES, linkTooLong } from "../src/names.ts" @@ -114,6 +114,13 @@ describe("formatting", () => { expect(dateOf(Date.UTC(2028, 10, 12) / 1000)).toBe("12\u00a0November 2028") }) + it("keeps a name of up to 25 letters whole, and shortens a longer one to its first 12 letters, ... and its last 3", () => { + for (const label of ["bakery", "a".repeat(25)]) expect(shortLabel(label), label).toBe(label) + expect(shortLabel("a".repeat(26))).toBe(`${"a".repeat(12)}...aaa`) + expect(shortLabel("the-best-bakery-in-lisbon-since-1987")).toBe("the-best-bak...987") + expect(shortLabel("m".repeat(63))).toHaveLength(18) + }) + const TERM_START = Date.UTC(2027, 0, 1) / 1000 it("counts the free days to the term's start, a part day as a whole one, and none once it has started", () => { diff --git a/webapp/test/screens-checkout.test.ts b/webapp/test/screens-checkout.test.ts index 20c0a58e..c487e3d6 100644 --- a/webapp/test/screens-checkout.test.ts +++ b/webapp/test/screens-checkout.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "vitest" import { - awaitsCode, changeOf, codeEntry, type CheckoutEvent, type CheckoutKind, type CheckoutState, FALLBACK_METHOD, initialState, reduce, screenOf, stepFor, + awaitsCode, changeOf, codeEntry, disputeDaysOf, type CheckoutEvent, type CheckoutKind, type CheckoutState, FALLBACK_METHOD, initialState, reduce, screenOf, stepFor, } from "../src/screens/checkout.ts" import { NO_LEAD } from "../src/screens/hold.ts" import type { Checkout } from "../src/session.ts" @@ -362,3 +362,19 @@ describe("codes-only mode", () => { expect(screenOf(reduce(refused, opened(refused))), "the review opened again").toBe("review") }) }) + +describe("disputeDaysOf", () => { + it("is the days the way to pay allows: 120 for a card, 14 for Bitcoin, Monero or a code", () => { + expect(disputeDaysOf(checkout({ method: "card" }), false)).toBe(120) + expect(disputeDaysOf(checkout({ method: "btc" }), false)).toBe(14) + expect(disputeDaysOf(checkout({ method: "xmr" }), false)).toBe(14) + expect(disputeDaysOf(checkout({ method: "card", code: CODE }), false)).toBe(14) + expect(disputeDaysOf(checkout({ method: "card", codeHere: true }), false), "the code field opened").toBe(14) + expect(disputeDaysOf(checkout({ method: "card" }), true), "codes-only mode").toBe(14) + }) + it("for a name selected for a taken order, is the days of that order's payment, whatever method the checkout holds", () => { + expect(disputeDaysOf(checkout({ method: "btc", order: { registrationId: "reg-9", method: "card", paid: 1500 } }), false)).toBe(120) + expect(disputeDaysOf(checkout({ method: "card", order: { registrationId: "reg-9", method: "xmr", paid: 1500 } }), false)).toBe(14) + expect(disputeDaysOf(checkout({ method: "card", order: { registrationId: "reg-9", method: "code", paid: 0 } }), false)).toBe(14) + }) +}) diff --git a/webapp/test/screens-names.test.ts b/webapp/test/screens-names.test.ts index 2d5c9214..ea4699e5 100644 --- a/webapp/test/screens-names.test.ts +++ b/webapp/test/screens-names.test.ts @@ -56,11 +56,12 @@ const storedEvent = (change: Partial = {}, hold: Hold | null = null): Li const list = (change: Partial = {}, state: Partial = {}): ListState => ({ ...initialList(stored(change), null, {}, {}, NOW), ...state }) describe("list helpers", () => { - it("lapsed: a registered name past its expiry, or one the search finds available again, is over", () => { + it("lapsed: a registered name past its expiry is over, whatever the search finds", () => { const view = registeredView() expect(lapsed({ view, answer: registered() }, NOW)).toBe(false) expect(lapsed({ view, answer: registered() }, NOW + 3 * YEAR_S * 1000)).toBe(true) - expect(lapsed({ view, answer: available }, NOW)).toBe(true) + expect(lapsed({ view, answer: available }, NOW + 3 * YEAR_S * 1000)).toBe(true) + expect(lapsed({ view, answer: available }, NOW), "a name unregistered before its expiry").toBe(false) expect(lapsed({ view: registration({ phase: "committed" }), answer: available }, NOW)).toBe(false) }) it("registrableAgain: free now once the search finds it available", () => { @@ -113,6 +114,7 @@ describe("list helpers", () => { ["nothing paid", registration(), invoice(), record(), ["Waiting for payment", "warn"]], ["a registration under way", registration({ phase: "registering" }), null, record(), ["Registering", "brand"]], ["a registered name", registeredView(), null, record(), ["Registered", "ok"]], + ["a registration ended in its dispute period", registration({ phase: "ended", label: "alice" }), null, record(), ["Ended", "bad"]], ["a name taken first", registration({ phase: "taken" }), null, record(), ["Taken first", "warn"]], ["a failed registration", registration({ phase: "failed" }), null, record(), ["Not registered", "bad"]], ] @@ -129,13 +131,14 @@ describe("list helpers", () => { expect(linksAction(hasLinks(record({ contact: CONTACT }), null))).toBe("Edit links") expect(linksAction(hasLinks(record(), registered({ contact: "", channel: CHANNEL })))).toBe("Edit links") }) - it("editable: a name in the app's wallet, or pointed at another resolver, is not edited here", () => { + it("editable: a name in the app's wallet, pointed at another resolver, or not answered as registered, is not edited here", () => { expect(editable(registered(), OWNER)).toBe(true) expect(editable(registered(), OWNER.toLowerCase())).toBe(true) expect(editable(registered(undefined, { owner: APP }), OWNER)).toBe(false) expect(editable(registered(null), OWNER)).toBe(false) - expect(editable(held, OWNER)).toBe(true) - expect(editable(available, OWNER)).toBe(true) + expect(editable(held, OWNER), "taken by another order").toBe(false) + expect(editable(available, OWNER), "unregistered on chain before the service's check").toBe(false) + expect(editable({ found: { type: "reserved" }, community: null }, OWNER)).toBe(false) }) it("hasLinks: a name's records once read, else the links it was ordered with", () => { expect(hasLinks(record(), registered()), "a contact address on chain").toBe(true) @@ -431,7 +434,8 @@ describe("edit", () => { const STATES: Record = { "edit-no-code": initialEdit("reg-1", null), "edit-unreadable": reduceEdit(opened, { type: "read-failed" }), - "edit-expired": answered(opened, available), + "edit-expired": answered(opened, available, registeredView({ expiresAt: NOW / 1000 - GRACE_S - 1 })), + "edit-ended": answered(opened, available, registration({ phase: "ended", label: "alice" })), "edit-in-app": answered(opened, registered(undefined, { owner: APP })), "edit-elsewhere": answered(opened, registered(null)), "edit-not-registered": answered(opened, { found: { type: "reserved" }, community: null }, registration({ phase: "committed" })), @@ -446,10 +450,15 @@ describe("edit", () => { ["a name whose read failed", STATES["edit-unreadable"], "edit-unreadable"], ["a name past its expiry", answered(opened, registered(), registeredView({ expiresAt: NOW / 1000 - 1 })), "edit-expired"], ["a name registered again by someone else", STATES["edit-expired"], "edit-expired"], + ["a registration ended in its dispute period", STATES["edit-ended"], "edit-ended"], + ["a registration ended, its name registered again since", answered(opened, registered(undefined, { owner: APP }), registration({ phase: "ended", label: "alice" })), "edit-ended"], + ["a name unregistered on chain before the service's check, read again", answered(opened, available), "edit-unreadable"], + ["a name reserved since, read again", answered(opened, { found: { type: "reserved" }, community: null }), "edit-unreadable"], ["a name moved to the app's wallet", STATES["edit-in-app"], "edit-in-app"], ["a name pointed at another resolver", STATES["edit-elsewhere"], "edit-elsewhere"], ["a name still being registered", STATES["edit-not-registered"], "edit-not-registered"], - ["a name an order holds", answered(opened, held), "edit-not-registered"], + ["a name an order holds, its own order not registered yet", answered(opened, held, registration({ phase: "committed" })), "edit-not-registered"], + ["a registered name an order holds now, read again", answered(opened, held), "edit-unreadable"], ["a registered name with its links", STATES.edit, "edit"], ] it.each(cases)("%s", (_, state, kind) => { diff --git a/webapp/test/screens-order.test.ts b/webapp/test/screens-order.test.ts index 932aad5b..71080873 100644 --- a/webapp/test/screens-order.test.ts +++ b/webapp/test/screens-order.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest" import type { Acceptance, Community, InvoiceView, RegistrationView } from "../src/api.ts" import { NO_LEAD } from "../src/screens/hold.ts" import { - CARD_SLOW_MS, closedBalance, type ClosedCase, closedCase, costOf, failedAlert, failedLead, finished, initialState, type Note, type OrderEvent, type OrderKind, + CARD_SLOW_MS, closedBalance, type ClosedCase, closedCase, costOf, disputeEndAhead, failedAlert, failedLead, finished, initialState, type Note, type OrderEvent, type OrderKind, type OrderState, reduce, refusalsOf, RETRY_MS, retryRefusal, REVEAL_ATTEMPTS, revealDue, revealKey, screenOf, STALL_MARGIN_MS, stalledAt, TX_STALL_MS, unreadDelay, wakeAt, askAgainDue, retryDue, supportCase, } from "../src/screens/order.ts" @@ -67,6 +67,7 @@ const STATES: Record = { confirming: read(crypto({ paidInFull: true, cryptoAmountPaid: "0.00025" })), registering: read(null, registration({ phase: "committing" })), registered: read(null, registration({ phase: "registered", label: "alice", registerTx: "0xe9", expiresAt: NOW / 1000 + 63072000 })), + ended: read(null, registration({ phase: "ended", label: "alice", registerTx: "0xe9" })), taken: read(crypto({ status: "paid", paidInFull: true }, { phase: "taken" })), failed: read(crypto({ status: "paid", paidInFull: true }, { phase: "failed", reason: "registryRefused" })), "not-on-device": read(null, registration({ phase: "committing" }), { record: null }), @@ -97,6 +98,8 @@ describe("screenOf", () => { ["an expired invoice with nothing received", STATES["status:closed"], "status:closed"], ["a registration link of an unpaid order", STATES["status:paid-by-invoice"], "status:paid-by-invoice"], ["a registered order", STATES.registered, "registered"], + ["a registration ended in its dispute period", STATES.ended, "ended"], + ["a registration ended, seen without the name code", read(null, registration({ phase: "ended", label: "alice" }), { record: null }), "ended"], ["a name taken first", STATES.taken, "taken"], ["a failed registration", STATES.failed, "failed"], ["a commit in a browser without the name code", STATES["not-on-device"], "not-on-device"], @@ -348,6 +351,16 @@ describe("costOf", () => { }) }) +describe("disputeEndAhead", () => { + const registered = (disputeUntil?: number) => read(null, registration({ phase: "registered", disputeUntil })) + it("is a registered name's dispute end while it is ahead", () => { + expect(disputeEndAhead(registered(NOW / 1000 + 1))).toBe(NOW / 1000 + 1) + }) + it("is null once the dispute end is reached, and for a name registered without one", () => { + for (const disputeUntil of [NOW / 1000, NOW / 1000 - 1, undefined]) expect(disputeEndAhead(registered(disputeUntil)), String(disputeUntil)).toBeNull() + }) +}) + describe("finished", () => { const paidLate = (reg: Short) => crypto({ status: "paid", paidInFull: true }, reg) it("follows money paid after the close until it is in the balance", () => { @@ -370,8 +383,9 @@ describe("finished", () => { const reversed: Short = { phase: "closed", closedBy: "reversed" } expect(finished(card({ status: "paid", amountPaid: 1500 }, reversed), registration(reversed))).toBe(true) }) - it("stops at a registered name, and follows an open invoice and a taken or failed order", () => { + it("stops at a registered name or an ended registration, and follows an open invoice and a taken or failed order", () => { expect(finished(null, registration({ phase: "registered" }))).toBe(true) + expect(finished(null, registration({ phase: "ended" }))).toBe(true) expect(finished(crypto(), registration())).toBe(false) expect(finished(null, registration({ phase: "taken" }))).toBe(false) }) @@ -502,8 +516,9 @@ describe("reveal helpers", () => { const view = registration(committed) const waiting = read(null, view) it("revealKey names the commit a reveal is signed for", () => { - expect(revealKey(view)).toBe(`reg-1 ${COMMITMENT} 4 ${NOW / 1000 + 3600} 0x3 ${SIGNED} 0`) - expect(revealKey(registration({ ...committed, acceptance: acceptanceFor(CHANGED) })), "and the acceptance it signs").toBe(`reg-1 ${COMMITMENT} 4 ${NOW / 1000 + 3600} 0x3 ${CHANGED} 0`) + expect(revealKey(view)).toBe(`reg-1 ${COMMITMENT} 4 ${NOW / 1000 + 3600} 14 0x3 ${SIGNED} 0`) + expect(revealKey(registration({ ...committed, acceptance: acceptanceFor(CHANGED) })), "and the acceptance it signs").toBe(`reg-1 ${COMMITMENT} 4 ${NOW / 1000 + 3600} 14 0x3 ${CHANGED} 0`) + expect(revealKey(registration({ ...committed, disputeDays: 120 })), "and the dispute days it signs").toBe(`reg-1 ${COMMITMENT} 4 ${NOW / 1000 + 3600} 120 0x3 ${SIGNED} 0`) }) it("a stored reveal ends its sending, so one the service clears is signed again under the same key", () => { const sent = reduce(waiting, { type: "reveal-sent", key: revealKey(view) }) @@ -558,6 +573,18 @@ describe("reveal helpers", () => { expect(revealDue({ ...waiting, reveal: { key, sending: false, refusals: REVEAL_ATTEMPTS } })).toBe(false) expect(revealDue({ ...waiting, reveal: { key, sending: false, refusals: REVEAL_ATTEMPTS - 1 } })).toBe(true) }) + it("a reveal over more dispute days than the payment allows is not signed again, nor taken as stalled, until the service asks another", () => { + const over = registration({ ...committed, disputeDays: 120 }) + const key = revealKey(over) + const timed = { ...read(null, over), since: { stage: "reg-1 committed", at: NOW } } + expect(stalledAt(timed)).not.toBeNull() + const declined = reduce(reduce(timed, { type: "reveal-sent", key }), { type: "reveal-declined", key, days: 120, allowed: 14 }) + expect(declined.declined).toEqual({ key, days: 120, allowed: 14 }) + expect(revealDue(declined)).toBe(false) + expect(stalledAt(declined)).toBeNull() + expect(revealDue({ ...declined, view: registration({ ...committed, disputeDays: 120, intentNonce: 5 }) }), "another reveal").toBe(true) + expect(revealDue({ ...declined, view: registration({ ...committed, disputeDays: 14 }) }), "the service's days corrected").toBe(true) + }) }) describe("wakeAt", () => { @@ -571,6 +598,13 @@ describe("wakeAt", () => { it("takes the earlier of two moments", () => { expect(wakeAt({ ...paying, view: registration({ ...committed, revealAfter: NOW / 1000 + 30 }) })).toBe(NOW + 30_000) }) + it("wakes a registered name's page at its dispute end, which a tick then takes away", () => { + const registered = read(null, registration({ phase: "registered", label: "alice", disputeUntil: NOW / 1000 + 30 })) + expect(wakeAt(registered)).toBe(NOW + 30_000) + const woken = reduce(registered, { type: "tick", now: wakeAt(registered)! }) + expect(disputeEndAhead(woken)).toBeNull() + expect(wakeAt(woken)).toBeNull() + }) it("sleeps when nothing waits on the clock", () => { expect(wakeAt(STATES["pay-crypto"])).toBeNull() expect(wakeAt(STATES.registered)).toBeNull() @@ -645,7 +679,7 @@ describe("initialState", () => { expect(initialState("inv-1", { until: NOW + 1000, lead: NO_LEAD }, reveal)).toEqual({ reference: "inv-1", seq: 0, now: 0, invoice: null, view: null, record: null, cardSubmittedAt: null, cardFailed: false, reveal, busy: null, note: null, hold: { until: NOW + 1000, lead: NO_LEAD }, price: null, gone: false, codeRefused: false, codeKept: false, codeCheckAt: null, ask: null, - nameStatus: null, since: null, + nameStatus: null, since: null, declined: null, }) }) }) diff --git a/webapp/test/screens-search.test.ts b/webapp/test/screens-search.test.ts index 4b8365e8..ed72aea1 100644 --- a/webapp/test/screens-search.test.ts +++ b/webapp/test/screens-search.test.ts @@ -329,8 +329,8 @@ describe("ownOrders", () => { expect(asked, "nothing older is read").toEqual(["r2"]) } }) - it("takes a registered or taken order, or one failed at its month's end, as neither open nor closed", async () => { - for (const [phase, failure] of [["registered", null], ["taken", null], ["failed", "monthEnded"]] as const) { + it("takes a registered, ended or taken order, or one failed at its month's end, as neither open nor closed", async () => { + for (const [phase, failure] of [["registered", null], ["ended", null], ["taken", null], ["failed", "monthEnded"]] as const) { expect(await ownOrders([order("r1")], reader({ r1: { phase, failure, invoice: "paid" } }).read), phase).toEqual({ open: null, closed: null }) } }) diff --git a/webapp/test/terms-vectors.test.ts b/webapp/test/terms-vectors.test.ts index 2b6386f1..355de0b3 100644 --- a/webapp/test/terms-vectors.test.ts +++ b/webapp/test/terms-vectors.test.ts @@ -106,7 +106,7 @@ describe.skipIf(!RECORDED)("the page's builders reproduce Appendix C", () => { sent.push(body) return new Response(JSON.stringify({ id: REGISTRATION_ID, version: 2, phase: { type: "queued" }, label: null, owner: OWNER, years: YEARS, price: 10000, payment: { type: "invoice", method: "btc" }, balance: null, - latePayment: null, commitTx: null, registerTx: null, community: null, ...body.fields as Record, + latePayment: null, commitTx: null, registerTx: null, disputeDays: 14, community: null, ...body.fields as Record, }), { status: 200 }) }) vi.resetModules() @@ -117,7 +117,7 @@ describe.skipIf(!RECORDED)("the page's builders reproduce Appendix C", () => { vi.unstubAllGlobals() }) - const draft = (terms: string) => ({ label: LABEL, links: NO_LINKS, chain: CHAIN, years: YEARS, termStart: TERM_START, ownerCode: OWNER_CODE, terms }) + const draft = (terms: string) => ({ label: LABEL, links: NO_LINKS, chain: CHAIN, years: YEARS, termStart: TERM_START, ownerCode: OWNER_CODE, terms, disputeDays: 14 }) it.each(TERMS)("order with terms %s", async (terms) => { const { flow } = await builders()