Skip to content

Commit

Permalink
fix: migrate modal re-renders (#2306)
Browse files Browse the repository at this point in the history
  • Loading branch information
grothem authored Jan 7, 2025
1 parent b8f2c71 commit 0df54b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
44 changes: 27 additions & 17 deletions src/components/transactions/MigrateV3/MigrateV3ModalContent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Trans } from '@lingui/macro';
import { Box, Button } from '@mui/material';
import { useRouter } from 'next/router';
import { useCallback } from 'react';
import { useMemo } from 'react';
import { UserMigrationReserves } from 'src/hooks/migration/useUserMigrationReserves';
import { UserSummaryForMigration } from 'src/hooks/migration/useUserSummaryForMigration';
import { useModalContext } from 'src/hooks/useModal';
Expand All @@ -12,6 +12,7 @@ import {
selectSelectedBorrowReservesForMigrationV3,
} from 'src/store/v3MigrationSelectors';
import { CustomMarket, getNetworkConfig } from 'src/utils/marketsAndNetworksConfig';
import { useShallow } from 'zustand/shallow';

import { TxErrorView } from '../FlowCommons/Error';
import { GasEstimationError } from '../FlowCommons/GasEstimationError';
Expand Down Expand Up @@ -40,22 +41,31 @@ export const MigrateV3ModalContent = ({
const router = useRouter();
const networkConfig = getNetworkConfig(currentChainId);

const { supplyPositions, borrowPositions } = useRootStore(
useCallback(
(state) => ({
supplyPositions: selectedUserSupplyReservesForMigration(
state.selectedMigrationSupplyAssets,
userMigrationReserves.supplyReserves,
userMigrationReserves.isolatedReserveV3
),
borrowPositions: selectSelectedBorrowReservesForMigrationV3(
state.selectedMigrationBorrowAssets,
toUserSummaryForMigration,
userMigrationReserves
),
}),
[userMigrationReserves, toUserSummaryForMigration]
)
const { selectedMigrationSupplyAssets, selectedMigrationBorrowAssets } = useRootStore(
useShallow((state) => ({
selectedMigrationSupplyAssets: state.selectedMigrationSupplyAssets,
selectedMigrationBorrowAssets: state.selectedMigrationBorrowAssets,
}))
);

const supplyPositions = useMemo(
() =>
selectedUserSupplyReservesForMigration(
selectedMigrationSupplyAssets,
userMigrationReserves.supplyReserves,
userMigrationReserves.isolatedReserveV3
),
[selectedMigrationSupplyAssets, userMigrationReserves]
);

const borrowPositions = useMemo(
() =>
selectSelectedBorrowReservesForMigrationV3(
selectedMigrationBorrowAssets,
toUserSummaryForMigration,
userMigrationReserves
),
[selectedMigrationBorrowAssets, toUserSummaryForMigration, userMigrationReserves]
);

const supplyAssets = supplyPositions.map((supplyAsset) => {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/migration/MigrationListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export const MigrationListItem = ({
</ListColumn>

<ListColumn>
<Box sx={{ display: 'flex' }}>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<IncentivesCard
value={v2APY}
symbol={userReserve.reserve.symbol}
Expand Down

1 comment on commit 0df54b7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

Please sign in to comment.