Skip to content

Commit

Permalink
chore: wip fix virtuoso list
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed Apr 9, 2024
1 parent 1a3250d commit 34f078d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export const SwitchAccountListItem = memo(

const { address: stxAddress, stxPublicKey } = stxAccount;

console.log('render switch');

const { isLoading, setIsLoading, setIsIdle } = useLoading(
'SWITCH_ACCOUNTS' + stxAddress || btcAddress
);
Expand All @@ -38,7 +36,7 @@ export const SwitchAccountListItem = memo(
// viewport. When opening the Switch Account dialog, we can see the output
// for every account in list, demonstrating that its rendering more than
// what's in the viewport.
console.log(index, stxAddress, btcAddress);
console.log('render switch', index);

Check failure on line 39 in src/app/features/dialogs/switch-account-dialog/components/switch-account-list-item.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

Unexpected console statement

const handleClick = async () => {
setIsLoading();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { token } from 'leather-styles/tokens';
import { pxStringToNumber } from '@shared/utils/px-string-to-number';

Check failure on line 7 in src/app/features/dialogs/switch-account-dialog/switch-account-dialog.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'pxStringToNumber' is declared but its value is never read.

import { useCreateAccount } from '@app/common/hooks/account/use-create-account';
import { useViewportMinWidth } from '@app/common/hooks/use-media-query';
import { useOnResizeListener } from '@app/common/hooks/use-on-resize-listener';

Check failure on line 11 in src/app/features/dialogs/switch-account-dialog/switch-account-dialog.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'useOnResizeListener' is declared but its value is never read.
import { useWalletType } from '@app/common/use-wallet-type';
import { useCurrentAccountIndex } from '@app/store/accounts/account';
Expand Down Expand Up @@ -40,17 +41,12 @@ export const SwitchAccountDialog = memo(({ isShowing, onClose }: DialogProps) =>
onClose();
};

const isAtleastBreakpointMd = useViewportMinWidth('md');

if (isShowing && stacksAddressesNum === 0 && btcAddressesNum === 0) {
return <AccountListUnavailable />;
}

// close now but need to test other things and bring back
// src/app/common/hooks/use-media-query.ts

// to get it working on resize

// fix other borders PR also

// #4370 SMELL without this early return the wallet crashes on new install with
// : Wallet is neither of type `ledger` nor `software`
// FIXME remove this when adding Create Account to Ledger in #2502 #4983
Expand All @@ -59,23 +55,25 @@ export const SwitchAccountDialog = memo(({ isShowing, onClose }: DialogProps) =>
const accountNum = stacksAddressesNum || btcAddressesNum;
const maxAccountsShown = accountNum > 10 ? 10 : accountNum;

Check failure on line 56 in src/app/features/dialogs/switch-account-dialog/switch-account-dialog.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'maxAccountsShown' is declared but its value is never read.

const isFullHeight = window.innerWidth <= pxStringToNumber(token('breakpoints.md'));
// clean this up
const footerHeight = isLedger ? 0 : 94;
const headerHeight = 72;

const offset = footerHeight + headerHeight;

const getVirtuosoHeight = (accountNum: number) => {
if (accountNum > 10) return isFullHeight ? '100vh' : virtuosoHeight * 10;
return virtuosoHeight * accountNum;
if (accountNum > 10) return isAtleastBreakpointMd ? '70vh' : '100vh';
return virtuosoHeight * accountNum + offset;
};

const maxHeight = getVirtuosoHeight(accountNum);

console.log('switch max height', maxHeight);

return (
<Dialog
header={<Header variant="dialog" title="Select account" />}
isShowing={isShowing}
onClose={onClose}
maxHeight={maxHeight}
contentMaxHeight={maxHeight}
footer={whenWallet({
software: (
<Footer>
Expand All @@ -95,8 +93,6 @@ export const SwitchAccountDialog = memo(({ isShowing, onClose }: DialogProps) =>
height: maxHeight,
}}
initialTopMostItemIndex={whenWallet({ ledger: 0, software: currentAccountIndex })}
// data={stacksAccounts}
// endReached={() => setAccountsShown(accountsShown + 1)}
totalCount={stacksAddressesNum}
itemContent={index => (
<Box key={index} my="space.05" px="space.05">
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/choose-account/components/accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const ChooseAccountsList = memo(() => {

if (!accounts) return null;
const accountNum = accounts.length;
const maxAccountsShown = accountNum > 10 ? 10 : accountNum;

Check failure on line 114 in src/app/pages/choose-account/components/accounts.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Cannot redeclare block-scoped variable 'maxAccountsShown'.

const maxAccountsShown = accountNum > 10 ? 10 : accountNum;

Check failure on line 116 in src/app/pages/choose-account/components/accounts.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Cannot redeclare block-scoped variable 'maxAccountsShown'.

Expand Down
12 changes: 6 additions & 6 deletions src/app/ui/components/containers/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface RadixDialogProps extends DialogProps {
footer?: ReactNode;
header?: ReactElement<any, string | JSXElementConstructor<any>>;
onGoBack?(): void;
maxHeight?: string | number;
contentMaxHeight?: string | number;
}

export function getHeightOffset(header: ReactNode, footer: ReactNode) {
Expand All @@ -36,14 +36,12 @@ export function Dialog({
header,
onClose,
isShowing,
maxHeight,
contentMaxHeight,
}: RadixDialogProps) {
if (!isShowing) return null;

const maxHeightOffset = getHeightOffset(header, footer);
const isFullHeight = window.innerWidth <= pxStringToNumber(token('breakpoints.md'));
const contentMaxHeight = isFullHeight ? '100vh' : getContentMaxHeight(maxHeightOffset);
console.log('content max height', contentMaxHeight, maxHeight);

return (
<RadixDialog.Root open>
<RadixDialog.Portal>
Expand Down Expand Up @@ -80,7 +78,9 @@ export function Dialog({
height="100%"
overflowY="auto"
style={{
maxHeight: maxHeight ? maxHeight : contentMaxHeight,
maxHeight: contentMaxHeight
? contentMaxHeight
: getContentMaxHeight(maxHeightOffset),
marginBottom: footer ? token('sizes.footerHeight') : token('spacing.space.04'),
}}
>
Expand Down

0 comments on commit 34f078d

Please sign in to comment.