Skip to content

Commit

Permalink
fix: Crash bcake migration page with unsupported chain (#10726)
Browse files Browse the repository at this point in the history
<!--
Before opening a pull request, please read the [contributing
guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md)
first
-->

<!-- start pr-codex -->

---

## PR-Codex overview
This PR refactors the `PosManagerMigrationFarmTable` component in
`PositionManagerTable.tsx`, optimizing the logic for generating the rows
and simplifying the handling of onStake and onUnStake functions.

### Detailed summary
- Introduced `noop` from `lodash` for `onStake` and `onUnStake`
functions.
- Changed the logic for generating `needToMigrateList` to use optional
chaining and a default empty array.
- Updated the `rows` mapping to directly return objects with structured
data.
- Removed conditional rendering based on `columnSchema` for the row
mapping.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
memoyil authored Sep 30, 2024
1 parent 20474c8 commit 69687b2
Showing 1 changed file with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Flex, Spinner } from '@pancakeswap/uikit'
import useActiveWeb3React from 'hooks/useActiveWeb3React'
import React, { useMemo } from 'react'
import { styled } from 'styled-components'
import noop from 'lodash/noop'
import EmptyText from '../MigrationTable/EmptyText'
import TableStyle from '../MigrationTable/StyledTable'
import TableHeader from '../MigrationTable/TableHeader'
Expand Down Expand Up @@ -41,15 +42,15 @@ export const PosManagerMigrationFarmTable: React.FC<React.PropsWithChildren<ITab
const { t } = useTranslation()
const { chainId } = useActiveWeb3React()

const needToMigrateList: VaultConfig[] = useMemo(() => {
if (!chainId) return []
return VAULTS_CONFIG_BY_CHAIN[chainId].filter(
(vault) => vault.address && vault?.bCakeWrapperAddress && vault?.bCakeWrapperAddress !== vault.address,
)
}, [chainId])
const rows = useMemo(() => {
if (!chainId || columnSchema !== V3Step1DesktopColumnSchema) return []

const rows = needToMigrateList.map((d) => {
return {
const needToMigrateList: VaultConfig[] =
VAULTS_CONFIG_BY_CHAIN[chainId]?.filter(
(vault) => vault.address && vault?.bCakeWrapperAddress && vault?.bCakeWrapperAddress !== vault.address,
) ?? []

return needToMigrateList.map((d) => ({
id: d.id,
data: {
token: d.currencyA.wrapped,
Expand All @@ -61,10 +62,10 @@ export const PosManagerMigrationFarmTable: React.FC<React.PropsWithChildren<ITab
bCakeWrapperAddress: d.bCakeWrapperAddress ?? '0x',
earningToken: d.earningToken.wrapped,
},
onStake: () => {},
onUnStake: () => {},
}
})
onStake: noop,
onUnStake: noop,
}))
}, [chainId, columnSchema])

return (
<Container>
Expand All @@ -79,12 +80,7 @@ export const PosManagerMigrationFarmTable: React.FC<React.PropsWithChildren<ITab
{account && userDataReady && rows.length === 0 && <EmptyText text={noStakedFarmText} />}
{account &&
userDataReady &&
rows.map((d) => {
if (columnSchema === V3Step1DesktopColumnSchema) {
return <PositionManagerFarmRow step={step} {...d} key={`table-row-${d.id}`} />
}
return null
})}
rows.map((d) => <PositionManagerFarmRow step={step} {...d} key={`table-row-${d.id}`} />)}
</TableStyle>
</Container>
)
Expand Down

0 comments on commit 69687b2

Please sign in to comment.