-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useResolveEnsName } from 'eth-hooks/dapps'; | ||
import { TEthersProvider } from 'eth-hooks/models'; | ||
|
||
export interface AddressProps { | ||
address: string; | ||
ensProvider?: TEthersProvider; | ||
blockExplorer?: string; | ||
} | ||
|
||
export interface AddressResult { | ||
shortAddress: string; | ||
ensName?: string; | ||
explorerLink: string; | ||
} | ||
|
||
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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe the hook should be called |
||
const address = props.address; | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. if invalid, return that in shortAddress |
||
|
||
return { | ||
shortAddress, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shortAddress can be called addressForDisplay |
||
ensName, | ||
explorerLink, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './address'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './components/eth-balance'; | ||
export * from './components/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.
Can we prefix interfaces with
I
and types withT
. it was the standard in eth hooks