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

Function listAwardsInfiniteQueryOptions

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

Source from the content-addressed store, hash-verified

482 };
483
484export const listAwardsInfiniteQueryOptions = ({
485 id,
486 type,
487 limit = DEFAULT_AWARDS_LIMIT,
488}: {
489 id: string;
490 type: AwardTypes;
491 limit?: number;
492}) => {
493 return {
494 queryKey: generateQueryKey(RequestKey.Awards, undefined, {
495 id,
496 type,
497 first: limit,
498 }),
499 queryFn: async ({ pageParam = '' }: { pageParam?: string }) => {
500 const gqlQueryFunction = listAwardsQueryMap[type];
501
502 if (!gqlQueryFunction) {
503 throw new Error(`Unsupported award type: ${type}`);
504 }
505
506 const isInitialPage = pageParam === '';
507
508 const gqlQuery = gqlQueryFunction({
509 includeTotal: isInitialPage,
510 });
511
512 const result = await gqlClient.request<{
513 awards: Connection<AwardListItem>;
514 awardsTotal?: LoggedUser['balance'];
515 }>(gqlQuery, {
516 id,
517 type,
518 first: limit,
519 after: pageParam,
520 });
521
522 // Custom mapping for source response
523 if (type === 'SQUAD') {
524 result.awards.edges = result.awards.edges.map(
525 (edge: Edge<AwardListItem>) => {
526 const newNode = edge.node as unknown as SquadAwardListItem;
527 return {
528 node: {
529 user: newNode.sender,
530 award: newNode.product,
531 awardTransaction: newNode.value,
532 },
533 };
534 },
535 );
536 }
537
538 return result;
539 },
540 initialPageParam: '',
541 staleTime: StaleTime.Default,

Callers 1

ListAwardsModalFunction · 0.90

Calls 2

generateQueryKeyFunction · 0.90
getNextPageParamFunction · 0.90

Tested by

no test coverage detected