Skip to content

Commit

Permalink
fix(extension): fix delete wallet functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
vetalcore committed Jul 17, 2024
1 parent 3f7f319 commit fc61ec1
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { SettingsCard } from './';
import { useTranslation } from 'react-i18next';
import { Typography } from 'antd';
import { Button } from '@lace/common';
import { Button, useObservable } from '@lace/common';
import { WarningModal } from '@views/browser/components/WarningModal';
import styles from './SettingsLayout.module.scss';
import { useWalletManager } from '@hooks';
Expand All @@ -13,20 +13,36 @@ import { useAnalyticsContext } from '@providers';
import { PostHogAction } from '@providers/AnalyticsProvider/analyticsTracker';
import cn from 'classnames';
import { getWalletAccountsQtyString } from '@src/utils/get-wallet-count-string';
import { Wallet } from '@lace/cardano';
import { AnyWallet, WalletType } from '@cardano-sdk/web-extension';

const { Title, Text } = Typography;

export const SettingsRemoveWallet = ({ popupView }: { popupView?: boolean }): React.ReactElement => {
const { t } = useTranslation();

const [isRemoveWalletAlertVisible, setIsRemoveWalletAlertVisible] = useState(false);
const { deleteWallet, walletRepository } = useWalletManager();
const { deleteWallet, walletRepository, walletManager } = useWalletManager();
const { walletInfo, setDeletingWallet, isSharedWallet } = useWalletStore();
const backgroundServices = useBackgroundServiceAPIContext();
const analytics = useAnalyticsContext();

const activeWalletId = useObservable(walletManager.activeWalletId$);
const wallets = useObservable(walletRepository.wallets$);
const activeWallet = wallets?.find(
(w: AnyWallet<Wallet.WalletMetadata, Wallet.AccountMetadata>) => w.walletId === activeWalletId?.walletId
);

const hasAssociatedSharedWallet =
!isSharedWallet &&
wallets?.some(
({ type, metadata }) =>
type === WalletType.Script &&
metadata.extendedAccountPublicKey === activeWallet?.metadata.extendedAccountPublicKey
);

const toggleRemoveWalletAlert = () => {
if (isSharedWallet) return;
if (hasAssociatedSharedWallet) return;
setIsRemoveWalletAlertVisible(!isRemoveWalletAlertVisible);

analytics.sendEventToPostHog(
Expand Down Expand Up @@ -75,7 +91,7 @@ export const SettingsRemoveWallet = ({ popupView }: { popupView?: boolean }): Re
className={styles.modalDescription}
data-testid={'remove-wallet-description'}
>
{isSharedWallet
{hasAssociatedSharedWallet
? t('browserView.settings.wallet.general.removeSharedWalletDescription')
: t('browserView.settings.wallet.general.removeWalletDescription')}
</Text>
Expand All @@ -85,7 +101,7 @@ export const SettingsRemoveWallet = ({ popupView }: { popupView?: boolean }): Re
onClick={toggleRemoveWalletAlert}
block={popupView}
data-testid="remove-wallet-button"
disabled={isSharedWallet}
disabled={hasAssociatedSharedWallet}
>
{t('browserView.settings.wallet.general.removeAction', { walletName: walletInfo.name })}
</Button>
Expand Down

0 comments on commit fc61ec1

Please sign in to comment.