Skip to content
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

fix: Enable Add proposer button for owners only #4744

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions apps/web/src/components/common/OnlyOwner/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useMemo, type ReactElement } from 'react'
import useIsSafeOwner from '@/hooks/useIsSafeOwner'
import useWallet from '@/hooks/wallets/useWallet'
import useConnectWallet from '../ConnectWallet/useConnectWallet'
import { Tooltip } from '@mui/material'

type CheckWalletProps = {
children: (ok: boolean) => ReactElement
}

enum Message {
NotSafeOwner = 'Your connected wallet is not a signer of this Safe Account',
}

const OnlyOwner = ({ children }: CheckWalletProps): ReactElement => {
const wallet = useWallet()
const isSafeOwner = useIsSafeOwner()
const connectWallet = useConnectWallet()

const message = useMemo(() => (!isSafeOwner ? Message.NotSafeOwner : undefined), [isSafeOwner])

if (!message) return children(true)

return (
<Tooltip title={message}>
<span onClick={wallet ? undefined : connectWallet}>{children(false)}</span>
</Tooltip>
)
}

export default OnlyOwner
6 changes: 3 additions & 3 deletions apps/web/src/components/settings/ProposersList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CheckWallet from '@/components/common/CheckWallet'
import { Chip } from '@/components/common/Chip'
import EnhancedTable from '@/components/common/EnhancedTable'
import tableCss from '@/components/common/EnhancedTable/styles.module.css'
import OnlyOwner from '@/components/common/OnlyOwner'
import Track from '@/components/common/Track'
import UpsertProposer from '@/features/proposers/components/UpsertProposer'
import DeleteProposerDialog from '@/features/proposers/components/DeleteProposerDialog'
Expand Down Expand Up @@ -100,7 +100,7 @@ const ProposersList = () => {

{isEnabled && (
<Box mb={2}>
<CheckWallet allowProposer={false}>
<OnlyOwner>
{(isOk) => (
<Track {...SETTINGS_EVENTS.PROPOSERS.ADD_PROPOSER}>
<Button
Expand All @@ -115,7 +115,7 @@ const ProposersList = () => {
</Button>
</Track>
)}
</CheckWallet>
</OnlyOwner>
</Box>
)}

Expand Down
Loading