Skip to content

Commit

Permalink
fix: add switch (subgraph/contract) for avalanche minichef hook (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
SarjuHansaliya authored Nov 10, 2023
1 parent 333a0ba commit 755e437
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/state/pstake/hooks/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PairState, usePair, usePairsContract } from 'src/data/Reserves';
import { useChainId, usePangolinWeb3 } from 'src/hooks';
import { useTokensContract } from 'src/hooks/tokens/evm';
import { useUSDCPrice } from 'src/hooks/useUSDCPrice/evm';
import { useShouldUseSubgraph } from 'src/state/papplication/hooks';
import { useMiniChefContract } from '../../../hooks/useContract';
import {
useMultipleContractSingleData,
Expand Down Expand Up @@ -61,6 +62,8 @@ const dummyApr: AprResult = {
swapFeeApr: 0,
};

const DEFIEDGE_TOKEN = '0xd947375F78df5B8FeEa6814eCd999ee64507a057';

export const useMinichefStakingInfos = (version = 2, pairToFilterBy?: Pair | null): MinichefStakingInfo[] => {
const { account } = usePangolinWeb3();
const chainId = useChainId();
Expand All @@ -78,6 +81,11 @@ export const useMinichefStakingInfos = (version = 2, pairToFilterBy?: Pair | nul
lpTokens.shift();
}

if (chainId === ChainId.AVALANCHE) {
const index = lpTokens.indexOf(DEFIEDGE_TOKEN);
index >= 0 && delete lpTokens[index];
}

const _tokens0Call = useMultipleContractSingleData(lpTokens, PANGOLIN_PAIR_INTERFACE, 'token0', []);
const _tokens1Call = useMultipleContractSingleData(lpTokens, PANGOLIN_PAIR_INTERFACE, 'token1', []);

Expand Down Expand Up @@ -697,4 +705,15 @@ export const useGetMinichefStakingInfosViaSubgraph = (): MinichefStakingInfo[] =
}, [chainId, png, rewardPerSecond, totalAllocPoint, rewardsExpiration, farms, farmsAprs, userPendingRewardsState]);
};

/**
* its wrapper hook to check which hook need to use based on subgraph on off
* @returns
*/
export function useMinicheInfos() {
const shouldUseSubgraph = useShouldUseSubgraph();
const useHook = shouldUseSubgraph ? useGetMinichefStakingInfosViaSubgraph : useMinichefStakingInfos;
const res = useHook();
return res;
}

/* eslint-enable max-lines */
7 changes: 4 additions & 3 deletions src/state/pstake/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { ChainId } from '@pangolindex/sdk';
import { useDummyMinichefHook } from './dummy';
import { useGetMinichefStakingInfosViaSubgraph, useMinichefStakingInfos } from './evm';
import { useGetMinichefStakingInfosViaSubgraph, useMinicheInfos, useMinichefStakingInfos } from './evm';

export type UseMinichefStakingInfosHookType = {
[chainId in ChainId]:
| typeof useMinichefStakingInfos
| typeof useDummyMinichefHook
| typeof useGetMinichefStakingInfosViaSubgraph;
| typeof useGetMinichefStakingInfosViaSubgraph
| typeof useMinicheInfos;
};

export const useMinichefStakingInfosHook: UseMinichefStakingInfosHookType = {
[ChainId.FUJI]: useMinichefStakingInfos,
[ChainId.AVALANCHE]: useGetMinichefStakingInfosViaSubgraph,
[ChainId.AVALANCHE]: useMinicheInfos,
[ChainId.WAGMI]: useMinichefStakingInfos,
[ChainId.COSTON]: useDummyMinichefHook,
[ChainId.SONGBIRD]: useDummyMinichefHook,
Expand Down

0 comments on commit 755e437

Please sign in to comment.