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(thirdweb): adds useChainMetadata hook to retrieve metadata for a chain #3857

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

gregfromstl
Copy link
Member

@gregfromstl gregfromstl commented Jul 29, 2024

TL;DR

This PR adds a new hook, useChainMetadata, to the thirdweb library. The hook allows developers to retrieve metadata for a specific blockchain, such as name, icon, available faucets, and block explorers.

What changed?

  • Added useChainMetadata hook in thirdweb/react.
  • Deprecated useChainQuery hook.
  • Updated documentation to reflect the new hook.

How to test?

  1. Import the useChainMetadata from thirdweb/react.
  2. Call the hook with a chain defined using defineChain.
  3. Check the returned metadata for correctness.

Why make this change?

This change provides a more intuitive and documented way to retrieve chain metadata, replacing the deprecated useChainQuery hook. It enhances developer experience by offering a straightforward API to access chain-related information.



PR-Codex overview

This PR adds a new useChainMetadata hook to retrieve chain metadata in the thirdweb package and updates related components to use this hook.

Detailed summary

  • Added useChainMetadata hook to retrieve chain metadata
  • Updated components to use useChainMetadata instead of useChainQuery
  • Updated documentation for the new hook

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented Jul 29, 2024

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

Name Status Preview Comments Updated (UTC)
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 9:19pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 9:19pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 9:19pm

Copy link

changeset-bot bot commented Jul 29, 2024

🦋 Changeset detected

Latest commit: d5e5467

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

This PR includes changesets to release 1 package
Name Type
thirdweb Minor

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

@github-actions github-actions bot added the TS SDK Involves changes to the v5 TypeScript SDK. label Jul 29, 2024
@graphite-app graphite-app bot requested a review from jnsdls July 29, 2024 16:34
@gregfromstl gregfromstl force-pushed the feat/add-use-chain-metadata-hook branch from 9c20b49 to 6bcb9d0 Compare July 29, 2024 16:35
Copy link

graphite-app bot commented Jul 29, 2024

Graphite Automations

"If PR for SDK -> Tag Joaquim, Jonas and Greg" took an action on this PR • (07/29/24)

1 reviewer was added to this PR based on Kien Ngo's automation.

Copy link
Member Author

gregfromstl commented Jul 29, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @gregfromstl and the rest of your teammates on Graphite Graphite

Copy link

graphite-app bot commented Jul 29, 2024

Your org requires the Graphite merge queue for merging into main

Add the label “merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link

codspeed-hq bot commented Jul 29, 2024

CodSpeed Performance Report

Merging #3857 will not alter performance

Comparing feat/add-use-chain-metadata-hook (d5e5467) with main (e26d070)

Summary

✅ 9 untouched benchmarks

Copy link
Contributor

github-actions bot commented Jul 29, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 43.16 KB (0%) 864 ms (0%) 4.1 s (+85.48% 🔺) 5 s
thirdweb (cjs) 91.37 KB (0%) 1.9 s (0%) 5.6 s (+15.3% 🔺) 7.5 s
thirdweb (minimal + tree-shaking) 4.79 KB (0%) 96 ms (0%) 271 ms (+52.05% 🔺) 366 ms
thirdweb/chains (tree-shaking) 492 B (0%) 10 ms (0%) 67 ms (+19.09% 🔺) 77 ms
thirdweb/react (minimal + tree-shaking) 13.62 KB (0%) 273 ms (0%) 668 ms (+151.23% 🔺) 940 ms

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 61.52%. Comparing base (e26d070) to head (d5e5467).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3857      +/-   ##
==========================================
+ Coverage   61.51%   61.52%   +0.01%     
==========================================
  Files         962      962              
  Lines       76559    76578      +19     
  Branches     3792     3787       -5     
==========================================
+ Hits        47092    47112      +20     
+ Misses      28782    28781       -1     
  Partials      685      685              
Flag Coverage Δ *Carryforward flag
legacy_packages 65.68% <ø> (ø) Carriedforward from e26d070
packages 60.83% <93.33%> (+0.01%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

Files Coverage Δ
...rdweb/src/react/core/hooks/others/useChainQuery.ts 51.02% <100.00%> (+5.56%) ⬆️
packages/thirdweb/src/storage/download.ts 93.10% <100.00%> (-0.08%) ⬇️
...nectWallet/screens/Buy/DirectPaymentModeScreen.tsx 12.03% <50.00%> (ø)
...onnectWallet/screens/Buy/TransactionModeScreen.tsx 11.06% <50.00%> (ø)

... and 1 file with indirect coverage changes

*
* @chain
*/
export const useChainMetadata = useChainQuery;
Copy link
Member

Choose a reason for hiding this comment

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

We are already exporting the getChainMetadata - I don't think we also need to export a hook version of it to keep the number of wrapper hooks at minimum

Copy link
Member

Choose a reason for hiding this comment

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

Deferring the final call to @jnsdls

Copy link
Member

Choose a reason for hiding this comment

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

personally don't think it hurts but yeah unsure if we need it

Copy link
Member Author

Choose a reason for hiding this comment

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

Needed this for the wallet UI

*
* @chain
*/
export const useChainMetadata = useChainQuery;
Copy link
Member

Choose a reason for hiding this comment

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

personally don't think it hurts but yeah unsure if we need it

@@ -8,9 +8,9 @@ export type DownloadOptions = Prettify<
}
>;

/** @import { createThirdwebClient } from "../client/client.js" */
Copy link
Member

Choose a reason for hiding this comment

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

what does this do?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's us link the type without needing to import it in the actual code

https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/

Copy link
Member

@MananTank MananTank Jul 29, 2024

Choose a reason for hiding this comment

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

Isn't this just for type imports though? + when you want to use that imported type in JSDoc

Copy link
Member

Choose a reason for hiding this comment

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

oh interesting - wonder how its gonna render on docs.

one simple thing we can do is just link to https://portal.thirdwerb.com/references/typescript/v5/<theFunction> with markdown, that i know renders well on portal

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah let's do that for now. I was afraid of broken links that way but should be fine

@gregfromstl gregfromstl force-pushed the feat/add-use-chain-metadata-hook branch from 6bcb9d0 to f7fa48a Compare July 29, 2024 19:52
Copy link

graphite-app bot commented Jul 29, 2024

Merge activity

… chain (#3857)

### TL;DR

This PR adds a new hook, `useChainMetadata`, to the thirdweb library. The hook allows developers to retrieve metadata for a specific blockchain, such as name, icon, available faucets, and block explorers.

### What changed?

- Added `useChainMetadata` hook in `thirdweb/react`.
- Deprecated `useChainQuery` hook.
- Updated documentation to reflect the new hook.

### How to test?

1. Import the `useChainMetadata` from `thirdweb/react`.
2. Call the hook with a chain defined using `defineChain`.
3. Check the returned metadata for correctness.

### Why make this change?

This change provides a more intuitive and documented way to retrieve chain metadata, replacing the deprecated `useChainQuery` hook. It enhances developer experience by offering a straightforward API to access chain-related information.

---

<!-- start pr-codex -->

---

## PR-Codex overview
This PR adds a new hook `useChainMetadata` to retrieve chain metadata in Thirdweb React. It also updates the `useChainQuery` hook to `useChainMetadata`.

### Detailed summary
- Added `useChainMetadata` hook to retrieve chain metadata
- Updated `useChainQuery` to `useChainMetadata`
- Improved documentation for `useChainMetadata`

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TS SDK Involves changes to the v5 TypeScript SDK.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants