Skip to content

Commit

Permalink
simplify author render
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 committed Nov 6, 2024
1 parent c6693de commit 54a1c06
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions components/groups/modals/groupInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,44 @@ export function GroupInfo({ group, policyAddress, address, onUpdate }: GroupInfo

const threshold = (policy?.decision_policy as ThresholdDecisionPolicySDKType)?.threshold ?? '0';

const renderAuthors = () => {
const authors = group.ipfsMetadata?.authors;
if (!authors) return <InfoItem label="Author" value="No author information" />;
function renderAuthors() {
const authors = group?.ipfsMetadata?.authors;

if (!authors) {
return <InfoItem label="Author" value="No author information" />;
}

const formatAddress = (author: string, index: number) => (
<InfoItem key={index} label="Address" value={author} isAddress={true} />
);

const formatAuthor = (author: string, index: number) => (
<InfoItem key={index} label={`Author ${index + 1}`} value={author} />
);

if (typeof authors === 'string') {
if (authors.startsWith('manifest1')) {
return (
<div className="grid grid-cols-2 gap-4">
<InfoItem label="Address" value={authors} isAddress={true} />
</div>
);
return <div className="grid grid-cols-2 gap-4">{formatAddress(authors, 0)}</div>;
}
return <InfoItem label="Author" value={authors} />;
return formatAuthor(authors, 0);
}

if (Array.isArray(authors)) {
const manifestAddresses = authors.filter(author => author.startsWith('manifest1'));

if (manifestAddresses.length > 0) {
return (
<div className="grid grid-cols-2 gap-4">
{manifestAddresses.map((author, index) => (
<InfoItem key={index} label="Address" value={author} isAddress={true} />
))}
{manifestAddresses.map((author, index) => formatAddress(author, index))}
</div>
);
}
return (
<div>
{authors.map((author, index) => (
<InfoItem key={index} label={`Author ${index + 1}`} value={author} />
))}
</div>
);

return <div>{authors.map((author, index) => formatAuthor(author, index))}</div>;
}

return <InfoItem label="Author" value="Invalid author information" />;
};
}

return (
<dialog id="group-info-modal" className="modal">
Expand Down

0 comments on commit 54a1c06

Please sign in to comment.