Skip to content

Commit

Permalink
Get chain id from useWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
sophialittlejohn committed Oct 17, 2024
1 parent 4af1569 commit ec8b499
Showing 1 changed file with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import BN from 'bn.js'
import { TransactionRequest } from 'ethers'
import * as React from 'react'
import { useEffect } from 'react'
import { Dec } from '../../utils/Decimal'
import { useEvmTransaction } from '../../utils/tinlake/useEvmTransaction'
import { useAddress } from '../../utils/useAddress'
Expand Down Expand Up @@ -41,21 +40,14 @@ export function InvestRedeemLiquidityPoolsProvider({ poolId, trancheId, children
isLoading: isInvestmentLoading,
} = useLiquidityPoolInvestment(poolId, trancheId, lpIndex)
const provider = useEvmProvider()
const [chainId, setChainId] = React.useState(1)
const { evm } = useWallet()
const chainId = evm.chainId || 1

const isAllowedToInvest = lpInvest?.isAllowedToInvest
const tranche = pool.tranches.find((t) => t.id === trancheId)
const { data: metadata, isLoading: isMetadataLoading } = usePoolMetadata(pool)
const trancheMeta = metadata?.tranches?.[trancheId]

useEffect(() => {
const getChainId = async () => {
const chainId = Number((await provider?.provider!.getNetwork())?.chainId || 1n)
setChainId(chainId)
}
getChainId()
}, [provider])

if (!tranche) throw new Error(`Token not found. Pool id: ${poolId}, token id: ${trancheId}`)

const trancheBalance = lpInvest?.tokenBalance?.toDecimal() ?? Dec(0)
Expand Down

0 comments on commit ec8b499

Please sign in to comment.