From f8670a6ccdfdd1fa0bc368acbba8a98067fc5fbc Mon Sep 17 00:00:00 2001 From: Manan Tank Date: Wed, 14 Feb 2024 23:32:36 +0530 Subject: [PATCH] add "connected to smart wallet" in CW details modal --- .../src/react/ui/ConnectWallet/Details.tsx | 126 +++++++++--------- packages/thirdweb/src/wallets/smart/index.ts | 2 + 2 files changed, 65 insertions(+), 63 deletions(-) diff --git a/packages/thirdweb/src/react/ui/ConnectWallet/Details.tsx b/packages/thirdweb/src/react/ui/ConnectWallet/Details.tsx index a0cc2724b8b..1d966aca922 100644 --- a/packages/thirdweb/src/react/ui/ConnectWallet/Details.tsx +++ b/packages/thirdweb/src/react/ui/ConnectWallet/Details.tsx @@ -20,7 +20,7 @@ import { Container, Line } from "../components/basic.js"; import { IconButton } from "../components/buttons.js"; import { useCustomTheme } from "../design-system/CustomThemeProvider.js"; import { fadeInAnimation } from "../design-system/animations.js"; -import { StyledButton } from "../design-system/elements.js"; +import { StyledButton, StyledDiv } from "../design-system/elements.js"; import { type Theme, iconSize, @@ -32,7 +32,7 @@ import { import { NetworkSelectorContent } from "./NetworkSelector.js"; import { onModalUnmount } from "./constants.js"; import type { SupportedTokens } from "./defaultTokens.js"; -import { Text } from "../components/text.js"; +import { Link, Text } from "../components/text.js"; import { CopyIcon } from "../components/CopyIcon.js"; import { shortenString } from "../../utils/addresses.js"; import { Img } from "../components/Img.js"; @@ -345,7 +345,7 @@ export const ConnectedWalletDetails: React.FC<{ {/* */} - {/* */} + {/* */} {/* Send and Receive */} @@ -398,7 +398,7 @@ export const ConnectedWalletDetails: React.FC<{ */} {/* */} - + {/* Network Switcher */} @@ -748,66 +748,66 @@ function AccountSwitcher({ ); } -// const ActiveDot = /* @__PURE__ */ StyledDiv(() => { -// const theme = useCustomTheme(); -// return { -// width: "8px", -// height: "8px", -// borderRadius: "50%", -// backgroundColor: theme.colors.success, -// }; -// }); - -// function ConnectedToSmartWallet() { -// const activeWallet = useWallet(); -// const chain = useChain(); -// const address = useAddress(); -// const locale = useTWLocale().connectWallet; - -// const [isSmartWalletDeployed, setIsSmartWalletDeployed] = useState(false); - -// useEffect(() => { -// if (activeWallet && activeWallet.walletId === walletIds.smartWallet) { -// const smartWallet = activeWallet as SmartWallet; -// smartWallet.isDeployed().then((isDeployed) => { -// setIsSmartWalletDeployed(isDeployed); -// }); -// } else { -// setIsSmartWalletDeployed(false); -// } -// }, [activeWallet]); - -// const content = ( -// -// -// {locale.connectedToSmartWallet} -// -// ); - -// if (chain && address && activeWallet?.walletId === walletIds.smartWallet) { -// return ( -// <> -// {isSmartWalletDeployed ? ( -// -// {content} -// -// ) : ( -// {content} -// )} - -// -// -// ); -// } +const ActiveDot = /* @__PURE__ */ StyledDiv(() => { + const theme = useCustomTheme(); + return { + width: "8px", + height: "8px", + borderRadius: "50%", + backgroundColor: theme.colors.success, + }; +}); -// return null; -// } +function ConnectedToSmartWallet() { + const activeAccount = useActiveAccount(); + const chainId = useActiveWalletChainId(); + const locale = useTWLocale().connectWallet; + const isSmartWallet = + activeAccount && "isSmartWallet" in activeAccount.wallet; + + const [isSmartWalletDeployed] = useState(false); + + // useEffect(() => { + // if (activeAccount && isSmartWallet) { + // (activeAccount.wallet as SmartWallet).isDeployed().then((isDeployed) => { + // setIsSmartWalletDeployed(isDeployed); + // }); + // } else { + // setIsSmartWalletDeployed(false); + // } + // }, [activeWallet]); + + const content = ( + + + {locale.connectedToSmartWallet} + + ); + + if (chainId && activeAccount && isSmartWallet) { + return ( + <> + {isSmartWalletDeployed ? ( + + {content} + + ) : ( + {content} + )} + + + + ); + } + + return null; +} // function EmbeddedWalletEmail() { // const emailQuery = useEmbeddedWalletUserEmail(); diff --git a/packages/thirdweb/src/wallets/smart/index.ts b/packages/thirdweb/src/wallets/smart/index.ts index 32a4f222ea4..0dc37b20653 100644 --- a/packages/thirdweb/src/wallets/smart/index.ts +++ b/packages/thirdweb/src/wallets/smart/index.ts @@ -148,6 +148,8 @@ export class SmartWallet implements WalletWithPersonalAccount { async disconnect(): Promise { this.personalAccount?.wallet.disconnect(); } + + // TODO: add isDeployed } async function smartAccount(