-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Manteca entity deposit addresses from the API (TASK-22107) #2933
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
33cb733
feat: fund Manteca flows at the API-served entity deposit address
jjramirezn 09199fa
fix: runtime-validate the API-served address; test every money-moving…
jjramirezn b45de3d
fix: surface the API's human message instead of a raw wire code on cl…
jjramirezn d71c473
fix: reject the zero address; pin the qr-pay page-level recipient wiring
jjramirezn 7da06ad
fix: claim-link fails closed on any invalid served address; withdraw …
jjramirezn a36aa99
fix: click Withdraw by name — the first button is the destination row…
jjramirezn 50e7e3d
test: pin the bank-withdraw recipient at the signing boundary, page-l…
jjramirezn d8798af
fix(claim): authenticated /claim + deploy-window fallback for the ent…
jjramirezn d288492
Merge origin/dev into feat/TASK-22107-manteca-entity-addresses
jjramirezn 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
Some comments aren't visible on the classic Files Changed page.
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
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
113 changes: 113 additions & 0 deletions
113
src/components/Claim/Link/views/__tests__/MantecaReviewStep.test.tsx
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,113 @@ | ||
| /** | ||
| * MantecaReviewStep — the claim-link offramp's pre-claim entity lookup. | ||
| * | ||
| * This is the safety boundary that keeps a ONE-SHOT claim link from funding | ||
| * the wrong Manteca entity after the 2026-09-14 split: | ||
| * - the API-served depositAddress from /withdraw/init must be the address | ||
| * the link is claimed to, | ||
| * - an init failure must abort BEFORE the link is spent — no claim, no | ||
| * withdraw — because the link cannot be re-claimed. | ||
| */ | ||
| import React from 'react' | ||
| import { render, screen, fireEvent, waitFor } from '@testing-library/react' | ||
| import { IntlWrapper } from '@/test-utils/intl' | ||
|
|
||
| const mockInitiateWithdraw = jest.fn() | ||
| const mockWithdraw = jest.fn() | ||
| jest.mock('@/services/manteca', () => ({ | ||
| mantecaApi: { | ||
| initiateWithdraw: (...args: unknown[]) => mockInitiateWithdraw(...args), | ||
| withdraw: (...args: unknown[]) => mockWithdraw(...args), | ||
| }, | ||
| })) | ||
|
|
||
| const mockAssociateClaim = jest.fn() | ||
| jest.mock('@/services/sendLinks', () => ({ | ||
| sendLinksApi: { associateClaim: (...args: unknown[]) => mockAssociateClaim(...args) }, | ||
| })) | ||
|
|
||
| const mockClaimLinkSecure = jest.fn() | ||
| jest.mock('@/components/Claim/useClaimLink', () => ({ | ||
| __esModule: true, | ||
| default: () => ({ claimLink: mockClaimLinkSecure }), | ||
| })) | ||
|
|
||
| jest.mock('@/hooks/useCurrency', () => ({ | ||
| useCurrency: () => ({ price: { sell: '1300' }, isLoading: false, refetch: jest.fn() }), | ||
| })) | ||
|
|
||
| jest.mock('@sentry/nextjs', () => ({ captureException: jest.fn() })) | ||
|
|
||
| jest.mock('@/components/0_Bruddle/Toast', () => ({ | ||
| ...jest.requireActual('@/components/0_Bruddle/Toast'), | ||
| useToast: () => ({ toast: jest.fn(), success: jest.fn(), error: jest.fn(), info: jest.fn() }), | ||
| })) | ||
|
|
||
| import MantecaReviewStep from '../MantecaReviewStep' | ||
|
|
||
| const SERVED_ADDRESS = '0x49200bF84dC26349C86ce040019063FeCE88CB1c' | ||
| const LEGACY_ADDRESS = '0x959e088a09f61aB01cb83b0eBCc74b2CF6d62053' | ||
|
|
||
| function renderStep() { | ||
| const setCurrentStep = jest.fn() | ||
| render( | ||
| <IntlWrapper> | ||
| <MantecaReviewStep | ||
| setCurrentStep={setCurrentStep} | ||
| claimLink="https://peanut.me/claim#p=test" | ||
| destinationAddress="somepixkey@bank.br" | ||
| amount="10.00" | ||
| currency="BRL" | ||
| /> | ||
| </IntlWrapper> | ||
| ) | ||
| return { setCurrentStep } | ||
| } | ||
|
|
||
| function clickConfirm() { | ||
| // The single primary action button on the review card. | ||
| fireEvent.click(screen.getAllByRole('button')[0]) | ||
|
jjramirezn marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| mockClaimLinkSecure.mockResolvedValue('0x' + 'ab'.repeat(32)) | ||
| mockAssociateClaim.mockResolvedValue(undefined) | ||
| mockWithdraw.mockResolvedValue({ data: { id: 'synthetic-1' } }) | ||
| }) | ||
|
|
||
| describe('MantecaReviewStep — pre-claim entity lookup', () => { | ||
| test('claims the link to the API-served entity deposit address', async () => { | ||
| mockInitiateWithdraw.mockResolvedValue({ data: { priceLockCode: 'pl-1', depositAddress: SERVED_ADDRESS } }) | ||
|
|
||
| renderStep() | ||
| clickConfirm() | ||
|
|
||
| await waitFor(() => expect(mockClaimLinkSecure).toHaveBeenCalledTimes(1)) | ||
| expect(mockInitiateWithdraw).toHaveBeenCalledWith({ amount: '10.00', currency: 'BRL' }) | ||
| expect(mockClaimLinkSecure).toHaveBeenCalledWith(expect.objectContaining({ address: SERVED_ADDRESS })) | ||
| await waitFor(() => expect(mockWithdraw).toHaveBeenCalledTimes(1)) | ||
| }) | ||
|
|
||
| test('falls back to the constant when an older API returns no depositAddress', async () => { | ||
| mockInitiateWithdraw.mockResolvedValue({ data: { priceLockCode: 'pl-1' } }) | ||
|
|
||
| renderStep() | ||
| clickConfirm() | ||
|
|
||
| await waitFor(() => expect(mockClaimLinkSecure).toHaveBeenCalledTimes(1)) | ||
| expect(mockClaimLinkSecure).toHaveBeenCalledWith(expect.objectContaining({ address: LEGACY_ADDRESS })) | ||
| }) | ||
|
|
||
| test('an init error aborts BEFORE the one-shot link is spent — no claim, no withdraw', async () => { | ||
| mockInitiateWithdraw.mockResolvedValue({ error: 'Failed to lock withdraw price.' }) | ||
|
|
||
| renderStep() | ||
| clickConfirm() | ||
|
|
||
| await waitFor(() => expect(mockInitiateWithdraw).toHaveBeenCalledTimes(1)) | ||
| expect(mockClaimLinkSecure).not.toHaveBeenCalled() | ||
| expect(mockWithdraw).not.toHaveBeenCalled() | ||
| expect(mockAssociateClaim).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
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,48 @@ | ||
| /** | ||
| * pickMantecaDepositAddress decides WHERE user USDC is irreversibly sent | ||
| * (qr-pay, bank withdraw, claim-link offramp), so every branch is pinned: | ||
| * the API-served entity address wins when valid, and anything else — empty | ||
| * string, malformed value, absent field — falls back to the local constant | ||
| * (with a Sentry report when a served value existed but failed validation). | ||
| */ | ||
| import { pickMantecaDepositAddress } from '../manteca.utils' | ||
|
|
||
| const mockCapture = jest.fn() | ||
| jest.mock('@sentry/nextjs', () => ({ | ||
| captureMessage: (...args: unknown[]) => mockCapture(...args), | ||
| })) | ||
|
|
||
| const FALLBACK = '0x959e088a09f61aB01cb83b0eBCc74b2CF6d62053' as const | ||
| const SERVED = '0x6E945f8EC93061f5f11Edc5e6Fb4A70BeB514e97' | ||
|
|
||
| beforeEach(() => mockCapture.mockClear()) | ||
|
|
||
| describe('pickMantecaDepositAddress', () => { | ||
| test('a valid API-served address wins over the constant', () => { | ||
| expect(pickMantecaDepositAddress(SERVED, FALLBACK)).toBe(SERVED) | ||
| expect(mockCapture).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('an absent field falls back silently (older API during rollout)', () => { | ||
| expect(pickMantecaDepositAddress(undefined, FALLBACK)).toBe(FALLBACK) | ||
| expect(pickMantecaDepositAddress(null, FALLBACK)).toBe(FALLBACK) | ||
| expect(mockCapture).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('an empty string does NOT slip past the fallback (?? would let it through)', () => { | ||
| expect(pickMantecaDepositAddress('', FALLBACK)).toBe(FALLBACK) | ||
| expect(mockCapture).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('the zero address is syntactically valid but never a recipient — falls back AND reports', () => { | ||
| expect(pickMantecaDepositAddress('0x0000000000000000000000000000000000000000', FALLBACK)).toBe(FALLBACK) | ||
| expect(mockCapture).toHaveBeenCalledTimes(1) | ||
| }) | ||
|
|
||
| test('a malformed served value falls back AND reports to Sentry', () => { | ||
| expect(pickMantecaDepositAddress('not-an-address', FALLBACK)).toBe(FALLBACK) | ||
| expect(pickMantecaDepositAddress('0x1234', FALLBACK)).toBe(FALLBACK) | ||
| expect(pickMantecaDepositAddress(42 as unknown, FALLBACK)).toBe(FALLBACK) | ||
| expect(mockCapture).toHaveBeenCalledTimes(3) | ||
| }) | ||
| }) |
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,32 @@ | ||
| import { isAddress, zeroAddress, type Address } from 'viem' | ||
| import * as Sentry from '@sentry/nextjs' | ||
|
|
||
| /** | ||
| * Pick the Manteca deposit recipient for a spend: the API-served | ||
| * entity-aware address when it is a real EVM address, else the local | ||
| * constant fallback. | ||
| * | ||
| * The wire value decides where user USDC is irreversibly sent, so it gets a | ||
| * RUNTIME check — a TypeScript cast validates nothing, and `??` alone would | ||
| * let an empty string (or any malformed value) through. A served value that | ||
| * exists but fails validation is reported to Sentry: after the 2026-09-14 | ||
| * entity split the constant fallback may fund the wrong entity, so ops must | ||
| * see it happening. | ||
| */ | ||
| export function pickMantecaDepositAddress(served: unknown, fallback: Address): Address { | ||
| if ( | ||
| typeof served === 'string' && | ||
| served.length > 0 && | ||
| isAddress(served, { strict: false }) && | ||
| served.toLowerCase() !== zeroAddress | ||
| ) { | ||
| return served as Address | ||
| } | ||
| if (served != null && served !== '') { | ||
| Sentry.captureMessage('Manteca depositAddress from API failed validation — using constant fallback', { | ||
| level: 'error', | ||
| extra: { served: String(served).slice(0, 64) }, | ||
| }) | ||
| } | ||
| return fallback | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.