-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add wallet data hooks and cb
- Loading branch information
Showing
7 changed files
with
160 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { MW_URL } from '~/shared/core/envs'; | ||
import { mwGET } from '~/shared/utils/mw-get'; | ||
|
||
import { walletDataResponseSchema } from '~/users/core/schemas'; | ||
|
||
export const getWalletData = async () => { | ||
const url = `${MW_URL}/siwe/check-wallet`; | ||
|
||
return mwGET({ | ||
url, | ||
label: 'getWalletData', | ||
responseSchema: walletDataResponseSchema, | ||
options: { | ||
credentials: 'include' as RequestCredentials, | ||
mode: 'cors' as RequestMode, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const CHECK_WALLET_ROLES = { | ||
ANON: 'ANON', | ||
ADMIN: 'ADMIN', | ||
DEV: 'DEV', | ||
ORG: 'ORG', | ||
} as const; | ||
|
||
export const CHECK_WALLET_FLOWS = { | ||
ANON: 'LOGIN', | ||
PICK_ROLE: 'PICK-ROLE', | ||
ADD_GITHUB_REPO: 'ADD-GITHUB-REPO', | ||
ONBOARD_PROFILE: 'ONBOARD-PROFILE', | ||
ONBOARD_REPO: 'ONBOARD-REPO', | ||
ONBOARD_REVIEWS: 'ONBOARD-REVIEWS', | ||
SIGNUP_COMPLETE: 'SIGNUP-COMPLETE', | ||
ADMIN_SYNONYMS: 'SYNONYMS', | ||
ADMIN_COMPLETE: 'ADMIN-COMPLETE', | ||
ORG_PROFILE: 'ORG-PROFILE', | ||
ORG_APPROVAL: 'ORG-APPROVAL-PENDING', | ||
ORG_COMPLETE: 'ORG-COMPLETE', | ||
ORG_REJECTED: 'ORG-REJECTED', | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const userQueryKeys = { | ||
all: ['users'] as const, | ||
walletData: () => [...userQueryKeys.all, 'wallet-data'] as const, | ||
}; | ||
export type UserQueryKeys = typeof userQueryKeys; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { z } from 'zod'; | ||
|
||
import { genericResponseSchema } from '~/shared/core/schemas'; | ||
|
||
import { CHECK_WALLET_FLOWS, CHECK_WALLET_ROLES } from './constants'; | ||
|
||
export const walletRoleSchema = z.union([ | ||
z.literal(CHECK_WALLET_ROLES.ANON), | ||
z.literal(CHECK_WALLET_ROLES.ADMIN), | ||
z.literal(CHECK_WALLET_ROLES.DEV), | ||
z.literal(CHECK_WALLET_ROLES.ORG), | ||
]); | ||
export type WalletRole = z.infer<typeof walletRoleSchema>; | ||
|
||
export const walletFlowSchema = z.union([ | ||
z.literal(CHECK_WALLET_FLOWS.ANON), | ||
z.literal(CHECK_WALLET_FLOWS.PICK_ROLE), | ||
z.literal(CHECK_WALLET_FLOWS.ADD_GITHUB_REPO), | ||
z.literal(CHECK_WALLET_FLOWS.ONBOARD_PROFILE), | ||
z.literal(CHECK_WALLET_FLOWS.ONBOARD_REPO), | ||
z.literal(CHECK_WALLET_FLOWS.ONBOARD_REVIEWS), | ||
z.literal(CHECK_WALLET_FLOWS.SIGNUP_COMPLETE), | ||
z.literal(CHECK_WALLET_FLOWS.ADMIN_SYNONYMS), | ||
z.literal(CHECK_WALLET_FLOWS.ADMIN_COMPLETE), | ||
z.literal(CHECK_WALLET_FLOWS.ORG_PROFILE), | ||
z.literal(CHECK_WALLET_FLOWS.ORG_APPROVAL), | ||
z.literal(CHECK_WALLET_FLOWS.ORG_COMPLETE), | ||
z.literal(CHECK_WALLET_FLOWS.ORG_REJECTED), | ||
]); | ||
|
||
export type WalletFlow = z.infer<typeof walletFlowSchema>; | ||
|
||
export const walletDataSchema = z.object({ | ||
role: walletRoleSchema, | ||
flow: walletFlowSchema, | ||
}); | ||
export type WalletData = z.infer<typeof walletDataSchema>; | ||
|
||
export const walletDataResponseSchema = z | ||
.object({ | ||
data: walletDataSchema, | ||
}) | ||
.merge(genericResponseSchema); | ||
export type WalletDataResponse = z.infer<typeof walletDataResponseSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { QUERY_STALETIME } from '~/shared/core/constants'; | ||
|
||
import { userQueryKeys } from '~/users/core/query-keys'; | ||
import { getWalletData } from '~/users/api/get-wallet-data'; | ||
|
||
export const useWalletData = () => { | ||
return useQuery({ | ||
queryKey: userQueryKeys.walletData(), | ||
queryFn: () => getWalletData(), | ||
staleTime: QUERY_STALETIME.DEFAULT, | ||
}); | ||
}; |