Skip to content

Commit db8533e

Browse files
fix(bridge): hide gas sponsorship banner for hardware wallets
Prevent swap quote sponsorship UI from rendering for hardware wallets, including sponsored-quote and insufficient-balance fallback paths, to align MON/SEI behavior with hardware wallet constraints. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4797726 commit db8533e

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

app/components/UI/Bridge/hooks/useShouldRenderGasSponsoredBanner/index.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { renderHook } from '@testing-library/react-hooks';
22
import { useShouldRenderGasSponsoredBanner } from './index';
33
import { useIsNetworkGasSponsored } from '../useIsNetworkGasSponsored';
4+
import { useIsHardwareWalletForBridge } from '../useIsHardwareWalletForBridge';
45
import { useSelector } from 'react-redux';
56
import {
67
selectSourceToken,
78
selectDestToken,
89
} from '../../../../../core/redux/slices/bridge';
910

1011
jest.mock('../useIsNetworkGasSponsored');
12+
jest.mock('../useIsHardwareWalletForBridge');
1113
jest.mock('react-redux', () => ({
1214
useSelector: jest.fn(),
1315
}));
@@ -16,6 +18,10 @@ const mockUseIsNetworkGasSponsored =
1618
useIsNetworkGasSponsored as jest.MockedFunction<
1719
typeof useIsNetworkGasSponsored
1820
>;
21+
const mockUseIsHardwareWalletForBridge =
22+
useIsHardwareWalletForBridge as jest.MockedFunction<
23+
typeof useIsHardwareWalletForBridge
24+
>;
1925
const mockUseSelector = useSelector as jest.MockedFunction<typeof useSelector>;
2026

2127
const SOURCE_CHAIN_ID = '0x1';
@@ -51,6 +57,7 @@ describe('useShouldRenderGasSponsoredBanner', () => {
5157
jest.clearAllMocks();
5258
mockTokens({});
5359
mockUseIsNetworkGasSponsored.mockReturnValue(false);
60+
mockUseIsHardwareWalletForBridge.mockReturnValue(false);
5461
});
5562

5663
describe('returns true when quoteGasSponsored is true', () => {
@@ -146,6 +153,43 @@ describe('useShouldRenderGasSponsoredBanner', () => {
146153
});
147154

148155
describe('returns false', () => {
156+
it('returns false when quote is sponsored but source account is a hardware wallet', () => {
157+
// Arrange
158+
mockUseIsHardwareWalletForBridge.mockReturnValue(true);
159+
160+
// Act
161+
const { result } = renderHook(() =>
162+
useShouldRenderGasSponsoredBanner({
163+
quoteGasSponsored: true,
164+
hasInsufficientBalance: false,
165+
}),
166+
);
167+
168+
// Assert
169+
expect(result.current).toBe(false);
170+
});
171+
172+
it('returns false when insufficient balance and network is sponsored but source account is a hardware wallet', () => {
173+
// Arrange
174+
mockTokens({
175+
sourceChainId: SOURCE_CHAIN_ID,
176+
destChainId: SAME_CHAIN_DEST_CHAIN_ID,
177+
});
178+
mockUseIsNetworkGasSponsored.mockReturnValue(true);
179+
mockUseIsHardwareWalletForBridge.mockReturnValue(true);
180+
181+
// Act
182+
const { result } = renderHook(() =>
183+
useShouldRenderGasSponsoredBanner({
184+
quoteGasSponsored: false,
185+
hasInsufficientBalance: true,
186+
}),
187+
);
188+
189+
// Assert
190+
expect(result.current).toBe(false);
191+
});
192+
149193
it('returns false when quoteGasSponsored is false and balance is sufficient', () => {
150194
// Arrange
151195
mockUseIsNetworkGasSponsored.mockReturnValue(false);

app/components/UI/Bridge/hooks/useShouldRenderGasSponsoredBanner/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
selectSourceToken,
55
selectDestToken,
66
} from '../../../../../core/redux/slices/bridge';
7+
import { useIsHardwareWalletForBridge } from '../useIsHardwareWalletForBridge';
78

89
interface Props {
910
quoteGasSponsored?: boolean;
@@ -16,6 +17,7 @@ export const useShouldRenderGasSponsoredBanner = ({
1617
}: Props) => {
1718
const sourceToken = useSelector(selectSourceToken);
1819
const destToken = useSelector(selectDestToken);
20+
const isHardwareWallet = useIsHardwareWalletForBridge();
1921
const isNetworkGasSponsored = useIsNetworkGasSponsored(sourceToken?.chainId);
2022

2123
// Sponsorship only applies to same-chain (swap) flows; cross-chain bridges
@@ -27,8 +29,9 @@ export const useShouldRenderGasSponsoredBanner = ({
2729
);
2830

2931
const shouldShowGasSponsored =
30-
quoteGasSponsored ||
31-
(hasInsufficientBalance && isNetworkGasSponsored && isSameChain);
32+
!isHardwareWallet &&
33+
(quoteGasSponsored ||
34+
(hasInsufficientBalance && isNetworkGasSponsored && isSameChain));
3235

3336
return shouldShowGasSponsored;
3437
};

0 commit comments

Comments
 (0)