From 56afab20b6265a6c8433b042b13f527f4824b058 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Thu, 30 Jan 2025 12:57:08 +0100 Subject: [PATCH] fix: onClose --- .../beacon-ui/src/components/info/index.tsx | 47 +++------- .../alert/components/alert-content/index.tsx | 7 -- .../ui/alert/components/info-alert/index.tsx | 90 ++++++++++--------- .../alert/components/pairing-alert/index.tsx | 14 +-- packages/beacon-ui/src/ui/alert/index.tsx | 27 ++++-- packages/beacon-ui/src/ui/common.ts | 36 ++++++-- 6 files changed, 113 insertions(+), 108 deletions(-) delete mode 100644 packages/beacon-ui/src/ui/alert/components/alert-content/index.tsx diff --git a/packages/beacon-ui/src/components/info/index.tsx b/packages/beacon-ui/src/components/info/index.tsx index 3d8ac7289..84e9ac3ad 100644 --- a/packages/beacon-ui/src/components/info/index.tsx +++ b/packages/beacon-ui/src/components/info/index.tsx @@ -1,49 +1,27 @@ -import React from "react"; -import "./styles.css"; -import { QRCodeIcon } from "../icons"; - -interface InfoProps { - title: string; - description?: string; - data?: string; - icon?: any; - border?: boolean; - iconBadge?: boolean; - bigIcon?: boolean; - buttons?: { - label: string; - type: "primary" | "secondary"; - onClick: () => void; - }[]; - downloadLink?: { url: string; label: string }; - onShowQRCodeClick?: (() => void) | (() => Promise); -} +import React from 'react' +import './styles.css' +import { QRCodeIcon } from '../icons' +import { InfoProps } from '../../ui/common' const Info: React.FC = (props: InfoProps) => { return ( -
+
{props.icon && (
{props.icon}
)}

{props.title}

- {props.description && ( -
{props.description}
- )} + {props.description &&
{props.description}
} {props.data &&
{props.data}
}
{props.buttons?.map((button, index) => ( )}
- ); -}; - + ) +} -export default Info; +export default Info diff --git a/packages/beacon-ui/src/ui/alert/components/alert-content/index.tsx b/packages/beacon-ui/src/ui/alert/components/alert-content/index.tsx deleted file mode 100644 index 78375c3e2..000000000 --- a/packages/beacon-ui/src/ui/alert/components/alert-content/index.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import PairingAlert from '../pairing-alert' - -const AlertContent = () => { - return -} - -export default AlertContent diff --git a/packages/beacon-ui/src/ui/alert/components/info-alert/index.tsx b/packages/beacon-ui/src/ui/alert/components/info-alert/index.tsx index 579b6f944..7f607ac49 100644 --- a/packages/beacon-ui/src/ui/alert/components/info-alert/index.tsx +++ b/packages/beacon-ui/src/ui/alert/components/info-alert/index.tsx @@ -1,50 +1,54 @@ +import { ConfigurableAlertProps } from '../../../common' import Info from '../../../../components/info' +import Alert from '../../../../components/alert' -const InfoAlert = ({ title, body, data }: any) => { +const InfoAlert = ({ title, body, data, open, onClose }: ConfigurableAlertProps) => { return ( - - - - - - } - title={title || 'No title'} - description={body || 'No description'} - data={data} - buttons={[ - { - label: 'Close', - type: 'primary', - onClick: () => console.log('todo') + + + + + + } - ]} - /> + title={title || 'No title'} + description={body || 'No description'} + data={data} + buttons={[ + { + label: 'Close', + type: 'primary', + onClick: onClose + } + ]} + /> + ) } export default InfoAlert 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 e3b82e552..c210ad56b 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 @@ -1,4 +1,4 @@ -import Alert from 'src/components/alert' +import Alert from '../../../../components/alert' import useConnect from '../../hooks/useConnect' import BugReportForm from 'src/components/bug-report-form' import Info from 'src/components/info' @@ -9,9 +9,9 @@ import { isIOS } from 'src/utils/platform' import { StorageKey } from '@airgap/beacon-types' import QR from 'src/components/qr' import useWallets from '../../hooks/useWallets' +import { ConfigurableAlertProps } from '../../../common' -// todo remove any -const PairingAlert: React.FC = (props) => { +const PairingAlert: React.FC = (props) => { const { walletConnectSyncCode: wcPayload, p2pSyncCode: p2pPayload, @@ -38,13 +38,7 @@ const PairingAlert: React.FC = (props) => { handleUpdateState, handleUpdateQRCode, handleShowMoreContent - ] = useConnect( - wcPayload, - p2pPayload, - postPayload, - wallets, - props.closeButtonCallback ?? (() => {}) - ) + ] = useConnect(wcPayload, p2pPayload, postPayload, wallets, props.onClose) const isOnline = navigator.onLine const walletList = Array.from(wallets.values()) const areMetricsEnabled = localStorage diff --git a/packages/beacon-ui/src/ui/alert/index.tsx b/packages/beacon-ui/src/ui/alert/index.tsx index 5dd8fa673..02be2f2d9 100644 --- a/packages/beacon-ui/src/ui/alert/index.tsx +++ b/packages/beacon-ui/src/ui/alert/index.tsx @@ -1,7 +1,7 @@ import { createRoot } from 'react-dom/client' import { useEffect, useState } from 'react' import { Subject } from '../../utils/subject' -import { AlertConfig } from '../common' +import { AlertConfig, ConfigurableAlertProps } from '../common' import PairingAlert from './components/pairing-alert' import InfoAlert from './components/info-alert' @@ -48,13 +48,26 @@ const AlertRoot = (props: AlertConfig) => { } }, [isOpen]) - const Alert = props.pairingPayload ? ( - - ) : ( - - ) + const onCloseHandler = () => { + closeAlert() + props.closeButtonCallback && props.closeButtonCallback() + } - return <>{mount && Alert} + const filteredProps: ConfigurableAlertProps = { + ...props, + onClose: onCloseHandler, + open: isOpen + } + + const Alert = () => { + return props.pairingPayload ? ( + + ) : ( + + ) + } + + return <>{mount && } } export { openAlert, closeAlert, closeAlerts } diff --git a/packages/beacon-ui/src/ui/common.ts b/packages/beacon-ui/src/ui/common.ts index 39020e4f3..e9df4ef6f 100644 --- a/packages/beacon-ui/src/ui/common.ts +++ b/packages/beacon-ui/src/ui/common.ts @@ -15,18 +15,18 @@ export interface AlertConfig { data?: string timer?: number buttons?: AlertButton[] - pairingPayload?: { - p2pSyncCode: string - postmessageSyncCode: string - walletConnectSyncCode: string - networkType: NetworkType - } + pairingPayload?: PairingPayload closeButtonCallback?: () => void disclaimerText?: string analytics?: AnalyticsInterface featuredWallets?: string[] } +export interface ConfigurableAlertProps extends Omit { + open: boolean + onClose: () => void +} + export interface AlertProps { open: boolean showMore?: boolean @@ -37,6 +37,13 @@ export interface AlertProps { onBackClick?: () => void } +export interface PairingPayload { + p2pSyncCode: string + postmessageSyncCode: string + walletConnectSyncCode: string + networkType: NetworkType +} + export interface PairOtherProps { walletList: MergedWallet[] p2pPayload: string @@ -44,6 +51,23 @@ export interface PairOtherProps { onClickLearnMore: () => void } +export interface InfoProps { + title: string + description?: string + data?: string + icon?: any + border?: boolean + iconBadge?: boolean + bigIcon?: boolean + buttons?: { + label: string + type: 'primary' | 'secondary' + onClick: () => void + }[] + downloadLink?: { url: string; label: string } + onShowQRCodeClick?: (() => void) | (() => Promise) +} + // TOAST export interface ToastAction {