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(tokens): add helpers for fetching metadata #77

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Quazia
Copy link
Member

@Quazia Quazia commented Feb 15, 2024

Adds helpers to get metadata given a contract address, or a UUID as well as a client wrapper that lets us pass in a single RPC and get back a client instance to perform calls against. We probably want to put these functions behind API routes.

@Quazia Quazia requested a review from a team as a code owner February 15, 2024 06:01
Copy link

changeset-bot bot commented Feb 15, 2024

🦋 Changeset detected

Latest commit: 36bb9f1

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Feb 15, 2024

Size Change: +4.3 kB (+18%) ⚠️

Total Size: 27.8 kB

Filename Size Change
dist/cjs/filter/filters.js 1.78 kB +2 B (0%)
dist/esm/filter/filters.js 2.25 kB -1 B (0%)
dist/cjs/client/ethereumClient.js 392 B +392 B (new file) 🆕
dist/cjs/quests/fetchQuestData.js 376 B +376 B (new file) 🆕
dist/cjs/tokens/erc1155.js 573 B +573 B (new file) 🆕
dist/cjs/tokens/erc721.js 572 B +572 B (new file) 🆕
dist/esm/client/ethereumClient.js 484 B +484 B (new file) 🆕
dist/esm/quests/fetchQuestData.js 401 B +401 B (new file) 🆕
dist/esm/tokens/erc1155.js 737 B +737 B (new file) 🆕
dist/esm/tokens/erc721.js 763 B +763 B (new file) 🆕
ℹ️ View Unchanged
Filename Size
dist/cjs/abi/erc20-quest.js 1.13 kB
dist/cjs/abi/erc20.js 578 B
dist/cjs/abi/quest-factory.js 2.08 kB
dist/cjs/actions/index.js 231 B
dist/cjs/actions/types.js 345 B
dist/cjs/constants.js 342 B
dist/cjs/errors/base.js 734 B
dist/cjs/errors/plugin.js 229 B
dist/cjs/errors/quest.js 331 B
dist/cjs/errors/utils.js 257 B
dist/cjs/errors/version.js 157 B
dist/cjs/filter/index.js 308 B
dist/cjs/filter/operators.js 268 B
dist/cjs/filter/types.js 124 B
dist/cjs/index.js 641 B
dist/cjs/quests/approveIfNeeded.js 525 B
dist/cjs/quests/constants.js 295 B
dist/cjs/quests/deployQuest.js 573 B
dist/cjs/quests/index.js 356 B
dist/cjs/quests/types.js 124 B
dist/cjs/utils/chains.js 375 B
dist/cjs/utils/compressJson.js 255 B
dist/cjs/utils/index.js 280 B
dist/esm/abi/erc20-quest.js 1.07 kB
dist/esm/abi/erc20.js 522 B
dist/esm/abi/quest-factory.js 2.02 kB
dist/esm/actions/index.js 100 B
dist/esm/actions/types.js 286 B
dist/esm/constants.js 303 B
dist/esm/errors/base.js 678 B
dist/esm/errors/plugin.js 158 B
dist/esm/errors/quest.js 276 B
dist/esm/errors/utils.js 164 B
dist/esm/errors/version.js 91 B
dist/esm/filter/index.js 135 B
dist/esm/filter/operators.js 162 B
dist/esm/filter/types.js 64 B
dist/esm/index.js 323 B
dist/esm/quests/approveIfNeeded.js 688 B
dist/esm/quests/constants.js 310 B
dist/esm/quests/deployQuest.js 494 B
dist/esm/quests/index.js 175 B
dist/esm/quests/types.js 64 B
dist/esm/utils/chains.js 448 B
dist/esm/utils/compressJson.js 279 B
dist/esm/utils/index.js 133 B

compressed-size-action

* @returns {Promise<any>} The action parameters extracted from the quest data.
*/
export async function fetchQuestActionParams(uuid: string): Promise<any> {
const endpoint = `https://api.rabbithole.gg/v1.2/quest/public/${uuid}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Would add a TODO or open up an issue to update this endpoint to a Boost API in the near future

}

/**
* Fetches the media URL from ERC1155 token metadata and performs basic validation or sanitization.
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think there's "basic validation or sanitization"

Copy link
Member Author

Choose a reason for hiding this comment

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

There's not - I'll change this comment we discussed using a service for this but I think we're just going to handle it with the dom purify in the front-end

Copy link
Member

Choose a reason for hiding this comment

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

Might be worth purifying on the BE wherever we serve the info to prevent passing dangerous data to third party clients or w/e

* @param {string} uuid The UUID of the quest.
* @returns {Promise<any>} The metadata of the ERC1155 token associated with the quest.
*/
export async function fetchERC1155MetadataByUUID(
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Wonder if it makes sense to rename function to fetchERC1155MetadataByQuestUUID? I don't like the long variable name I suggested though lol

Copy link
Member Author

Choose a reason for hiding this comment

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

I like it, rather a more specific long name

tokenId: number,
): Promise<string | undefined> {
const metadata = await fetchERC721Metadata(client, contractAddress, tokenId)
// Here, you'd add logic to sanitize or validate the URL?
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh did we want to actually add validation / sanitization?

Copy link
Member Author

Choose a reason for hiding this comment

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

No I don't think so, was considering it but as mentioned above I think we handle this in the FE

@JamieLottering
Copy link
Member

Any updates on this @Quazia ? Going to need this for dynamic boost names

@Quazia
Copy link
Member Author

Quazia commented Feb 20, 2024

@JamieLottering Just pushed the PR blocking this up for review but I'm going to re-open this PR into the other repo now that all this code has been ported over. Top priority is getting this upstream. Also are you going to need protocol specific dynamic name generation for Sound? If so I can export that from the plug-in, I'm guessing yes.

@benjaminykim
Copy link

@JamieLottering Just pushed the PR blocking this up for review but I'm going to re-open this PR into the other repo now that all this code has been ported over. Top priority is getting this upstream. Also are you going to need protocol specific dynamic name generation for Sound? If so I can export that from the plug-in, I'm guessing yes.

yes, we need sound and mirror

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.

4 participants