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] - Display referendum Titles, add react-query #49

Merged
merged 9 commits into from
May 22, 2024

Conversation

UrbanWill
Copy link
Collaborator

@UrbanWill UrbanWill commented May 21, 2024

Description

⛑️ What was done:

  • Fetch referendum data from Subsquare API and display referendum titles on Proposal Dropdown and Pending Votes components
  • Titles with default to previously existing behavior for unsupported chains or proposals without title

Technical:

  • Installed react-query and react-query devtools for fetching and caching Rest (or GraphQL) apis. React-query docs
  • Created reusable custom hook to fetch & referendum data by ID
    Note: The API does not support a request with an array of IDs, N requests are required to get the data for each referendum. API calls to unsupported chains are not executed, though they how appear on client side cache as chainId, { isChainSupported: false }, id

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Ready to merge

🧪 How to test:

  1. Visit /voting
  2. If the chain is supported by Subsquare, the proposals dropdown will show the titles of the proposals
  3. Cast a vote
  4. If the chain is supported by Subsquare, Pending Votes list will show the correct title
  5. Check react-query devtools if you are interested in understanding how the client-side cache works with the query-keys

🖼️ Screenshots:

Screen.Recording.2024-05-20.at.17.18.54.mov

React-query dev tools cache explorer:
If you are new to react-query, the left side is a list of the client side cache. Each item has an unique query key array as an identifier. For this hook the chain name, isChainSupported and the referendum ID are being used for uniqueness and debugging readability.
On the right side the details of a given query is displayed, including the cached data.

Screenshot 2024-05-21 at 9 46 53

Copy link

vercel bot commented May 21, 2024

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

Name Status Preview Comments Updated (UTC)
polkadot-multisig ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2024 6:57am
signet-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2024 6:57am

@UrbanWill UrbanWill marked this pull request as ready for review May 21, 2024 04:23
Copy link
Collaborator

@chrisling-dev chrisling-dev left a comment

Choose a reason for hiding this comment

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

LGTM after comment

const referendumData = referendumsData?.find(ref => ref?.referendumIndex === referendum.index)
return (
<Select.Option
headlineText={referendumData?.title || `Proposal #${referendum.index}`}
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets include the proposal number?

Suggested change
headlineText={referendumData?.title || `Proposal #${referendum.index}`}
headlineText={`#${referendum.index}: ${referendumData?.title}` || `Proposal #${referendum.index}`}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done :)

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