Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: denom info modal #37

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions components/bank/components/__tests__/tokenList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ describe('TokenList', () => {

await waitFor(() => {
expect(screen.getByLabelText('Close modal')).toBeInTheDocument();
expect(screen.getByText('NAME')).toBeInTheDocument();
expect(screen.getByText('SYMBOL')).toBeInTheDocument();
expect(screen.getByText('DESCRIPTION')).toBeInTheDocument();
expect(screen.getByText('EXPONENT')).toBeInTheDocument();
expect(screen.getByText('Name')).toBeInTheDocument();
expect(screen.getByText('Ticker')).toBeInTheDocument();
expect(screen.getByText('Description')).toBeInTheDocument();
});
});

Expand Down
68 changes: 20 additions & 48 deletions components/factory/modals/denomInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
import { TruncatedAddressWithCopy } from '@/components/react/addressCopy';
import { FaExternalLinkAlt } from 'react-icons/fa';
import { MetadataSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/bank/v1beta1/bank';
import { useRouter } from 'next/router';

export const DenomInfoModal: React.FC<{
denom: MetadataSDKType | null;
modalId: string;
isOpen?: boolean;
onClose?: () => void;
}> = ({ denom, modalId, isOpen, onClose }) => {
let nameIsAddress = false;
if (denom?.name.startsWith('factory/manifest1')) {
nameIsAddress = true;

Check warning on line 14 in components/factory/modals/denomInfo.tsx

View check run for this annotation

Codecov / codecov/patch

components/factory/modals/denomInfo.tsx#L14

Added line #L14 was not covered by tests
}
return (
<dialog
id={modalId}
Expand All @@ -28,50 +31,17 @@
</form>
<h3 className="text-xl font-semibold text-[#161616] dark:text-white mb-6">Denom Details</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<InfoItem label="NAME" value={denom?.name ?? 'No name available'} />
<InfoItem label="SYMBOL" value={denom?.symbol ?? 'No symbol available'} />
{denom?.description && (
<InfoItem
label="DESCRIPTION"
value={denom?.description ?? 'No description available'}
/>
)}
{denom?.denom_units[1]?.exponent && (
<InfoItem
label="EXPONENT"
value={denom?.denom_units[1]?.exponent?.toString() ?? '0'}
/>
)}
</div>
<div>
{denom?.denom_units?.map(
(
unit: {
denom: string;
aliases?: string[];
exponent?: number;
},
index: number
) => (
<div key={index} className="mb-4">
<InfoItem label="DENOM" value={unit?.denom} />
<InfoItem label="ALIASES" value={unit?.aliases?.join(', ') || 'No aliases'} />
</div>
)
)}
</div>
</div>
<h4 className="text-lg font-semibold text-[#161616] dark:text-white mt-6 mb-4">
Additional Information
</h4>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<InfoItem
label="BASE"
value={denom?.base ? decodeURIComponent(denom.base) : ''}
isAddress={true}
label="Name"
value={denom?.name ?? 'No name available'}
isAddress={nameIsAddress}
/>
<InfoItem label="Ticker" value={denom?.display.toUpperCase() ?? 'No ticker available'} />
<InfoItem
label="Description"
value={denom?.description ?? 'No description available'}
className="col-span-2 row-span-2"
/>
<InfoItem label="DISPLAY" value={denom?.display ?? 'No display available'} />
</div>
</div>
<form method="dialog" className="modal-backdrop" onSubmit={onClose}>
Expand All @@ -85,31 +55,33 @@
label,
value,
isAddress = false,
className = '',
}: {
label: string;
value: string;
isAddress?: boolean;
className?: string;
}) {
return (
<div className="mb-4 flex flex-col">
<div className={`mb-4 flex flex-col ${className}`}>
<p className="text-sm font-semibold text-[#00000099] dark:text-[#FFFFFF99] mb-2">{label}</p>
<div className="bg-base-300 rounded-[16px] p-4 flex-grow">
<div className="bg-base-300 rounded-[16px] p-4 flex-grow h-full">
{isAddress ? (
<div className="flex items-center">
<TruncatedAddressWithCopy address={value} slice={8} />
<TruncatedAddressWithCopy address={value} slice={17} />

Check warning on line 71 in components/factory/modals/denomInfo.tsx

View check run for this annotation

Codecov / codecov/patch

components/factory/modals/denomInfo.tsx#L71

Added line #L71 was not covered by tests
<a
href={`${process.env.NEXT_PUBLIC_TESTNET_EXPLORER_URL}/account/${value}`}
target="_blank"
aria-label={`View ${value} on block explorer (opens in new tab)`}
rel="noopener noreferrer"
className="ml-2 text-primary hover:text-primary/50"
>
<FaExternalLinkAlt aria-hidden="true" />{' '}
<FaExternalLinkAlt aria-hidden="true" />

Check warning on line 79 in components/factory/modals/denomInfo.tsx

View check run for this annotation

Codecov / codecov/patch

components/factory/modals/denomInfo.tsx#L79

Added line #L79 was not covered by tests
<span className="sr-only">External link</span>
</a>
</div>
) : (
<p className="text-[#161616] dark:text-white truncate" title={value}>
<p className="text-[#161616] dark:text-white" title={value}>
{value}
</p>
)}
Expand Down
Loading