|
1 | 1 | import { useEffect } from 'react' |
2 | 2 |
|
3 | 3 | import { useFeatureFlags, useSetIsBridgingEnabled } from '@cowprotocol/common-hooks' |
4 | | -import { useIsSmartContractWallet } from '@cowprotocol/wallet' |
| 4 | +import { useIsSmartContractWallet, useWalletInfo } from '@cowprotocol/wallet' |
5 | 5 |
|
6 | 6 | import { useTradeTypeInfo } from 'modules/trade' |
7 | 7 |
|
8 | 8 | import { Routes } from '../constants/routes' |
9 | 9 |
|
10 | 10 | export function BridgingEnabledUpdater(): null { |
| 11 | + const { account } = useWalletInfo() |
11 | 12 | const { isBridgingEnabled } = useFeatureFlags() |
12 | 13 | const tradeTypeInfo = useTradeTypeInfo() |
13 | 14 | const isSmartContractWallet = useIsSmartContractWallet() |
14 | 15 | const setIsBridgingEnabled = useSetIsBridgingEnabled() |
15 | 16 |
|
16 | 17 | const isSwapRoute = tradeTypeInfo?.route === Routes.SWAP |
17 | 18 |
|
18 | | - function shouldEnableBridging( |
19 | | - featureFlagEnabled: boolean, |
20 | | - scWallet: boolean | undefined, |
21 | | - swapRoute: boolean, |
22 | | - ): boolean { |
23 | | - // Only enable bridging once we definitively know it's an EOA (strict false) |
24 | | - return featureFlagEnabled && scWallet === false && swapRoute |
25 | | - } |
| 19 | + const isWalletCompatible = Boolean(account ? isSmartContractWallet === false : true) |
| 20 | + const shouldEnableBridging = isBridgingEnabled && isWalletCompatible && isSwapRoute |
26 | 21 |
|
27 | 22 | useEffect(() => { |
28 | | - setIsBridgingEnabled(shouldEnableBridging(isBridgingEnabled, isSmartContractWallet, isSwapRoute)) |
29 | | - }, [setIsBridgingEnabled, isBridgingEnabled, isSmartContractWallet, isSwapRoute]) |
| 23 | + setIsBridgingEnabled(shouldEnableBridging) |
| 24 | + }, [setIsBridgingEnabled, shouldEnableBridging]) |
30 | 25 |
|
31 | 26 | return null |
32 | 27 | } |
0 commit comments