From ebab00d7bdba6a4c1aaf803ad34ce981c50be872 Mon Sep 17 00:00:00 2001 From: Jack Short Date: Thu, 22 Jun 2023 16:16:41 -0400 Subject: [PATCH] fix: adding wallet connect v2 behind feature flag (#6826) * fix: adding wallet connect v2 behind feature flag * passing unit tests --- .../FeatureFlagModal/FeatureFlagModal.tsx | 7 ++++++ src/components/WalletModal/Option.tsx | 25 +++++++++++++++---- src/components/WalletModal/index.tsx | 9 ++++++- src/connection/index.test.tsx | 2 +- src/connection/index.ts | 4 +-- src/featureFlags/flags/walletConnectV2.ts | 9 +++++++ src/featureFlags/index.tsx | 1 + 7 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 src/featureFlags/flags/walletConnectV2.ts diff --git a/src/components/FeatureFlagModal/FeatureFlagModal.tsx b/src/components/FeatureFlagModal/FeatureFlagModal.tsx index f2ef0a2e09..15261734e6 100644 --- a/src/components/FeatureFlagModal/FeatureFlagModal.tsx +++ b/src/components/FeatureFlagModal/FeatureFlagModal.tsx @@ -3,6 +3,7 @@ import { DetailsV2Variant, useDetailsV2Flag } from 'featureFlags/flags/nftDetail import { useRoutingAPIForPriceFlag } from 'featureFlags/flags/priceRoutingApi' import { TraceJsonRpcVariant, useTraceJsonRpcFlag } from 'featureFlags/flags/traceJsonRpc' import { UnifiedRouterVariant, useRoutingAPIV2Flag } from 'featureFlags/flags/unifiedRouter' +import { useWalletConnectV2Flag } from 'featureFlags/flags/walletConnectV2' import { useUpdateAtom } from 'jotai/utils' import { Children, PropsWithChildren, ReactElement, ReactNode, useCallback, useState } from 'react' import { X } from 'react-feather' @@ -221,6 +222,12 @@ export default function FeatureFlagModal() { featureFlag={FeatureFlag.routingAPIPrice} label="Use the URA or routing-api for price fetches" /> + (null) + const walletConnectV2AsDefault = useWalletConnectV2AsDefault() + useOnClickOutside(popoverElement, onClose) + if (!show) return null return ( @@ -146,8 +151,14 @@ function PopupButtonContent({ connection, isDarkMode, show, onClick, onClose }:
- Connect with v1 - Support for v1 will be discontinued June 28. + + Connect with {walletConnectV2AsDefault ? t`v1` : t`v2`} + + + {walletConnectV2AsDefault + ? t`Support for v1 will be discontinued June 28.` + : t`Under development and unsupported by most wallets`} +
) @@ -170,9 +181,11 @@ export default function Option({ connection }: OptionProps) { const isCurrentOptionPending = isSomeOptionPending && activationState.connection.type === connection.type const isDarkMode = useIsDarkMode() + const walletConnectV2AsDefault = useWalletConnectV2AsDefault() + const handleClickConnectViaWCv1 = (e: MouseEvent) => { e.stopPropagation() - tryActivation(walletConnectV1Connection, () => { + tryActivation(walletConnectV2AsDefault ? walletConnectV1Connection : walletConnectV2Connection, () => { setWC1PromptOpen(false) toggleAccountDrawerOpen() }) @@ -182,7 +195,9 @@ export default function Option({ connection }: OptionProps) { setWC1PromptOpen(true) } - const showExtraMenuToggle = connection.type === ConnectionType.WALLET_CONNECT_V2 && !isCurrentOptionPending + const isWalletConnect = + connection.type === ConnectionType.WALLET_CONNECT || connection.type === ConnectionType.WALLET_CONNECT_V2 + const showExtraMenuToggle = isWalletConnect && !isCurrentOptionPending return ( diff --git a/src/components/WalletModal/index.tsx b/src/components/WalletModal/index.tsx index 17df90fab5..cee6f13581 100644 --- a/src/components/WalletModal/index.tsx +++ b/src/components/WalletModal/index.tsx @@ -4,7 +4,9 @@ import { AutoColumn } from 'components/Column' import { AutoRow } from 'components/Row' import { getConnections, networkConnection } from 'connection' import { ActivationStatus, useActivationState } from 'connection/activate' +import { ConnectionType } from 'connection/types' import { isSupportedChain } from 'constants/chains' +import { useWalletConnectV2AsDefault } from 'featureFlags/flags/walletConnectV2' import { useEffect } from 'react' import { Settings } from 'react-feather' import styled from 'styled-components/macro' @@ -44,6 +46,11 @@ export default function WalletModal({ openSettings }: { openSettings: () => void const { activationState } = useActivationState() + const walletConnectV2AsDefault = useWalletConnectV2AsDefault() + const hiddenWalletConnectType = walletConnectV2AsDefault + ? ConnectionType.WALLET_CONNECT + : ConnectionType.WALLET_CONNECT_V2 + // Keep the network connector in sync with any active user connector to prevent chain-switching on wallet disconnection. useEffect(() => { if (chainId && isSupportedChain(chainId) && connector !== networkConnection.connector) { @@ -63,7 +70,7 @@ export default function WalletModal({ openSettings }: { openSettings: () => void {connections - .filter((connection) => connection.shouldDisplay()) + .filter((connection) => connection.shouldDisplay() && connection.type !== hiddenWalletConnectType) .map((connection) => (