From 1c71748ede86b15cf81f714cc500c99f7765d4ca Mon Sep 17 00:00:00 2001 From: mehditorabiv Date: Wed, 22 Jan 2025 10:46:27 +0300 Subject: [PATCH] fix discourse tooltip content --- src/pages/Identifiers/Identifiers.tsx | 45 ++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/pages/Identifiers/Identifiers.tsx b/src/pages/Identifiers/Identifiers.tsx index 4fc42aa..0c70691 100644 --- a/src/pages/Identifiers/Identifiers.tsx +++ b/src/pages/Identifiers/Identifiers.tsx @@ -36,12 +36,16 @@ import useSnackbarStore from '../../store/useSnackbarStore'; import { contracts } from '../../utils/contracts/eas/contracts'; import { useSigner } from '../../utils/eas-wagmi-utils'; +interface IMetadata { + baseURL: string; + id: string; +} interface Identifier { name: string; icon: React.ElementType; verified: boolean; uid: string; - revealedSecret?: string; + revealedSecret?: string | IMetadata; } export default function Identifiers() { @@ -50,9 +54,15 @@ export default function Identifiers() { const { showSnackbar } = useSnackbarStore(); const [userIdentifiers, setUserIdentifiers] = useState([ { name: 'Discord', icon: FaDiscord, verified: false, uid: '' }, - { name: 'Discourse', icon: FaDiscourse, verified: false, uid: '' }, + { + name: 'Discourse', + icon: FaDiscourse, + verified: false, + uid: '', + }, { name: 'Google', icon: FaGoogle, verified: false, uid: '' }, ]); + const [openTooltips, setOpenTooltips] = useState<{ [key: string]: boolean }>( {} ); @@ -105,6 +115,7 @@ export default function Identifiers() { userIdentifiers, attestations ); + setUserIdentifiers(resolvedIdentifiers); } else { setUserIdentifiers((prev) => @@ -195,6 +206,16 @@ export default function Identifiers() { setUserIdentifiers((prev) => prev.map((id) => { if (id.uid === identifier.uid) { + if (identifier.name === 'Discourse') { + return { + ...id, + revealedSecret: { + id: response.data.id, + baseURL: response.data.metadata.baseURL, + }, + }; + } + return { ...id, revealedSecret: response.data.id, @@ -241,6 +262,23 @@ export default function Identifiers() { return identifier.verified ? 'Revoke' : 'Connect'; }; + const getRevealedSecret = (identifier: Identifier | null) => { + if (!identifier) return 'No data available'; + + if (identifier.name === 'Discourse' && identifier.revealedSecret) { + if (typeof identifier.revealedSecret === 'object') { + const { id, baseURL } = identifier.revealedSecret; + return `Topic ID: ${id || 'N/A'} - Topic URL: ${baseURL || 'N/A'}`; + } + } + + if (identifier.revealedSecret) { + return `Account ID: ${identifier.revealedSecret || 'N/A'}`; + } + + return 'No data available'; + }; + if (attestationsLoading) { return ; } @@ -309,8 +347,7 @@ export default function Identifiers() { loading[identifier.uid] ? ( ) : ( - identifier.revealedSecret && - `Account ID: ${identifier.revealedSecret}` + `${getRevealedSecret(identifier)}` ) } arrow