Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: my position is not loading when switch the network #343

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions packages/diva-app/src/component/Dashboard/MyPositions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useQuery } from 'react-query'
import ERC20 from '@diva/contracts/abis/erc20.json'
import styled from 'styled-components'
import { GrayText } from '../Trade/Orders/UiStyles'
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import { CoinIconPair } from '../CoinIcon'
import { useAppSelector } from '../../Redux/hooks'
import {
Expand Down Expand Up @@ -434,6 +434,7 @@ const columns: GridColDef[] = [
export function MyPositions() {
const { provider, address: userAddress } = useConnectionContext()
const [page, setPage] = useState(0)
const [filterPosition, setFilterPosition] = useState([])
const pools = useAppSelector((state) => selectPools(state))
const poolsRequestStatus = useAppSelector(selectRequestStatus('app/pools'))

Expand Down Expand Up @@ -578,26 +579,30 @@ export function MyPositions() {
return response
})

const tokenBalances = balances.data
useEffect(() => {
const tokenBalances = balances.data

const filteredRows =
tokenBalances != null
? rows
.filter(
(v) =>
tokenBalances[v.address.id] != null &&
tokenBalances[v.address.id].gt(0)
)
.map((v) => ({
...v,
Balance:
parseInt(formatUnits(tokenBalances[v.address.id])) < 0.01
? '<0.01'
: parseFloat(formatUnits(tokenBalances[v.address.id])).toFixed(
4
),
}))
: []
const filteredRows =
tokenBalances != null
? rows
.filter(
(v) =>
tokenBalances[v.address.id] != null &&
tokenBalances[v.address.id].gt(0)
)
.map((v) => ({
...v,
Balance:
parseInt(formatUnits(tokenBalances[v.address.id])) < 0.01
? '<0.01'
: parseFloat(
formatUnits(tokenBalances[v.address.id])
).toFixed(4),
}))
: []

setFilterPosition(filteredRows)
}, [balances])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is just wrapping it inside a useEffect - I don't think that solves anything?


return (
<Stack
Expand Down Expand Up @@ -627,7 +632,7 @@ export function MyPositions() {
<SideMenu />
<PoolsTable
page={page}
rows={filteredRows}
rows={filterPosition}
loading={balances.isLoading || poolsRequestStatus === 'pending'}
columns={columns}
onPageChange={(page) => setPage(page)}
Expand Down