Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Fee-offsetting diff should not be visible when disabled
Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz>
  • Loading branch information
emreboga committed Oct 19, 2025
commit e1223f0c7fbe2806e57897d51f910a79a12a2706
86 changes: 86 additions & 0 deletions src/views/v3/Bridge/AssetPicker/FeeOffset.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { amount as sdkAmount } from '@wormhole-foundation/sdk';

import FeeOffset from './FeeOffset';
import { dark } from 'theme';
import config from 'config';

const theme = createTheme({
palette: dark as any,
Expand All @@ -26,6 +27,17 @@ vi.mock('hooks/useGetTokens', () => ({
})),
}));

// Mock the config module
vi.mock('config', () => ({
default: {
ui: {
experimental: {
feeOffsetting: true,
},
},
},
}));

const mockToken = {
key: 'USDC',
symbol: 'USDC',
Expand Down Expand Up @@ -109,4 +121,78 @@ describe('FeeOffset', () => {
const infoIcon = screen.getByTestId('InfoOutlineIcon');
expect(infoIcon).toBeInTheDocument();
});

it('does not render when feeOffsetting is disabled in config', async () => {
const { calculateFeeOffset } = vi.mocked(await import('utils/fees'));
const { useGetTokens } = vi.mocked(await import('hooks/useGetTokens'));

const mockedConfig = vi.mocked(config);
mockedConfig.ui.experimental!.feeOffsetting = false;

const feeOffset = sdkAmount.fromBaseUnits(1000n, 6);
calculateFeeOffset.mockReturnValue(feeOffset);
useGetTokens.mockReturnValue({
sourceToken: mockToken,
destToken: undefined,
} as any);

const store = createMockStore(
sdkAmount.fromBaseUnits(100000n, 6),
'TestRoute',
);

render(<FeeOffset />, {
wrapper: AppWrapper(store),
});

expect(screen.queryByText(/\+.*USDC/)).not.toBeInTheDocument();

// Reset config for other tests
mockedConfig.ui.experimental!.feeOffsetting = true;
});

it('does not render when feeOffsetAmount is undefined', async () => {
const { calculateFeeOffset } = vi.mocked(await import('utils/fees'));
const { useGetTokens } = vi.mocked(await import('hooks/useGetTokens'));

calculateFeeOffset.mockReturnValue(undefined);
useGetTokens.mockReturnValue({
sourceToken: mockToken,
destToken: undefined,
} as any);

const store = createMockStore(
sdkAmount.fromBaseUnits(100000n, 6),
'TestRoute',
);

render(<FeeOffset />, {
wrapper: AppWrapper(store),
});

expect(screen.queryByText(/\+.*USDC/)).not.toBeInTheDocument();
});

it('does not render when feeOffsetAmount is zero', async () => {
const { calculateFeeOffset } = vi.mocked(await import('utils/fees'));
const { useGetTokens } = vi.mocked(await import('hooks/useGetTokens'));

const feeOffset = sdkAmount.fromBaseUnits(0n, 6); // Zero amount
calculateFeeOffset.mockReturnValue(feeOffset);
useGetTokens.mockReturnValue({
sourceToken: mockToken,
destToken: undefined,
} as any);

const store = createMockStore(
sdkAmount.fromBaseUnits(100000n, 6),
'TestRoute',
);

render(<FeeOffset />, {
wrapper: AppWrapper(store),
});

expect(screen.queryByText(/\+.*USDC/)).not.toBeInTheDocument();
});
});
7 changes: 6 additions & 1 deletion src/views/v3/Bridge/AssetPicker/FeeOffset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Box, Tooltip, Typography, useTheme } from '@mui/material';
import InfoOutlineIcon from '@mui/icons-material/InfoOutline';
import { amount as sdkAmount } from '@wormhole-foundation/sdk';

import config from 'config';
import type { RootState } from 'store';
import { calculateFeeOffset } from 'utils/fees';
import { useGetTokens } from 'hooks/useGetTokens';
Expand All @@ -28,7 +29,11 @@ function FeeOffset() {
);

const feeDisplay = useMemo(() => {
if (!feeOffsetAmount || sdkAmount.units(feeOffsetAmount) === 0n) {
if (
!config.ui?.experimental?.feeOffsetting ||
!feeOffsetAmount ||
sdkAmount.units(feeOffsetAmount) === 0n
) {
return null;
}

Expand Down
Loading