Skip to content

Commit 34bb7cb

Browse files
authored
fix: [lw-12345] adjust initial page size for tokens tab (#1719)
1 parent 6ecbfa0 commit 34bb7cb

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

apps/browser-extension-wallet/src/hooks/useWalletActivities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { WalletActivitiesSlice, useWalletStore } from '@src/stores';
55
import noop from 'lodash/noop';
66
import { mapWalletActivities } from '@src/stores/slices';
77
import { Wallet } from '@lace/cardano';
8-
import { AssetActivityListProps, useGroupedActivitiesPageSize } from '@lace/core';
8+
import { AssetActivityListProps, useItemsPageSize } from '@lace/core';
99
import { useTxHistoryLoader } from './useTxHistoryLoader';
1010

1111
type UseWalletActivitiesProps = {
@@ -82,7 +82,7 @@ export const useWalletActivitiesPaginated = ({
8282

8383
const cardanoFiatPrice = priceResult?.cardano?.price;
8484

85-
const pageSize = useGroupedActivitiesPageSize();
85+
const pageSize = useItemsPageSize();
8686

8787
const { loadMore: txHistoryLoaderLoadMore, loadedHistory } = useTxHistoryLoader(pageSize);
8888

apps/browser-extension-wallet/src/views/browser-view/features/assets/components/Assets.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React, { useCallback, useEffect, useMemo, useState } from 'react';
33
import isNil from 'lodash/isNil';
44
import { Wallet } from '@lace/cardano';
5-
import { AssetTableProps } from '@lace/core';
5+
import { AssetTableProps, useItemsPageSize } from '@lace/core';
66
import { useObservable } from '@lace/common';
77
import { useBalances, useFetchCoinPrice, useRedirection } from '@hooks';
88
import { useWalletStore } from '@src/stores';
@@ -34,7 +34,7 @@ import { useIsSmallerScreenWidthThan } from '@hooks/useIsSmallerScreenWidthThan'
3434
import { BREAKPOINT_SMALL } from '@src/styles/constants';
3535
import { MidnightEventBanner } from './MidnightEventBanner';
3636

37-
const LIST_CHUNK_SIZE = 12;
37+
const LIST_ITEM_HEIGHT = 80;
3838
const SEND_COIN_OUTPUT_ID = 'output1';
3939
const ASSETS_OTHER_THAN_ADA = 2;
4040

@@ -69,9 +69,14 @@ export const Assets = ({ topSection }: AssetsProps): React.ReactElement => {
6969

7070
const [isActivityDetailsOpen, setIsActivityDetailsOpen] = useState(false);
7171
const [fullAssetList, setFullAssetList] = useState<AssetTableProps['rows']>();
72-
const [listItemsAmount, setListItemsAmount] = useState(LIST_CHUNK_SIZE);
72+
const pageSize = useItemsPageSize(LIST_ITEM_HEIGHT);
73+
const [listItemsAmount, setListItemsAmount] = useState(pageSize);
7374
const [selectedAssetId, setSelectedAssetId] = useState<string | undefined>();
7475

76+
useEffect(() => {
77+
setListItemsAmount(pageSize);
78+
}, [pageSize]);
79+
7580
const assetsInfo = useObservable(inMemoryWallet.assetInfo$);
7681

7782
// Wallet's coin balance in ADA and converted to fiat, including available rewards
@@ -286,7 +291,7 @@ export const Assets = ({ topSection }: AssetsProps): React.ReactElement => {
286291
isBalanceLoading={isBalanceLoading}
287292
isLoadingFirstTime={isLoadingFirstTime}
288293
onRowClick={onAssetRowClick}
289-
onTableScroll={() => setListItemsAmount((prevState) => prevState + LIST_CHUNK_SIZE)}
294+
onTableScroll={() => setListItemsAmount((prevState) => prevState + pageSize)}
290295
totalAssets={fullAssetList?.length ?? 0}
291296
/>
292297
);

packages/core/src/ui/components/Activity/GroupedAssetActivityList.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ import isNumber from 'lodash/isNumber';
88

99
const { Text } = Typography;
1010

11-
export const useGroupedActivitiesPageSize = (): number => {
11+
const ESTIMATED_MIN_GROUP_HEIGHT = 100;
12+
13+
export const useItemsPageSize = (estimatedItemHeight = ESTIMATED_MIN_GROUP_HEIGHT): number => {
1214
// workaround for bug in react-infinite-scroll-component
1315
// related to not loading more elements if the height of the container is less than the height of the window
1416
// see: https://github.com/ankeetmaini/react-infinite-scroll-component/issues/380
1517
// ticket for proper fix on our end: https://input-output.atlassian.net/browse/LW-8986
1618
// initialWindowHeight state needed to ensure that page size remains the same if window is resized
1719
const [initialWindowHeight] = useState(window.innerHeight);
18-
const ESTIMATED_MIN_GROUP_HEIGHT = 100;
1920
// eslint-disable-next-line no-magic-numbers
20-
return Math.max(5, Math.floor(initialWindowHeight / ESTIMATED_MIN_GROUP_HEIGHT));
21+
return Math.max(5, Math.floor(initialWindowHeight / estimatedItemHeight));
2122
};
2223

2324
export interface GroupedAssetActivityListProps {

packages/staking/src/features/activity/RewardsHistory.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Box, Text } from '@input-output-hk/lace-ui-toolkit';
2-
import { AssetActivityListProps, GroupedAssetActivityList, useGroupedActivitiesPageSize } from '@lace/core';
2+
import { AssetActivityListProps, GroupedAssetActivityList, useItemsPageSize } from '@lace/core';
33
import { Skeleton } from 'antd';
44
import { StateStatus } from 'features/outside-handles-provider';
55
import take from 'lodash/take';
@@ -16,7 +16,7 @@ type RewardsHistoryProps = {
1616
export const RewardsHistory = ({ groupedRewardsActivities, walletActivitiesStatus }: RewardsHistoryProps) => {
1717
const { t } = useTranslation();
1818

19-
const pageSize = useGroupedActivitiesPageSize();
19+
const pageSize = useItemsPageSize();
2020
const [paginatedLists, setPaginatedLists] = useState<AssetActivityListProps[]>([]);
2121

2222
const loadMoreData = useCallback(() => {

0 commit comments

Comments
 (0)