-
Notifications
You must be signed in to change notification settings - Fork 13
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 7 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
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
230 changes: 230 additions & 0 deletions
230
src/app/(mobile-ui)/withdraw/manteca/__tests__/withdraw-manteca-recipient.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,230 @@ | ||
| /** | ||
| * Bank-withdraw signing boundary (2026-09-14 Manteca entity split). | ||
| * | ||
| * Drives the page through amount → lock-price → review → Withdraw and pins | ||
| * the money decision AT the signSpend boundary: the depositAddress served | ||
| * by /withdraw/init survives the priceLock state handoff and is the exact | ||
| * recipient signed to; an older API without the field falls back to the | ||
| * legacy constant. Mock strategy mirrors qr-pay-states.test.tsx: mock every | ||
| * hook/service at module level, drive the rendered page. | ||
| */ | ||
| /* eslint-disable react/display-name */ | ||
| import React from 'react' | ||
| import { render, screen, fireEvent, waitFor, act } from '@testing-library/react' | ||
| import { IntlWrapper } from '@/test-utils/intl' | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
|
|
||
| // ---------- module-level mocks ---------- | ||
|
|
||
| const mockSearchParams = new Map<string, string>() | ||
| jest.mock('next/navigation', () => ({ | ||
| useSearchParams: () => ({ get: (key: string) => mockSearchParams.get(key) ?? null }), | ||
| useRouter: () => ({ push: jest.fn(), back: jest.fn(), replace: jest.fn(), prefetch: jest.fn() }), | ||
| usePathname: () => '/withdraw/manteca', | ||
| useParams: () => ({}), | ||
| })) | ||
| jest.mock('next/image', () => (props: Record<string, unknown>) => { | ||
| return React.createElement('img', props as object) | ||
| }) | ||
|
|
||
| const mockSignSpend = jest.fn() | ||
| jest.mock('@/hooks/wallet/useSignSpendBundle', () => ({ | ||
| useSignSpendBundle: () => ({ signSpend: mockSignSpend }), | ||
| })) | ||
| jest.mock('@/hooks/wallet/useWallet', () => ({ | ||
| useWallet: () => ({ spendableBalance: 1_000_000_000n, formattedSpendableBalance: '1000.00' }), | ||
| })) | ||
| jest.mock('@/hooks/wallet/useStaleSessionGuard', () => ({ | ||
| useStaleSessionGuard: () => jest.fn(async () => false), | ||
| })) | ||
| jest.mock('@/hooks/wallet/spendPreflight', () => ({ | ||
| SessionKeyGrantRequiredError: class SessionKeyGrantRequiredError extends Error {}, | ||
| })) | ||
| jest.mock('@/hooks/useRainCardOverview', () => ({ | ||
| useRainCardOverview: () => ({ overview: null }), | ||
| })) | ||
| jest.mock('@/hooks/useSafeBack', () => ({ useSafeBack: () => jest.fn() })) | ||
| jest.mock('@/hooks/useFriendlyError', () => ({ | ||
| useFriendlyError: () => (e: unknown) => ({ kind: 'message', message: String(e) }), | ||
| })) | ||
| jest.mock('@/hooks/wallet/usePendingTransactions', () => ({ | ||
| usePendingTransactions: () => ({ hasPendingTransactions: false }), | ||
| })) | ||
| jest.mock('@/hooks/useIdentityVerification', () => ({ | ||
| useIdentityVerification: () => ({ isVerified: true }), | ||
| })) | ||
| jest.mock('@/hooks/useCapabilities', () => ({ | ||
| useCapabilities: () => ({ rails: [], nextActions: [] }), | ||
| })) | ||
| jest.mock('@/context/authContext', () => ({ | ||
| useAuth: () => ({ user: { user: { userId: 'user-1' } }, isAuthed: true, fetchUser: jest.fn() }), | ||
| })) | ||
| jest.mock('@/utils/regions.utils', () => ({ | ||
| ...jest.requireActual('@/utils/regions.utils'), | ||
| isVerifiedForCountry: () => true, | ||
| deriveProviderRejection: () => null, | ||
| })) | ||
| jest.mock('@/hooks/useMultiPhaseKycFlow', () => ({ | ||
| useMultiPhaseKycFlow: () => ({ | ||
| isLoading: false, | ||
| error: null, | ||
| phase: null, | ||
| start: jest.fn(), | ||
| reset: jest.fn(), | ||
| config: null, | ||
| sdkToken: null, | ||
| handleInitiateKyc: jest.fn(), | ||
| }), | ||
| })) | ||
| jest.mock('@/hooks/useCurrency', () => ({ | ||
| useCurrency: () => ({ | ||
| code: 'ars', | ||
| price: { sell: '1300', buy: '1300' }, | ||
| isLoading: false, | ||
| refetch: jest.fn(), | ||
| }), | ||
| })) | ||
| jest.mock('@/features/limits/hooks/useLimitsValidation', () => ({ | ||
| useLimitsValidation: () => ({ isBlocking: false, isWarning: false, currency: 'USD' }), | ||
| })) | ||
| jest.mock('@/features/limits/utils', () => ({ | ||
| ...jest.requireActual('@/features/limits/utils'), | ||
| getLimitsWarningCardProps: () => null, | ||
| isBrUserEligibleForLimitIncrease: () => false, | ||
| })) | ||
| jest.mock('@/context/ModalsContext', () => ({ | ||
| useModalsContext: () => ({ setIsSupportModalOpen: jest.fn(), openSupportWithMessage: jest.fn() }), | ||
| })) | ||
| jest.mock('@/components/Kyc/InitiateKycModal', () => ({ InitiateKycModal: () => null })) | ||
| jest.mock('@/components/Kyc/SumsubKycModals', () => ({ SumsubKycModals: () => null })) | ||
| jest.mock('@/components/Kyc/SumsubKycWrapper', () => ({ SumsubKycWrapper: () => null })) | ||
| jest.mock('@/components/Global/NavHeader', () => ({ __esModule: true, default: () => null })) | ||
| jest.mock('@/components/Global/RateUnavailable/RateGateScreen', () => ({ __esModule: true, default: () => null })) | ||
| jest.mock('@/components/Global/SoundPlayer', () => ({ SoundPlayer: () => null })) | ||
| jest.mock('@/components/Withdraw/views/PixKeySend.view', () => ({ __esModule: true, default: () => null })) | ||
| jest.mock('@/components/Global/Banner/MantecaTransfersMaintenanceView', () => ({ | ||
| MantecaTransfersMaintenanceView: () => null, | ||
| })) | ||
| jest.mock('@/config/underMaintenance.config', () => ({ | ||
| __esModule: true, | ||
| default: { disabledMantecaCurrencies: [] }, | ||
| underMaintenanceConfig: { disabledMantecaCurrencies: [] }, | ||
| })) | ||
| jest.mock('@/utils/network-triage', () => ({ | ||
| captureNetworkTriagedFailure: jest.fn(), | ||
| isNetworkLayerFailure: () => false, | ||
| })) | ||
| jest.mock('posthog-js', () => ({ capture: jest.fn(), default: { capture: jest.fn() } })) | ||
| jest.mock('@sentry/nextjs', () => ({ | ||
| captureException: jest.fn(), | ||
| captureMessage: jest.fn(), | ||
| withScope: (cb: (scope: Record<string, jest.Mock>) => void) => | ||
| cb( | ||
| new Proxy({} as Record<string, jest.Mock>, { | ||
| get: () => jest.fn(), | ||
| }) | ||
| ), | ||
| })) | ||
|
|
||
| // Amount entry, simplified to a single input driving BOTH denominations. | ||
| jest.mock('@/components/Global/AmountInput', () => (props: Record<string, unknown>) => { | ||
| const setPrimary = props.setPrimaryAmount as (v: string) => void | ||
| const setSecondary = props.setSecondaryAmount as (v: string) => void | ||
| return ( | ||
| <input | ||
| data-testid="amount-input" | ||
| onChange={(e) => { | ||
| setSecondary(e.target.value) | ||
| setPrimary((Number(e.target.value) * 1300).toFixed(2)) | ||
| }} | ||
| /> | ||
| ) | ||
| }) | ||
|
|
||
| const mockInitiateWithdraw = jest.fn() | ||
| const mockWithdrawWithSignedTx = jest.fn() | ||
| jest.mock('@/services/manteca', () => ({ | ||
| ...jest.requireActual('@/services/manteca'), | ||
| mantecaApi: { | ||
| initiateWithdraw: (...args: unknown[]) => mockInitiateWithdraw(...args), | ||
| withdrawWithSignedTx: (...args: unknown[]) => mockWithdrawWithSignedTx(...args), | ||
| }, | ||
| })) | ||
|
|
||
| import MantecaWithdrawPage from '../page' | ||
|
|
||
| const SERVED_ADDRESS = '0x49200bF84dC26349C86ce040019063FeCE88CB1c' | ||
| const LEGACY_ADDRESS = '0x959e088a09f61aB01cb83b0eBCc74b2CF6d62053' | ||
|
|
||
| function renderPage() { | ||
| mockSearchParams.clear() | ||
| mockSearchParams.set('country', 'argentina') | ||
| mockSearchParams.set('method', 'bank') | ||
| mockSearchParams.set('destination', '0000003100064523644259') | ||
| mockSearchParams.set('isSavedAccount', 'true') | ||
| const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } }) | ||
| render( | ||
| <IntlWrapper> | ||
| <QueryClientProvider client={queryClient}> | ||
| <MantecaWithdrawPage /> | ||
| </QueryClientProvider> | ||
| </IntlWrapper> | ||
| ) | ||
| } | ||
|
|
||
| async function driveToWithdraw(priceLock: Record<string, unknown>) { | ||
| mockInitiateWithdraw.mockResolvedValue({ data: priceLock }) | ||
| renderPage() | ||
|
|
||
| fireEvent.change(await screen.findByTestId('amount-input'), { target: { value: '10' } }) | ||
| fireEvent.click(screen.getByRole('button', { name: /continue/i })) | ||
| await waitFor(() => expect(mockInitiateWithdraw).toHaveBeenCalledTimes(1)) | ||
|
|
||
| const withdrawButton = await screen.findByRole('button', { name: /withdraw/i }) | ||
| await act(async () => { | ||
| fireEvent.click(withdrawButton) | ||
| }) | ||
| await waitFor(() => expect(mockSignSpend).toHaveBeenCalledTimes(1)) | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| mockSignSpend.mockResolvedValue({ | ||
| strategy: 'smart-only', | ||
| signedUserOp: { | ||
| signedUserOp: { sender: '0x1', nonce: '0x0', callData: '0x', signature: '0x' }, | ||
| chainId: '42161', | ||
| entryPointAddress: '0xentry', | ||
| }, | ||
| }) | ||
| mockWithdrawWithSignedTx.mockResolvedValue({ data: { id: 'synthetic-1' } }) | ||
| }) | ||
|
|
||
| describe('bank-withdraw recipient at the signing boundary', () => { | ||
| test('the API-served entity depositAddress survives the priceLock handoff and reaches signSpend', async () => { | ||
| await driveToWithdraw({ | ||
| priceLockCode: 'pl-1', | ||
| price: '1300', | ||
| expiresAt: '2026-09-14T00:00:00Z', | ||
| usdAmount: '10', | ||
| fiatAmount: '13000.00', | ||
| currency: 'ars', | ||
| depositAddress: SERVED_ADDRESS, | ||
| }) | ||
|
|
||
| expect(mockSignSpend).toHaveBeenCalledWith(expect.objectContaining({ recipient: SERVED_ADDRESS })) | ||
| }) | ||
|
|
||
| test('an older API without the field falls back to the legacy constant', async () => { | ||
| await driveToWithdraw({ | ||
| priceLockCode: 'pl-1', | ||
| price: '1300', | ||
| expiresAt: '2026-09-14T00:00:00Z', | ||
| usdAmount: '10', | ||
| fiatAmount: '13000.00', | ||
| currency: 'ars', | ||
| }) | ||
|
|
||
| expect(mockSignSpend).toHaveBeenCalledWith(expect.objectContaining({ recipient: LEGACY_ADDRESS })) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.