Skip to content

Commit

Permalink
Disable account remove action
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Nov 8, 2023
1 parent aee7c15 commit bd24524
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ export const ManageableAccount = ({
}: {
wallet: Wallet
isActive: boolean
deleteWallet: (address: string) => void
deleteWallet?: (address: string) => void
selectWallet: (address: string) => void
}) => {
const { t } = useTranslation()
const [layerVisibility, setLayerVisibility] = useState(false)
const isMobile = useContext(ResponsiveContext) === 'small'
const handleDelete = (address: string) => {
deleteWallet(address)
setLayerVisibility(false)
}
const handleDelete = deleteWallet
? (address: string) => {
deleteWallet(address)
setLayerVisibility(false)
}
: undefined

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { ResponsiveContext } from 'grommet/es6/contexts/ResponsiveContext'
import { Tab } from 'grommet/es6/components/Tab'
import { Tabs } from 'grommet/es6/components/Tabs'
import { Text } from 'grommet/es6/components/Text'
import { Tip } from 'grommet/es6/components/Tip'
import { Copy } from 'grommet-icons/es6/icons/Copy'
import { CircleInformation } from 'grommet-icons/es6/icons/CircleInformation'
import { useTranslation } from 'react-i18next'
import { NoTranslate } from 'app/components/NoTranslate'
import { Wallet } from '../../../../state/wallet/types'
Expand All @@ -19,7 +21,7 @@ import { uintToBase64, hex2uint } from '../../../../lib/helpers'
import { DeleteAccount } from './DeleteAccount'

interface ManageableAccountDetailsProps {
deleteWallet: (address: string) => void
deleteWallet?: (address: string) => void
wallet: Wallet
}

Expand Down Expand Up @@ -55,12 +57,34 @@ export const ManageableAccountDetails = ({ deleteWallet, wallet }: ManageableAcc
disabled={!wallet.privateKey}
onClick={() => setLayerVisibility(true)}

Check warning on line 58 in src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx#L58

Added line #L58 was not covered by tests
/>
<Button
plain
color="status-error"
label={t('toolbar.settings.delete.title', 'Delete Account')}
onClick={() => setDeleteLayerVisibility(true)}
/>

{deleteWallet ? (
<Button

Check warning on line 62 in src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx#L62

Added line #L62 was not covered by tests
plain
color="status-error"
label={t('toolbar.settings.delete.title', 'Delete Account')}
onClick={() => setDeleteLayerVisibility(true)}

Check warning on line 66 in src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx#L66

Added line #L66 was not covered by tests
/>
) : (
<Tip

Check warning on line 69 in src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx#L69

Added line #L69 was not covered by tests
content={t(
'toolbar.settings.delete.tooltip',
'You must have at least one account at all times.',
)}
dropProps={{ align: { bottom: 'top' } }}
>
<Box>
<Button
icon={<CircleInformation size="18px" color="status-error" />}
disabled={true}
plain
color="status-error"
label={t('toolbar.settings.delete.title', 'Delete Account')}
onClick={() => setDeleteLayerVisibility(true)}

Check warning on line 83 in src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx#L83

Added line #L83 was not covered by tests
/>
</Box>
</Tip>
)}
</Box>
</Box>
{layerVisibility && (
Expand Down Expand Up @@ -118,7 +142,7 @@ export const ManageableAccountDetails = ({ deleteWallet, wallet }: ManageableAcc
</Tabs>
</LayerContainer>
)}
{deleteLayerVisibility && (
{deleteLayerVisibility && deleteWallet && (
<DeleteAccount
onDelete={() => deleteWallet(wallet.address)}
onCancel={() => setDeleteLayerVisibility(false)}

Check warning on line 148 in src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/Account/ManageableAccountDetails.tsx#L145-L148

Added lines #L145 - L148 were not covered by tests
Expand Down
15 changes: 10 additions & 5 deletions src/app/components/Toolbar/Features/AccountSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
*/
import { walletActions } from 'app/state/wallet'
import { selectAddress, selectWallets } from 'app/state/wallet/selectors'
import { selectAddress, selectWallets, selectHasOneAccount } from 'app/state/wallet/selectors'
import { Box } from 'grommet/es6/components/Box'
import { Button } from 'grommet/es6/components/Button'
import { memo } from 'react'
Expand All @@ -22,6 +22,7 @@ export const AccountSelector = memo((props: Props) => {
const dispatch = useDispatch()
const wallets = useSelector(selectWallets)
const activeAddress = useSelector(selectAddress)
const hasOneAccount = useSelector(selectHasOneAccount)

const selectWallet = (address: string) => {
dispatch(walletActions.selectWallet(address))
Expand All @@ -32,10 +33,14 @@ export const AccountSelector = memo((props: Props) => {
<ManageableAccount
key={wallet.address}
wallet={wallet}
deleteWallet={(address: string) => {
dispatch(walletActions.deleteWallet(address))
wallet.address === activeAddress && dispatch(walletActions.selectFirstWallet())
}}
deleteWallet={
hasOneAccount
? undefined
: (address: string) => {
dispatch(walletActions.deleteWallet(address))
wallet.address === activeAddress && dispatch(walletActions.selectFirstWallet())

Check warning on line 41 in src/app/components/Toolbar/Features/AccountSelector/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/components/Toolbar/Features/AccountSelector/index.tsx#L40-L41

Added lines #L40 - L41 were not covered by tests
}
}
selectWallet={selectWallet}
isActive={wallet.address === activeAddress}
/>
Expand Down
4 changes: 4 additions & 0 deletions src/app/state/wallet/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ export const selectPublicKey = createSelector([selectActiveWallet], wallet => wa
export const selectBalance = createSelector([selectActiveWallet], wallet => wallet?.balance)
export const selectType = createSelector([selectActiveWallet], wallet => wallet?.type)
export const selectHasAccounts = createSelector([selectWallets], wallets => Object.keys(wallets).length > 0)
export const selectHasOneAccount = createSelector(
[selectWallets],
wallets => Object.keys(wallets).length === 1,
)
3 changes: 2 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@
"delete": {
"description": "Are you sure you want to delete the following account?",
"inputHelp": "This action cannot be undone. To continue please enter ‘delete’ below.",
"title": "Delete Account"
"title": "Delete Account",
"tooltip": "You must have at least one account at all times."
},
"exportPrivateKey": {
"confirm": "I understand, reveal my private key",
Expand Down

0 comments on commit bd24524

Please sign in to comment.