-
Notifications
You must be signed in to change notification settings - Fork 2
Migrating address component #6
base: main
Are you sure you want to change the base?
Conversation
const blockExplorerLink = (address: string, blockExplorer?: string): string => | ||
`${blockExplorer || 'https://etherscan.io/'}address/${address}`; | ||
|
||
export const useAddress = (props: AddressProps): AddressResult => { |
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 would add tsdocs comments similar to eth-hooks. It helps create automated documentation later. https://scaffold-eth.github.io/eth-hooks/docs/api/modules/Hooks. @stevenpslade
import { useResolveEnsName } from 'eth-hooks/dapps'; | ||
import { TEthersProvider } from 'eth-hooks/models'; | ||
|
||
export interface AddressProps { |
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 prefix interfaces with I
and types with T
. it was the standard in eth hooks
const [ensName] = useResolveEnsName(props.ensProvider, address); | ||
const explorerLink = blockExplorerLink(address, props.blockExplorer); | ||
|
||
const shortAddress = address ? `${address.substring(0, 5)}...${address.substring(address.length - 4)}` : ''; |
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 think we should check validity of address using ethers.utils
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.
if invalid, return that in shortAddress
const shortAddress = address ? `${address.substring(0, 5)}...${address.substring(address.length - 4)}` : ''; | ||
|
||
return { | ||
shortAddress, |
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.
shortAddress can be called addressForDisplay
const blockExplorerLink = (address: string, blockExplorer?: string): string => | ||
`${blockExplorer || 'https://etherscan.io/'}address/${address}`; | ||
|
||
export const useAddress = (props: AddressProps): AddressResult => { |
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.
maybe the hook should be called useAddressForDisplay
?
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.
The test should mock all the eth-hooks hooks and check if it works. maybe one case for invalid address, undefined address and valid address.
Part of Migrate Components and TS-ify
This PR is migrating the Address component from eth-components and Typescript-ifying it.