Skip to content

Commit

Permalink
add chaind into state to prevent errors on switch
Browse files Browse the repository at this point in the history
  • Loading branch information
iamoskvin committed Jun 9, 2024
1 parent 7cfdc97 commit a40a35f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/components/vault/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { Currency, CurrencyAmount } from '@vnaysn/jediswap-sdk-core'
import { removeExtraDecimals } from 'utils/removeExtraDecimals'
import { Trans } from '@lingui/macro'
import { formatUnits } from 'ethers/lib/utils'
import { useSelector } from 'react-redux'
import { AppState } from 'state/reducer'
interface TokenData {
[key: string]: any
}
Expand Down Expand Up @@ -50,7 +52,8 @@ export function useUserShares(
withdrawError: any
insufficientBalance: boolean
} {
const { address, chainId } = useAccountDetails()
const { address } = useAccountDetails()
const chainId = useSelector((state: AppState) => state.vaults.chainId)
const shares = useQuery({
queryKey: [`balance_of/${address}/${vaultAddress}/${chainId}`],
queryFn: async () => {
Expand Down
12 changes: 10 additions & 2 deletions src/state/vaults/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import { ChainId, Currency, CurrencyAmount, Token } from '@vnaysn/jediswap-sdk-c
import { useBalance } from '@starknet-react/core'
import { Trans } from '@lingui/macro'
import { useParams } from 'react-router-dom'
import { updateAllVaults, updateUserVaults, updateInput, updateWithdrawInput, VaultState } from './reducer'
import {
updateAllVaults,
updateUserVaults,
updateInput,
updateWithdrawInput,
VaultState,
updateChainId,
} from './reducer'
import { useAppDispatch, useAppSelector } from '../hooks'
import teahouseLogo from '../../assets/vaults/teahouse.svg'
import { useAccountBalance, useAccountDetails } from '../../hooks/starknet-react'
Expand Down Expand Up @@ -186,6 +193,7 @@ export function useAllVaults() {
}, {})
if (!ignore) {
dispatch(updateAllVaults(combinedData))
dispatch(updateChainId(chainId))
setIsLoading(false)
}
} catch (e) {
Expand All @@ -202,7 +210,7 @@ export function useAllVaults() {
}
}, [chainId])

return { data: allVaults, error, isLoading }
return { data: allVaults, error, isLoading, chainId }
}

export function useVaultActionHandlers(): {
Expand Down
12 changes: 9 additions & 3 deletions src/state/vaults/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @ts-ignore

import { createSlice } from '@reduxjs/toolkit'
import { Token } from '@vnaysn/jediswap-sdk-core'
import { ChainId, Token } from '@vnaysn/jediswap-sdk-core'
import { Field } from './actions'

interface URLs {
Expand Down Expand Up @@ -56,7 +56,7 @@ export type Vault = {
riskLevel: string
share: Share
strategyType: string
type: string,
type: string
performance: any
}

Expand All @@ -70,13 +70,15 @@ export interface VaultState {
readonly independentField: Field
readonly typedValue: string
readonly withdrawTypedValue: string
readonly chainId: ChainId | null
}
export const initialState: VaultState = {
allVaults: null,
users: {},
independentField: Field.CURRENCY_A,
typedValue: '',
withdrawTypedValue: '',
chainId: null,
}

const vaultsSlice = createSlice({
Expand All @@ -99,9 +101,13 @@ const vaultsSlice = createSlice({
updateWithdrawInput(state, { payload: { typedValue } }) {
state.withdrawTypedValue = typedValue
},
updateChainId(state, { payload }) {
state.chainId = payload
},
},
})

export const { updateAllVaults, updateUserVaults, updateInput, updateWithdrawInput } = vaultsSlice.actions
export const { updateAllVaults, updateUserVaults, updateInput, updateWithdrawInput, updateChainId } =
vaultsSlice.actions

export default vaultsSlice.reducer

0 comments on commit a40a35f

Please sign in to comment.