Skip to content

Commit

Permalink
fix discourse tooltip content
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Jan 22, 2025
1 parent 3b18603 commit 1c71748
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions src/pages/Identifiers/Identifiers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -50,9 +54,15 @@ export default function Identifiers() {
const { showSnackbar } = useSnackbarStore();
const [userIdentifiers, setUserIdentifiers] = useState<Identifier[]>([
{ 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 }>(
{}
);
Expand Down Expand Up @@ -105,6 +115,7 @@ export default function Identifiers() {
userIdentifiers,
attestations
);

setUserIdentifiers(resolvedIdentifiers);
} else {
setUserIdentifiers((prev) =>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 <CircularProgress />;
}
Expand Down Expand Up @@ -309,8 +347,7 @@ export default function Identifiers() {
loading[identifier.uid] ? (
<CircularProgress color="inherit" size={20} />
) : (
identifier.revealedSecret &&
`Account ID: ${identifier.revealedSecret}`
`${getRevealedSecret(identifier)}`
)
}
arrow
Expand Down

0 comments on commit 1c71748

Please sign in to comment.