-
Notifications
You must be signed in to change notification settings - Fork 14
fix(withdraw): show the cross-chain withdrawal cap message and retry the route (TASK-22154) #2931
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 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bc90092
fix(withdraw): show the cross-chain cap message and let Retry recompu…
abalinda 4edd885
fix(withdraw): name the charge on bridge quotes so the cap covers non…
abalinda 8d0b5b2
fix(withdraw): Retry sees the current route error; shown wait never u…
abalinda 42de3c5
fix(withdraw): bridge-path errors carry the API code too
abalinda f2e511f
fix(withdraw): guard Retry against double taps, test the bridge charg…
abalinda 3844036
fix(withdraw): payment-framed cap message for request payers
abalinda 11f59bf
test(withdraw): pin the Retry double-tap guard
abalinda d81184d
fix(withdraw): the bridge commit names its charge too
abalinda 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
107 changes: 107 additions & 0 deletions
107
src/features/payments/shared/hooks/__tests__/useCrossChainTransfer.test.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /** | ||
| * useCrossChainTransfer — the bridge path (destination token outside USDC/USDT) | ||
| * must name its charge on POST /rhino/bridge/quote: that is what makes the API | ||
| * reserve a cap slot and bind the charge to its destination (peanut-api-ts | ||
| * #1497 gates the quote only when contextId is present). claim-xchain has no | ||
| * charge and must NOT send one, or the gate refuses it with 403. | ||
| */ | ||
| import { renderHook, act } from '@testing-library/react' | ||
|
|
||
| const mockGetBridgeQuote = jest.fn() | ||
| const mockCommitBridgeQuote = jest.fn() | ||
| jest.mock('@/services/rhino-bridge', () => ({ | ||
| getBridgeQuote: (...args: unknown[]) => mockGetBridgeQuote(...args), | ||
| commitBridgeQuote: (...args: unknown[]) => mockCommitBridgeQuote(...args), | ||
| getBridgeStatus: jest.fn(), | ||
| isQuoteNearExpiry: () => false, | ||
| })) | ||
| jest.mock('@/services/rhino-sda', () => ({ previewSdaTransfer: jest.fn(), provisionSdaTransfer: jest.fn() })) | ||
| jest.mock('@sentry/nextjs', () => ({ captureException: jest.fn() })) | ||
| jest.mock('@/hooks/useFriendlyError', () => ({ | ||
| useFriendlyError: () => (e: unknown) => (e instanceof Error ? e.message : String(e)), | ||
| })) | ||
| jest.mock('@/app/actions/tokens', () => ({ estimateTransactionCostUsd: jest.fn().mockResolvedValue(0) })) | ||
| jest.mock('@/utils/peanut-claim.utils', () => ({ prepareRequestLinkFulfillmentTransaction: jest.fn() })) | ||
| jest.mock('@/interfaces/peanut-sdk-types', () => ({})) | ||
| jest.mock('@/constants/rhino.consts', () => ({ | ||
| chainIdToRhinoName: (id: string) => ({ '42161': 'ARBITRUM', '8453': 'BASE' })[id], | ||
| })) | ||
| jest.mock('@/constants/chainRegistry.consts', () => ({ NON_EVM_WITHDRAW_CHAINS: {} })) | ||
| jest.mock('@/utils/general.utils', () => ({ | ||
| areEvmAddressesEqual: (a: string, b: string) => a.toLowerCase() === b.toLowerCase(), | ||
| getTokenSymbol: () => 'ETH', | ||
| })) | ||
|
|
||
| import { useCrossChainTransfer } from '../useCrossChainTransfer' | ||
|
|
||
| const SOURCE = { | ||
| address: '0x1111111111111111111111111111111111111111' as `0x${string}`, | ||
| tokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' as `0x${string}`, | ||
| chainId: '42161', | ||
| tokenAmount: '5', | ||
| } | ||
| const ETH_ON_BASE = { | ||
| recipientAddress: '0x000000000000000000000000000000000000dEaD', | ||
| tokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', | ||
| tokenAmount: '0.002', | ||
| tokenDecimals: 18, | ||
| tokenType: 0, | ||
| chainId: '8453', | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| mockGetBridgeQuote.mockReset().mockResolvedValue({ | ||
| quoteId: 'quote-1', | ||
| isSwap: false, | ||
| amountIn: '5', | ||
| amountOut: '0.002', | ||
| feeUsd: 0.5, | ||
| expiresAt: new Date(Date.now() + 60_000).toISOString(), | ||
| }) | ||
| mockCommitBridgeQuote.mockReset().mockResolvedValue({ | ||
| kind: 'deposit-with-id', | ||
| contractAddress: '0x2222222222222222222222222222222222222222', | ||
| commitmentId: 'ab', | ||
| }) | ||
| }) | ||
|
|
||
| describe('useCrossChainTransfer — bridge path names its charge', () => { | ||
| it('withdraw: the bridge quote carries context + contextId so the API can cap it', async () => { | ||
| const { result } = renderHook(() => useCrossChainTransfer()) | ||
|
|
||
| await act(async () => { | ||
| await result.current.calculate({ | ||
| source: SOURCE, | ||
| destination: ETH_ON_BASE, | ||
| context: 'withdraw', | ||
| contextId: 'charge-1', | ||
| skipGasEstimate: true, | ||
| }) | ||
| }) | ||
|
|
||
| expect(mockGetBridgeQuote).toHaveBeenCalledTimes(1) | ||
| expect(mockGetBridgeQuote).toHaveBeenCalledWith( | ||
| expect.objectContaining({ chainOut: 'BASE', tokenOut: 'ETH', context: 'withdraw', contextId: 'charge-1' }) | ||
| ) | ||
| expect(result.current.error).toBeNull() | ||
| expect(result.current.transactions).toHaveLength(2) | ||
| }) | ||
|
|
||
| it('claim-xchain: no charge exists, so no context is sent (the gate would refuse it)', async () => { | ||
| const { result } = renderHook(() => useCrossChainTransfer()) | ||
|
|
||
| await act(async () => { | ||
| await result.current.calculate({ | ||
| source: SOURCE, | ||
| destination: ETH_ON_BASE, | ||
| context: 'claim-xchain', | ||
| contextId: 'pubkey-1', | ||
| skipGasEstimate: true, | ||
| }) | ||
| }) | ||
|
|
||
| const body = mockGetBridgeQuote.mock.calls[0][0] as Record<string, unknown> | ||
| expect(body).not.toHaveProperty('context') | ||
| expect(body).not.toHaveProperty('contextId') | ||
| }) | ||
| }) |
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
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.