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

Token gate #121

Merged
merged 14 commits into from
Dec 22, 2021
Merged

Token gate #121

merged 14 commits into from
Dec 22, 2021

Conversation

hone1er
Copy link
Contributor

@hone1er hone1er commented Dec 14, 2021

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.

Screen Shot 2021-12-14 at 8 18 03 AM

@changeset-bot
Copy link

changeset-bot bot commented Dec 14, 2021

🦋 Changeset detected

Latest commit: 9da1577

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

This PR includes changesets to release 2 packages
Name Type
@web3-ui/components Minor
@web3-ui/core Patch

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

@AlexNi245
Copy link
Contributor

You should merge the current main branch into this one to resolve the merge conflicts

useEffect(() => {
async function setBalance() {
const balance = await getTokenBalance();
setTokenQuantity(parseInt(balance, 16));
Copy link
Contributor

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

Copy link
Member

@Dhaiwat10 Dhaiwat10 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Left a few questions.

image

Also, for some reason I cannot see these two stories

@@ -6,7 +6,7 @@ import { Address } from './Address';

/**
* We need to mock the Clipboard API by creating a global navigator object.
*
*
Copy link
Member

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!

Copy link
Contributor Author

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.

Copy link
Member

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

packages/components/src/components/TokenGate/TokenGate.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();
Copy link
Member

Choose a reason for hiding this comment

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

  1. Do we need a signer to read data?
  2. If we do need a signer in all cases, what do you think of accepting a signer as a prop instead of a provider?

Copy link
Contributor Author

@hone1er hone1er Dec 18, 2021

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.

Copy link
Member

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 :)

Copy link
Member

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?

Copy link
Contributor Author

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?

@hone1er
Copy link
Contributor Author

hone1er commented Dec 18, 2021

Thanks for the PR! Left a few questions.

image

Also, for some reason I cannot see these two stories

Thanks for the PR! Left a few questions.

image

Also, for some reason I cannot see these two stories

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.

Copy link
Contributor Author

@hone1er hone1er left a 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.

const [loadedStatus, setloadedStatus] = useState<boolean>(false);
// connect to contract address to get balance
async function getTokenBalance() {
const signer = provider!.getSigner();
Copy link
Contributor Author

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.
*
*
Copy link
Contributor Author

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.

Copy link
Member

@Dhaiwat10 Dhaiwat10 left a 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 :)

Comment on lines 3 to 6
/**
* The provider or signer to fetch the address from the ens
*/
walletBalance: number;
Copy link
Member

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);
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// return children within simple container(className optional)
// return children within simple container

@Dhaiwat10 Dhaiwat10 mentioned this pull request Dec 20, 2021
…ted docstring for TokenGate and removed console.log from file.
Copy link
Contributor Author

@hone1er hone1er left a 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.

@Dhaiwat10 Dhaiwat10 merged commit aa9b2f6 into main Dec 22, 2021
@Dhaiwat10 Dhaiwat10 deleted the tokenGate branch December 22, 2021 11:23
@github-actions github-actions bot mentioned this pull request Dec 22, 2021
@Dhaiwat10
Copy link
Member

@allcontributors add @hone1er for code

@allcontributors
Copy link
Contributor

@Dhaiwat10

I've put up a pull request to add @hone1er! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TokenGate component
3 participants