-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
191 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import avatar from './assets/avatar.svg'; | ||
import PropTypes from 'prop-types'; | ||
import defaultAvatar from './assets/avatar.svg'; | ||
import { usePrimaryName } from './hooks/usePrimaryName'; | ||
|
||
export const CustomAvatar = () => { | ||
return <img src={avatar} className="w-full" />; | ||
export const CustomAvatar = ({ size }) => { | ||
const { avatar } = usePrimaryName(); | ||
|
||
return <img src={avatar || defaultAvatar} width={size} height={size} />; | ||
}; | ||
|
||
CustomAvatar.propTypes = { | ||
size: PropTypes.number, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import PropTypes from 'prop-types'; | ||
import { ConnectButton as RainbowBtn } from '@rainbow-me/rainbowkit'; | ||
import { Button } from './Button'; | ||
import defaultAvatar from '../../assets/avatar.svg'; | ||
import { usePrimaryName } from '../../hooks/usePrimaryName'; | ||
|
||
const Custom = ({ | ||
account, | ||
chain, | ||
openAccountModal, | ||
openChainModal, | ||
openConnectModal, | ||
}) => { | ||
const { name, avatar } = usePrimaryName(); | ||
const connected = account && chain; | ||
|
||
if (!connected) { | ||
return <Button onClick={openConnectModal}>Connect Wallet</Button>; | ||
} | ||
|
||
if (chain.unsupported) { | ||
return ( | ||
<Button | ||
onClick={openChainModal} | ||
type="button" | ||
className="bg-red-600 whitespace-nowrap" | ||
> | ||
Wrong network | ||
</Button> | ||
); | ||
} | ||
|
||
return ( | ||
<button | ||
className="p-1 bg-white rounded-lg shadow justify-start items-center inline-flex gap-1 cursor-pointer hover:scale-105 transition duration-200" | ||
onClick={openAccountModal} | ||
> | ||
<div className="text-sky-950 font-semibold hidden md:block pl-1"> | ||
{account.displayBalance} | ||
</div> | ||
<div className="px-1.5 py-1 bg-neutral-100 rounded-lg justify-end items-center gap-1.5 flex"> | ||
<img | ||
alt={name} | ||
src={avatar || account.ensAvatar || defaultAvatar} | ||
className="w-6 h-6 rounded-full overflow-hidden" | ||
/> | ||
|
||
<div className="text-neutral-900 font-semibold"> | ||
{name || account.ensName || account.displayName} | ||
</div> | ||
</div> | ||
</button> | ||
); | ||
}; | ||
|
||
Custom.propTypes = { | ||
account: PropTypes.object, | ||
chain: PropTypes.object, | ||
openAccountModal: PropTypes.func, | ||
openChainModal: PropTypes.func, | ||
openConnectModal: PropTypes.func, | ||
}; | ||
|
||
export const ConnectButton = () => { | ||
return <RainbowBtn.Custom>{Custom}</RainbowBtn.Custom>; | ||
}; |
4 changes: 2 additions & 2 deletions
4
src/components/RegisterButton.jsx → src/components/button/RegisterButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useAccount, useReadContracts } from 'wagmi'; | ||
import { abi } from '../abi'; | ||
import { PRIMARY_NAME_CONTRACT_ADDR } from '../constants'; | ||
|
||
export const usePrimaryName = () => { | ||
const { address } = useAccount(); | ||
|
||
const res = useReadContracts({ | ||
contracts: [ | ||
{ | ||
address: PRIMARY_NAME_CONTRACT_ADDR, | ||
abi: abi, | ||
functionName: 'getName', | ||
args: [address, 614n], | ||
}, | ||
{ | ||
address: PRIMARY_NAME_CONTRACT_ADDR, | ||
abi: abi, | ||
functionName: 'getText', | ||
args: [address, 'avatar', 614n], | ||
}, | ||
], | ||
}); | ||
|
||
const name = res.data?.[0]?.result; | ||
const avatar = res.data?.[1]?.result; | ||
|
||
return { name, avatar, ...res }; | ||
}; |