From fc61ec19c222bfc341898a2e087cff52c4287001 Mon Sep 17 00:00:00 2001 From: vetalcore Date: Wed, 17 Jul 2024 22:28:50 +0300 Subject: [PATCH] fix(extension): fix delete wallet functionality --- .../components/SettingsRemoveWallet.tsx | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/settings/components/SettingsRemoveWallet.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/settings/components/SettingsRemoveWallet.tsx index e4859f3a0..d97d85385 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/settings/components/SettingsRemoveWallet.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/settings/components/SettingsRemoveWallet.tsx @@ -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'; @@ -13,6 +13,8 @@ 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; @@ -20,13 +22,27 @@ export const SettingsRemoveWallet = ({ popupView }: { popupView?: boolean }): Re 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) => 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( @@ -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')} @@ -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 })}