@mezo-org/passport 0.4.0-dev.4 → 0.4.0-dev.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -22
- package/dist/src/api/auth.d.ts +36 -59
- package/dist/src/api/auth.d.ts.map +1 -1
- package/dist/src/api/auth.js +21 -49
- package/dist/src/api/auth.js.map +1 -1
- package/dist/src/api/client.d.ts +24 -0
- package/dist/src/api/client.d.ts.map +1 -0
- package/dist/src/api/client.js +54 -0
- package/dist/src/api/client.js.map +1 -0
- package/dist/src/api/fetch-error.d.ts +5 -0
- package/dist/src/api/fetch-error.d.ts.map +1 -0
- package/dist/src/api/fetch-error.js +8 -0
- package/dist/src/api/fetch-error.js.map +1 -0
- package/dist/src/api/index.d.ts +3 -0
- package/dist/src/api/index.d.ts.map +1 -0
- package/dist/src/api/index.js +3 -0
- package/dist/src/api/index.js.map +1 -0
- package/dist/src/api/portal.d.ts +33 -0
- package/dist/src/api/portal.d.ts.map +1 -0
- package/dist/src/api/portal.js +23 -0
- package/dist/src/api/portal.js.map +1 -0
- package/dist/src/assets/DefaultAvatar.d.ts +5 -0
- package/dist/src/assets/DefaultAvatar.d.ts.map +1 -0
- package/dist/src/assets/DefaultAvatar.js +21 -0
- package/dist/src/assets/DefaultAvatar.js.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +8 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js +39 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Content.d.ts +23 -0
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Content.js +27 -0
- package/dist/src/components/Dropdown/Content.js.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts +7 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js +13 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts +27 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.js +68 -0
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.js +34 -0
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.js +57 -0
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js +64 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +44 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
- package/dist/src/components/Dropdown/index.d.ts +3 -0
- package/dist/src/components/Dropdown/index.d.ts.map +1 -0
- package/dist/src/components/Dropdown/index.js +2 -0
- package/dist/src/components/Dropdown/index.js.map +1 -0
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +2 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/config.d.ts +41 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +20 -5
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +6 -2
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +8 -4
- package/dist/src/constants.js.map +1 -1
- package/dist/src/hooks/constants.d.ts +1 -0
- package/dist/src/hooks/constants.d.ts.map +1 -1
- package/dist/src/hooks/constants.js +1 -0
- package/dist/src/hooks/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +4 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +4 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +7 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +24 -0
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
- package/dist/src/hooks/useAuthApiClient.d.ts +1 -1
- package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts +73 -0
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -0
- package/dist/src/hooks/useAuthenticateWithWallet.js +69 -0
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -0
- package/dist/src/hooks/useBorrowData.d.ts +60 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +122 -0
- package/dist/src/hooks/useBorrowData.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts +23 -173
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +7 -4
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useCreateSession.d.ts +12 -101
- package/dist/src/hooks/useCreateSession.d.ts.map +1 -1
- package/dist/src/hooks/useCreateSession.js +10 -8
- package/dist/src/hooks/useCreateSession.js.map +1 -1
- package/dist/src/hooks/useDropdownData.d.ts +47 -0
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
- package/dist/src/hooks/useDropdownData.js +95 -0
- package/dist/src/hooks/useDropdownData.js.map +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts.map +1 -1
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js.map +1 -1
- package/dist/src/hooks/useGetAccountByAddress.d.ts +2 -2
- package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -1
- package/dist/src/hooks/useGetAccountByMezoId.d.ts +2 -2
- package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.d.ts +16 -2
- package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.js +25 -3
- package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
- package/dist/src/hooks/useGetSession.d.ts +1 -1
- package/dist/src/hooks/useGetSession.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.d.ts +15 -175
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +7 -4
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- package/dist/src/hooks/usePortalApiClient.d.ts +2 -0
- package/dist/src/hooks/usePortalApiClient.d.ts.map +1 -0
- package/dist/src/hooks/usePortalApiClient.js +6 -0
- package/dist/src/hooks/usePortalApiClient.js.map +1 -0
- package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
- package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
- package/dist/src/hooks/useRefreshPassport.js +44 -0
- package/dist/src/hooks/useRefreshPassport.js.map +1 -0
- package/dist/src/hooks/useSignInWithDiscord.d.ts +12 -100
- package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithDiscord.js +6 -3
- package/dist/src/hooks/useSignInWithDiscord.js.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.d.ts +12 -100
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.js +6 -34
- package/dist/src/hooks/useSignInWithWallet.js.map +1 -1
- package/dist/src/hooks/useSignOut.d.ts +12 -28
- package/dist/src/hooks/useSignOut.d.ts.map +1 -1
- package/dist/src/hooks/useSignOut.js +7 -4
- package/dist/src/hooks/useSignOut.js.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.d.ts +73 -0
- package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -0
- package/dist/src/hooks/useSignUpWithWallet.js +11 -0
- package/dist/src/hooks/useSignUpWithWallet.js.map +1 -0
- package/dist/src/hooks/useTokensBalances.d.ts +74 -0
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
- package/dist/src/hooks/useTokensBalances.js +140 -0
- package/dist/src/hooks/useTokensBalances.js.map +1 -0
- package/dist/src/hooks/useUpdateMezoId.d.ts +30 -136
- package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useUpdateMezoId.js +7 -4
- package/dist/src/hooks/useUpdateMezoId.js.map +1 -1
- package/dist/src/hooks/useWalletAccount.d.ts +13 -0
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
- package/dist/src/hooks/useWalletAccount.js +29 -0
- package/dist/src/hooks/useWalletAccount.js.map +1 -0
- package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
- package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
- package/dist/src/hooks/useWatchTransferEvents.js +63 -0
- package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/contracts/index.d.ts +13 -0
- package/dist/src/lib/contracts/index.d.ts.map +1 -0
- package/dist/src/lib/contracts/index.js +57 -0
- package/dist/src/lib/contracts/index.js.map +1 -0
- package/dist/src/provider.d.ts +10 -13
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +11 -20
- package/dist/src/provider.js.map +1 -1
- package/dist/src/stores/dropdownStore.d.ts +12 -0
- package/dist/src/stores/dropdownStore.d.ts.map +1 -0
- package/dist/src/stores/dropdownStore.js +13 -0
- package/dist/src/stores/dropdownStore.js.map +1 -0
- package/dist/src/utils/address.d.ts +15 -0
- package/dist/src/utils/address.d.ts.map +1 -0
- package/dist/src/utils/address.js +37 -0
- package/dist/src/utils/address.js.map +1 -0
- package/dist/src/utils/address.test.d.ts +2 -0
- package/dist/src/utils/address.test.d.ts.map +1 -0
- package/dist/src/utils/address.test.js +40 -0
- package/dist/src/utils/address.test.js.map +1 -0
- package/dist/src/utils/cryptoAssets.d.ts +44 -0
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.js +131 -0
- package/dist/src/utils/cryptoAssets.js.map +1 -0
- package/dist/src/utils/cryptoAssets.test.d.ts +2 -0
- package/dist/src/utils/cryptoAssets.test.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.test.js +67 -0
- package/dist/src/utils/cryptoAssets.test.js.map +1 -0
- package/dist/src/utils/currency.d.ts +14 -0
- package/dist/src/utils/currency.d.ts.map +1 -0
- package/dist/src/utils/currency.js +27 -0
- package/dist/src/utils/currency.js.map +1 -0
- package/dist/src/utils/currency.test.d.ts +2 -0
- package/dist/src/utils/currency.test.d.ts.map +1 -0
- package/dist/src/utils/currency.test.js +34 -0
- package/dist/src/utils/currency.test.js.map +1 -0
- package/dist/src/utils/numbers.d.ts +58 -0
- package/dist/src/utils/numbers.d.ts.map +1 -0
- package/dist/src/utils/numbers.js +132 -0
- package/dist/src/utils/numbers.js.map +1 -0
- package/dist/src/utils/numbers.test.d.ts +2 -0
- package/dist/src/utils/numbers.test.d.ts.map +1 -0
- package/dist/src/utils/numbers.test.js +170 -0
- package/dist/src/utils/numbers.test.js.map +1 -0
- package/package.json +13 -5
- package/src/api/auth.ts +72 -129
- package/src/api/client.ts +78 -0
- package/src/api/fetch-error.ts +8 -0
- package/src/api/index.ts +2 -0
- package/src/api/portal.ts +57 -0
- package/src/assets/DefaultAvatar.tsx +74 -0
- package/src/components/Dropdown/ConnectedTrigger.tsx +76 -0
- package/src/components/Dropdown/Content.tsx +98 -0
- package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
- package/src/components/Dropdown/Dropdown.tsx +148 -0
- package/src/components/Dropdown/ListingItem.tsx +80 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
- package/src/components/Dropdown/README.md +41 -0
- package/src/components/Dropdown/Receive/Receive.tsx +119 -0
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
- package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
- package/src/components/Dropdown/Root/Root.tsx +147 -0
- package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
- package/src/components/Dropdown/Root/WelcomeBlock.tsx +91 -0
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/components/Dropdown/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/config.ts +27 -6
- package/src/constants.ts +8 -4
- package/src/hooks/constants.ts +1 -0
- package/src/hooks/index.ts +7 -1
- package/src/hooks/useAssetsConversionRates.ts +32 -0
- package/src/hooks/useAuthenticateWithWallet.ts +102 -0
- package/src/hooks/useBorrowData.ts +143 -0
- package/src/hooks/useCreateAccount.ts +19 -5
- package/src/hooks/useCreateSession.ts +22 -9
- package/src/hooks/useDropdownData.ts +139 -0
- package/src/hooks/useEnsureNoSessionAndFetchNonce.ts +1 -0
- package/src/hooks/useGetAccountByAddress.ts +2 -2
- package/src/hooks/useGetAccountByMezoId.ts +2 -2
- package/src/hooks/useGetCurrentAccount.ts +46 -6
- package/src/hooks/useGetSession.ts +1 -1
- package/src/hooks/useLinkAccount.ts +18 -5
- package/src/hooks/usePortalApiClient.ts +6 -0
- package/src/hooks/useRefreshPassport.ts +56 -0
- package/src/hooks/useSignInWithDiscord.ts +14 -5
- package/src/hooks/useSignInWithWallet.ts +14 -42
- package/src/hooks/useSignOut.ts +18 -4
- package/src/hooks/useSignUpWithWallet.ts +21 -0
- package/src/hooks/useTokensBalances.ts +187 -0
- package/src/hooks/useUpdateMezoId.ts +19 -4
- package/src/hooks/useWalletAccount.ts +55 -0
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +9 -1
- package/src/lib/contracts/index.ts +88 -0
- package/src/provider.ts +30 -37
- package/src/stores/dropdownStore.ts +20 -0
- package/src/utils/address.test.ts +48 -0
- package/src/utils/address.ts +45 -0
- package/src/utils/cryptoAssets.test.ts +79 -0
- package/src/utils/cryptoAssets.ts +173 -0
- package/src/utils/currency.test.ts +38 -0
- package/src/utils/currency.ts +32 -0
- package/src/utils/numbers.test.ts +220 -0
- package/src/utils/numbers.ts +188 -0
|
@@ -1,30 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useQueryClient,
|
|
3
|
+
useMutation,
|
|
4
|
+
MutationOptions,
|
|
5
|
+
DefaultError,
|
|
6
|
+
} from "@tanstack/react-query"
|
|
2
7
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
|
-
import { CreateSessionRequest } from "../api
|
|
8
|
+
import type { CreateSessionRequest, CreateSessionResponse } from "../api"
|
|
4
9
|
import { QUERY_KEYS } from "./constants"
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* This hook is not exposed for external consumers. For creating session they
|
|
8
13
|
* should use `useSignIn` hook related to the authentication method.
|
|
9
14
|
*/
|
|
10
|
-
export function useCreateSession(
|
|
15
|
+
export function useCreateSession(
|
|
16
|
+
mutationOptions: Omit<
|
|
17
|
+
MutationOptions<CreateSessionResponse, DefaultError, CreateSessionRequest>,
|
|
18
|
+
"mutationFn" | "mutationKey"
|
|
19
|
+
> = {},
|
|
20
|
+
) {
|
|
11
21
|
const queryClient = useQueryClient()
|
|
12
22
|
const authApiClient = useAuthApiClient()
|
|
13
23
|
|
|
24
|
+
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
|
|
25
|
+
|
|
14
26
|
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
15
27
|
mutationFn: (createSessionRequest: CreateSessionRequest) =>
|
|
16
28
|
authApiClient.createSession(createSessionRequest),
|
|
17
|
-
onSuccess: () => {
|
|
18
|
-
// Since `getSession` query also has code in
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
// queries
|
|
29
|
+
onSuccess: (data, variables, context) => {
|
|
30
|
+
// Since `getSession` query also has code in its query keys we can't set
|
|
31
|
+
// query data for a specific query, because we don't know if the code was
|
|
32
|
+
// used or not. Because of that we just reset all getSession queries
|
|
22
33
|
queryClient.resetQueries({ queryKey: [QUERY_KEYS.SESSION] })
|
|
23
34
|
queryClient.resetQueries({
|
|
24
35
|
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
25
36
|
})
|
|
37
|
+
|
|
38
|
+
if (customOnSuccess) customOnSuccess(data, variables, context)
|
|
26
39
|
},
|
|
27
|
-
...
|
|
40
|
+
...restMutationOptions,
|
|
28
41
|
})
|
|
29
42
|
|
|
30
43
|
return { createSession: mutate, createSessionAsync: mutateAsync, ...rest }
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { useBalance } from "wagmi"
|
|
2
|
+
import { useGetCurrentAccount } from "."
|
|
3
|
+
import {
|
|
4
|
+
CryptoAssetKey,
|
|
5
|
+
isBitcoinLikeCryptoAsset,
|
|
6
|
+
mapCryptoAssetToDetails,
|
|
7
|
+
} from "../utils/cryptoAssets"
|
|
8
|
+
import { fromFixedPoint } from "../utils/numbers"
|
|
9
|
+
import useAssetsConversionRates from "./useAssetsConversionRates"
|
|
10
|
+
import useWalletAccount from "./useWalletAccount"
|
|
11
|
+
import { useTokensBalances } from "./useTokensBalances"
|
|
12
|
+
import { useBorrowData } from "./useBorrowData"
|
|
13
|
+
import { CHAIN_ID } from "../constants"
|
|
14
|
+
import { usePassportContext } from "./usePassportContext"
|
|
15
|
+
import { useWatchTransferEventsForAllTokens } from "./useWatchTransferEvents"
|
|
16
|
+
|
|
17
|
+
export type DropdownCryptoAsset<T = CryptoAssetKey> = {
|
|
18
|
+
type: T
|
|
19
|
+
balance: bigint
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DEFAULT_ASSET_DATA = {
|
|
23
|
+
rawBalance: 0n,
|
|
24
|
+
formattedBalance: "0.0000",
|
|
25
|
+
usdBalance: 0,
|
|
26
|
+
formattedUsdBalance: "$0.00",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Aggregates dropdown data for Dropdown component.
|
|
31
|
+
* @param {accountDataRefetchInterval: number, nativeBalanceRefetchInterval: number }
|
|
32
|
+
* Object containing refetch intervals time (in milliseconds) for account data
|
|
33
|
+
* (like mats or mezo id) and for native balance. After that time the specific
|
|
34
|
+
* value should be marked as stale and re-fetched. Default value for both is
|
|
35
|
+
* 90000 (90 secs).
|
|
36
|
+
* @returns Dropdown data.
|
|
37
|
+
* @dev This hook is for internal use only.
|
|
38
|
+
*/
|
|
39
|
+
export default function useDropdownData({
|
|
40
|
+
accountDataRefetchInterval = 90000,
|
|
41
|
+
nativeBalanceRefetchInterval = 90000,
|
|
42
|
+
}) {
|
|
43
|
+
const {
|
|
44
|
+
walletAddress,
|
|
45
|
+
accountAddress,
|
|
46
|
+
networkFamily: walletType,
|
|
47
|
+
} = useWalletAccount()
|
|
48
|
+
const { environment = "mainnet" } = usePassportContext()
|
|
49
|
+
const { data: btcBalance } = useBalance({
|
|
50
|
+
address: accountAddress,
|
|
51
|
+
chainId: CHAIN_ID[environment],
|
|
52
|
+
query: {
|
|
53
|
+
staleTime: nativeBalanceRefetchInterval,
|
|
54
|
+
refetchInterval: nativeBalanceRefetchInterval,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
const { data: passportAccount } = useGetCurrentAccount({
|
|
58
|
+
staleTime: accountDataRefetchInterval,
|
|
59
|
+
refetchInterval: accountDataRefetchInterval,
|
|
60
|
+
enabled: !!accountAddress,
|
|
61
|
+
})
|
|
62
|
+
const { data: assetsConversionRates } = useAssetsConversionRates()
|
|
63
|
+
const { data: tokensBalances } = useTokensBalances()
|
|
64
|
+
const { data: debt } = useBorrowData()
|
|
65
|
+
|
|
66
|
+
useWatchTransferEventsForAllTokens()
|
|
67
|
+
|
|
68
|
+
const mezoId = passportAccount?.mezoId
|
|
69
|
+
|
|
70
|
+
const detailedAssets = [
|
|
71
|
+
["BTC", btcBalance?.value ?? 0n],
|
|
72
|
+
...Object.entries(tokensBalances ?? {}),
|
|
73
|
+
].map((asset) => {
|
|
74
|
+
const [type, balance] = asset as [CryptoAssetKey, bigint]
|
|
75
|
+
|
|
76
|
+
let usdConversionRate: number | undefined
|
|
77
|
+
if (isBitcoinLikeCryptoAsset(type))
|
|
78
|
+
usdConversionRate = assetsConversionRates?.usd.btc
|
|
79
|
+
if (type === "mT") {
|
|
80
|
+
usdConversionRate = assetsConversionRates?.usd.t
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return mapCryptoAssetToDetails(type, balance, usdConversionRate || 1)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const btcData = detailedAssets.find(({ type }) => type === "BTC")!
|
|
87
|
+
const musdData = detailedAssets.find(({ type }) => type === "MUSD")!
|
|
88
|
+
const otherAssetsData = detailedAssets.filter(
|
|
89
|
+
({ type }) => !["BTC", "MUSD"].includes(type),
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
const otherAssetsCount = otherAssetsData.filter(
|
|
93
|
+
(asset) => asset.rawBalance !== 0n,
|
|
94
|
+
).length
|
|
95
|
+
|
|
96
|
+
const assets = {
|
|
97
|
+
btc: btcData || {
|
|
98
|
+
type: "BTC",
|
|
99
|
+
...DEFAULT_ASSET_DATA,
|
|
100
|
+
},
|
|
101
|
+
musd: musdData || {
|
|
102
|
+
type: "mUSD",
|
|
103
|
+
...DEFAULT_ASSET_DATA,
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const otherAssetsUsdTotal = otherAssetsData.reduce(
|
|
108
|
+
(sum, { usdBalance }) => sum + usdBalance,
|
|
109
|
+
0,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
const usdTotalBalance = detailedAssets.reduce(
|
|
113
|
+
(sum, { usdBalance }) => sum + usdBalance,
|
|
114
|
+
0,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
const matsBalance = passportAccount?.mats.totalMats || 0
|
|
118
|
+
|
|
119
|
+
const usdCollateral = fromFixedPoint(
|
|
120
|
+
(debt?.collateral ?? 0n) * BigInt(assetsConversionRates?.usd.btc ?? 0),
|
|
121
|
+
18,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
const usdTroveDebt = fromFixedPoint(debt?.troveDebt ?? 0n, 18)
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
mezoId,
|
|
128
|
+
matsBalance,
|
|
129
|
+
accountAddress,
|
|
130
|
+
walletAddress,
|
|
131
|
+
walletType,
|
|
132
|
+
usdTotalBalance,
|
|
133
|
+
usdTroveDebt,
|
|
134
|
+
usdCollateral,
|
|
135
|
+
assets,
|
|
136
|
+
otherAssetsCount,
|
|
137
|
+
otherAssetsUsdTotal,
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -2,12 +2,12 @@ import { useQuery, skipToken, UseBaseQueryOptions } from "@tanstack/react-query"
|
|
|
2
2
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
3
|
import { QUERY_KEYS } from "./constants"
|
|
4
4
|
import { ONE_MINUTE_MS } from "../utils/time"
|
|
5
|
-
import { GetAccountByMezoIdOrAddressResponse } from "../api
|
|
5
|
+
import type { GetAccountByMezoIdOrAddressResponse } from "../api"
|
|
6
6
|
|
|
7
7
|
export function useGetAccountByAddress(
|
|
8
8
|
address?: string,
|
|
9
9
|
queryOptions: Omit<
|
|
10
|
-
UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse>,
|
|
10
|
+
UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse | null>,
|
|
11
11
|
"queryKey" | "queryFn"
|
|
12
12
|
> = {},
|
|
13
13
|
) {
|
|
@@ -2,12 +2,12 @@ import { useQuery, skipToken, UseBaseQueryOptions } from "@tanstack/react-query"
|
|
|
2
2
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
3
|
import { QUERY_KEYS } from "./constants"
|
|
4
4
|
import { ONE_MINUTE_MS } from "../utils/time"
|
|
5
|
-
import { GetAccountByMezoIdOrAddressResponse } from "../api
|
|
5
|
+
import type { GetAccountByMezoIdOrAddressResponse } from "../api"
|
|
6
6
|
|
|
7
7
|
export function useGetAccountByMezoId(
|
|
8
8
|
mezoId?: string,
|
|
9
9
|
queryOptions: Omit<
|
|
10
|
-
UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse>,
|
|
10
|
+
UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse | null>,
|
|
11
11
|
"queryKey" | "queryFn"
|
|
12
12
|
> = {},
|
|
13
13
|
) {
|
|
@@ -1,20 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
|
-
import { QUERY_KEYS } from "./constants"
|
|
1
|
+
import { UseBaseQueryOptions, useQuery } from "@tanstack/react-query"
|
|
4
2
|
import { ONE_MINUTE_MS } from "../utils/time"
|
|
5
|
-
import {
|
|
3
|
+
import { QUERY_KEYS } from "./constants"
|
|
4
|
+
import { useAuthApiClient } from "./useAuthApiClient"
|
|
5
|
+
import { usePortalApiClient } from "./usePortalApiClient"
|
|
6
|
+
import type { GetCurrentAccountResponse } from "../api"
|
|
7
|
+
|
|
8
|
+
type GetCurrentAccountResponseWithMats = GetCurrentAccountResponse & {
|
|
9
|
+
mats: {
|
|
10
|
+
totalMats: number
|
|
11
|
+
}
|
|
12
|
+
}
|
|
6
13
|
|
|
7
14
|
export function useGetCurrentAccount(
|
|
8
15
|
queryOptions: Omit<
|
|
9
|
-
UseBaseQueryOptions<
|
|
16
|
+
UseBaseQueryOptions<GetCurrentAccountResponseWithMats>,
|
|
10
17
|
"queryKey" | "queryFn"
|
|
11
18
|
> = {},
|
|
12
19
|
) {
|
|
13
20
|
const authApiClient = useAuthApiClient()
|
|
21
|
+
const portalApiClient = usePortalApiClient()
|
|
14
22
|
|
|
15
23
|
return useQuery({
|
|
16
24
|
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
17
|
-
queryFn: () =>
|
|
25
|
+
queryFn: async () => {
|
|
26
|
+
const currentAccount = await authApiClient.getCurrentAccount()
|
|
27
|
+
const linkedWallets = currentAccount?.linkedAccounts?.filter(
|
|
28
|
+
(account) => account.type === "wallet",
|
|
29
|
+
)
|
|
30
|
+
if (!linkedWallets || linkedWallets.length === 0) {
|
|
31
|
+
return {
|
|
32
|
+
...currentAccount,
|
|
33
|
+
mats: {
|
|
34
|
+
totalMats: 0,
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const addresses = linkedWallets.map(
|
|
40
|
+
(account) => account.btcAddress || account.evmAddress,
|
|
41
|
+
)
|
|
42
|
+
const mats = await Promise.all(
|
|
43
|
+
addresses.map((address) => portalApiClient.getPortalMats(address)),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
const totalMats = mats.reduce(
|
|
47
|
+
(sumMats, currentMats) => sumMats + currentMats.totalMats,
|
|
48
|
+
0,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
...currentAccount,
|
|
53
|
+
mats: {
|
|
54
|
+
totalMats,
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
},
|
|
18
58
|
staleTime: ONE_MINUTE_MS,
|
|
19
59
|
retry: 1,
|
|
20
60
|
...queryOptions,
|
|
@@ -2,7 +2,7 @@ import { useQuery, UseBaseQueryOptions } from "@tanstack/react-query"
|
|
|
2
2
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
3
|
import { QUERY_KEYS } from "./constants"
|
|
4
4
|
import { ONE_MINUTE_MS } from "../utils/time"
|
|
5
|
-
import { GetSessionResponse } from "../api
|
|
5
|
+
import type { GetSessionResponse } from "../api"
|
|
6
6
|
|
|
7
7
|
export function useGetSession(
|
|
8
8
|
code?: string,
|
|
@@ -1,19 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useQueryClient,
|
|
3
|
+
useMutation,
|
|
4
|
+
MutationOptions,
|
|
5
|
+
DefaultError,
|
|
6
|
+
} from "@tanstack/react-query"
|
|
2
7
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
|
-
import { LinkAccountRequest } from "../api
|
|
8
|
+
import type { LinkAccountRequest, LinkAccountResponse } from "../api"
|
|
4
9
|
import { QUERY_KEYS } from "./constants"
|
|
5
10
|
|
|
6
|
-
export function useLinkAccount(
|
|
11
|
+
export function useLinkAccount(
|
|
12
|
+
mutationOptions: Omit<
|
|
13
|
+
MutationOptions<LinkAccountResponse, DefaultError, LinkAccountRequest>,
|
|
14
|
+
"mutationFn" | "mutationKey"
|
|
15
|
+
> = {},
|
|
16
|
+
) {
|
|
7
17
|
const queryClient = useQueryClient()
|
|
8
18
|
const authApiClient = useAuthApiClient()
|
|
9
19
|
|
|
20
|
+
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
|
|
21
|
+
|
|
10
22
|
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
11
23
|
mutationFn: (linkAccountRequest: LinkAccountRequest) =>
|
|
12
24
|
authApiClient.linkAccount(linkAccountRequest),
|
|
13
|
-
onSuccess: () => {
|
|
25
|
+
onSuccess: (data, variables, context) => {
|
|
14
26
|
queryClient.resetQueries({ queryKey: [QUERY_KEYS.ACCOUNT] })
|
|
27
|
+
if (customOnSuccess) customOnSuccess(data, variables, context)
|
|
15
28
|
},
|
|
16
|
-
...
|
|
29
|
+
...restMutationOptions,
|
|
17
30
|
})
|
|
18
31
|
|
|
19
32
|
return { linkAccount: mutate, linkAccountAsync: mutateAsync, ...rest }
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
2
|
+
import { useCallback } from "react"
|
|
3
|
+
import { useAccount, useBalance } from "wagmi"
|
|
4
|
+
import { QUERY_KEYS } from "./constants"
|
|
5
|
+
import { useInvalidateBorrowData } from "./useBorrowData"
|
|
6
|
+
import { useInvalidateTokensBalances } from "./useTokensBalances"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hook to refresh the passport using query invalidation mechanism.
|
|
10
|
+
* By calling the refresh function, the latest data will be refetched as soon as possible.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const { refreshCurrentAccount, refreshUsdConversion } = useRefreshPassport()
|
|
14
|
+
*
|
|
15
|
+
* // Call this function to refresh the current account
|
|
16
|
+
* const handlerefreshCurrentAccount = async () => {
|
|
17
|
+
* await refreshCurrentAccount()
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
export function useRefreshPassport() {
|
|
21
|
+
const { address } = useAccount()
|
|
22
|
+
const queryClient = useQueryClient()
|
|
23
|
+
const { invalidateBorrowData } = useInvalidateBorrowData()
|
|
24
|
+
const { invalidateTokensBalances } = useInvalidateTokensBalances()
|
|
25
|
+
const { queryKey: nativeTokenQueryKey } = useBalance({ address })
|
|
26
|
+
|
|
27
|
+
const refreshCurrentAccount = useCallback(
|
|
28
|
+
() =>
|
|
29
|
+
queryClient.invalidateQueries({
|
|
30
|
+
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
31
|
+
}),
|
|
32
|
+
[queryClient],
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const refreshUsdConversion = useCallback(
|
|
36
|
+
() =>
|
|
37
|
+
queryClient.invalidateQueries({
|
|
38
|
+
queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
|
|
39
|
+
}),
|
|
40
|
+
[queryClient],
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const refreshTokensBalances = useCallback(async () => {
|
|
44
|
+
await queryClient.invalidateQueries({
|
|
45
|
+
queryKey: nativeTokenQueryKey,
|
|
46
|
+
})
|
|
47
|
+
await invalidateTokensBalances()
|
|
48
|
+
}, [queryClient, nativeTokenQueryKey, invalidateTokensBalances])
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
refreshCurrentAccount,
|
|
52
|
+
refreshUsdConversion,
|
|
53
|
+
refreshBorrowData: invalidateBorrowData,
|
|
54
|
+
refreshTokensBalances,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
import { useMutation } from "@tanstack/react-query"
|
|
1
|
+
import { MutationOptions, useMutation } from "@tanstack/react-query"
|
|
2
2
|
import { useCreateSession } from "./useCreateSession"
|
|
3
3
|
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce"
|
|
4
|
+
import type { AuthenticationProviderRedirectResponse } from "../api"
|
|
4
5
|
|
|
5
|
-
function useSignInWithDiscord(
|
|
6
|
+
function useSignInWithDiscord(
|
|
7
|
+
mutationOptions: Omit<
|
|
8
|
+
MutationOptions<AuthenticationProviderRedirectResponse>,
|
|
9
|
+
"mutationFn" | "mutationKey"
|
|
10
|
+
> = {},
|
|
11
|
+
) {
|
|
6
12
|
const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce()
|
|
7
13
|
const { createSessionAsync } = useCreateSession()
|
|
8
14
|
|
|
9
15
|
const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
|
|
10
|
-
mutationFn: async () => {
|
|
16
|
+
mutationFn: async (): Promise<AuthenticationProviderRedirectResponse> => {
|
|
11
17
|
await ensureNoSessionAndFetchNonce()
|
|
12
18
|
|
|
13
|
-
return createSessionAsync({
|
|
19
|
+
return (await createSessionAsync({
|
|
14
20
|
type: "discord",
|
|
15
|
-
})
|
|
21
|
+
})) as AuthenticationProviderRedirectResponse
|
|
22
|
+
// ^ By passing type: "discord" we know for sure the return type is
|
|
23
|
+
// AuthenticationProviderRedirectResponse
|
|
16
24
|
},
|
|
25
|
+
...mutationOptions,
|
|
17
26
|
})
|
|
18
27
|
|
|
19
28
|
return {
|
|
@@ -1,48 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useCreateSession } from "./useCreateSession"
|
|
5
|
-
import { createSignInWithWalletMessage } from "../utils/siww"
|
|
6
|
-
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce"
|
|
1
|
+
import { MutationOptions } from "@tanstack/react-query"
|
|
2
|
+
import { useAuthenticateWithWallet } from "./useAuthenticateWithWallet"
|
|
3
|
+
import type { Session } from "../api"
|
|
7
4
|
|
|
8
|
-
function useSignInWithWallet(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
mutationFn: async () => {
|
|
17
|
-
if (!address) {
|
|
18
|
-
throw new Error("Sign in error: Wallet not connected!")
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const nonce = await ensureNoSessionAndFetchNonce()
|
|
22
|
-
|
|
23
|
-
const networkFamily = btcAddress ? "bitcoin" : "evm"
|
|
24
|
-
const messageResult = createSignInWithWalletMessage(
|
|
25
|
-
btcAddress ? btcAddress! : address!,
|
|
26
|
-
nonce,
|
|
27
|
-
networkFamily,
|
|
28
|
-
chainId,
|
|
29
|
-
)
|
|
30
|
-
const signatureResult = await signMessageAsync({
|
|
31
|
-
message: messageResult,
|
|
32
|
-
connector,
|
|
33
|
-
})
|
|
34
|
-
return createSessionAsync({
|
|
35
|
-
type: "wallet",
|
|
36
|
-
message: messageResult,
|
|
37
|
-
signature: signatureResult,
|
|
38
|
-
})
|
|
39
|
-
},
|
|
40
|
-
})
|
|
5
|
+
function useSignInWithWallet(
|
|
6
|
+
mutationOptions: Omit<
|
|
7
|
+
MutationOptions<Session>,
|
|
8
|
+
"mutationFn" | "mutationKey"
|
|
9
|
+
> = {},
|
|
10
|
+
) {
|
|
11
|
+
const { authenticateWithWallet, authenticateWithWalletAsync, ...rest } =
|
|
12
|
+
useAuthenticateWithWallet(false, mutationOptions)
|
|
41
13
|
|
|
42
14
|
return {
|
|
43
|
-
signInWithWallet:
|
|
44
|
-
signInWithWalletAsync:
|
|
45
|
-
...
|
|
15
|
+
signInWithWallet: authenticateWithWallet,
|
|
16
|
+
signInWithWalletAsync: authenticateWithWalletAsync,
|
|
17
|
+
...rest,
|
|
46
18
|
}
|
|
47
19
|
}
|
|
48
20
|
|
package/src/hooks/useSignOut.ts
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
MutationOptions,
|
|
3
|
+
useMutation,
|
|
4
|
+
useQueryClient,
|
|
5
|
+
} from "@tanstack/react-query"
|
|
2
6
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
7
|
import { QUERY_KEYS } from "./constants"
|
|
8
|
+
import type { DeleteSessionResponse } from "../api"
|
|
4
9
|
|
|
5
|
-
export function useSignOut(
|
|
10
|
+
export function useSignOut(
|
|
11
|
+
mutationOptions: Omit<
|
|
12
|
+
MutationOptions<DeleteSessionResponse>,
|
|
13
|
+
"mutationFn" | "mutationKey"
|
|
14
|
+
> = {},
|
|
15
|
+
) {
|
|
6
16
|
const queryClient = useQueryClient()
|
|
7
17
|
const authApiClient = useAuthApiClient()
|
|
8
18
|
|
|
19
|
+
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
|
|
20
|
+
|
|
9
21
|
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
10
22
|
mutationFn: () => authApiClient.deleteSession(),
|
|
11
|
-
onSuccess: () => {
|
|
23
|
+
onSuccess: (data, variables, context) => {
|
|
12
24
|
queryClient.resetQueries({ queryKey: [QUERY_KEYS.SESSION] })
|
|
13
25
|
queryClient.resetQueries({
|
|
14
26
|
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
15
27
|
})
|
|
28
|
+
|
|
29
|
+
if (customOnSuccess) customOnSuccess(data, variables, context)
|
|
16
30
|
},
|
|
17
|
-
...
|
|
31
|
+
...restMutationOptions,
|
|
18
32
|
})
|
|
19
33
|
|
|
20
34
|
return { signOut: mutate, signOutAsync: mutateAsync, ...rest }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MutationOptions } from "@tanstack/react-query"
|
|
2
|
+
import { useAuthenticateWithWallet } from "./useAuthenticateWithWallet"
|
|
3
|
+
import type { Session } from "../api"
|
|
4
|
+
|
|
5
|
+
function useSignUpWithWallet(
|
|
6
|
+
mutationOptions: Omit<
|
|
7
|
+
MutationOptions<Session>,
|
|
8
|
+
"mutationFn" | "mutationKey"
|
|
9
|
+
> = {},
|
|
10
|
+
) {
|
|
11
|
+
const { authenticateWithWallet, authenticateWithWalletAsync, ...rest } =
|
|
12
|
+
useAuthenticateWithWallet(true, mutationOptions)
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
signUpWithWallet: authenticateWithWallet,
|
|
16
|
+
signUpWithWalletAsync: authenticateWithWalletAsync,
|
|
17
|
+
...rest,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { useSignUpWithWallet }
|