({
user,
sourceId,
}: {
user?: Pick<LoggedUser, 'id'>;
sourceId?: string;
})
| 42 | } |
| 43 | |
| 44 | export const squadWalletQueryOptions = ({ |
| 45 | user, |
| 46 | sourceId, |
| 47 | }: { |
| 48 | user?: Pick<LoggedUser, 'id'>; |
| 49 | sourceId?: string; |
| 50 | }) => ({ |
| 51 | queryKey: generateQueryKey(RequestKey.SquadWallet, user, sourceId), |
| 52 | queryFn: async (): Promise<SquadWallet | null> => { |
| 53 | try { |
| 54 | const { source, squadSubscription } = |
| 55 | await gqlClient.request<SquadWalletData>(SQUAD_WALLET_QUERY, { |
| 56 | sourceId, |
| 57 | }); |
| 58 | |
| 59 | // only the paid seats of an active plan can spend it |
| 60 | if (!squadSubscription.plan || !source.currentMember?.seat) { |
| 61 | return null; |
| 62 | } |
| 63 | |
| 64 | return { |
| 65 | sourceId: source.id, |
| 66 | name: source.name, |
| 67 | handle: source.handle, |
| 68 | balance: squadSubscription.coresBalance, |
| 69 | }; |
| 70 | } catch { |
| 71 | // the subscription is only visible to squad admins and moderators |
| 72 | return null; |
| 73 | } |
| 74 | }, |
| 75 | enabled: !!user?.id && !!sourceId, |
| 76 | }); |
no test coverage detected