From 5b6b3280c9f0595da811606c12a27920683c1466 Mon Sep 17 00:00:00 2001 From: Nabil-Aufa <181296848+Nabil-Aufa@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:38:24 +0700 Subject: [PATCH 1/2] fix(#97): Advance details name AdMob for an AdMob advance, from the API's source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #107 adds `source` to every /advances row, read from the request_advance call. The client keeps it, and reads a row without one (an API from before #107) or with an unknown one as AdSense. "AdSense revenue, …" on Repayment becomes "AdMob revenue, …" for an AdMob advance. Co-Authored-By: Claude Opus 5.5 --- fe/src/lib/api/client.test.ts | 47 ++++++++++++++++++- fe/src/lib/api/client.ts | 11 ++++- fe/src/lib/api/types.ts | 5 ++ fe/src/lib/ledger.test.ts | 1 + .../repayment/components/AdvanceDetails.tsx | 2 +- fe/tests/e2e/api.ts | 1 + fe/tests/e2e/repayment.spec.ts | 19 ++++++++ 7 files changed, 82 insertions(+), 4 deletions(-) diff --git a/fe/src/lib/api/client.test.ts b/fe/src/lib/api/client.test.ts index 97862c0..cba08e0 100644 --- a/fe/src/lib/api/client.test.ts +++ b/fe/src/lib/api/client.test.ts @@ -1,4 +1,4 @@ -import { afterEach, describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import { getAdvances, getTransactions, usingMockApi } from "./client"; const BORROWER = "GBORROWER"; @@ -41,3 +41,48 @@ describe("the fixture client's forepay.mock.ledger switch", () => { expect(await getAdvances(BORROWER)).toHaveLength(1); }); }); + +describe("the #16 API's advances", () => { + afterEach(() => { + vi.unstubAllEnvs(); + vi.unstubAllGlobals(); + vi.resetModules(); + }); + + /** `getAdvances` against an API that answers `rows`, read with the API set at import time. */ + async function advancesFrom(rows: object[]) { + vi.stubEnv("NEXT_PUBLIC_API_URL", "https://api.test"); + vi.stubGlobal("fetch", async () => new Response(JSON.stringify(rows))); + vi.resetModules(); + const client = await import("./client"); + return client.getAdvances(BORROWER); + } + + const row = { + nullifier: "aa", + borrower: BORROWER, + windowStart: "2026-07-01", + windowEnd: "2026-09-30", + revenueCents: "36000", + principal: "900000000", + repaid: "0", + openedAt: "1791806400", + txHash: "adv", + }; + + it("keeps AdMob's source (#107)", async () => { + const [advance] = await advancesFrom([{ ...row, source: "AdMob" }]); + expect(advance.source).toBe("AdMob"); + expect(advance.revenueCents).toBe(36_000n); + }); + + it("reads a row without a source, from an API before #107, as AdSense", async () => { + const [advance] = await advancesFrom([row]); + expect(advance.source).toBe("AdSense"); + }); + + it("reads a source it does not know as AdSense", async () => { + const [advance] = await advancesFrom([{ ...row, source: "YouTube" }]); + expect(advance.source).toBe("AdSense"); + }); +}); diff --git a/fe/src/lib/api/client.ts b/fe/src/lib/api/client.ts index 14e9770..62fce8a 100644 --- a/fe/src/lib/api/client.ts +++ b/fe/src/lib/api/client.ts @@ -34,8 +34,14 @@ async function fetchJson(path: string): Promise { /** Every advance this wallet has taken, newest first. */ export async function getAdvances(borrower: string): Promise { if (usingMockApi) return mock.advances(borrower); - const rows = await fetchJson[]>(`/advances?borrower=${encodeURIComponent(borrower)}`); - return rows.map((r) => fromWire(r, ["revenueCents", "principal", "repaid", "openedAt"])); + const rows = await fetchJson<(Wire & { source?: string })[]>( + `/advances?borrower=${encodeURIComponent(borrower)}`, + ); + return rows.map((r) => ({ + ...fromWire(r, ["revenueCents", "principal", "repaid", "openedAt"]), + // Missing before #107, and those advances are all AdSense. + source: r.source === "AdMob" ? "AdMob" : "AdSense", + })); } /** Every advance and repayment for this wallet, newest first. */ @@ -76,6 +82,7 @@ const mock = { return [ { nullifier: NULLIFIER, + source: "AdSense", borrower, windowStart: "2026-07-01", windowEnd: "2026-09-30", diff --git a/fe/src/lib/api/types.ts b/fe/src/lib/api/types.ts index 65b534f..44333f1 100644 --- a/fe/src/lib/api/types.ts +++ b/fe/src/lib/api/types.ts @@ -10,6 +10,11 @@ export type AdvanceSummary = { /** 32 bytes as hex. `repay` takes it (ARCHITECTURE.md §10, question 1). */ nullifier: string; + /** + * Where the revenue was earned (#97), read by #107 from the `request_advance` call. An API from before + * #107 sends none, and every advance it lists is AdSense's. + */ + source: "AdSense" | "AdMob"; borrower: string; /** The attested three-month window, `YYYY-MM-DD`. */ windowStart: string; diff --git a/fe/src/lib/ledger.test.ts b/fe/src/lib/ledger.test.ts index 73fc511..18b7316 100644 --- a/fe/src/lib/ledger.test.ts +++ b/fe/src/lib/ledger.test.ts @@ -17,6 +17,7 @@ const OPENED = 1_791_806_400n; // 12 Oct 2026 function advance(over: Partial = {}): AdvanceSummary { return { nullifier: "aa", + source: "AdSense", borrower: "G", windowStart: "2026-07-01", windowEnd: "2026-09-30", diff --git a/fe/src/modules/repayment/components/AdvanceDetails.tsx b/fe/src/modules/repayment/components/AdvanceDetails.tsx index 5301e35..da02875 100644 --- a/fe/src/modules/repayment/components/AdvanceDetails.tsx +++ b/fe/src/modules/repayment/components/AdvanceDetails.tsx @@ -29,7 +29,7 @@ export function AdvanceDetails({ const rows: { label: string; value: ReactNode }[] = [ { label: "Advanced", value: formatUsdc(advance.principal) }, { - label: `AdSense revenue, ${formatWindow(advance.windowStart, advance.windowEnd).short}`, + label: `${advance.source} revenue, ${formatWindow(advance.windowStart, advance.windowEnd).short}`, value: formatUsdCents(advance.revenueCents), }, ...(sized ? [{ label: "How it was sized", value: sized }] : []), diff --git a/fe/tests/e2e/api.ts b/fe/tests/e2e/api.ts index 373143b..7d530c6 100644 --- a/fe/tests/e2e/api.ts +++ b/fe/tests/e2e/api.ts @@ -29,6 +29,7 @@ export function frameLedger(): Ledger { advances: [ { nullifier: NULLIFIER, + source: "AdSense", borrower: E2E_ADDRESS, windowStart: "2026-07-01", windowEnd: "2026-09-30", diff --git a/fe/tests/e2e/repayment.spec.ts b/fe/tests/e2e/repayment.spec.ts index 9b25783..2b4a09b 100644 --- a/fe/tests/e2e/repayment.spec.ts +++ b/fe/tests/e2e/repayment.spec.ts @@ -506,6 +506,25 @@ test("advance details say how it was sized, from the contract's own rate", async await expect(details.getByText("How it was sized").locator("..")).toContainText("25% of $360.00"); }); +test("advance details name where the revenue was earned, from the API's source", async ({ page, isMobile }) => { + test.skip(isMobile, "advance details are the desktop layout's"); + const ledger = frameLedger(); + ledger.advances[0].source = "AdMob"; + await open(page, "/repayment", ledger); + const details = page.getByRole("heading", { name: "Advance details" }).locator(".."); + await expect(details.getByText("AdMob revenue, Jul to Sep 2026")).toBeVisible(); + await expect(details).not.toContainText("AdSense"); +}); + +test("advance details read an advance without a source, from an API before #107, as AdSense", async ({ page, isMobile }) => { + test.skip(isMobile, "advance details are the desktop layout's"); + const ledger = frameLedger(); + delete (ledger.advances[0] as Partial<(typeof ledger.advances)[0]>).source; + await open(page, "/repayment", ledger); + const details = page.getByRole("heading", { name: "Advance details" }).locator(".."); + await expect(details.getByText("AdSense revenue, Jul to Sep 2026")).toBeVisible(); +}); + test("the sizing row holds its place while the contract's sizing loads", async ({ page, isMobile }) => { test.skip(isMobile, "advance details are the desktop layout's"); await open(page, "/repayment", frameLedger(), { advance: { sizingDelayMs: 1500 } }); From ff054240b7b32e4fabfd1dab1f37deb32f275cda Mon Sep 17 00:00:00 2001 From: Nabil-Aufa <181296848+Nabil-Aufa@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:46:40 +0700 Subject: [PATCH 2/2] fix(#97): keep the revenue window whole when the Advance details label wraps Co-Authored-By: Claude Opus 5.5 --- .../repayment/components/AdvanceDetails.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/fe/src/modules/repayment/components/AdvanceDetails.tsx b/fe/src/modules/repayment/components/AdvanceDetails.tsx index da02875..88ef0f5 100644 --- a/fe/src/modules/repayment/components/AdvanceDetails.tsx +++ b/fe/src/modules/repayment/components/AdvanceDetails.tsx @@ -26,21 +26,28 @@ export function AdvanceDetails({ }) { const sized: ReactNode = terms === "loading" ? : sizingLabel(advance, terms); - const rows: { label: string; value: ReactNode }[] = [ - { label: "Advanced", value: formatUsdc(advance.principal) }, + const rows: { key: string; label: ReactNode; value: ReactNode }[] = [ + { key: "advanced", label: "Advanced", value: formatUsdc(advance.principal) }, { - label: `${advance.source} revenue, ${formatWindow(advance.windowStart, advance.windowEnd).short}`, + key: "revenue", + // When the label has to wrap, the window moves to the next line whole, never the year alone. + label: ( + <> + {advance.source} revenue,{" "} + {formatWindow(advance.windowStart, advance.windowEnd).short} + + ), value: formatUsdCents(advance.revenueCents), }, - ...(sized ? [{ label: "How it was sized", value: sized }] : []), - { label: "Received on", value: formatLedgerTime(advance.openedAt) }, + ...(sized ? [{ key: "sized", label: "How it was sized", value: sized }] : []), + { key: "received", label: "Received on", value: formatLedgerTime(advance.openedAt) }, ]; return (

Advance details

{rows.map((r) => ( -
+
{r.label}
{r.value}