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

feat: add view components #1483

Merged
merged 7 commits into from
Oct 23, 2024
Merged

feat: add view components #1483

merged 7 commits into from
Oct 23, 2024

Conversation

alessey
Copy link
Contributor

@alessey alessey commented Oct 23, 2024

What changed? Why?
Add nft view components

Notes to reviewers

How has it been tested?

Copy link

vercel bot commented Oct 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
onchainkit-coverage ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2024 5:59pm
onchainkit-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2024 5:59pm
onchainkit-routes ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2024 5:59pm

Comment on lines +16 to +18
onLoading,
onLoaded,
onError,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these just be onStatus?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd need to basically create a pseudo lifecycle status to change to onStatus. I could handle lifecycle status in the children, but I was trying to keep the mediaLoaded/success logic centralized in one place.


export function NFTLastSoldPrice({
className,
label = 'Mint price',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we standardize on label? we use text in our other components

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

label seems more flexible if you ever want to change from string to ReactNode

Comment on lines 52 to 79
if (mediaType.isVideo) {
return (
<NFTVideo
onLoading={handleLoading}
onLoaded={handleLoaded}
onError={handleError}
/>
);
}

if (mediaType.isAudio) {
return (
<div className="relative w-full">
<NFTImage />
<div className="absolute bottom-[20px] mx-auto w-full">
<NFTAudio />
</div>
</div>
);
}

return (
<NFTImage
onLoading={handleLoading}
onLoaded={handleLoaded}
onError={handleError}
/>
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer a switch here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason? performance differences at this point are negligible

Copy link
Contributor

@0xAlec 0xAlec Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not for performance but for > 2 cases ifl it's cleaner to just use a switch compared to multiple if statements

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely a nit though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, it made more sense when i switched to an enum anyways

Comment on lines 43 to 50
const mediaType = useMemo(() => {
return {
isVideo: mimeType?.startsWith('video'),
isAudio:
mimeType?.startsWith('audio') || mimeType?.startsWith('application'),
isImage: mimeType?.startsWith('image'),
};
}, [mimeType]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer returning an enum here rather than an object with always 2/3 null values

} as Record<string, ReactNode>;

export function NFTNetwork({ className, label = 'Network' }: NFTNetworkProps) {
const { chain } = useOnchainKit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should deprecate this top-level chain prop, so I don't recommend using it here.

Is there any other way to tell which chain the NFT is on?

<circle cx="73" cy="73" r="73" fill="#0052FF" />
<path
d="M73.323 123.729C101.617 123.729 124.553 100.832 124.553 72.5875C124.553 44.343 101.617 21.4463 73.323 21.4463C46.4795 21.4463 24.4581 42.0558 22.271 68.2887H89.9859V76.8864H22.271C24.4581 103.119 46.4795 123.729 73.323 123.729Z"
fill="white"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the fill always meant to be white here? Is the intention for it to NOT update based off of the current theme?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I didn't think the base logo should change

Comment on lines +34 to +45
return (
<div
className={cn(
'flex items-center justify-between py-1',
text.label2,
className,
)}
>
<div>{label}</div>
<div>{formattedDate}</div>
</div>
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these divs are unnecessary and can be removed:

Suggested change
return (
<div
className={cn(
'flex items-center justify-between py-1',
text.label2,
className,
)}
>
<div>{label}</div>
<div>{formattedDate}</div>
</div>
);
return (
<div
className={cn(
'flex items-center justify-between py-1',
text.label2,
className,
)}
>
{label}
{formattedDate}
</div>
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since i'm flex space-between these divs are needed so the content is aligned left/right, otherwise they'd be treated as a single text node

Comment on lines +22 to +36
return (
<div
className={cn(
'flex items-center justify-between py-1',
text.label2,
className,
)}
>
<div>{label}</div>
<div className="flex items-center gap-2">
<div className="h-4 w-4 object-cover">{networkMap[chain.name]}</div>
<div>{chain.name}</div>
</div>
</div>
);
Copy link
Contributor

@cpcramer cpcramer Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can remove these divs that don't have styling:

Suggested change
return (
<div
className={cn(
'flex items-center justify-between py-1',
text.label2,
className,
)}
>
<div>{label}</div>
<div className="flex items-center gap-2">
<div className="h-4 w-4 object-cover">{networkMap[chain.name]}</div>
<div>{chain.name}</div>
</div>
</div>
);
return (
<div
className={cn(
'flex items-center justify-between py-1',
text.label2,
className,
)}
>
{label}
<div className="flex items-center gap-2">
<div className="h-4 w-4 object-cover">{networkMap[chain.name]}</div>
{chain.name}
</div>
</div>
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is possible, but I think its easier to see whats going on using an element as a flex-child vs. a text node.

className,
)}
>
<div>{label}</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<div>{label}</div>
{label}

videoRef.current.onerror = (error: string | Event) => {
onError?.({
error: typeof error === 'string' ? error : error.type,
code: 'NmNVc01', // NFT module NFTVideo component 01 error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add all of the possible error codes in a error / const file and reference from it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me revisit that at the end

@alessey alessey requested a review from cpcramer October 23, 2024 17:06

const handleTransitionEnd = () => {
setTransitionEnded(true);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit but should this be useCallback just to keep consistent

onLoading?: (mediaUrl: string) => void;
onLoaded?: () => void;
onError?: (error: NFTError) => void;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit move to types file

type NFTLastSoldPriceProps = {
className?: string;
label?: ReactNode;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit move to types

type NFTMintDateProps = {
className?: string;
label?: ReactNode;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit move to types

@alessey alessey merged commit 4447721 into main Oct 23, 2024
16 checks passed
@alessey alessey deleted the alessey/nft-2 branch October 23, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants