-
Notifications
You must be signed in to change notification settings - Fork 14
chore: back-merge main → dev (SP-153 + hotfixes) #2586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hugo0
wants to merge
28
commits into
dev
Choose a base branch
from
backmerge-main-to-dev-20260729
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
95b07e0
feat: chain-aware ENS resolution + visible resolved address in withdraw
0xkkonrad c88ce7f
fix: invalidate recipient while chain-switch ENS re-resolution is in …
jjramirezn f92d52d
test: add printableAddress to the general.utils mock
jjramirezn 7de6e7b
feat: consent-ledger echo + re-consent click-through (tos-v1 phase 2)
jjramirezn a172da1
fix: emit prettier-stable output from the legal-versions generator
jjramirezn 849ee41
fix: key the re-consent check to the user, not the session
jjramirezn 6133d6f
fix: apply CodeRabbit findings on the consent client
jjramirezn b6e9845
test(re-consent): pin modal safety properties + doc sets; report cons…
jjramirezn a3c1497
fix(card): force collateral-only routing on lock/cancel
abalinda 27e8eae
fix(withdraw): stop success receipt showing 'Sent to undefined'
kushagrasarathe fdbde98
fix(ens): warm-cache resolved names in localstorage to stop address f…
kushagrasarathe 3645d59
fix(ens): guard warm-cache root shape against malformed localstorage
kushagrasarathe aa5da01
fix(ens): evict warm cache on client-settled no-name; keep AddressLin…
kushagrasarathe b10ece9
Update content submodule to latest main
Hugo0 28a5cc5
Merge pull request #2575 from peanutprotocol/auto/update-content-2026…
Hugo0 8eeb352
Update content submodule to latest main
Hugo0 e00563e
Merge pull request #2576 from peanutprotocol/auto/update-content-2026…
Hugo0 b151e80
Merge pull request #2571 from peanutprotocol/hotfix/card-lock-force-c…
jjramirezn ff5bb72
Merge pull request #2572 from peanutprotocol/hotfix/withdraw-receipt-…
jjramirezn ede6c7a
Merge pull request #2573 from peanutprotocol/fix/ens-name-warm-cache
jjramirezn 7cbe967
fix(re-consent): make the terms prompt escapable, per our own ToS §17
Hugo0 9c776d9
fix(re-consent): defer to the document's effective date, not a fixed …
Hugo0 d716787
chore(legal-versions): regenerate from the pinned content submodule
Hugo0 46f321a
Merge pull request #2579 from peanutprotocol/fix/re-consent-soft-gate
jjramirezn e8eca13
Merge pull request #2569 from peanutprotocol/release/sp-153-cherry-picks
jjramirezn 4c7a0fc
hotfix: redirect bare card legal slugs to their /en pages
jjramirezn e914cb6
Merge pull request #2581 from peanutprotocol/hotfix/card-legal-redirects
Hugo0 54fcd01
Merge branch 'main' into dev — back-merge SP-153 + hotfixes
Hugo0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Generates src/constants/legal-versions.generated.ts from the legal content | ||
| // submodule (src/content/content/legal/<slug>/en.md): version = frontmatter | ||
| // `last_updated`, hash = sha256 of the raw en.md bytes. The consent ledger | ||
| // (peanut-api `consent_records`) stores what the user was actually shown, so | ||
| // these values must come from the same files the legal pages render — never | ||
| // hand-edit the generated file. Runs on predev/prebuild; commit the output so | ||
| // CI and static analysis see it without running the generator. | ||
| import { createHash } from 'node:crypto' | ||
| import { readdirSync, readFileSync, writeFileSync, existsSync } from 'node:fs' | ||
| import { dirname, join, resolve } from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
|
|
||
| const root = resolve(dirname(fileURLToPath(import.meta.url)), '..') | ||
| const legalDir = join(root, 'src/content/content/legal') | ||
| const outFile = join(root, 'src/constants/legal-versions.generated.ts') | ||
|
|
||
| if (!existsSync(legalDir)) { | ||
| // Submodule not checked out (e.g. a bare CI job) — keep the committed file. | ||
| console.warn('[legal-versions] src/content submodule missing, keeping committed constants') | ||
| process.exit(0) | ||
| } | ||
|
|
||
| const entries = [] | ||
| for (const slug of readdirSync(legalDir).sort()) { | ||
| const file = join(legalDir, slug, 'en.md') | ||
| if (!existsSync(file)) continue | ||
| const raw = readFileSync(file) | ||
| const match = /^last_updated:\s*["']?(\d{4}-\d{2}-\d{2})["']?\s*$/m.exec(raw.toString('utf8')) | ||
| if (!match) { | ||
| console.error(`[legal-versions] ${slug}/en.md has no last_updated frontmatter — refusing to generate`) | ||
| process.exit(1) | ||
| } | ||
| const hash = createHash('sha256').update(raw).digest('hex') | ||
| entries.push({ slug, version: match[1], hash }) | ||
| } | ||
|
|
||
| // output must be byte-stable under prettier so predev never dirties the tree: | ||
| // one field per line (printWidth 120), keys quoted only when not identifiers | ||
| const key = (slug) => (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(slug) ? slug : `'${slug}'`) | ||
| const body = entries | ||
| .map( | ||
| ({ slug, version, hash }) => | ||
| ` ${key(slug)}: {\n version: '${version}',\n hash: '${hash}',\n },` | ||
| ) | ||
| .join('\n') | ||
|
|
||
| writeFileSync( | ||
| outFile, | ||
| `// AUTO-GENERATED by scripts/generate-legal-versions.mjs — do not edit. | ||
| // version = frontmatter last_updated; hash = sha256 of the raw en.md in the | ||
| // src/content submodule. Echoed to the consent ledger so the backend records | ||
| // exactly which document revision the user was shown. | ||
| export interface LegalDocumentVersion { | ||
| version: string | ||
| hash: string | ||
| } | ||
|
|
||
| export const LEGAL_DOCUMENT_VERSIONS = { | ||
| ${body} | ||
| } as const | ||
|
|
||
| export type LegalDocumentSlug = keyof typeof LEGAL_DOCUMENT_VERSIONS | ||
| ` | ||
| ) | ||
| console.log(`[legal-versions] wrote ${entries.length} documents to src/constants/legal-versions.generated.ts`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| /** | ||
| * Regression tests for the lock/cancel collateral withdrawal (prod incident | ||
| * 2026-07-24): both modals MUST force collateral-only routing when returning | ||
| * spending power. Without `forceStrategy`, live routing picks smart-only | ||
| * whenever the smart wallet covers the amount (spendPreflight), and the | ||
| * modals then reject their own artifact ("Unexpected withdrawal strategy"), | ||
| * so users with wallet balance ≥ card balance could neither lock nor cancel. | ||
| * | ||
| * Contracts locked down here, for BOTH modals: | ||
| * 1. spendingPower > 0 → signSpend is called WITH forceStrategy: | ||
| * 'collateral-only' (the assertion that catches the regression) and the | ||
| * signed withdrawal is delivered to the backend call, | ||
| * 2. an unloaded overview fails closed BEFORE signing — undefined reads as | ||
| * zero spending power, which would silently skip the withdrawal and get | ||
| * the action rejected server-side, | ||
| * 3. a loaded overview with zero spending power proceeds without signing | ||
| * (no passkey prompt when there is nothing to return). | ||
| */ | ||
| import React, { type ReactNode } from 'react' | ||
| import { render, screen, fireEvent } from '@testing-library/react' | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
| import { NextIntlClientProvider } from 'next-intl' | ||
| import en from '@/i18n/app/messages/en.json' | ||
| import LockCardModal from '@/components/Card/LockCardModal' | ||
| import CancelCardModal from '@/components/Card/CancelCardModal' | ||
| import { useRainCardOverview } from '@/hooks/useRainCardOverview' | ||
| import { useWallet } from '@/hooks/wallet/useWallet' | ||
| import { useSignSpendBundle } from '@/hooks/wallet/useSignSpendBundle' | ||
| import { rainApi } from '@/services/rain' | ||
|
|
||
| const WALLET = '0xafbea1a6a6036d7d827e08072cd4315248b77352' | ||
|
|
||
| jest.mock('posthog-js', () => ({ __esModule: true, default: { capture: jest.fn() } })) | ||
| jest.mock('@/hooks/useRainCardOverview', () => ({ | ||
| useRainCardOverview: jest.fn(), | ||
| RAIN_CARD_OVERVIEW_QUERY_KEY: 'rain-card-overview', | ||
| })) | ||
| jest.mock('@/hooks/wallet/useWallet', () => ({ useWallet: jest.fn() })) | ||
| jest.mock('@/hooks/wallet/useSignSpendBundle', () => ({ useSignSpendBundle: jest.fn() })) | ||
| jest.mock('@/services/rain', () => ({ | ||
| rainApi: { | ||
| lockCard: jest.fn(), | ||
| activateCard: jest.fn(), | ||
| cancelCard: jest.fn(), | ||
| submitCancellationFeedback: jest.fn(), | ||
| }, | ||
| })) | ||
| // Modal chrome and the slide gesture are not under test — render passthroughs. | ||
| jest.mock('@/components/Global/Modal', () => ({ | ||
| __esModule: true, | ||
| default: ({ visible, children }: { visible: boolean; children: React.ReactNode }) => | ||
| visible ? <div>{children}</div> : null, | ||
| })) | ||
| jest.mock('@/components/Card/SlideToAction', () => ({ | ||
| __esModule: true, | ||
| default: ({ label, onComplete, disabled }: { label: string; onComplete: () => void; disabled?: boolean }) => ( | ||
| <button onClick={onComplete} disabled={disabled}> | ||
| {label} | ||
| </button> | ||
| ), | ||
| })) | ||
|
|
||
| const mockOverview = useRainCardOverview as jest.Mock | ||
| const mockUseWallet = useWallet as jest.Mock | ||
| const mockUseSignSpendBundle = useSignSpendBundle as jest.Mock | ||
| const mockLockCard = rainApi.lockCard as jest.Mock | ||
| const mockCancelCard = rainApi.cancelCard as jest.Mock | ||
| const mockSignSpend = jest.fn() | ||
|
|
||
| const RAIN_WITHDRAWAL = { preparationId: 'prep-1', amount: '10060000' } | ||
| // $10.06 spending power — the reporting user's exact state. | ||
| const OVERVIEW = { balance: { spendingPower: 1006 } } | ||
| const FORCED_SIGN_ARGS = { | ||
| requiredUsdcAmount: 10_060_000n, // 1006 cents → 6dp USDC units | ||
| recipient: WALLET, | ||
| rainSpendingPower: 10_060_000n, | ||
| kind: 'CRYPTO_WITHDRAW', | ||
| forceStrategy: 'collateral-only', | ||
| } | ||
|
|
||
| // Real `en.json`, not a key-echoing stub: the assertions below match on the | ||
| // user-visible strings ("Slide to Lock", "Card locked"), so the messages have to | ||
| // be the published ones. Both modals call useTranslations('card'). | ||
| const Wrapper = ({ children }: { children: ReactNode }) => ( | ||
| <NextIntlClientProvider locale="en" messages={en} timeZone="UTC"> | ||
| <QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}> | ||
| {children} | ||
| </QueryClientProvider> | ||
| </NextIntlClientProvider> | ||
| ) | ||
|
|
||
| const setup = (overview?: { balance: { spendingPower: number } }) => { | ||
| mockOverview.mockReturnValue({ overview }) | ||
| mockUseWallet.mockReturnValue({ address: WALLET }) | ||
| mockUseSignSpendBundle.mockReturnValue({ signSpend: mockSignSpend }) | ||
| } | ||
|
|
||
| const renderLock = () => | ||
| render(<LockCardModal cardId="card-1" mode="lock" isOpen onClose={jest.fn()} />, { wrapper: Wrapper }) | ||
| const renderCancel = () => render(<CancelCardModal cardId="card-1" isOpen onClose={jest.fn()} />, { wrapper: Wrapper }) | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| mockSignSpend.mockResolvedValue({ strategy: 'collateral-only', rainWithdrawal: RAIN_WITHDRAWAL }) | ||
| mockLockCard.mockResolvedValue({}) | ||
| mockCancelCard.mockResolvedValue({}) | ||
| }) | ||
|
|
||
| describe('LockCardModal — lock with spending power', () => { | ||
| it('forces collateral-only routing and delivers the withdrawal to the lock call', async () => { | ||
| setup(OVERVIEW) | ||
| renderLock() | ||
| fireEvent.click(screen.getByText('Slide to Lock')) | ||
| expect(await screen.findByText('Card locked')).toBeInTheDocument() | ||
| expect(mockSignSpend).toHaveBeenCalledWith(FORCED_SIGN_ARGS) | ||
| expect(mockLockCard).toHaveBeenCalledWith('card-1', RAIN_WITHDRAWAL) | ||
| }) | ||
|
|
||
| it('fails closed before signing when the overview has not loaded', async () => { | ||
| setup(undefined) | ||
| renderLock() | ||
| fireEvent.click(screen.getByText('Slide to Lock')) | ||
| expect(await screen.findByText(/still loading/)).toBeInTheDocument() | ||
| expect(mockSignSpend).not.toHaveBeenCalled() | ||
| expect(mockLockCard).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('locks without signing when there is no spending power to return', async () => { | ||
| setup({ balance: { spendingPower: 0 } }) | ||
| renderLock() | ||
| fireEvent.click(screen.getByText('Slide to Lock')) | ||
| expect(await screen.findByText('Card locked')).toBeInTheDocument() | ||
| expect(mockSignSpend).not.toHaveBeenCalled() | ||
| expect(mockLockCard).toHaveBeenCalledWith('card-1', undefined) | ||
| }) | ||
| }) | ||
|
|
||
| describe('CancelCardModal', () => { | ||
| it('forces collateral-only routing and delivers the withdrawal to the cancel call', async () => { | ||
| setup(OVERVIEW) | ||
| renderCancel() | ||
| fireEvent.click(screen.getByText('Slide to Cancel')) | ||
| expect(await screen.findByText('Card canceled')).toBeInTheDocument() | ||
| expect(mockSignSpend).toHaveBeenCalledWith(FORCED_SIGN_ARGS) | ||
| expect(mockCancelCard).toHaveBeenCalledWith('card-1', { verifiedWithdrawal: RAIN_WITHDRAWAL }) | ||
| }) | ||
|
|
||
| it('fails closed before signing when the overview has not loaded', async () => { | ||
| setup(undefined) | ||
| renderCancel() | ||
| fireEvent.click(screen.getByText('Slide to Cancel')) | ||
| expect(await screen.findByText(/still loading/)).toBeInTheDocument() | ||
| expect(mockSignSpend).not.toHaveBeenCalled() | ||
| expect(mockCancelCard).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('cancels without signing when there is no spending power to return', async () => { | ||
| setup({ balance: { spendingPower: 0 } }) | ||
| renderCancel() | ||
| fireEvent.click(screen.getByText('Slide to Cancel')) | ||
| expect(await screen.findByText('Card canceled')).toBeInTheDocument() | ||
| expect(mockSignSpend).not.toHaveBeenCalled() | ||
| expect(mockCancelCard).toHaveBeenCalledWith('card-1', { verifiedWithdrawal: undefined }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Localize the loading failure message.
Both modals expose a hard-coded English error through
setError, bypassing the existingcardtranslations.src/components/Card/LockCardModal.tsx#L69-L74: replace the literal with at('errors.…')key.src/components/Card/CancelCardModal.tsx#L63-L68: use the same translated key.Based on supplied library context, card errors are localized through
t(...).📍 Affects 2 files
src/components/Card/LockCardModal.tsx#L69-L74(this comment)src/components/Card/CancelCardModal.tsx#L63-L68🤖 Prompt for AI Agents