-
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
Add AddressInput component #41
Conversation
@allcontributors add @Nazeeh21 for code |
I've put up a pull request to add @Nazeeh21! 🎉 |
@allcontributors add @Dhaiwat10 for code, review |
I've put up a pull request to add @Dhaiwat10! 🎉 |
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.
Great work overall! Left some comments and questions. Also, please add docstrings etc. We want to document our code well.
packages/components/.babelrc
Outdated
"@babel/preset-react" | ||
] | ||
"presets": ["@babel/preset-env", "@babel/preset-typescript", "@babel/preset-react"], | ||
"plugins": ["@babel/plugin-proposal-class-properties"] |
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.
What was this added for?
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.
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.
packages/components/babel.config.js
Outdated
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, | ||
}; | ||
}; |
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.
Same as above. Why was this added?
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.
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); |
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.
Use useWallet
in stories instead
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.
Sure, I'll update that
export interface AddressInputProps { | ||
provider: ethers.providers.Web3Provider; | ||
value: string; | ||
setValue: (value: string) => void; |
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 change this prop's name to onChange
.
} catch (error) { | ||
console.log('error in fetching balance', error); | ||
} |
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.
We need some error handling in the UI, too. At the moment, the user will not know if an error has occurred.
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.
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') { |
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.
Why do we need to check for this?
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.
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> |
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.
This is a label so use <FormLabel />
from Chakra instead
} | ||
}, [inputValue]); | ||
return ( | ||
<div> |
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.
We don't need this div
<Input | ||
mt={2} | ||
mb={2} | ||
value={inputValue} | ||
onChange={(e) => setInputValue(e.target.value)} | ||
placeholder='Input address' | ||
/> |
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.
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 😄
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.
Sure! I'll try implementing it and will surely ask you for help if I'll get stuck somewhere.
I've updated the PR implementing the requested changes. |
@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 |
const getAddressFromEns = async () => { | ||
try { | ||
let address = await provider.resolveName(deboucedValued); | ||
console.log({ address }); |
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.
[nit pick] did you want to leave the console log statement here?
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.
No, it's solely for dev purposes. I'll remove it.
}) => { | ||
const [inputValue, setInputValue] = useState(''); | ||
const deboucedValued = useDebounce(inputValue, 700); | ||
const [, setEnsValue] = useState(''); |
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 this state setter here? Since we're not reading the value, do we really need to set it?
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.
Yeah, the use of this variable can be avoided, and probably it won't be needed.
|
||
describe('AddressInput', () => { | ||
it('renders', () => { | ||
const provider = new MockProvider(); |
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.
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
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.
Thanks for this reference. I'll take a look.
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.
Thanks for the review @narbs91!
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.
No prob at all, this things looking pretty dope you've all done an awesome job! Keep it up 🚀
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.
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. 😃
Yeah sure. For me also the tests were not giving any output while running I am trying the solution provided by @narbs91, hopefully, that would fix the error. |
Awesome @Nazeeh21, let us know if you find a fix |
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.