-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathindex.ts
More file actions
37 lines (32 loc) · 1.19 KB
/
index.ts
File metadata and controls
37 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { useIsNetworkGasSponsored } from '../useIsNetworkGasSponsored';
import { useSelector } from 'react-redux';
import {
selectSourceToken,
selectDestToken,
} from '../../../../../core/redux/slices/bridge';
import { useIsHardwareWalletForBridge } from '../useIsHardwareWalletForBridge';
interface Props {
quoteGasSponsored?: boolean;
hasInsufficientBalance: boolean;
}
export const useShouldRenderGasSponsoredBanner = ({
quoteGasSponsored,
hasInsufficientBalance,
}: Props) => {
const sourceToken = useSelector(selectSourceToken);
const destToken = useSelector(selectDestToken);
const isHardwareWallet = useIsHardwareWalletForBridge();
const isNetworkGasSponsored = useIsNetworkGasSponsored(sourceToken?.chainId);
// Sponsorship only applies to same-chain (swap) flows; cross-chain bridges
// are never sponsored even on networks listed as sponsored.
const isSameChain = Boolean(
sourceToken?.chainId &&
destToken?.chainId &&
sourceToken.chainId === destToken.chainId,
);
const shouldShowGasSponsored =
!isHardwareWallet &&
(quoteGasSponsored ||
(hasInsufficientBalance && isNetworkGasSponsored && isSameChain));
return shouldShowGasSponsored;
};