Skip to content

Commit

Permalink
fix: [lw-12345] adjust initial page size for tokens tab (#1719)
Browse files Browse the repository at this point in the history
  • Loading branch information
vetalcore authored Feb 18, 2025
1 parent 6ecbfa0 commit 34bb7cb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { WalletActivitiesSlice, useWalletStore } from '@src/stores';
import noop from 'lodash/noop';
import { mapWalletActivities } from '@src/stores/slices';
import { Wallet } from '@lace/cardano';
import { AssetActivityListProps, useGroupedActivitiesPageSize } from '@lace/core';
import { AssetActivityListProps, useItemsPageSize } from '@lace/core';
import { useTxHistoryLoader } from './useTxHistoryLoader';

type UseWalletActivitiesProps = {
Expand Down Expand Up @@ -82,7 +82,7 @@ export const useWalletActivitiesPaginated = ({

const cardanoFiatPrice = priceResult?.cardano?.price;

const pageSize = useGroupedActivitiesPageSize();
const pageSize = useItemsPageSize();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import isNil from 'lodash/isNil';
import { Wallet } from '@lace/cardano';
import { AssetTableProps } from '@lace/core';
import { AssetTableProps, useItemsPageSize } from '@lace/core';
import { useObservable } from '@lace/common';
import { useBalances, useFetchCoinPrice, useRedirection } from '@hooks';
import { useWalletStore } from '@src/stores';
Expand Down Expand Up @@ -34,7 +34,7 @@ import { useIsSmallerScreenWidthThan } from '@hooks/useIsSmallerScreenWidthThan'
import { BREAKPOINT_SMALL } from '@src/styles/constants';
import { MidnightEventBanner } from './MidnightEventBanner';

const LIST_CHUNK_SIZE = 12;
const LIST_ITEM_HEIGHT = 80;
const SEND_COIN_OUTPUT_ID = 'output1';
const ASSETS_OTHER_THAN_ADA = 2;

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

const [isActivityDetailsOpen, setIsActivityDetailsOpen] = useState(false);
const [fullAssetList, setFullAssetList] = useState<AssetTableProps['rows']>();
const [listItemsAmount, setListItemsAmount] = useState(LIST_CHUNK_SIZE);
const pageSize = useItemsPageSize(LIST_ITEM_HEIGHT);
const [listItemsAmount, setListItemsAmount] = useState(pageSize);
const [selectedAssetId, setSelectedAssetId] = useState<string | undefined>();

useEffect(() => {
setListItemsAmount(pageSize);
}, [pageSize]);

const assetsInfo = useObservable(inMemoryWallet.assetInfo$);

// Wallet's coin balance in ADA and converted to fiat, including available rewards
Expand Down Expand Up @@ -286,7 +291,7 @@ export const Assets = ({ topSection }: AssetsProps): React.ReactElement => {
isBalanceLoading={isBalanceLoading}
isLoadingFirstTime={isLoadingFirstTime}
onRowClick={onAssetRowClick}
onTableScroll={() => setListItemsAmount((prevState) => prevState + LIST_CHUNK_SIZE)}
onTableScroll={() => setListItemsAmount((prevState) => prevState + pageSize)}
totalAssets={fullAssetList?.length ?? 0}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import isNumber from 'lodash/isNumber';

const { Text } = Typography;

export const useGroupedActivitiesPageSize = (): number => {
const ESTIMATED_MIN_GROUP_HEIGHT = 100;

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

export interface GroupedAssetActivityListProps {
Expand Down
4 changes: 2 additions & 2 deletions packages/staking/src/features/activity/RewardsHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Text } from '@input-output-hk/lace-ui-toolkit';
import { AssetActivityListProps, GroupedAssetActivityList, useGroupedActivitiesPageSize } from '@lace/core';
import { AssetActivityListProps, GroupedAssetActivityList, useItemsPageSize } from '@lace/core';
import { Skeleton } from 'antd';
import { StateStatus } from 'features/outside-handles-provider';
import take from 'lodash/take';
Expand All @@ -16,7 +16,7 @@ type RewardsHistoryProps = {
export const RewardsHistory = ({ groupedRewardsActivities, walletActivitiesStatus }: RewardsHistoryProps) => {
const { t } = useTranslation();

const pageSize = useGroupedActivitiesPageSize();
const pageSize = useItemsPageSize();
const [paginatedLists, setPaginatedLists] = useState<AssetActivityListProps[]>([]);

const loadMoreData = useCallback(() => {
Expand Down

0 comments on commit 34bb7cb

Please sign in to comment.