MCPcopy Create free account
hub / github.com/dailydotdev/apps / listAwardsInfiniteQueryOptions

Function listAwardsInfiniteQueryOptions

packages/shared/src/graphql/njord.ts:525–591  ·  view source on GitHub ↗
({
  id,
  type,
  limit = DEFAULT_AWARDS_LIMIT,
}: {
  id: string;
  type: AwardTypes;
  limit?: number;
})

Source from the content-addressed store, hash-verified

523 };
524
525export const listAwardsInfiniteQueryOptions = ({
526 id,
527 type,
528 limit = DEFAULT_AWARDS_LIMIT,
529}: {
530 id: string;
531 type: AwardTypes;
532 limit?: number;
533}) => {
534 return {
535 queryKey: generateQueryKey(RequestKey.Awards, undefined, {
536 id,
537 type,
538 first: limit,
539 }),
540 queryFn: async ({ pageParam = '' }: { pageParam?: string }) => {
541 const gqlQueryFunction = listAwardsQueryMap[type];
542
543 if (!gqlQueryFunction) {
544 throw new Error(`Unsupported award type: ${type}`);
545 }
546
547 const isInitialPage = pageParam === '';
548
549 const gqlQuery = gqlQueryFunction({
550 includeTotal: isInitialPage,
551 });
552
553 const result = await gqlClient.request<{
554 awards: Connection<AwardListItem>;
555 awardsTotal?: LoggedUser['balance'];
556 }>(gqlQuery, {
557 id,
558 type,
559 first: limit,
560 after: pageParam,
561 });
562
563 // Custom mapping for source response
564 if (type === 'SQUAD') {
565 result.awards.edges = result.awards.edges.map(
566 (edge: Edge<AwardListItem>) => {
567 const newNode = edge.node as unknown as SquadAwardListItem;
568 return {
569 node: {
570 user: newNode.sender,
571 award: newNode.product,
572 awardTransaction: newNode.value,
573 },
574 };
575 },
576 );
577 }
578
579 return result;
580 },
581 initialPageParam: '',
582 staleTime: StaleTime.Default,

Callers 1

ListAwardsModalFunction · 0.90

Calls 2

generateQueryKeyFunction · 0.90
getNextPageParamFunction · 0.90

Tested by

no test coverage detected