Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
454 changes: 454 additions & 0 deletions docs/design/forepay.pen

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion fe/src/lib/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ describe("proveFailureCopy", () => {
"noAdsense",
"googleSignInAdmob",
"noAdmob",
"noRevenue",
"noRevenueAdmob",
"relayFailed",
"relayBusy",
"proofRunning",
Expand All @@ -154,7 +156,7 @@ describe("proveFailureCopy", () => {
it("says nothing was charged only when that is true", () => {
expect(proveFailureCopy("refused").body).toMatch(/Nothing was charged/);
// The relay's failures happen before anything reaches Stellar.
for (const k of ["googleSignIn", "noAdsense", "googleSignInAdmob", "noAdmob", "relayFailed", "proofRunning", "proofGone", "relayUnreachable"] as const) {
for (const k of ["googleSignIn", "noAdsense", "googleSignInAdmob", "noAdmob", "noRevenue", "noRevenueAdmob", "relayFailed", "proofRunning", "proofGone", "relayUnreachable"] as const) {
expect(proveFailureCopy(k).body).toMatch(/Nothing was charged/);
}
for (const k of ["relayBusy", "googleUnavailable", "popupBlocked"] as const) {
Expand All @@ -169,6 +171,17 @@ describe("proveFailureCopy", () => {
expect(new Set(all).size).toBe(kinds.length);
});

it("points a creator with no revenue at the other source", () => {
expect(proveFailureCopy("noRevenue")).toEqual({
title: "No AdSense revenue to prove",
body: "We found no AdSense revenue in the last three complete months. If you earn with AdMob, go back and prove that instead. Nothing was charged.",
});
expect(proveFailureCopy("noRevenueAdmob")).toEqual({
title: "No AdMob revenue to prove",
body: "We found no AdMob revenue in the last three complete months. If you earn with AdSense, go back and prove that instead. Nothing was charged.",
});
});

it("names the wallet that declined", () => {
expect(proveFailureCopy("declined", "xBull").title).toBe("You declined in xBull");
});
Expand Down
13 changes: 13 additions & 0 deletions fe/src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export function contractFailureCopy(code: number, sourceName = "AdSense"): Failu
* - `googleSignIn`: Google refused the sign-in the relay was handed, for example an expired one.
* - `noAdsense`: the Google account has no AdSense account, several, or one that is not approved (relay `account`).
* - `googleSignInAdmob`, `noAdmob`: the same two for an AdMob proof (#97).
* - `noRevenue`, `noRevenueAdmob`: the account earned nothing in the three months (relay `empty`).
* - `relayFailed`: the relay could not make the proof, on its side. Nothing was charged.
* - `relayBusy`: the relay is proving for others and its queue is full.
* - `proofRunning`: a proof for this wallet is already running, started from a tab that lost it.
Expand Down Expand Up @@ -241,6 +242,8 @@ export type ProveFailure =
| "noAdsense"
| "googleSignInAdmob"
| "noAdmob"
| "noRevenue"
| "noRevenueAdmob"
| "relayFailed"
| "relayBusy"
| "proofRunning"
Expand Down Expand Up @@ -345,6 +348,16 @@ export function proveFailureCopy(kind: ProveFailure, walletName = "Freighter"):
title: "We could not use your AdMob account",
body: "We could not find one AdMob account on this Google account. Sign in with the account that owns your AdMob, then try again. Nothing was charged.",
};
case "noRevenue":
return {
title: "No AdSense revenue to prove",
body: "We found no AdSense revenue in the last three complete months. If you earn with AdMob, go back and prove that instead. Nothing was charged.",
};
case "noRevenueAdmob":
return {
title: "No AdMob revenue to prove",
body: "We found no AdMob revenue in the last three complete months. If you earn with AdSense, go back and prove that instead. Nothing was charged.",
};
case "relayFailed":
return {
title: "We could not finish your proof",
Expand Down
9 changes: 9 additions & 0 deletions fe/src/lib/reclaim/relay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ describe("relayProveRevenue", () => {
expect((e as RelayError).code).toBe("account");
});

it("a job that found no earnings keeps the code empty, and the source", async () => {
const r = relay([{ id: "j1", stage: "failed", error: { code: "empty", message: "no earnings" } }]);
const s = relayProveRevenue(BORROWER, () => {}, { relayUrl: "https://r", signIn: signedIn, fetch: r.fetch, sleep: noSleep, jobs: store().jobs, source: "admob" });
const e = await s.result.catch((x) => x);
expect(e).toBeInstanceOf(RelayError);
expect((e as RelayError).code).toBe("empty");
expect((e as RelayError).source).toBe("admob");
});

it("names the relay's refusal by its code, and by the status when there is none", async () => {
const cases: [number, object, string][] = [
[409, { error: "x", code: "running" }, "running"],
Expand Down
2 changes: 1 addition & 1 deletion fe/src/lib/reclaim/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export type RelayOptions = {
sleep?: (ms: number) => Promise<void>;
};

const CODES: readonly RelayErrorCode[] = ["token", "account", "running", "busy", "unconfigured", "provider", "prove", "audit", "internal"];
const CODES: readonly RelayErrorCode[] = ["token", "account", "empty", "running", "busy", "unconfigured", "provider", "prove", "audit", "internal"];

class Abandoned extends Error {}

Expand Down
2 changes: 2 additions & 0 deletions fe/src/lib/reclaim/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class RelayNotReadyError extends Error {
* Why the relay could not make the proof, by whose move it is (docs/api.md):
* - `token`: Google refused the sign-in, for example an expired one. Signing in again fixes it.
* - `account`: no approved AdSense account (or no AdMob account) behind that Google account.
* - `empty`: the account earned nothing in the three months. Proving again proves the same nothing.
* - `running`: a proof for this wallet is already running, started from a tab that no longer has it.
* - `gone`: the proof this tab was waiting on is no longer on the relay (it restarted, or an hour passed).
* - `busy`: the relay is proving for others and its queue is full.
Expand All @@ -57,6 +58,7 @@ export class RelayNotReadyError extends Error {
export type RelayErrorCode =
| "token"
| "account"
| "empty"
| "running"
| "gone"
| "busy"
Expand Down
8 changes: 8 additions & 0 deletions fe/src/modules/advance/components/FailurePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ export function FailurePanel({
illustration = <IlloSessionCancelled data-illo="session-cancelled" />;
actions = <Button onClick={a.onProve}>Prove my revenue</Button>;
break;
// The relay found no earnings in the window (#97). Not on the board yet. Proving again would read the
// same months, so only Back: from 2a the creator can pick the other source. The picture and single
// Back of "Not enough revenue yet", on 2a's step since there is no offer.
case "noRevenue":
case "noRevenueAdmob":
illustration = <IlloNoAdvanceYet data-illo="no-advance-yet" />;
actions = back;
break;
case "proofGone":
illustration = <IlloProofExpired data-illo="proof-expired" />;
actions = <>{proveAgain}{back}</>;
Expand Down
3 changes: 3 additions & 0 deletions fe/src/modules/advance/failures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ describe("proveFailure", () => {
// An AdMob proof names AdMob where the creator has to act on their Google account (#97).
expect(proveFailure(new RelayError("token", "x", "admob"))).toEqual({ kind: "googleSignInAdmob" });
expect(proveFailure(new RelayError("account", "x", "admob"))).toEqual({ kind: "noAdmob" });
// No revenue in the window: its own words, not "try again in a few minutes".
expect(proveFailure(new RelayError("empty", "x"))).toEqual({ kind: "noRevenue" });
expect(proveFailure(new RelayError("empty", "x", "admob"))).toEqual({ kind: "noRevenueAdmob" });
expect(proveFailure(new RelayError("gone", "x", "admob"))).toEqual({ kind: "proofGone" });
for (const code of ["provider", "prove", "audit", "internal"] as const) {
expect(proveFailure(new RelayError(code, "x"))).toEqual({ kind: "relayFailed" });
Expand Down
1 change: 1 addition & 0 deletions fe/src/modules/advance/failures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function sorted(e: unknown): AdvanceFailure {
const kinds: Partial<Record<RelayErrorCode, ProveFailure>> = {
token: e.source === "admob" ? "googleSignInAdmob" : "googleSignIn",
account: e.source === "admob" ? "noAdmob" : "noAdsense",
empty: e.source === "admob" ? "noRevenueAdmob" : "noRevenue",
running: "proofRunning",
gone: "proofGone",
busy: "relayBusy",
Expand Down
30 changes: 30 additions & 0 deletions fe/tests/e2e/relay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ test("a Google account with no AdSense the relay can read is named", async ({ pa
await expect(page.getByRole("button", { name: "Back" })).toBeVisible();
});

test("an AdSense account that earned nothing is named, and only Back is offered", async ({ page }) => {
const relay = relayFor({ j1: [{ id: "j1", stage: "failed", error: { code: "empty", message: "no AdSense earnings" } }] });
await connect(page, relay, "ok");
await prove(page);
await expect(heading(page, "No AdSense revenue to prove")).toBeVisible();
await expect(page.getByText("We found no AdSense revenue in the last three complete months", { exact: false })).toBeVisible();
await expect(page.getByText("If you earn with AdMob, go back and prove that instead.", { exact: false })).toBeVisible();
await expect(page.locator('[data-illo="no-advance-yet"]')).toBeVisible();
// Proving again would read the same months.
await expect(page.getByRole("button", { name: "Prove again" })).toHaveCount(0);
await page.getByRole("button", { name: "Back" }).click();
await expect(page.getByRole("radio", { name: /AdSense/ })).toBeChecked();
await expect(page.getByRole("button", { name: "Prove my revenue" })).toBeVisible();
});

test("closing Google's window is named, and proving can start again", async ({ page }) => {
const relay = relayFor();
await connect(page, relay, "closed");
Expand Down Expand Up @@ -348,6 +363,21 @@ test("a Google account with no AdMob is named as AdMob, and Prove again stays on
expect(relay.posts.map((p) => p.source)).toEqual(["admob", "admob"]);
});

test("an AdMob account that earned nothing is named as AdMob, and Back stays on AdMob", async ({ page }) => {
const relay = relayFor({ j1: [{ id: "j1", stage: "failed", error: { code: "empty", message: "no AdMob earnings" } }] });
await connect(page, relay, "ok");
await chooseAdmob(page);
await prove(page);
await expect(heading(page, "No AdMob revenue to prove")).toBeVisible();
await expect(page.getByText("We found no AdMob revenue in the last three complete months", { exact: false })).toBeVisible();
await expect(page.getByText("If you earn with AdSense, go back and prove that instead.", { exact: false })).toBeVisible();
await expect(page.locator('[data-illo="no-advance-yet"]')).toBeVisible();
await expect(page.getByRole("button", { name: "Prove again" })).toHaveCount(0);
await page.getByRole("button", { name: "Back" }).click();
await expect(page.getByRole("radio", { name: /AdMob/ })).toBeChecked();
expect(relay.posts.map((p) => p.source)).toEqual(["admob"]);
});

test("an AdMob proof resumed after leaving stays AdMob: its reading, its failure, Prove again and Back", async ({ page }) => {
const relay = relayFor({ j1: [{ id: "j1", stage: "failed", error: { code: "account", message: "no AdMob account" } }] });
relay.hold = true;
Expand Down