-
Notifications
You must be signed in to change notification settings - Fork 14
fix(fees): one fee source — Rhino's quoted fee verbatim, one NetworkFeeRow (TASK-21991) #2902
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
abalinda
wants to merge
8
commits into
dev
Choose a base branch
from
fix/21991-network-fee-one-source
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 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b524efc
fix(fees): show Rhino's quoted fee verbatim, one row for every confir…
abalinda 39bdcf7
fix(claim): price bank claims with an EVM address; one fee test file
abalinda 0add891
fix(claim): a cross-chain route is only reusable for the recipient it…
abalinda fac5669
test(claim): routes carry quotedFor in the fixtures
abalinda 815092c
fix(withdraw): re-quote an expired Rhino quote before signing; show a…
abalinda fe5de92
fix(quotes): decide expiry at the tap; never select an out-of-order o…
abalinda 9ba89cc
fix(quotes): expiry decided at the tap on every Rhino consumer; super…
abalinda 9330432
fix(quotes): retire in-flight claim quotes on a destination switch; h…
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
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
102 changes: 102 additions & 0 deletions
102
src/components/Claim/Link/Onchain/__tests__/Confirm.view.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,102 @@ | ||
| import React from 'react' | ||
| import { screen } from '@testing-library/react' | ||
| import { renderWithIntl } from '@/test-utils/intl' | ||
|
|
||
| jest.mock('next/navigation', () => ({ useSearchParams: () => ({ get: () => null }) })) | ||
| jest.mock('posthog-js', () => ({ __esModule: true, default: { capture: jest.fn() } })) | ||
| jest.mock('@sentry/nextjs', () => ({ captureException: jest.fn() })) | ||
| jest.mock('@/components/Global/NavHeader', () => ({ __esModule: true, default: () => null })) | ||
| jest.mock('@/components/Global/PeanutActionDetailsCard', () => ({ __esModule: true, default: () => null })) | ||
| jest.mock('@/components/Global/DisplayIcon', () => ({ __esModule: true, default: () => null })) | ||
| jest.mock('@/components/0_Bruddle/Button', () => ({ | ||
| Button: ({ children }: { children: React.ReactNode }) => <button>{children}</button>, | ||
| })) | ||
| jest.mock('@/context/loadingStates.context', () => { | ||
| const ReactActual = jest.requireActual('react') | ||
| return { loadingStateContext: ReactActual.createContext({ setLoadingState: jest.fn(), isLoading: false }) } | ||
| }) | ||
| jest.mock('@/context/tokenSelector.context', () => { | ||
| const ReactActual = jest.requireActual('react') | ||
| return { | ||
| tokenSelectorContext: ReactActual.createContext({ | ||
| selectedChainID: '8453', | ||
| selectedTokenAddress: '0xusdc', | ||
| isXChain: true, | ||
| }), | ||
| } | ||
| }) | ||
| jest.mock('@/hooks/useTokenChainIcons', () => ({ | ||
| useTokenChainIcons: () => ({ resolvedChainName: 'Base', resolvedTokenSymbol: 'USDC' }), | ||
| })) | ||
| jest.mock('@/hooks/wallet/useWallet', () => ({ useWallet: () => ({ address: '0x2222' }) })) | ||
| jest.mock('@/context/authContext', () => ({ useAuth: () => ({ user: null }) })) | ||
| jest.mock('../../../useClaimLink', () => ({ | ||
| __esModule: true, | ||
| default: () => ({ claimLinkXchain: jest.fn(), claimLink: jest.fn() }), | ||
| })) | ||
| jest.mock('@/hooks/useRecipientDisplay', () => ({ useRecipientDisplay: () => ({ displayName: 'bob' }) })) | ||
| jest.mock('@/hooks/useFriendlyError', () => ({ useFriendlyError: () => (e: unknown) => String(e) })) | ||
| jest.mock('@/services/sendLinks', () => ({ sendLinksApi: { associateClaim: jest.fn() } })) | ||
| jest.mock('@/constants/analytics.consts', () => ({ ANALYTICS_EVENTS: {} })) | ||
| jest.mock('@/config/underMaintenance.config', () => ({ | ||
| __esModule: true, | ||
| default: { disableXchainSend: false }, | ||
| CROSS_CHAIN_DISABLED_MESSAGE: '', | ||
| })) | ||
| jest.mock('@/components/Invites/badge-campaign-context', () => ({ badgeCampaignForLegacyWire: () => null })) | ||
| jest.mock('../../../Claim.consts', () => ({})) | ||
|
|
||
| import { ConfirmClaimLinkView } from '../Confirm.view' | ||
|
|
||
| const props = { | ||
| onNext: jest.fn(), | ||
| onPrev: jest.fn(), | ||
| setClaimType: jest.fn(), | ||
| claimLinkData: { | ||
| amount: 10_000_000n, | ||
| tokenDecimals: 6, | ||
| tokenSymbol: 'USDC', | ||
| chainId: '42161', | ||
| link: 'https://peanut.test/claim', | ||
| senderAddress: '0x9999', | ||
| sender: null, | ||
| }, | ||
| recipient: { address: '0x2222', name: '' }, | ||
| tokenPrice: 1, | ||
| setTransactionHash: jest.fn(), | ||
| attachment: { message: '', attachmentUrl: '' }, | ||
| } as unknown as React.ComponentProps<typeof ConfirmClaimLinkView> | ||
|
|
||
| describe('ConfirmClaimLinkView — max network fee row', () => { | ||
| it('shows the sponsored label for a zero-fee cross-chain route', () => { | ||
| renderWithIntl( | ||
| <ConfirmClaimLinkView | ||
| {...props} | ||
| selectedRoute={{ | ||
| chainId: '8453', | ||
| tokenAddress: '0xusdc', | ||
| receiveAmount: '10', | ||
| feeUsd: 0, | ||
| quotedFor: '0x2222', | ||
| }} | ||
| /> | ||
| ) | ||
| expect(screen.getByText('Sponsored by Peanut!')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows a quoted route fee verbatim', () => { | ||
| renderWithIntl( | ||
| <ConfirmClaimLinkView | ||
| {...props} | ||
| selectedRoute={{ | ||
| chainId: '8453', | ||
| tokenAddress: '0xusdc', | ||
| receiveAmount: '9.5', | ||
| feeUsd: 0.5, | ||
| quotedFor: '0x2222', | ||
| }} | ||
| /> | ||
| ) | ||
| expect(screen.getByText('$0.50')).toBeInTheDocument() | ||
| }) | ||
| }) |
33 changes: 33 additions & 0 deletions
33
src/components/Global/NetworkFeeRow/__tests__/NetworkFeeRow.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,33 @@ | ||
| import React from 'react' | ||
| import { screen } from '@testing-library/react' | ||
| import { renderWithIntl } from '@/test-utils/intl' | ||
| import NetworkFeeRow from '@/components/Global/NetworkFeeRow' | ||
|
|
||
| describe('NetworkFeeRow', () => { | ||
| it('shows the sponsored label for a zero cross-chain quote (the 1:1 account config)', () => { | ||
| renderWithIntl(<NetworkFeeRow label="Network fee" feeUsd={0} isCrossChain />) | ||
| expect(screen.getByText('Sponsored by Peanut!')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows a non-zero quote verbatim', () => { | ||
| renderWithIntl(<NetworkFeeRow label="Network fee" feeUsd={0.51} isCrossChain />) | ||
| expect(screen.getByText('$0.51')).toBeInTheDocument() | ||
| expect(screen.queryByText('Sponsored by Peanut!')).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('is sponsored on same-chain even if a stale fee is passed', () => { | ||
| renderWithIntl(<NetworkFeeRow label="Network fee" feeUsd={0.51} isCrossChain={false} />) | ||
| expect(screen.getByText('Sponsored by Peanut!')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('strikes through paymaster-covered gas next to the sponsored label', () => { | ||
| renderWithIntl(<NetworkFeeRow label="Network fee" isCrossChain={false} sponsoredGasUsd={0.05} />) | ||
| expect(screen.getByText('$ 0.05')).toHaveClass('line-through') | ||
| expect(screen.getByText('Sponsored by Peanut!')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows a dash when estimation failed', () => { | ||
| renderWithIntl(<NetworkFeeRow label="Network fee" isCrossChain estimationFailed />) | ||
| expect(screen.getByText('-')).toBeInTheDocument() | ||
| }) | ||
| }) |
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,68 @@ | ||
| 'use client' | ||
|
|
||
| import { PaymentInfoRow } from '@/components/Payment/PaymentInfoRow' | ||
| import { formatNetworkFee } from '@/utils/cross-chain-fee.utils' | ||
| import { useTranslations } from 'next-intl' | ||
|
|
||
| /** | ||
| * The one network-fee row for confirm screens. Reads the quote's `feeUsd` | ||
| * verbatim (no arithmetic here) and renders the sponsored label, the | ||
| * struck-through sponsored gas, or the formatted fee — the same way on every | ||
| * screen (DS audit: "Fee row 'Sponsored by Peanut!' recipe"). | ||
| */ | ||
| interface NetworkFeeRowProps { | ||
| label: string | ||
| /** Rhino's quoted total fee, verbatim from the hook. Undefined before a | ||
| * quote resolves or on same-chain transfers. */ | ||
| feeUsd?: number | ||
| isCrossChain: boolean | ||
| loading?: boolean | ||
| moreInfoText?: string | ||
| /** Gas the paymaster covers on a same-chain send — shown struck through | ||
| * next to the sponsored label when it reaches a cent. */ | ||
| sponsoredGasUsd?: number | ||
| /** Route or fee estimation failed — shows a dash instead of a number. */ | ||
| estimationFailed?: boolean | ||
| hideBottomBorder?: boolean | ||
| } | ||
|
|
||
| export default function NetworkFeeRow({ | ||
| label, | ||
| feeUsd, | ||
| isCrossChain, | ||
| loading, | ||
| moreInfoText, | ||
| sponsoredGasUsd, | ||
| estimationFailed, | ||
| hideBottomBorder, | ||
| }: NetworkFeeRowProps) { | ||
| const tCommon = useTranslations('common') | ||
| const fee = formatNetworkFee(feeUsd, isCrossChain) | ||
|
|
||
| let value: React.ReactNode | ||
| if (estimationFailed) { | ||
| value = '-' | ||
| } else if (fee !== null) { | ||
| value = fee | ||
| } else if (sponsoredGasUsd !== undefined && sponsoredGasUsd >= 0.01) { | ||
| value = ( | ||
| <> | ||
| <span className="line-through">$ {sponsoredGasUsd.toFixed(2)}</span> | ||
| {' - '} | ||
| <span className="font-medium text-foreground-secondary">{tCommon('sponsoredByPeanut')}</span> | ||
| </> | ||
| ) | ||
| } else { | ||
| value = tCommon('sponsoredByPeanut') | ||
| } | ||
|
|
||
| return ( | ||
| <PaymentInfoRow | ||
| label={label} | ||
| value={value} | ||
| loading={loading} | ||
| moreInfoText={moreInfoText} | ||
| hideBottomBorder={hideBottomBorder} | ||
| /> | ||
| ) | ||
| } |
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.