-
Notifications
You must be signed in to change notification settings - Fork 152
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
TokenBalance Component #97
Conversation
🦋 Changeset detectedLatest commit: 8ef2478 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 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 |
@AlexNi245 sorry for not getting back to this yet. Since this PR has quite a bit of code I just need a bit more to review everything. Thanks for your patience mate |
.changeset/config.json
Outdated
@@ -1,12 +1,9 @@ | |||
{ | |||
"$schema": "https://unpkg.com/@changesets/config@1.6.3/schema.json", | |||
"changelog": [ |
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 are you removing this, this is repo config
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.
Actually, this was not on purpose. Must have occurred during the upstream merge
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'll revert this
package.json
Outdated
"dependencies": { | ||
"@web3-ui/hooks": "0.4.0" | ||
}, | ||
"peerDependencies": { |
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.
It's already in the regular deps, we put it here only if we require the user to manually install the package in question
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 tried to solve the failing Ci step by adding this. Unfortunately, it doesn't solve that issue. Have you an idea what to 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.
Because you are importing from src
}; | ||
|
||
const Headline = (name: string) => ( | ||
<Heading as='h3' size='sm'> |
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.
Inline components can't maintain their referential identity and are subject to constant remounting. Hoisting outside of this closure will resolve that
No worries @Dhaiwat10 take your time! If there is anything I can help you with, just let me know. |
import React, { useContext, useEffect, useState } from 'react'; | ||
import { Box, Flex, Heading, Image } from '@chakra-ui/react'; | ||
import { TokenLogo } from './components/Logo'; | ||
import { useTokenBalance, Web3Context } from '@web3-ui/hooks/src'; |
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.
@AlexNi245 cross package imports like these are not allowed in libs, reduce it to @web3-ui/hooks
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.
Thank you for clearing this up. Wasn't aware of this.
Your linter seems a bit goofy 😅 you will have to add the package here https://github.com/Developer-DAO/web3-ui/blob/main/packages/components/package.json#L30 |
Just need to add a changeset "minor" and we're there, you can use the link here #97 (comment) or use |
packages/components/src/components/TokenBalance/TokenBalance.tsx
Outdated
Show resolved
Hide resolved
Yes, you're right I really like this pattern :) Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
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.
Left some comments!
import React from 'react'; | ||
import { Image } from '@chakra-ui/react'; | ||
|
||
export const TokenLogo = ({ tokenContractAddress }) => ( | ||
<Image | ||
src={`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/${tokenContractAddress}/logo.png`} | ||
/> | ||
); | ||
|
||
//i.E. Dai | ||
//https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6B175474E89094C44Da98b954EedeAC495271d0F/logo.png |
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 we move this component over to the TokenBalance.tsx
? We don't need a separate file 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.
You can also remove those comments
packages/hooks/src/Provider.tsx
Outdated
@@ -89,7 +89,7 @@ export const Provider: React.FC<ProviderProps> = ({ | |||
setConnection(connection); | |||
const provider = new ethers.providers.Web3Provider(connection); | |||
setProvider(provider); | |||
const chainId = await provider.getNetwork().then(network => network.chainId); | |||
const chainId = await provider.getNetwork().then((network) => network.chainId); |
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 should revert this since I don't think this is in the scope of this PR
packages/hooks/src/Provider.tsx
Outdated
@@ -126,7 +126,7 @@ export const Provider: React.FC<ProviderProps> = ({ | |||
const onAccountsChanged = async () => { | |||
const provider = new ethers.providers.Web3Provider(connection); | |||
setProvider(provider); | |||
const chainId = await provider.getNetwork().then(network => network.chainId); | |||
const chainId = await provider.getNetwork().then((network) => network.chainId); |
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!
import React from 'react'; | ||
import { Heading } from '@chakra-ui/react'; | ||
|
||
export const Headline = (name: string) => ( | ||
<Heading as='h3' size='sm'> | ||
{name} | ||
</Heading> | ||
); |
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 we also move this to TokenBalance.tsx
?
}; | ||
|
||
return ( | ||
<Flex borderRadius='lg' borderWidth='1px' overflow='hidden' px='4' py='2'> |
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.
Defining static styles and not letting the user set these styles if they want is not what we want. Can we accept all the props a Chakra Flex
component would expect and spread them here? Our <AddressInput />
does the same for the Chakra Input
component.
.changeset/config.json
Outdated
{ | ||
"repo": "Developer-DAO/web3-ui" | ||
} |
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 this, please?
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 make these small changes please and we're good to go
const Headline = (name: string) => ( | ||
<Heading as='h3' size='sm'> | ||
{name} | ||
</Heading> | ||
); |
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.
Like Jovi suggested:
const Headline = (name: string) => ( | |
<Heading as='h3' size='sm'> | |
{name} | |
</Heading> | |
); | |
const Headline = (name: string) => { | |
return ( | |
<Heading as='h3' size='sm'> | |
{name} | |
</Heading> | |
); | |
} |
.changeset/config.json
Outdated
"@changesets/changelog-github", | ||
{ "repo": "Developer-DAO/web3-ui" } | ||
], | ||
"changelog": ["@changesets/changelog-github", { "repo": "Developer-DAO/web3-ui" }], |
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 should not be changed. Can you make sure this change goes away please?
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.
sir, I almost lost my mind on this but I got the feeling this file was formatted by the commit hook. I have pushed it multiple times just to notice that this file still has unwanted changes.
[ | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "name", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" |
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 rename this file to ERC20.json
instead?
packages/hooks/src/index.ts
Outdated
export {useWallet, useContract} from './hooks'; | ||
export {useTokenBalance} from './hooks/useTokenBalance'; | ||
export {Provider, Web3Context} from './Provider'; | ||
export type {ProviderProps, Web3ContextType} from './Provider'; | ||
export {NETWORKS, CHAIN_ID_TO_NETWORK, ERC20ABI} from './constants'; |
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.
All of these lines should not be changed. Only the last line is actually being changed. Can you reset these?
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 must be also the result of the post commit hook. I reverted the first few lines just to notice that they have changed again after I committed my changes.
I can use -no--verify again to restore the first 5 lines. But maybe it's intended that the commit hook applies certain formatting rules to each file even the affected file has nothing to do with the 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.
I see. No worries then.
fixing index.js fix headline component
@AlexNi245 I think you commited some |
packages/components/package.json
Outdated
@@ -28,6 +28,7 @@ | |||
"module": "dist/web3-ui-components.esm.js", | |||
"types": "dist/web3-ui-components.cjs.d.ts", | |||
"dependencies": { | |||
"@web3-ui/hooks": "0.4.0", |
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.
One more thing that came to my mind recently is that the components
package should not rely on the hooks
package in any way. We want both of these packages to function well together but also independently.
This is why I feel like we shouldn't do any data fetching at all inside any of our components
. Here is what I propose:
- Move the current implementation to the
core
package. - Make the current implementation (inside
components
) so that it does not handle any data fetching but just accepts the data it needs to render.
Let me know if this is unclear. More than happy to discuss this in further detail since I think this is an important topic.
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 you mean this component shouldn't have any state at all and just renders given props ? Then we can remove the useTokenBalance hook from the Component.
Is that what you meant in the second point?
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.
@AlexNi245 yes! The current verison of this component which does have some state and fetches data should be in the core
package and not in the components
package. This is what we did recently for #121 too.
tldr:
<TokenBalance />
incomponents
shouldn't have any state, it should just render some data that you pass to it.<TokenBalance />
incore
should have state and should use theuseTokenBalance
hook
Sorry for that, they are deleted now |
@AlexNi245 just checking in. Do you need any help? |
Hi @Dhaiwat10 actually I was on vacation since Christmas.I will come back home on Thursday. My apologies for not responding but I will apply your suggestions till the end of the week:) |
No worries at all mate, enjoy! |
# Conflicts: # packages/components/package.json # packages/components/src/components/index.ts # packages/hooks/src/index.ts
@AlexNi245 since this PR's history was extremely messed up, I copied your changes from here and opened a new PR here: #237. Closing this one |
Closes #42
Description
This component shows the amount of a certain ERC20 token that the connected user owns. Besides displaying it has the following features:
📝 Additional Information
During the work i noticed a few things. I would love to hear your opinions on this @Dhaiwat10 @etr2460 @Ibby-devv
Screenshot