Skip to content

Commit

Permalink
fix(extension): handle select by checking checkbox from list view
Browse files Browse the repository at this point in the history
  • Loading branch information
vetalcore committed May 17, 2024
1 parent 74a6fc0 commit 4688efb
Showing 1 changed file with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { PostHogAction } from '@lace/common';
import { Table } from '@lace/ui';
import React from 'react';
import { MultidelegationDAppCompatibilityModal } from 'features/modals/MultidelegationDAppCompatibilityModal';
import React, { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useOutsideHandles } from '../../outside-handles-provider';
import { MAX_POOLS_COUNT, StakePoolDetails, isPoolSelectedSelector, useDelegationPortfolioStore } from '../../store';

import { config } from './config';

export const StakePoolsListRow = ({ stakePool, hexId, id, ...data }: StakePoolDetails): React.ReactElement => {
Expand All @@ -16,33 +18,57 @@ export const StakePoolsListRow = ({ stakePool, hexId, id, ...data }: StakePoolDe
selectionsFull: store.selectedPortfolio.length === MAX_POOLS_COUNT,
}));

const { multidelegationDAppCompatibility, triggerMultidelegationDAppCompatibility } = useOutsideHandles();
const [showDAppCompatibilityModal, setShowDAppCompatibilityModal] = useState(false);

const onClick = () => {
portfolioMutators.executeCommand({ data: stakePool, type: 'ShowPoolDetailsFromList' });
analytics.sendEventToPostHog(PostHogAction.StakingBrowsePoolsStakePoolDetailClick);
};

const onSelect = () => {
const onPoolSelect = useCallback(() => {
if (poolAlreadySelected) {
portfolioMutators.executeCommand({ data: hexId, type: 'UnselectPoolFromList' });
analytics.sendEventToPostHog(PostHogAction.StakingBrowsePoolsUnselectClick);
} else {
portfolioMutators.executeCommand({ data: [stakePool], type: 'SelectPoolFromList' });
analytics.sendEventToPostHog(PostHogAction.StakingBrowsePoolsStakeClick);
}
};
}, [analytics, hexId, poolAlreadySelected, portfolioMutators, stakePool]);

const onDAppCompatibilityConfirm = useCallback(() => {
triggerMultidelegationDAppCompatibility();
onPoolSelect();
}, [onPoolSelect, triggerMultidelegationDAppCompatibility]);

const onSelect = useCallback(() => {
if (multidelegationDAppCompatibility && !poolAlreadySelected) {
setShowDAppCompatibilityModal(true);
} else {
onPoolSelect();
}
}, [multidelegationDAppCompatibility, onPoolSelect, poolAlreadySelected]);

return (
<Table.Row<Omit<StakePoolDetails, 'stakePool' | 'hexId' | 'id'>>
columns={config.columns}
cellRenderers={config.renderer}
data={data}
selected={poolAlreadySelected}
onClick={onClick}
selectionDisabledMessage={t('browsePools.tooltips.maxNumberPoolsSelected')}
dataTestId="stake-pool"
withSelection
keyProp={id}
{...((!selectionsFull || poolAlreadySelected) && { onSelect })}
/>
<>
<Table.Row<Omit<StakePoolDetails, 'stakePool' | 'hexId' | 'id'>>
columns={config.columns}
cellRenderers={config.renderer}
data={data}
selected={poolAlreadySelected}
onClick={onClick}
selectionDisabledMessage={t('browsePools.tooltips.maxNumberPoolsSelected')}
dataTestId="stake-pool"
withSelection
keyProp={id}
{...((!selectionsFull || poolAlreadySelected) && { onSelect })}
/>
{showDAppCompatibilityModal && (
<MultidelegationDAppCompatibilityModal
visible={multidelegationDAppCompatibility}
onConfirm={onDAppCompatibilityConfirm}
/>
)}
</>
);
};

0 comments on commit 4688efb

Please sign in to comment.