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

Add AddressInput component #41

Merged
merged 11 commits into from
Dec 6, 2021
Merged

Add AddressInput component #41

merged 11 commits into from
Dec 6, 2021

Conversation

naz3eh
Copy link
Member

@naz3eh naz3eh commented Nov 30, 2021

This PR fixes #9
I've added the AddressInput component that returns the address for the entered ENS. This PR is still in development.
Everyone's thoughts are welcome.

@naz3eh naz3eh marked this pull request as draft November 30, 2021 20:26
@Dhaiwat10 Dhaiwat10 self-requested a review December 2, 2021 00:48
@Dhaiwat10
Copy link
Member

@allcontributors add @Nazeeh21 for code

@allcontributors
Copy link
Contributor

@Dhaiwat10

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

@Dhaiwat10
Copy link
Member

@allcontributors add @Dhaiwat10 for code, review

@allcontributors
Copy link
Contributor

@Dhaiwat10

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

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.

Great work overall! Left some comments and questions. Also, please add docstrings etc. We want to document our code well.

"@babel/preset-react"
]
"presets": ["@babel/preset-env", "@babel/preset-typescript", "@babel/preset-react"],
"plugins": ["@babel/plugin-proposal-class-properties"]
Copy link
Member

Choose a reason for hiding this comment

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

What was this added for?

Copy link
Member Author

@naz3eh naz3eh Dec 3, 2021

Choose a reason for hiding this comment

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

While running the test, I was getting this error Support for the experimental syntax 'jsx' isn't currently enabled.

So I had a look at different issues and found that this was due to the babel_configurations. So I added this.

Comment on lines 1 to 15
module.exports = function (api) {
const presets = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-flow'];
const plugins = ['@babel/plugin-transform-runtime'];

/** this is just for minimal working purposes,
* for testing larger applications it is
* advisable to cache the transpiled modules in
* node_modules/.bin/.cache/@babel/register* */
api.cache(false);

return {
presets,
plugins,
};
};
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. Why was this added?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was also added to fix the above-mentioned error.

import { ethers } from 'ethers';

storiesOf('AddressInput', module).add('default', () => {
const provider = new ethers.providers.Web3Provider(window.ethereum);
Copy link
Member

Choose a reason for hiding this comment

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

Use useWallet in stories instead

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I'll update that

export interface AddressInputProps {
provider: ethers.providers.Web3Provider;
value: string;
setValue: (value: string) => void;
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 change this prop's name to onChange.

Comment on lines 34 to 70
} catch (error) {
console.log('error in fetching balance', error);
}
Copy link
Member

Choose a reason for hiding this comment

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

We need some error handling in the UI, too. At the moment, the user will not know if an error has occurred.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it. I'll add the alert, display it in the UI and also return an error message to the user.

How does this sound?

};

useEffect(() => {
if (typeof window.ethereum !== 'undefined') {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to check for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, I forgot to remove it 😅 . While developing, I was using it but I am no longer using it in any of the places. I'll remove it.

}, [inputValue]);
return (
<div>
<Text>Input address</Text>
Copy link
Member

Choose a reason for hiding this comment

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

This is a label so use <FormLabel /> from Chakra instead

}
}, [inputValue]);
return (
<div>
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this div

Comment on lines 56 to 91
<Input
mt={2}
mb={2}
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
placeholder='Input address'
/>
Copy link
Member

Choose a reason for hiding this comment

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

We want to support all props that a Chakra <Input /> supports and spread them here onto this <Input />. Let me know if you need help with this 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! I'll try implementing it and will surely ask you for help if I'll get stuck somewhere.

@naz3eh
Copy link
Member Author

naz3eh commented Dec 4, 2021

I've updated the PR implementing the requested changes.
Now, I'm looking at the test to get it passed.

@Dhaiwat10
Copy link
Member

@Nazeeh21 can you please post more information about what problems you are facing with the tests? I am asking around for help and having some tldr info on the problem would be great.

I ran the test locally and it seems like it keeps on running forever. For anyone who's reviewing, please run yarn in the root and then yarn test -t="AddressInput"

const getAddressFromEns = async () => {
try {
let address = await provider.resolveName(deboucedValued);
console.log({ address });
Copy link

Choose a reason for hiding this comment

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

[nit pick] did you want to leave the console log statement here?

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, it's solely for dev purposes. I'll remove it.

}) => {
const [inputValue, setInputValue] = useState('');
const deboucedValued = useDebounce(inputValue, 700);
const [, setEnsValue] = useState('');
Copy link

Choose a reason for hiding this comment

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

Do we need this state setter here? Since we're not reading the value, do we really need to set 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.

Yeah, the use of this variable can be avoided, and probably it won't be needed.


describe('AddressInput', () => {
it('renders', () => {
const provider = new MockProvider();
Copy link

Choose a reason for hiding this comment

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

This is the repo that @codingwithmanny came up with when we were exploring mocking providers. In the link you'll find how the metamask provider was mocked and you can use that as a guide; however, there doesn't seem to be a universal mock wallet provider as I think everyone kinda has there own implemented standards

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for this reference. I'll take a look.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the review @narbs91!

Copy link

Choose a reason for hiding this comment

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

No prob at all, this things looking pretty dope you've all done an awesome job! Keep it up 🚀

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the repo that @codingwithmanny came up with when we were exploring mocking providers.

@narbs91 This worked for me and tests are now passing. Thanks for helping me out. 😃

@naz3eh
Copy link
Member Author

naz3eh commented Dec 6, 2021

can you please post more information about what problems you are facing with the tests? I am asking around for help and having some tldr info on the problem would be great.

I ran the test locally and it seems like it keeps on running forever. For anyone who's reviewing, please run yarn in the root and then yarn test -t="AddressInput"


Yeah sure. For me also the tests were not giving any output while running yarn test -t="AddressInput" in the root directory. However, when I run npx jest ./src/components/AddressInput in /packages/components/ folder, I came across this error.

image

I am trying the solution provided by @narbs91, hopefully, that would fix the error.

@Dhaiwat10
Copy link
Member

Awesome @Nazeeh21, let us know if you find a fix

@naz3eh naz3eh marked this pull request as ready for review December 6, 2021 06:14
@Dhaiwat10 Dhaiwat10 merged commit ed78267 into master Dec 6, 2021
@Dhaiwat10 Dhaiwat10 deleted the fix/issue-9 branch December 6, 2021 07:13
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.

ETH wallet address input with support for ENS domains
3 participants