Repository navigation
#17 Front end relay client behind proveRevenue - #75
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
9ab5165 to
b5b1bde
Compare
cffa219 to
10ba87a
Compare
|
Retargeted to This was based on Green and mergeable now. Not reviewing it yet — same as #73, I would rather read it properly than approve it on momentum. It also touches Two things from the contract side that bear on this PR:
|
Nabil-Aufa
left a comment
There was a problem hiding this comment.
@Lin1er, thanks. The seam is the right size, the mock path is untouched, and the scope check on the token (adsense.readonly actually granted) is a good catch. I read the diff against docs/api.md on #73 and against the screens around proveRevenue. These are what I found, with the most important first.
Must fix before merge
-
The waiting copy says "This takes a few seconds".
Advance.tsx:388shows "Reading your revenue: This takes a few seconds. Keep this page open." With the relay, that stage lasts about ten minutes plus the queue. A creator who believes "a few seconds" leaves, and loses the proof (see 2). This needs words that set the wait honestly. That copy is mine; I will write it unless you want to. -
Leaving or reloading during the ten minutes loses the proof, and coming back fails.
abandon()only stops polling. The job keeps running on the relay, and the job id lives only in memory.- The tab bar is right there, so a creator who comes back to
/advancestarts a newPOST /proofs. That gets409("already in progress"), which shows "We could not finish your proof", while their proof finishes unseen. Jobs are kept for an hour (docs/api.md), so the result is still there to be had. - Proposal: keep
{ borrower, jobId }insessionStorage, asmodules/advance/pending.tsalready does for a sent advance. On return, poll that job instead of signing in again. On #73, a409could also return the running job'sid, so a tab that lost its storage can pick the job up.
-
A relay that does not answer is reported as Stellar.
fetchfailing onPOST /proofsor a poll throws aTypeError.sorted()infailures.tsmaps that tounreachable, "We could not reach Stellar", which is wrong and sends the creator to check the wrong thing.- Map transport failures from
relay.tsto aRelayError(internal, or a newunreachablecode), so they reachrelayFailed. - The Google script failing to load (
loadGis) needs the same. Today "Google sign-in failed to load" falls through tounexpected.
- Map transport failures from
Should fix
-
The popup can be blocked the first time.
requestAccessToken()runs afterawait loadGis(). When the script is not cached, the popup opens outside the click's user activation, and browsers may block it.- Load the script when 2a mounts, so the press opens the popup at once.
- Also handle
error_callbackwithtype: "popup_failed_to_open"on its own: today it reads as "You closed the AdSense window", but the creator closed nothing.
-
409,503busy and503"relay not configured" all becomerelayFailed, "Try again in a few minutes".409is this wallet's own running job; with 2 it becomes a resume, not an error.503with"relay": falseis our misconfiguration and should read likerelayNotReady, not "try again".
-
The 30-minute give-up (
timeoutMs) ends asrelayFailedwhile the job may still finish within the relay's hour. With 2 in place, keep polling the stored job instead of starting over. -
No e2e for the relay path. The unit tests are good. The three new panels and the popup stage are not covered in Playwright, though. A routed
/proofsand a stubbedwindow.google.accounts.oauth2would cover them liketests/e2e/rpc.tscovers Stellar.
Copy and design (mine to finish, noted so they are not lost)
- The waiting panel says "Log in to AdSense in the new window". It is now Google's sign-in, so it should say something like "Sign in with Google in the new window".
- The three new failure panels all use the session-cancelled illustration and "Prove my revenue" + "Back".
noAdsenseprobably wants its own words about which Google account to use; "Nothing was saved" is vague next to our "Nothing was charged" rule. - The board: the three panels and the long wait need adding to the design. @AncungAulia
Happy to take 1, 4 (the preload) and the copy myself on top of this PR if you prefer. 2 and 3 are in relay.ts, so tell me whether you want them or I do them.
These came from a review pass without a separate verification step (I read the code, I did not run it against a live relay), so please treat them as candidates and check each one.
🤖 Generated with Claude Code
|
@Nabil-Aufa thanks, all seven check out against the code. Split as you proposed:
On the wait: proving is about a minute on the relay host ( I will push to this branch and say so here. Agreed on landing #71 first for |
The front end has to tell "your proof is still running" from "the relay is full" from "the relay is not set up here", and the status alone cannot: 503 means two of them. Each refusal now says which in `code`. 409 deliberately does not return the running job's id. A borrower's address is public, and the id is what reads their revenue, so the front end keeps the id it was given with the 202 (review on #75).
Review on #75: - The job id is kept in sessionStorage. Coming back to /advance, or reloading, while the relay proves waits on the same job without a second sign-in, instead of a new POST the relay refuses as already running. A kept job the relay no longer has (restart, or past its hour) starts a fresh proof. The id is cleared once the job ends, not when the screen is left. - A relay that does not answer is RelayError unreachable, not "We could not reach Stellar". Google's script failing to load is googleUnavailable. - error_callback popup_failed_to_open is popupBlocked: the creator closed nothing. - 409 is running, 503 is busy or unconfigured, read from the relay's new `code` (#73), the status as fallback. unconfigured reads like relayNotReady, not "try again". - No 30-minute give-up: polling runs to the hour after which the claim is too old and the relay has forgotten the job. - preloadSignIn() is exported for 2a to call on mount (the preload in 4). The copy for the four new panels is a first pass for Nabil to replace.
|
@Nabil-Aufa pushed 2, 3, 5, 6 and the
The copy for the four new kinds ( |
…d claim (#73) * feat(#17): proof relay, POST /proofs and GET /proofs/:id The relay takes the borrower's G… and a Google access token with adsense.readonly, proves the trailing AdSense revenue with zkFetch, and returns request_advance's arguments. The G… goes into contextAddress before the attestor signs, so the binding is inside the signed claim (#9). Proving takes about ten minutes of CPU with snarkjs, so the request answers 202 with a job id and the front end polls. One proof runs at a time; one job per borrower; a short queue. Jobs live in memory and the token only in the running job's closure: never stored, logged or returned, and scrubbed from errors. The pre-flight checks (account, READY, response shape) move from the prove:adsense CLI to adsense/account.ts and relay/prove.ts, so the CLI and the relay run the same code. Failures carry a code that says whose move it is: token, account, provider, prove, audit. The browser flow and the API are in docs/api.md. * docs(#17): the API and the relay, public at api-forepay.jameshub.fun Deployed from feat/17-proof-relay with #74 merged in. /config reports the recorded addresses and relay: true; /ready answers. A smoke proof made on the host was signed by the production attestor in 54 s and passes verify_proof in simulation, with the one-byte flip refused as #5. * docs(#17): proving takes about a minute on the relay host, not ten * feat(#17): relay errors carry a code: running, busy, unconfigured The front end has to tell "your proof is still running" from "the relay is full" from "the relay is not set up here", and the status alone cannot: 503 means two of them. Each refusal now says which in `code`. 409 deliberately does not return the running job's id. A borrower's address is public, and the id is what reads their revenue, so the front end keeps the id it was given with the 202 (review on #75). * fix(#17): refuse an access token too short to be Google's Scrubbing a one-character token out of a failure message cut that character out of every word ("e[redacted]pired"), seen live on the relay. Google's tokens run to hundreds of characters; under 16 is a 400.
|
@Nabil-Aufa — one item in your review should be dropped rather than implemented, and it is worth saying before @Lin1er builds it. Item 2's second half would leak creators' revenue
The job id is a bearer capability: whoever holds it can If the
The rest of item 2 is right, and is the whole fixThe For a tab that genuinely lost its storage (hard reload, crash, another device) there is no safe recovery without proving control of the wallet, which means signing a challenge the relay verifies. That is a real feature and not a 30-day one. So the honest behaviour is prove again, with copy that says so — much better than today's "We could not finish your proof", which is what you correctly flagged. And one thing neither of us caught: a resumed job can hand you a dead proofThe relay keeps a finished job readable for an hour, and the contract refuses a proof older than an hour, measured from the attestor's Nothing is charged — simulation refuses it before submission — but it is the worst place in the flow to fail, and your resume is what makes it likely. I asked James to put the deadline in the job view: /** Unix seconds after which the contract will refuse this proof as stale. */
expiresAt?: number; // Number(request.timestampS) + 3600With that, 2a can say "this proof has expired, prove again" before asking for a signature. Please check for it when you wire the resume; if it is not there yet, Everything else in your review reads right to me, and item 1 is the most important thing on this PR: "This takes a few seconds" for a ten-minute wait is what causes the data loss in item 2. |
proveRevenue now uses the #17 relay when NEXT_PUBLIC_RELAY_URL and NEXT_PUBLIC_GOOGLE_CLIENT_ID are set. The creator signs in with Google's own popup (Identity Services token client, adsense.readonly only), the token and the wallet's G… go once to POST /proofs, and the job is polled until it answers with request_advance's arguments. No Reclaim SDK runs in the browser. Stages keep their meaning: waiting while Google's popup is open, reading from the relay job until it ends. Closing the popup, or allowing without the AdSense scope, is ReclaimCancelledError, as closing the window was. Reopening waits on the newest popup. An abandoned session stops polling and never settles. Relay failures carry the relay's code. Three new prove failures say whose move it is: googleSignIn (sign in again), noAdsense, relayFailed. The mock is unchanged while NEXT_PUBLIC_RELAY_URL is empty.
Review on #75: - The job id is kept in sessionStorage. Coming back to /advance, or reloading, while the relay proves waits on the same job without a second sign-in, instead of a new POST the relay refuses as already running. A kept job the relay no longer has (restart, or past its hour) starts a fresh proof. The id is cleared once the job ends, not when the screen is left. - A relay that does not answer is RelayError unreachable, not "We could not reach Stellar". Google's script failing to load is googleUnavailable. - error_callback popup_failed_to_open is popupBlocked: the creator closed nothing. - 409 is running, 503 is busy or unconfigured, read from the relay's new `code` (#73), the status as fallback. unconfigured reads like relayNotReady, not "try again". - No 30-minute give-up: polling runs to the hour after which the claim is too old and the relay has forgotten the job. - preloadSignIn() is exported for 2a to call on mount (the preload in 4). The copy for the four new panels is a first pass for Nabil to replace.
8176b6f to
bb65d2e
Compare
|
Rebased onto |
Nabil-Aufa
left a comment
There was a problem hiding this comment.
@Lin1er, thanks for the rebase and the fixes. I re-read bb65d2e against my first review and docs/api.md, and ran it: lint and typecheck clean, 187 unit tests and 206 Playwright tests pass here.
Fixed as asked: relay failures are the relay's (polls included), popup_failed_to_open has its own panel, 409 / 503 read the relay's code, the 30-minute give-up is gone, and a proof that finishes while the creator is away is found on return. A poll that fails on the network keeps the id, so the next press resumes. Good.
Must fix
- A kept job the relay no longer has opens Google's popup outside any press. When
follow(kept)gets404(the relay restarted, or the creator is back more than an hour after the job ended),prove()clears the id and callssignIn()straight away.- From the mount effect (
proofRunning(address)→prove()), that is a popup with no click at all. - From a press, it opens after an
await, outside the click's user activation. - Either way the browser blocks it, and the creator reads "Your browser blocked the Google window", which is not what happened. I confirmed the call with a throwaway test: kept id, relay answering
404, andsignInruns once with no press. - Proposal: on
404, clear the id and end the session back at 2a (a new error kind, or a quiet return to the start), so the next press opens the popup inside its click.
- From the mount effect (
Small
proofRunningcopy promises a pick-up that cannot happen. "Try again in a few minutes to pick it up": the409deliberately carries no id (docs/api.md), so a tab that lost it can only start a new proof once the old one ends. That copy is mine; I will rewrite it with the other panels.- One slot for every wallet.
JOB_KEYholds one{ borrower, id }, so proving with a second wallet in the same tab overwrites the first one's id. Rare; fine to leave, worth a comment.
As agreed, I am taking the waiting copy, preloadSignIn() on 2a, the panel copy, the stale-proof check before signing and the e2e. Since you are away until tomorrow, I can also do 1 on this branch as a separate commit, unless you would rather keep it.
🤖 Generated with Claude Code
…in outside a press
When the relay answers 404 for the job id this tab kept (it restarted, or the hour
passed), the session used to clear it and call signIn() straight away. From the mount
effect that opens Google's popup with no press at all, and from a press it opens after
an await. The browser blocks it, and the creator read "Your browser blocked the Google
window", which is not what happened.
Now the session ends as RelayError("gone"), shown as "Your earlier proof has ended"
with Prove my revenue, so the next sign-in opens inside a click.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the popup Also on a failure panel, whose Prove my revenue starts the same sign-in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… relay's panels - Waiting: "Sign in with Google in the new window", naming the account and the AdSense box to tick. 2a says "Sign in with Google" too. - Reading: about a minute, longer behind a queue; other pages are safe, a closed tab means proving again. It no longer promises a few seconds. - noAdsense names the Google account as the thing to change. - proofRunning no longer promises to pick the job up: a 409 carries no id, so it says to wait for it to end and prove again. - busy has its own panel, "Forepay is busy right now", instead of relayFailed. - "Nothing was saved" becomes "Nothing was charged", the rule the other panels follow. - "You closed the Google window", since the window is Google's now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A second e2e build has NEXT_PUBLIC_RELAY_URL and a Google client id set (the relay-desktop and relay-mobile projects). Google's sign-in is a stub on window.google, which relay.ts uses when it is already there, and the spec answers /proofs as docs/api.md describes. Covered: the offer after a real-shaped job, noAdsense, the Google window closed and blocked, a full queue, a 409 from a tab that lost its job, leaving and coming back to the same job with one sign-in and one POST, and a kept job the relay no longer has, which must not open Google's window until the creator presses. Jobs are polled every 200 ms under NEXT_PUBLIC_E2E, as the mock shortens its delays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lashes 2a From the strict review of the four commits before this one: - proofGone: "Your earlier proof is gone", worded for both causes (the relay restarted, or an hour passed); the proof did not necessarily finish. Proof-expired illustration. - noAdsense covers all of the relay's `account` cases: none, several, or not approved. - popupBlocked and googleUnavailable: "Nothing was read or charged", like relayBusy. The cancelled panel keeps the board's "Nothing was read or saved"; the previous commit's body overstated how far that rule went. - The relay panels pair "Prove again" with "Back" in a row, as the board's pairs do; "Prove my revenue" did not fit half the row. - Back on /advance with a kept job, "Reading your revenue" shows from the first render, as a pending advance does, so 2a's button never flashes. - Comments: why accept has no clock check on the proof (simulation refuses with 12 before the wallet is asked), the reading copy describes the relay, and JOB_KEY holds one wallet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…me, and make the relay build optional - Unit: a poll that fails on the network keeps the id, and the next press reaches gone with no sign-in. The relay kinds' "Nothing was charged" claims are asserted. - e2e: token and prove failures with Prove again, a relay that does not answer, Google's script loading on 2a before any press, the script failing to load, and no flash of 2a's button when coming back to a running proof. - PW_RELAY=0 leaves out the relay dev server and its projects, for quicker single-spec runs. README and .env.example say what the second build and NEXT_PUBLIC_E2E now do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s every account case From the strict re-review: - A failure that keeps the job id (a poll that failed on the network) left "Back" on a "Reading your revenue" spinner with nothing running: the start screen shows it for a kept job, and toStart() never started the session. toStart() now waits on the kept job, as it does on a pending advance. Two e2e: Back after a failed poll reaches the offer with one sign-in and one POST; Back after a gone job returns to 2a. - noAdsense: "We could not use your AdSense account", true for none, several, or not approved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Lin1er, since you are away I took the must-fix from my last review as agreed, plus my own part, as commits on top of What changed
Fixes found in review:
The stale-proof check: not added, on purposeI said I would add a clock check before signing. It is not needed:
The e2e "a proof that expires while the offer is open is named at accept" covers it. A comment in One behaviour worth knowingWhile the relay is down and a job id is kept, "Back" shows "We could not reach Forepay" again. The creator reaches 2a once the relay answers (the job is done or gone) or the tab is closed. Nothing can be proved without the relay meanwhile. For the board (@AncungAulia)Changed on purpose. These replace strings on "Prove and accept / States and interactions", because the window is Google's now and the relay takes about a minute:
New panels, not on the board yet. Each has "Prove again" and "Back":
All but proofGone use the session-cancelled illustration for now. The board draws "Prove again" + "Back" stacked. The code puts the pair in one row from 768 up, under section 08's rule, as the code-12 and code-14 panels already do. Tell me if the board should win. Checked
Still mine after merge: the env in Vercel (@AncungAulia) and the 🤖 Generated with Claude Code |
|
@Nabil-Aufa thanks for taking these. I read Checked here on Agreed on leaving out the clock check: simulation refuses a stale proof before the wallet is asked, and the e2e pins it. The |
app.forepay.xyz serves fe/ from main on testnet. The record says how it was checked, by the rendered page in Chrome and headless Chromium, and that the API now answers the deployed origin. The screenshots are all of the live app. None of the offer, signing or repayment is included: on this deployment proving runs on the mock, which the contract refuses, until the relay client (#75) and a real proof (#77) land. Deliverable 2 stays Partial for that reason. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
app.forepay.xyz serves fe/ from main on testnet. The record says how it was checked, by the rendered page in Chrome and headless Chromium, and that the API now answers the deployed origin. The screenshots are all of the live app. None of the offer, signing or repayment is included: on this deployment proving runs on the mock, which the contract refuses, until the relay client (#75) and a real proof (#77) land. Deliverable 2 stays Partial for that reason. Co-authored-by: Nabil-Aufa <181296848+Nabil-Aufa@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
@Nabil-Aufa your review from 2026-10-23 is still Changes requested, although every item in it is fixed, by your own commits @Lexirieru the branch is |
Nabil-Aufa
left a comment
There was a problem hiding this comment.
Every item from my reviews of 2026-10-20 and 2026-10-23 is fixed, in d4ec16b…2fdfa59, and @Lin1er has accepted those commits above. Checked again on 2fdfa59: the head is unchanged since the strict review passed, CI is green (Rust, TypeScript, Python, Vercel), and it merges into current main with no conflicts. Approving. @Lexirieru, it is ready for your merge.
🤖 Generated with Claude Code
|
Merging under the working agreement's two-day clause: approved on 2026-10-26 at Without |
Refs #17. This PR is stacked on #57 (#20, @Nabil-Aufa) and only touches the
proveRevenueseam. Nabil, it's your branch, so merge it into #57 or cherry-pick it, whichever you prefer.The relay itself is in #73. Its API is documented in
docs/api.md→ "The proof relay".What changes
lib/reclaim/relay.ts:adsense.readonlyonly. It loads Google's script, not an npm package.POST /proofswith{ borrower, accessToken }, then pollsGET /proofs/:idevery 5 s.AdvanceRequest, convertingtimestampSandepochwithBigInt().proveRevenue:NEXT_PUBLIC_RELAY_URLandNEXT_PUBLIC_GOOGLE_CLIENT_IDare both set.relayNotReady.Stages keep their meaning:
waitingis while Google's popup is open;readinglasts from the relay job until it ends.ReclaimCancelledError, which already shows as "You closed the AdSense window".reopenopens a new popup; if an older popup closes, the session doesn't end.abandonstops polling, and the session never settles.Three new prove failures, each mapped from the relay's error code:
googleSignIn(token);noAdsense(account);relayFailed(busy, or a failure on our side).The copy follows the existing rules and the tests check it. Nabil: the wording and illustrations are yours, so change them freely.
.env.example, README and ARCHITECTURE §3 now coverNEXT_PUBLIC_GOOGLE_CLIENT_ID.Needed to run it for real
CORS_ORIGINS.Verified
vitest: 137 pass, including six new relay-client tests:READYAdSense account (FEASIBILITY GATE: one real AdSense revenue proof verified on testnet #5).