From f0bea2f253880a8b849e81ee265f2af9185fd4f9 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Thu, 16 Jan 2025 12:44:31 +0100 Subject: [PATCH] feat: mount&unmount on root --- .../alert/components/pairing-alert/index.tsx | 670 +++++++++--------- packages/beacon-ui/src/ui/alert/index.tsx | 16 +- 2 files changed, 341 insertions(+), 345 deletions(-) diff --git a/packages/beacon-ui/src/ui/alert/components/pairing-alert/index.tsx b/packages/beacon-ui/src/ui/alert/components/pairing-alert/index.tsx index 0246cb94a..e3b82e552 100644 --- a/packages/beacon-ui/src/ui/alert/components/pairing-alert/index.tsx +++ b/packages/beacon-ui/src/ui/alert/components/pairing-alert/index.tsx @@ -9,7 +9,6 @@ import { isIOS } from 'src/utils/platform' import { StorageKey } from '@airgap/beacon-types' import QR from 'src/components/qr' import useWallets from '../../hooks/useWallets' -import { useEffect, useState } from 'react' // todo remove any const PairingAlert: React.FC = (props) => { @@ -51,18 +50,6 @@ const PairingAlert: React.FC = (props) => { const areMetricsEnabled = localStorage ? localStorage.getItem(StorageKey.ENABLE_METRICS) === 'true' : false - const [show, setShow] = useState(true) - - useEffect(() => { - if (props.open) { - setShow(true) - } else { - // we need to wait a little before unmounting the component - // because otherwise the "fade-out" animation - // wouldn't have enough time to play - setTimeout(() => setShow(false), 300) - } - }, [props.open]) const generateWCError = (title: string) => { const errorMessage = localStorage ? localStorage.getItem(StorageKey.WC_INIT_ERROR) : undefined @@ -118,198 +105,247 @@ const PairingAlert: React.FC = (props) => { } return ( - <> - {show && ( - handleClickWallet(id, props)} - onClickOther={handleClickOther} + handleClickWallet(id, props)} + onClickOther={handleClickOther} + /> + ) + } + onClickShowMore={handleShowMoreContent} + onBackClick={ + state === 'install' || + state === 'qr' || + (state === 'wallets' && isMobile) || + state === 'help' + ? () => handleUpdateState('top-wallets') + : undefined + } + > +
+ {state === 'install' && ( +
+ {isOnline && wallet?.types.includes('web') && ( + handleNewTab(props, wallet) + } + ]} /> - ) - } - onClickShowMore={handleShowMoreContent} - onBackClick={ - state === 'install' || - state === 'qr' || - (state === 'wallets' && isMobile) || - state === 'help' - ? () => handleUpdateState('top-wallets') - : undefined - } - > -
- {state === 'install' && ( -
- {isOnline && wallet?.types.includes('web') && ( - handleNewTab(props, wallet) - } - ]} - /> - )} - {!isMobile && wallet?.types.includes('extension') && ( - handleClickConnectExtension() - } - ] - : [ - { - label: 'Install extension', - type: 'primary', - onClick: () => handleClickInstallExtension() - } - ] - } - /> - )} - {!isMobile && wallet?.types.includes('desktop') && ( - handleClickOpenDesktopApp() - }, - { - label: 'Download desktop app', - type: 'secondary', - onClick: () => handleClickDownloadDesktopApp() - } - ]} - /> - )} - {!isMobile && - (qrCode?.length ?? 0) && - wallet?.types.includes('ios') && - (wallet?.types.length as number) > 1 && } - {!isMobile && - (qrCode?.length ?? 0) && - wallet?.types.includes('ios') && - (wallet?.types.length as number) <= 1 && } - {isMobile && - wallet?.types.includes('ios') && - (!wallet?.supportedInteractionStandards?.includes('wallet_connect') || - isWCWorking ? ( - { - if (!wallet) { - return - } - - handleDeepLinking( - wallet.supportedInteractionStandards?.includes('wallet_connect') - ? wcPayload - : p2pPayload - ) - } + onClick: () => handleClickConnectExtension() } - ]} - downloadLink={ - wallet?.name.toLowerCase().includes('kukai') && isIOS(window) - ? { - label: 'Get Kukai Mobile >', - url: 'https://ios.kukai.app' - } - : undefined - } - onShowQRCodeClick={async () => { - const syncCode = wallet?.supportedInteractionStandards?.includes( - 'wallet_connect' - ) - ? wcPayload - : p2pPayload - - if (!syncCode.length || !wallet) { - props.onClose() + ] + : [ + { + label: 'Install extension', + type: 'primary', + onClick: () => handleClickInstallExtension() + } + ] + } + /> + )} + {!isMobile && wallet?.types.includes('desktop') && ( + handleClickOpenDesktopApp() + }, + { + label: 'Download desktop app', + type: 'secondary', + onClick: () => handleClickDownloadDesktopApp() + } + ]} + /> + )} + {!isMobile && + (qrCode?.length ?? 0) && + wallet?.types.includes('ios') && + (wallet?.types.length as number) > 1 && } + {!isMobile && + (qrCode?.length ?? 0) && + wallet?.types.includes('ios') && + (wallet?.types.length as number) <= 1 && } + {isMobile && + wallet?.types.includes('ios') && + (!wallet?.supportedInteractionStandards?.includes('wallet_connect') || isWCWorking ? ( + { + if (!wallet) { return } - if (isMobile && wallet.types.includes('ios') && wallet.types.length === 1) { - handleDeepLinking(syncCode) - } else { - handleUpdateQRCode(syncCode) + handleDeepLinking( + wallet.supportedInteractionStandards?.includes('wallet_connect') + ? wcPayload + : p2pPayload + ) + } + } + ]} + downloadLink={ + wallet?.name.toLowerCase().includes('kukai') && isIOS(window) + ? { + label: 'Get Kukai Mobile >', + url: 'https://ios.kukai.app' } + : undefined + } + onShowQRCodeClick={async () => { + const syncCode = wallet?.supportedInteractionStandards?.includes( + 'wallet_connect' + ) + ? wcPayload + : p2pPayload + + if (!syncCode.length || !wallet) { + props.onClose() + return + } + + if (isMobile && wallet.types.includes('ios') && wallet.types.length === 1) { + handleDeepLinking(syncCode) + } else { + handleUpdateQRCode(syncCode) + } - handleUpdateState('qr') - // todo setDisplayQrExtra(true) - }} - /> - ) : ( - generateWCError(`Connect with ${wallet?.name} Mobile`) - ))} -
+ handleUpdateState('qr') + // todo setDisplayQrExtra(true) + }} + /> + ) : ( + generateWCError(`Connect with ${wallet?.name} Mobile`) + ))} +
+ )} + {state === 'qr' && ( +
+ {!displayQRExtra ? ( + {}} + p2pPayload={p2pPayload} + wcPayload={wcPayload} + > + ) : ( + )} - {state === 'qr' && ( -
+ )} +
+ handleClickWallet(id, props)} + onClickOther={handleClickOther} + /> +
+
= (props) => { display: 'flex', flexDirection: 'column', gap: '0.9em' - }} - > - {!displayQRExtra ? ( - {}} - p2pPayload={p2pPayload} - wcPayload={wcPayload} - > - ) : ( - - )} -
- )} -
- handleClickWallet(id, props)} - onClickOther={handleClickOther} + } + : { + opacity: 0, + height: 0, + overflow: 'hidden', + transform: 'scale(1.1)', + transition: 'all ease 0.3s', + display: 'flex', + flexDirection: 'column', + gap: '0.9em' + } + } + > + {areMetricsEnabled && } + {!areMetricsEnabled && ( + <> + + + + + } + title="What is a wallet?" + description="Wallets let you send, receive, store and interact with digital assets. Your wallet can be used as an easy way to login, instead of having to remember a password." /> -
-
- {areMetricsEnabled && } - {!areMetricsEnabled && ( - <> - - - - - } - title="What is a wallet?" - description="Wallets let you send, receive, store and interact with digital assets. Your wallet can be used as an easy way to login, instead of having to remember a password." - /> - - - - - - } - title="Not sure where to start?" - description="If you are new to the Web3, we recommend that you start by creating a Kukai wallet. Kukai is a fast way of creating your first wallet using your preferred social account." - /> - - )} -
-
- handleClickWallet(id, props)} - onClickLearnMore={() => handleUpdateState('help')} - otherWallets={ - isMobile - ? { - images: [walletList[3].image, walletList[4].image, walletList[5].image], - onClick: () => handleUpdateState('wallets') - } - : undefined + + + + + } + title="Not sure where to start?" + description="If you are new to the Web3, we recommend that you start by creating a Kukai wallet. Kukai is a fast way of creating your first wallet using your preferred social account." /> -
-
- - )} - + + )} +
+
+ handleClickWallet(id, props)} + onClickLearnMore={() => handleUpdateState('help')} + otherWallets={ + isMobile + ? { + images: [walletList[3].image, walletList[4].image, walletList[5].image], + onClick: () => handleUpdateState('wallets') + } + : undefined + } + /> +
+
+ ) } diff --git a/packages/beacon-ui/src/ui/alert/index.tsx b/packages/beacon-ui/src/ui/alert/index.tsx index 1e12dd121..db788a093 100644 --- a/packages/beacon-ui/src/ui/alert/index.tsx +++ b/packages/beacon-ui/src/ui/alert/index.tsx @@ -29,11 +29,25 @@ const closeAlerts = () => { const AlertRoot = (props: AlertConfig) => { const [isOpen, setIsOpen] = useState(true) + const [mount, setMount] = useState(false) + useEffect(() => { const sub = show$.subscribe((value) => setIsOpen(value)) return () => sub.unsubscribe() }, []) - return + + useEffect(() => { + if (isOpen) { + setMount(true) + } else { + // we need to wait a little before unmounting the component + // because otherwise the "fade-out" animation + // wouldn't have enough time to play + setTimeout(() => setMount(false), 300) + } + }, [isOpen]) + + return <>{mount && } } export { openAlert, closeAlert, closeAlerts }