Skip to content

Commit

Permalink
fix(STK-156): Update Swapr dapp codebase due to subgraph changes (#1932)
Browse files Browse the repository at this point in the history
* prune: remove now unneeded files
* prune: remove unneeded code related to single sided campaigns
  • Loading branch information
ElRodrigote authored Dec 9, 2024
1 parent 0c63028 commit 28178df
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 284 deletions.
11 changes: 0 additions & 11 deletions src/graphql/GetSingleSidedStakingCampaign.query.gql

This file was deleted.

15 changes: 0 additions & 15 deletions src/graphql/GetSingleSidedStakingCampaigns.query.gql

This file was deleted.

14 changes: 0 additions & 14 deletions src/graphql/GetStakingCampaings.query.gql

This file was deleted.

10 changes: 0 additions & 10 deletions src/graphql/fragments/SingleSidedStakingCampaignFragment.gql

This file was deleted.

10 changes: 0 additions & 10 deletions src/graphql/fragments/SingleSidedStakingCampaignRewardFragment.gql

This file was deleted.

53 changes: 0 additions & 53 deletions src/hooks/singleSidedStakeCampaigns/useSingleSidedCampaign.ts

This file was deleted.

This file was deleted.

86 changes: 3 additions & 83 deletions src/hooks/useAllLiquidityMiningCampaigns.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BigintIsh, Pair, Token } from '@swapr/sdk'
import { BigintIsh, Pair } from '@swapr/sdk'

import { useCallback, useMemo } from 'react'

