Skip to content

Commit

Permalink
prevent readonly wallets from voting
Browse files Browse the repository at this point in the history
  • Loading branch information
wolverineks committed Nov 29, 2022
1 parent e1a1d62 commit 20d46e5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/Catalyst/VotingBanner.tsx
Expand Up @@ -46,8 +46,7 @@ export const VotingBanner = ({onPress, disabled}: Props) => {
}

checkCatalystFundInfo()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
}, [canVote, wallet])

if (!showCatalystBanner) return null

Expand Down
2 changes: 1 addition & 1 deletion src/Catalyst/hooks.ts
Expand Up @@ -15,7 +15,7 @@ export const useCanVote = (wallet: YoroiWallet) => {
)

return {
canVote: isHaskellShelley(wallet.walletImplementationId),
canVote: !wallet.isReadOnly && isHaskellShelley(wallet.walletImplementationId),
sufficientFunds,
}
}
Expand Down
22 changes: 15 additions & 7 deletions src/Menu/Menu.stories.tsx
Expand Up @@ -6,10 +6,18 @@ import {mocks} from '../../storybook'
import {SelectedWalletProvider} from '../SelectedWallet'
import {Menu} from './Menu'

storiesOf('Menu', module).add('Menu, insufficient funds', () => (
<QueryClientProvider client={new QueryClient()}>
<SelectedWalletProvider wallet={mocks.wallet}>
<Menu />
</SelectedWalletProvider>
</QueryClientProvider>
))
storiesOf('Menu', module)
.add('voting, insufficient funds', () => (
<QueryClientProvider client={new QueryClient()}>
<SelectedWalletProvider wallet={mocks.wallet}>
<Menu />
</SelectedWalletProvider>
</QueryClientProvider>
))
.add('voting, isHW', () => (
<QueryClientProvider client={new QueryClient()}>
<SelectedWalletProvider wallet={mocks.readonlyWallet}>
<Menu />
</SelectedWalletProvider>
</QueryClientProvider>
))
17 changes: 14 additions & 3 deletions src/Menu/Menu.tsx
Expand Up @@ -103,9 +103,19 @@ const SupportLink = () => {
)
}

const Item = ({label, left, onPress}: {label: string; left: React.ReactElement; onPress: () => void}) => {
const Item = ({
label,
left,
disabled = false,
onPress,
}: {
label: string
left: React.ReactElement
disabled?: boolean
onPress: () => void
}) => {
return (
<TouchableOpacity onPress={onPress} style={styles.item}>
<TouchableOpacity onPress={onPress} style={styles.item} disabled={disabled}>
{left}
<Spacer width={12} />
<Text style={styles.itemText}>{label}</Text>
Expand All @@ -124,7 +134,7 @@ const Settings = Item
const KnowledgeBase = Item
const Catalyst = ({label, left, onPress}: {label: string; left: React.ReactElement; onPress: () => void}) => {
const wallet = useSelectedWallet()
const {sufficientFunds} = useCanVote(wallet)
const {canVote, sufficientFunds} = useCanVote(wallet)

const [showInsufficientFundsModal, setShowInsufficientFundsModal] = React.useState(false)

Expand All @@ -134,6 +144,7 @@ const Catalyst = ({label, left, onPress}: {label: string; left: React.ReactEleme
label={label}
onPress={() => (sufficientFunds ? onPress() : setShowInsufficientFundsModal(true))}
left={left}
disabled={!canVote}
/>

<InsufficientFundsModal
Expand Down
10 changes: 8 additions & 2 deletions storybook/mocks/wallet.ts
Expand Up @@ -211,7 +211,7 @@ const wallet: YoroiWallet = {
},
}

const hwWallet = {
const hwWallet: YoroiWallet = {
...wallet,
isHW: true,
hwDeviceInfo: {
Expand All @@ -225,11 +225,16 @@ const hwWallet = {
},
}

const osWallet = {
const osWallet: YoroiWallet = {
...wallet,
isEasyConfirmationEnabled: true,
}

const readonlyWallet: YoroiWallet = {
...wallet,
isReadOnly: true,
}

const txid = '31b1abca49857fd50c7959cc019d14c7dc5deaa754ba45372fb21748c411f210'

const getTransactions = {
Expand Down Expand Up @@ -568,6 +573,7 @@ export const mocks = {
wallet,
osWallet,
hwWallet,
readonlyWallet,

stakePoolId,

Expand Down

0 comments on commit 20d46e5

Please sign in to comment.