Skip to content

Conversation

aditya520
Copy link
Member

No description provided.

Copy link

vercel bot commented Aug 28, 2024

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

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 3, 2024 4:07pm
staking-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 3, 2024 4:07pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
xc-admin-frontend ⬜️ Ignored (Inspect) Visit Preview Sep 3, 2024 4:07pm

Copy link
Collaborator

@cprussin cprussin left a comment

Choose a reason for hiding this comment

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

LGTM, minor stylistic nits but not really that important and you can disregard if you prefer

<div>
<h3 className="mb-2 text-lg font-bold">Results</h3>
<Code language="json">{stringifyResponse(status.data)}</Code>
{props.type === EvmApiType.Write && status.data && typeof status.data === 'object' && 'hash' in status.data && typeof status.data.hash === 'string' ? (
Copy link
Collaborator

Choose a reason for hiding this comment

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

For these kinds of cases I suggest you use zod for this kind of thing and it's much easier to write and also easier to read and understand, e.g. make a Result component and use it here, something like this:

import { z } from "zod";
...
const Results = ({ data }) => {
    const parsed = hashSchema.safeParse(data);

    return parsed.success ? (
        <>
            <Code language="json">Tx Hash: {parsed.data.hash}</Code>
            ...
        </>
    ) : (
        <Code language="json">{stringifyResponse(status.data)}</Code>
    )
}

const hashSchema = z.strictObject({ hash: z.string() });

Copy link
Member Author

Choose a reason for hiding this comment

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

This looks much cleaner. I will keep it mind to use it now.

@aditya520 aditya520 merged commit 14dc53f into main Sep 3, 2024
6 checks passed
@aditya520 aditya520 deleted the (feat)-add-hyperlink-api-reference branch September 3, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants