Skip to content

Commit

Permalink
Add fetching single pools from API
Browse files Browse the repository at this point in the history
  • Loading branch information
timjrobinson committed Aug 24, 2023
1 parent 613c2e3 commit 37ca90a
Show file tree
Hide file tree
Showing 7 changed files with 3,096 additions and 179 deletions.
39 changes: 2 additions & 37 deletions src/composables/queries/usePoolQuery.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { QueryObserverOptions, useQuery } from '@tanstack/vue-query';
import { computed, reactive, Ref, ref } from 'vue';

import { GraphQLArgs } from '@balancer-labs/sdk';

import QUERY_KEYS from '@/constants/queryKeys';
import { useTokens } from '@/providers/tokens.provider';

import { poolsStoreService } from '@/services/pool/pools-store.service';
import { Pool } from '@/services/pool/types';

import { tokensListExclBpt, tokenTreeLeafs } from '../usePoolHelpers';

import { POOLS } from '@/constants/pools';
import { configService } from '@/services/config/config.service';
import { PoolDecorator } from '@/services/pool/decorators/pool.decorator';
import PoolRepository from '@/services/pool/pool.repository';
import { balancerAPIService } from '@/services/balancer/api/balancer-api.service';

type QueryOptions = QueryObserverOptions<Pool>;

Expand All @@ -23,53 +18,23 @@ export default function usePoolQuery(
isEnabled: Ref<boolean> = ref(true),
options: QueryOptions = {}
) {
/**
* If pool is already downloaded, we can use it instantly
* it may be if user came to pool page from home page
*/
const poolInfo = poolsStoreService.findPool(id);

/**
* COMPOSABLES
*/
const { injectTokens, tokens } = useTokens();

const poolRepository = new PoolRepository(tokens);

/**
* COMPUTED
*/
const enabled = computed(() => isEnabled.value);

/**
* METHODS
*/

function getQueryArgs(): GraphQLArgs {
const queryArgs: GraphQLArgs = {
chainId: configService.network.chainId,
where: {
id: { eq: id?.toLowerCase() },
totalShares: { gt: -1 }, // Avoid the filtering for low liquidity pools
poolType: { in: POOLS.IncludedPoolTypes },
},
};
return queryArgs;
}

/**
* QUERY INPUTS
*/
const queryKey = QUERY_KEYS.Pools.Current(id);

const queryFn = async () => {
let pool: Pool;
if (poolInfo) {
pool = poolInfo;
} else {
pool = await poolRepository.fetch(getQueryArgs());
}

let pool: Pool = await await balancerAPIService.pool.get({ id });
if (!pool) throw new Error('Pool does not exist');

// If the pool is cached from homepage it may not have onchain set, so update it
Expand Down
1 change: 1 addition & 0 deletions src/services/api/graphql/generated/api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ input GqlUserSwapVolumeFilter {
type GqlVotingGauge {
addedTimestamp: Int
address: Bytes!
childGaugeAddress: Bytes
isKilled: Boolean!
relativeWeightCap: String
}
Expand Down
Loading

0 comments on commit 37ca90a

Please sign in to comment.