-
Notifications
You must be signed in to change notification settings - Fork 151
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
Token gate #121
Token gate #121
Conversation
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 9da1577 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
You should merge the current main branch into this one to resolve the merge conflicts |
packages/components/src/components/TokenGate/TokenGate.stories.tsx
Outdated
Show resolved
Hide resolved
packages/components/src/components/TokenGate/TokenGate.stories.tsx
Outdated
Show resolved
Hide resolved
useEffect(() => { | ||
async function setBalance() { | ||
const balance = await getTokenBalance(); | ||
setTokenQuantity(parseInt(balance, 16)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useTokenBalance also provides a field formattedBalance to display a user-readable and correctly calculated balance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -6,7 +6,7 @@ import { Address } from './Address'; | |||
|
|||
/** | |||
* We need to mock the Clipboard API by creating a global navigator object. | |||
* | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert all the changes in this file? I think it's not related to your PR. Let's keep the Git history and blame clean!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad i totally did that on accident. Showing my noobness to open-source. Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hone1er no you're good haha
const [loadedStatus, setloadedStatus] = useState<boolean>(false); | ||
// connect to contract address to get balance | ||
async function getTokenBalance() { | ||
const signer = provider!.getSigner(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Do we need a signer to read data?
- If we do need a signer in all cases, what do you think of accepting a
signer
as a prop instead of aprovider
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would work. But should we take the signer at all? Or should we allow the dev to pass the quantity held by the wallet?
In the core package it would use the get balance hook to provide that for the dev.
Maybe the dev has the wallet balance in their app's state already so fetching the balance for them could be undesirable.
And if they want the balance fetched for them they can use the core package version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the core package it would use the get balance hook to provide that for the dev. Maybe the dev has the wallet balance in their app's state already so fetching the balance for them could be undesirable.
With you on this. Let's just take the balance as a prop :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hone1er do you also want to add Token Gate to core
in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dhaiwat10 Yeah i can add it to core as well. I do that in a new folder in core/src/components?
packages/components/src/components/TokenGate/TokenGate.stories.tsx
Outdated
Show resolved
Hide resolved
On these it is because the default returns null if access is denied. So, access denied default should always be empty, and with loader should show a spinner while loading then show reactNode if you get access or null(the default) if you don't. With loader requires you to hold at least 1 DevDao NFT in the wallet you connected. |
…updated component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed much of the logic. Now it just takes the walletBalance instead of taking a provider and fetching the balance. Still need to revert that change to address.test.tsx.
packages/components/src/components/TokenGate/TokenGate.stories.tsx
Outdated
Show resolved
Hide resolved
const [loadedStatus, setloadedStatus] = useState<boolean>(false); | ||
// connect to contract address to get balance | ||
async function getTokenBalance() { | ||
const signer = provider!.getSigner(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dhaiwat10 Yeah i can add it to core as well. I do that in a new folder in core/src/components?
@@ -6,7 +6,7 @@ import { Address } from './Address'; | |||
|
|||
/** | |||
* We need to mock the Clipboard API by creating a global navigator object. | |||
* | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad i totally did that on accident. Showing my noobness to open-source. Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Left some suggestions :)
/** | ||
* The provider or signer to fetch the address from the ens | ||
*/ | ||
walletBalance: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to update the docstring! 😄
children, | ||
deniedMessage, | ||
}) => { | ||
console.log(walletBalance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this console.log
}) => { | ||
console.log(walletBalance); | ||
|
||
// return children within simple container(className optional) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// return children within simple container(className optional) | |
// return children within simple container |
…ted docstring for TokenGate and removed console.log from file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented changes suggested by @Dhaiwat10
Fixed whitespace in Address.test.tsx to keep history clean. Removed console.log statement. Updated the docstring.
@allcontributors add @hone1er for code |
I've put up a pull request to add @hone1er! 🎉 |
Closes #98
Description
This component restricts access to all child components unless certain erc-20/erc-721 token requirements are met. It takes as parameters a provider and contract address, and required number of tokens(defaults to 1) as props to determine access.
📝 Additional Information
Definitely would like some feedback on what should be returned by default in a few different cases. For example with no wallet connected it currently will return null by default unless a "deniedMessage" is provided.