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

Function listAwardsInfiniteQueryOptions

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

Source from the content-addressed store, hash-verified

464 };
465
466export const listAwardsInfiniteQueryOptions = ({
467 id,
468 type,
469 limit = DEFAULT_AWARDS_LIMIT,
470}: {
471 id: string;
472 type: AwardTypes;
473 limit?: number;
474}) => {
475 return {
476 queryKey: generateQueryKey(RequestKey.Awards, undefined, {
477 id,
478 type,
479 first: limit,
480 }),
481 queryFn: async ({ pageParam = '' }: { pageParam?: string }) => {
482 const gqlQueryFunction = listAwardsQueryMap[type];
483
484 if (!gqlQueryFunction) {
485 throw new Error(`Unsupported award type: ${type}`);
486 }
487
488 const isInitialPage = pageParam === '';
489
490 const gqlQuery = gqlQueryFunction({
491 includeTotal: isInitialPage,
492 });
493
494 const result = await gqlClient.request<{
495 awards: Connection<AwardListItem>;
496 awardsTotal?: LoggedUser['balance'];
497 }>(gqlQuery, {
498 id,
499 type,
500 first: limit,
501 after: pageParam,
502 });
503
504 // Custom mapping for source response
505 if (type === 'SQUAD') {
506 result.awards.edges = result.awards.edges.map(
507 (edge: Edge<AwardListItem>) => {
508 const newNode = edge.node as unknown as SquadAwardListItem;
509 return {
510 node: {
511 user: newNode.sender,
512 award: newNode.product,
513 awardTransaction: newNode.value,
514 },
515 };
516 },
517 );
518 }
519
520 return result;
521 },
522 initialPageParam: '',
523 staleTime: StaleTime.Default,

Callers 1

ListAwardsModalFunction · 0.90

Calls 2

generateQueryKeyFunction · 0.90
getNextPageParamFunction · 0.90

Tested by

no test coverage detected