Skip to content

Commit

Permalink
chore: actioned apojuice code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
woodenfurniture committed May 7, 2024
1 parent b283270 commit 941d562
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
34 changes: 16 additions & 18 deletions src/components/ManageAccountsDrawer/components/ImportAccounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type TableRowProps = {
accountIds: AccountId[]
accountNumber: number
asset: Asset
onAccountIdsActiveChange: (accountIds: AccountId[], isActive: boolean) => void
onActiveAccountIdsChange: (accountIds: AccountId[], isActive: boolean) => void
}

type TableRowAccountProps = {
Expand All @@ -60,7 +60,6 @@ type TableRowAccountProps = {
const disabledProps = { opacity: 0.5, cursor: 'not-allowed', userSelect: 'none' }

const TableRowAccount = forwardRef<TableRowAccountProps, 'div'>(({ asset, accountId }, ref) => {
const translate = useTranslate()
const accountLabel = useMemo(() => accountIdToLabel(accountId), [accountId])
const pubkey = useMemo(() => fromAccountId(accountId).account, [accountId])
const isUtxoAccount = useMemo(() => isUtxoAccountId(accountId), [accountId])
Expand All @@ -77,11 +76,7 @@ const TableRowAccount = forwardRef<TableRowAccountProps, 'div'>(({ asset, accoun
<Td fontWeight='bold'>
<Tooltip label={pubkey} isDisabled={isUtxoAccount}>
<div ref={ref}>
{isUtxoAccount ? (
<RawText>{`${accountLabel} ${translate('common.account')}`}</RawText>
) : (
<MiddleEllipsis value={accountLabel} />
)}
<MiddleEllipsis value={accountLabel} />
</div>
</Tooltip>
</Td>
Expand All @@ -97,19 +92,27 @@ const TableRowAccount = forwardRef<TableRowAccountProps, 'div'>(({ asset, accoun
})

const TableRow = forwardRef<TableRowProps, 'div'>(
({ asset, accountNumber, accountIds, onAccountIdsActiveChange }, ref) => {
({ asset, accountNumber, accountIds, onActiveAccountIdsChange }, ref) => {
const isAccountEnabledInRedux = useAppSelector(state =>
selectIsAnyAccountIdEnabled(state, accountIds),
)

const [isAccountActive, toggleIsAccountActive] = useToggle(isAccountEnabledInRedux)

useEffect(() => {
onAccountIdsActiveChange(accountIds, isAccountActive)
}, [accountIds, isAccountActive, isAccountEnabledInRedux, onAccountIdsActiveChange])
onActiveAccountIdsChange(accountIds, isAccountActive)
}, [accountIds, isAccountActive, isAccountEnabledInRedux, onActiveAccountIdsChange])

const firstAccount = useMemo(() => accountIds[0], [accountIds])
const otherAccounts = useMemo(() => accountIds.slice(1), [accountIds])
const otherAccountIds = useMemo(() => accountIds.slice(1), [accountIds])
const otherAccounts = useMemo(() => {
return otherAccountIds.map(accountId => (
<Tr opacity={isAccountActive ? '1' : '0.5'}>
<Td colSpan={2} bg='background.surface.raised.base' />
<TableRowAccount key={accountId} ref={ref} asset={asset} accountId={accountId} />
</Tr>
))
}, [asset, isAccountActive, otherAccountIds, ref])

return (
<>
Expand All @@ -123,12 +126,7 @@ const TableRow = forwardRef<TableRowProps, 'div'>(

<TableRowAccount ref={ref} asset={asset} accountId={firstAccount} />
</Tr>
{otherAccounts.map(accountId => (
<Tr opacity={isAccountActive ? '1' : '0.5'}>
<Td colSpan={2} bg='background.surface.raised.base'></Td>
<TableRowAccount key={accountId} ref={ref} asset={asset} accountId={accountId} />
</Tr>
))}
{otherAccounts}
</>
)
},
Expand Down Expand Up @@ -265,7 +263,7 @@ export const ImportAccounts = ({ chainId, onClose }: ImportAccountsProps) => {
accountNumber={accountNumber}
accountIds={accountIds}
asset={asset}
onAccountIdsActiveChange={handleAccountIdsActiveChange}
onActiveAccountIdsChange={handleAccountIdsActiveChange}
/>
)
})
Expand Down
2 changes: 1 addition & 1 deletion src/state/slices/portfolioSlice/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const selectIsAnyAccountIdEnabled = createCachedSelector(
selectPortfolioAccounts,
(_state: ReduxState, accountIds: AccountId[]) => accountIds,
(accountsById, accountIds): boolean => {
if (accountIds === undefined) return false
if (accountIds.length === 0) return false
return accountIds.some(accountId => accountsById[accountId] !== undefined)
},
)((_s: ReduxState, accountIds) => JSON.stringify(accountIds))
Expand Down

0 comments on commit 941d562

Please sign in to comment.