Skip to content

feat(xc_admin_frontend): add more details to summary view #1612

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

Merged

Conversation

cprussin
Copy link
Collaborator

This PR extends the summary to include publisher and price account details for addPublisher and delPublisher instructions.

screenshot-2024-05-24-183617

@cprussin cprussin requested review from cctdaniel and guibescos May 25, 2024 01:55
Copy link

vercel bot commented May 25, 2024

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

Name Status Preview Comments Updated (UTC)
xc-admin-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2024 11:12pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
example-oracle-amm ⬜️ Ignored (Inspect) Visit Preview May 27, 2024 11:12pm

@cprussin
Copy link
Collaborator Author

For some reason, Vercel isn't posting the preview URL, even though the preview built (probably because I'm working on a fork...)

In any case, here's a preview URL that's particularly extreme, with a ton of addPublisher and delPublisher commands:

https://xc-admin-frontend-2dsxc5l6p-pyth-web.vercel.app/?vercelToolbarCode=uKzMsd55JQiCTaw&tab=proposals&proposal=4feQoLU6WCXbNiS8wGw69qD5rEVH51JWyKwMxCknw37q

default:
return {
name: parsedInstruction.name,
} as const
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the point of the "as const"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

as const does two things:

  1. It narrows the inference engine. In particular, this means that e.g. the type of { name: 'addPublisher' } is interpreted with the name field's type as the literal "addPublisher" instead of the type string.
  2. It marks types as readonly

It's a bit of a shame that typescript doesn't have a nice syntax for narrowly inferring types that does only #1 without #2 since the readonly modifier is, IMO, quite clunky and not very useful.

I did this for #1 -- it actually doesn't matter in this code because the fact that parsedInstruction.name can be any arbitrary string means that the inference engine actually can't match the literal addPublisher to the case on line 106 (as far as I know typescript is not smart enough to infer that the case here only matches for any string except addPublisher and delPublisher). However, it doesn't make sense to me that an instruction can be an arbitrary name, that seems like something that eventually will be enumerated, and the idea is that by doing this now, eventually if we do enumerate the names, it would be very very easy to update this function so that type inference can correctly match the shape of the return value based on the instruction name. This would be especially valuable if we added more bespoke summaries for different instruction types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In case you're curious, here's a good illustration in the typescript playground of the difference between using the const assertion vs not: https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAJiAyiAtgUygCwJZgOYwC8MAFAIYBOeAXDNBbngJREB8MA3gLABQMdAd2xRgmUpWade-fsDIQ0MAOQAjMgC8ltChgCuFMJxhgy6Wqo1KANHVQYc+WgFYYAXwDc0mXDQAzMroANlDaegZGJmbKEHZYjACigQrWtuhx+IkKtFAUuooeXq68RTy8oJCwCMhpDngA6sKYAMLg0ETiVLT0jCyE7Nx8gsKiHZIDMjByCspqmqFQ+oYcxqZo5rMpMTWMzm4w8pOtUJ6D-D7+QSEwOgvhy5Fr0bG1mWibzwlJjzl5ewfl0BO-BKriAA.

If you take a look at the .d.ts tab on the right side, you'll see how typescript infers the types. If you see how doSomethingWithConst gets inferred with literals, it essentially allows any consuming code that matches name to baz to automatically infer correctly that something is 5 and somethingElse is undefined.

@guibescos
Copy link
Contributor

This is great, please add it for non wormhole proposals as well

@cprussin cprussin force-pushed the summarized-view-for-price-feed-proposals branch from c0697a2 to dd1f07e Compare May 27, 2024 22:40
Copy link

vercel bot commented May 27, 2024

@cprussin is attempting to deploy a commit to the pyth-web Team on Vercel.

A member of the Team first needs to authorize it.

This PR extends the summary to include publisher and price account details for
addPublisher and delPublisher instructions.
@guibescos guibescos merged commit 443b769 into pyth-network:main May 28, 2024
@cprussin cprussin deleted the summarized-view-for-price-feed-proposals branch May 28, 2024 14:46
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