Skip to content

Commit

Permalink
fix: Enable Add proposer button for owners only (#4744)
Browse files Browse the repository at this point in the history
* fix: Enable Add proposer button for owners only

* fix: Add wallet connected status check to OnlyOwner
  • Loading branch information
usame-algan authored Jan 17, 2025
1 parent ea7dc6d commit 236e002
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
40 changes: 40 additions & 0 deletions apps/web/src/components/common/OnlyOwner/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 {
WalletNotConnected = 'Please connect your wallet',
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(() => {
if (!wallet) {
return Message.WalletNotConnected
}

if (!isSafeOwner) {
return Message.NotSafeOwner
}
}, [isSafeOwner, wallet])

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

0 comments on commit 236e002

Please sign in to comment.