* feat: do not redirect to wallet on portfolio page * fix: use connected wallet for AccountMenu * fix: fixed ghost AccountDetails * feat: created ShareBar and share functionality * fix: don’t show shareBar if no address is present * fix: stupid 'next/navigation' * tidy: format * fix: fixed tests * ✨ routing and pages for HLS (#538) * 🐛 use useAccountIds * fix: fixed the tests * fix: accountIds is now a suspense --------- Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { useCallback } from 'react'
|
|
|
|
import AccountCreateFirst from 'components/Account/AccountCreateFirst'
|
|
import { ACCOUNT_MENU_BUTTON_ID } from 'components/Account/AccountMenuContent'
|
|
import Button from 'components/Button'
|
|
import { Account, PlusCircled } from 'components/Icons'
|
|
import WalletConnectButton from 'components/Wallet/WalletConnectButton'
|
|
import useAccountId from 'hooks/useAccountId'
|
|
import useAccountIds from 'hooks/useAccountIds'
|
|
import useStore from 'store'
|
|
|
|
export default function ActionButton(props: ButtonProps) {
|
|
const { className, color, variant, size } = props
|
|
const defaultProps = { className, color, variant, size }
|
|
const address = useStore((s) => s.address)
|
|
|
|
const { data: accountIds } = useAccountIds(address || '')
|
|
const selectedAccountId = useAccountId()
|
|
|
|
const handleCreateAccountClick = useCallback(() => {
|
|
useStore.setState({ focusComponent: { component: <AccountCreateFirst /> } })
|
|
}, [])
|
|
|
|
if (!address) return <WalletConnectButton {...defaultProps} />
|
|
|
|
if (accountIds && accountIds.length === 0) {
|
|
return (
|
|
<Button
|
|
onClick={handleCreateAccountClick}
|
|
leftIcon={<PlusCircled />}
|
|
text='Create Account'
|
|
{...defaultProps}
|
|
/>
|
|
)
|
|
}
|
|
|
|
if (!selectedAccountId) {
|
|
return (
|
|
<Button
|
|
text='Select Account'
|
|
onClick={() => document.getElementById(ACCOUNT_MENU_BUTTON_ID)?.click()}
|
|
leftIcon={<Account />}
|
|
rightIcon={undefined}
|
|
{...defaultProps}
|
|
/>
|
|
)
|
|
}
|
|
|
|
return <Button {...props} />
|
|
}
|