import { SubgraphLiquidityMiningCampaign, SubgraphSingleSidedStakingCampaign } from '../apollo'
import { SubgraphLiquidityMiningCampaign } from '../apollo'
import { PairsFilterType } from '../components/Pool/ListFilter'
import { useGetLiquidityMiningCampaignsQuery, useGetStakingCampaignsQuery } from '../graphql/generated/schema'
import { useGetLiquidityMiningCampaignsQuery } from '../graphql/generated/schema'
import { useAllTokensFromActiveListsOnCurrentChain } from '../state/lists/hooks'
import {
getLowerTimeLimit,
Expand All @@ -13,7 +13,6 @@ import {
sortActiveCampaigns,
sortExpiredCampaigns,
toLiquidityMiningCampaign,
toSingleSidedStakeCampaign,
} from '../utils/liquidityMining'

import { useSWPRToken } from './swpr/useSWPRToken'
Expand All @@ -23,8 +22,6 @@ import { useNativeCurrency } from './useNativeCurrency'
import { useActiveWeb3React } from './index'

export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFilterType) {
const token0Address = pair?.token0?.address.toLowerCase()
const token1Address = pair?.token1?.address.toLowerCase()
const pairAddress = pair?.liquidityToken.address.toLowerCase()

const { chainId, account } = useActiveWeb3React()
Expand All @@ -39,16 +36,6 @@ export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFi
const memoizedLowerTimeLimit = useMemo(() => getLowerTimeLimit(), [])
const tokensInCurrentChain = useAllTokensFromActiveListsOnCurrentChain()

const {
data: singleSidedCampaigns,
loading: singleSidedLoading,
error: singleSidedCampaignsError,
} = useGetStakingCampaignsQuery({
variables: {
userId: subgraphAccountId,
},
})

const {
data: pairCampaigns,
loading: campaignLoading,
Expand All @@ -69,14 +56,10 @@ export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFi

return useMemo(() => {
if (
singleSidedLoading ||
!chainId ||
campaignLoading ||
!SWPRToken ||
singleSidedCampaignsError ||
campaignError ||
!singleSidedCampaigns ||
!singleSidedCampaigns?.singleSidedStakingCampaigns ||
!pairCampaigns ||
!pairCampaigns.liquidityMiningCampaigns ||
loadingKpiTokens
Expand Down Expand Up @@ -132,64 +115,6 @@ export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFi
}
}

for (let i = 0; i < singleSidedCampaigns.singleSidedStakingCampaigns.length; i++) {
const campaign = singleSidedCampaigns.singleSidedStakingCampaigns[i]

if (
(token0Address &&
token1Address &&
campaign.stakeToken.id.toLowerCase() !== token0Address &&
campaign.stakeToken.id.toLowerCase() !== token1Address) ||
(dataFilter === PairsFilterType.MY && campaign.singleSidedStakingPositions.length === 0)
)
continue
const containsKpiToken = !!campaign.rewards.find(
reward => !!kpiTokens.find(kpiToken => kpiToken.address.toLowerCase() === reward?.token.address.toLowerCase())
)
const stakeToken = new Token(
chainId,
campaign.stakeToken.id,
parseInt(campaign.stakeToken.decimals),
campaign.stakeToken.symbol,
campaign.stakeToken.name
)

let singleSidedStakeCampaign
try {
singleSidedStakeCampaign = toSingleSidedStakeCampaign(
chainId,
campaign as SubgraphSingleSidedStakingCampaign,
stakeToken,
campaign.stakeToken.totalSupply,
nativeCurrency,
campaign.stakeToken.derivedNativeCurrency
)
} catch (e) {
// TODO: Investigate why `derivedNativeCurrency` is zero
console.error('Campaign', { campaign })
continue
}

const hasStake = campaign.singleSidedStakingPositions.length > 0
const isExpired = parseInt(campaign.endsAt) < timestamp || parseInt(campaign.endsAt) > memoizedLowerTimeLimit

if (dataFilter !== PairsFilterType.SWPR || SWPRToken.equals(stakeToken)) {
if (hasStake || singleSidedStakeCampaign.currentlyActive || isUpcoming(singleSidedStakeCampaign.startsAt)) {
activeCampaigns.unshift({
campaign: singleSidedStakeCampaign,
staked: hasStake,
containsKpiToken: containsKpiToken,
})
} else if (isExpired) {
expiredCampaigns.unshift({
campaign: singleSidedStakeCampaign,
staked: hasStake,
containsKpiToken: containsKpiToken,
})
}
}
}

return {
loading: false,
miningCampaigns: {
Expand All @@ -198,12 +123,9 @@ export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFi
},
}
}, [
singleSidedLoading,
chainId,
campaignLoading,
singleSidedCampaignsError,
campaignError,
singleSidedCampaigns,
pairCampaigns,
loadingKpiTokens,
pairAddress,
Expand All @@ -215,7 +137,5 @@ export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFi
memoizedLowerTimeLimit,
SWPRToken,
isUpcoming,
token0Address,
token1Address,
])
}
11 changes: 3 additions & 8 deletions src/pages/Pools/LiquidityMiningCampaign/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { RowBetween, RowFixed } from '../../../components/Row'
import { UndecoratedLink } from '../../../components/UndercoratedLink'
import { PairState, usePair } from '../../../data/Reserves'
import { useActiveWeb3React } from '../../../hooks'
import { useSingleSidedCampaign } from '../../../hooks/singleSidedStakeCampaigns/useSingleSidedCampaign'
import { useToken } from '../../../hooks/Tokens'
import { useLiquidityMiningCampaign } from '../../../hooks/useLiquidityMiningCampaign'
import { useRouter } from '../../../hooks/useRouter'
Expand Down Expand Up @@ -56,10 +55,6 @@ export default function LiquidityMiningCampaign() {
const token1 = useToken(currencyIdB)
const isSingleSidedCampaign = location.pathname.includes('/single-sided-campaign')

const { singleSidedStakingCampaign, loading: singleSidedCampaignLoading } = useSingleSidedCampaign(
liquidityMiningCampaignId!
)

const wrappedPair = usePair(token0 || undefined, token1 || undefined)
const pairOrUndefined = useMemo(() => wrappedPair[1] || undefined, [wrappedPair])
const { campaign, containsKpiToken, loading } = useLiquidityMiningCampaign(pairOrUndefined, liquidityMiningCampaignId)
Expand All @@ -77,7 +72,7 @@ export default function LiquidityMiningCampaign() {
const AddLiquidityButtonComponent =
lpTokenBalance && lpTokenBalance.equalTo('0') ? ResponsiveButtonPrimary : ResponsiveButtonSecondary

const showSingleSidedCampaignLoader = isSingleSidedCampaign && (token0 === null || singleSidedCampaignLoading)
const showSingleSidedCampaignLoader = isSingleSidedCampaign && !token0 === null
const showCampaignLoader = !isSingleSidedCampaign && (token1 === null || token0 === null)

return (
Expand Down Expand Up @@ -142,10 +137,10 @@ export default function LiquidityMiningCampaign() {
</NavLink>
</ButtonRow>
</TitleRow>
{((!isSingleSidedCampaign && !loading) || (!singleSidedCampaignLoading && isSingleSidedCampaign)) && (
{((!isSingleSidedCampaign && !loading) || isSingleSidedCampaign) && (
<LiquidityMiningCampaignView
isSingleSidedStake={isSingleSidedCampaign}
campaign={isSingleSidedCampaign ? singleSidedStakingCampaign : campaign}
campaign={campaign}
containsKpiToken={containsKpiToken}
/>
)}
Expand Down
Loading

0 comments on commit 28178df

Please sign in to comment.