@mezo-org/passport 0.4.0-dev.0 → 0.4.0-dev.10
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/dist/src/api/auth.d.ts +78 -0
- package/dist/src/api/auth.d.ts.map +1 -0
- package/dist/src/api/auth.js +77 -0
- package/dist/src/api/auth.js.map +1 -0
- 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 +32 -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/AccountAddress.d.ts +8 -0
- package/dist/src/components/Dropdown/AccountAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/AccountAddress.js +66 -0
- package/dist/src/components/Dropdown/AccountAddress.js.map +1 -0
- package/dist/src/components/Dropdown/AccountAssets.d.ts +14 -0
- package/dist/src/components/Dropdown/AccountAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/AccountAssets.js +44 -0
- package/dist/src/components/Dropdown/AccountAssets.js.map +1 -0
- package/dist/src/components/Dropdown/AccountBalance.d.ts +7 -0
- package/dist/src/components/Dropdown/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/AccountBalance.js +18 -0
- package/dist/src/components/Dropdown/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +7 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js +30 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Content.d.ts +9 -0
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Content.js +69 -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 +20 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.js +64 -0
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts +8 -0
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/WelcomeBlock.js +44 -0
- package/dist/src/components/Dropdown/WelcomeBlock.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/hooks/constants.d.ts +7 -0
- package/dist/src/hooks/constants.d.ts.map +1 -0
- package/dist/src/hooks/constants.js +7 -0
- package/dist/src/hooks/constants.js.map +1 -0
- package/dist/src/hooks/index.d.ts +10 -0
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +10 -0
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsUSDConversion.d.ts +8 -0
- package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsUSDConversion.js +21 -0
- package/dist/src/hooks/useAssetsUSDConversion.js.map +1 -0
- package/dist/src/hooks/useAuthApiClient.d.ts +2 -0
- package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -0
- package/dist/src/hooks/useAuthApiClient.js +6 -0
- package/dist/src/hooks/useAuthApiClient.js.map +1 -0
- 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/useCreateAccount.d.ts +108 -0
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -0
- package/dist/src/hooks/useCreateAccount.js +21 -0
- package/dist/src/hooks/useCreateAccount.js.map +1 -0
- package/dist/src/hooks/useCreateSession.d.ts +76 -0
- package/dist/src/hooks/useCreateSession.d.ts.map +1 -0
- package/dist/src/hooks/useCreateSession.js +29 -0
- package/dist/src/hooks/useCreateSession.js.map +1 -0
- package/dist/src/hooks/useDropdownData.d.ts +45 -0
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
- package/dist/src/hooks/useDropdownData.js +74 -0
- package/dist/src/hooks/useDropdownData.js.map +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts +5 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts.map +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js +34 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js.map +1 -0
- package/dist/src/hooks/useGetAccountByAddress.d.ts +4 -0
- package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -0
- package/dist/src/hooks/useGetAccountByAddress.js +17 -0
- package/dist/src/hooks/useGetAccountByAddress.js.map +1 -0
- package/dist/src/hooks/useGetAccountByMezoId.d.ts +4 -0
- package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -0
- package/dist/src/hooks/useGetAccountByMezoId.js +17 -0
- package/dist/src/hooks/useGetAccountByMezoId.js.map +1 -0
- package/dist/src/hooks/useGetCurrentAccount.d.ts +18 -0
- package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -0
- package/dist/src/hooks/useGetCurrentAccount.js +37 -0
- package/dist/src/hooks/useGetCurrentAccount.js.map +1 -0
- package/dist/src/hooks/useGetSession.d.ts +4 -0
- package/dist/src/hooks/useGetSession.d.ts.map +1 -0
- package/dist/src/hooks/useGetSession.js +15 -0
- package/dist/src/hooks/useGetSession.js.map +1 -0
- package/dist/src/hooks/useLinkAccount.d.ts +72 -0
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -0
- package/dist/src/hooks/useLinkAccount.js +19 -0
- package/dist/src/hooks/useLinkAccount.js.map +1 -0
- package/dist/src/hooks/usePassportContext.d.ts +3 -0
- package/dist/src/hooks/usePassportContext.d.ts.map +1 -0
- package/dist/src/hooks/usePassportContext.js +10 -0
- package/dist/src/hooks/usePassportContext.js.map +1 -0
- 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/useSignInWithDiscord.d.ts +73 -0
- package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -0
- package/dist/src/hooks/useSignInWithDiscord.js +25 -0
- package/dist/src/hooks/useSignInWithDiscord.js.map +1 -0
- package/dist/src/hooks/useSignInWithWallet.d.ts +73 -0
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -0
- package/dist/src/hooks/useSignInWithWallet.js +11 -0
- package/dist/src/hooks/useSignInWithWallet.js.map +1 -0
- package/dist/src/hooks/useSignOut.d.ts +72 -0
- package/dist/src/hooks/useSignOut.d.ts.map +1 -0
- package/dist/src/hooks/useSignOut.js +22 -0
- package/dist/src/hooks/useSignOut.js.map +1 -0
- 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/useUpdateMezoId.d.ts +108 -0
- package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -0
- package/dist/src/hooks/useUpdateMezoId.js +19 -0
- package/dist/src/hooks/useUpdateMezoId.js.map +1 -0
- package/dist/src/hooks/useWalletAccount.d.ts +12 -0
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
- package/dist/src/hooks/useWalletAccount.js +28 -0
- package/dist/src/hooks/useWalletAccount.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/provider.d.ts +17 -0
- package/dist/src/provider.d.ts.map +1 -0
- package/dist/src/provider.js +16 -0
- package/dist/src/provider.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 +35 -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 +32 -0
- package/dist/src/utils/address.test.js.map +1 -0
- package/dist/src/utils/cryptoAssets.d.ts +28 -0
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.js +73 -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 +50 -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 +26 -0
- package/dist/src/utils/numbers.d.ts.map +1 -0
- package/dist/src/utils/numbers.js +40 -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 +54 -0
- package/dist/src/utils/numbers.test.js.map +1 -0
- package/dist/src/utils/siww.d.ts +4 -0
- package/dist/src/utils/siww.d.ts.map +1 -0
- package/dist/src/utils/siww.js +19 -0
- package/dist/src/utils/siww.js.map +1 -0
- package/dist/src/utils/time.d.ts +5 -0
- package/dist/src/utils/time.d.ts.map +1 -0
- package/dist/src/utils/time.js +5 -0
- package/dist/src/utils/time.js.map +1 -0
- package/package.json +13 -5
- package/src/api/auth.ts +178 -0
- 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 +56 -0
- package/src/assets/DefaultAvatar.tsx +74 -0
- package/src/components/Dropdown/AccountAddress.tsx +130 -0
- package/src/components/Dropdown/AccountAssets.tsx +110 -0
- package/src/components/Dropdown/AccountBalance.tsx +38 -0
- package/src/components/Dropdown/ConnectedTrigger.tsx +56 -0
- package/src/components/Dropdown/Content.tsx +148 -0
- package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
- package/src/components/Dropdown/Dropdown.tsx +111 -0
- package/src/components/Dropdown/README.md +51 -0
- package/src/components/Dropdown/WelcomeBlock.tsx +92 -0
- package/src/components/Dropdown/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/hooks/constants.ts +6 -0
- package/src/hooks/index.ts +10 -0
- package/src/hooks/useAssetsUSDConversion.ts +31 -0
- package/src/hooks/useAuthApiClient.ts +6 -0
- package/src/hooks/useAuthenticateWithWallet.ts +98 -0
- package/src/hooks/useCreateAccount.ts +36 -0
- package/src/hooks/useCreateSession.ts +44 -0
- package/src/hooks/useDropdownData.ts +131 -0
- package/src/hooks/useEnsureNoSessionAndFetchNonce.ts +46 -0
- package/src/hooks/useGetAccountByAddress.ts +25 -0
- package/src/hooks/useGetAccountByMezoId.ts +25 -0
- package/src/hooks/useGetCurrentAccount.ts +62 -0
- package/src/hooks/useGetSession.ts +22 -0
- package/src/hooks/useLinkAccount.ts +33 -0
- package/src/hooks/usePassportContext.ts +11 -0
- package/src/hooks/usePortalApiClient.ts +6 -0
- package/src/hooks/useSignInWithDiscord.ts +35 -0
- package/src/hooks/useSignInWithWallet.ts +21 -0
- package/src/hooks/useSignOut.ts +35 -0
- package/src/hooks/useSignUpWithWallet.ts +21 -0
- package/src/hooks/useUpdateMezoId.ts +33 -0
- package/src/hooks/useWalletAccount.ts +53 -0
- package/src/index.ts +2 -0
- package/src/provider.ts +50 -0
- package/src/utils/address.test.ts +38 -0
- package/src/utils/address.ts +43 -0
- package/src/utils/cryptoAssets.test.ts +61 -0
- package/src/utils/cryptoAssets.ts +93 -0
- package/src/utils/currency.test.ts +38 -0
- package/src/utils/currency.ts +32 -0
- package/src/utils/numbers.test.ts +73 -0
- package/src/utils/numbers.ts +55 -0
- package/src/utils/siww.ts +31 -0
- package/src/utils/time.ts +4 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useSignMessage } from "wagmi";
|
|
2
|
+
import { useMutation } from "@tanstack/react-query";
|
|
3
|
+
import { useCreateAccount } from "./useCreateAccount";
|
|
4
|
+
import { useCreateSession } from "./useCreateSession";
|
|
5
|
+
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce";
|
|
6
|
+
import { createSignInWithWalletMessage } from "../utils/siww";
|
|
7
|
+
import { useGetAccountByAddress } from "./useGetAccountByAddress";
|
|
8
|
+
import useWalletAccount from "./useWalletAccount";
|
|
9
|
+
function useAuthenticateWithWallet(shouldCreateAccount = false, mutationOptions = {}) {
|
|
10
|
+
const { address, chainId, connector, networkFamily } = useWalletAccount();
|
|
11
|
+
const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce();
|
|
12
|
+
const { createSessionAsync } = useCreateSession();
|
|
13
|
+
const { createAccountAsync } = useCreateAccount();
|
|
14
|
+
const { signMessageAsync } = useSignMessage();
|
|
15
|
+
const { refetch: getAccountByAddress } = useGetAccountByAddress(address, {
|
|
16
|
+
enabled: false,
|
|
17
|
+
retry: false,
|
|
18
|
+
});
|
|
19
|
+
const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
|
|
20
|
+
mutationFn: async () => {
|
|
21
|
+
if (!address) {
|
|
22
|
+
throw new Error("Sign in error: Wallet not connected!");
|
|
23
|
+
}
|
|
24
|
+
const nonce = await ensureNoSessionAndFetchNonce();
|
|
25
|
+
const messageResult = createSignInWithWalletMessage(address, nonce, networkFamily, chainId);
|
|
26
|
+
const signatureResult = await signMessageAsync({
|
|
27
|
+
message: messageResult,
|
|
28
|
+
connector,
|
|
29
|
+
});
|
|
30
|
+
if (shouldCreateAccount) {
|
|
31
|
+
const getAccountByAddressResult = await getAccountByAddress();
|
|
32
|
+
if (getAccountByAddressResult.data) {
|
|
33
|
+
throw new Error("Wallet authentication failed: Account creation failed. Account already exists.");
|
|
34
|
+
}
|
|
35
|
+
if (getAccountByAddressResult.error) {
|
|
36
|
+
throw new Error(`Wallet authentication failed: Account creation failed. Could not verify if account already exists: ${getAccountByAddressResult.error}`);
|
|
37
|
+
}
|
|
38
|
+
// Fetch was successful, but no account was found
|
|
39
|
+
try {
|
|
40
|
+
const createAccountResult = await createAccountAsync({
|
|
41
|
+
type: "wallet",
|
|
42
|
+
message: messageResult,
|
|
43
|
+
signature: signatureResult,
|
|
44
|
+
});
|
|
45
|
+
if (!createAccountResult) {
|
|
46
|
+
throw new Error("Failed to create new account");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw new Error(`Wallet authentication failed: Account creation failed: ${error}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return (await createSessionAsync({
|
|
54
|
+
type: "wallet",
|
|
55
|
+
message: messageResult,
|
|
56
|
+
signature: signatureResult,
|
|
57
|
+
}));
|
|
58
|
+
// ^ By passing type: "wallet" we know for sure the return type is Session
|
|
59
|
+
},
|
|
60
|
+
...mutationOptions,
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
authenticateWithWallet: mutate,
|
|
64
|
+
authenticateWithWalletAsync: mutateAsync,
|
|
65
|
+
...signInMutationRestParameters,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export { useAuthenticateWithWallet };
|
|
69
|
+
//# sourceMappingURL=useAuthenticateWithWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuthenticateWithWallet.js","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { MutationOptions, DefaultError } from "@tanstack/react-query";
|
|
2
|
+
import type { CreateAccountRequest, CreateAccountResponse } from "../api";
|
|
3
|
+
export declare function useCreateAccount(mutationOptions?: Omit<MutationOptions<CreateAccountResponse, DefaultError, CreateAccountRequest>, "mutationFn" | "mutationKey">): {
|
|
4
|
+
data: undefined;
|
|
5
|
+
variables: undefined;
|
|
6
|
+
error: null;
|
|
7
|
+
isError: false;
|
|
8
|
+
isIdle: true;
|
|
9
|
+
isPending: false;
|
|
10
|
+
isSuccess: false;
|
|
11
|
+
status: "idle";
|
|
12
|
+
reset: () => void;
|
|
13
|
+
context: unknown;
|
|
14
|
+
failureCount: number;
|
|
15
|
+
failureReason: Error | null;
|
|
16
|
+
isPaused: boolean;
|
|
17
|
+
submittedAt: number;
|
|
18
|
+
createAccount: import("@tanstack/react-query").UseMutateFunction<{
|
|
19
|
+
mezoId: string;
|
|
20
|
+
hasModifiedMezoId: boolean;
|
|
21
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
22
|
+
}, Error, CreateAccountRequest, unknown>;
|
|
23
|
+
createAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
24
|
+
mezoId: string;
|
|
25
|
+
hasModifiedMezoId: boolean;
|
|
26
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
27
|
+
}, Error, CreateAccountRequest, unknown>;
|
|
28
|
+
} | {
|
|
29
|
+
data: undefined;
|
|
30
|
+
variables: CreateAccountRequest;
|
|
31
|
+
error: null;
|
|
32
|
+
isError: false;
|
|
33
|
+
isIdle: false;
|
|
34
|
+
isPending: true;
|
|
35
|
+
isSuccess: false;
|
|
36
|
+
status: "pending";
|
|
37
|
+
reset: () => void;
|
|
38
|
+
context: unknown;
|
|
39
|
+
failureCount: number;
|
|
40
|
+
failureReason: Error | null;
|
|
41
|
+
isPaused: boolean;
|
|
42
|
+
submittedAt: number;
|
|
43
|
+
createAccount: import("@tanstack/react-query").UseMutateFunction<{
|
|
44
|
+
mezoId: string;
|
|
45
|
+
hasModifiedMezoId: boolean;
|
|
46
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
47
|
+
}, Error, CreateAccountRequest, unknown>;
|
|
48
|
+
createAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
49
|
+
mezoId: string;
|
|
50
|
+
hasModifiedMezoId: boolean;
|
|
51
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
52
|
+
}, Error, CreateAccountRequest, unknown>;
|
|
53
|
+
} | {
|
|
54
|
+
data: undefined;
|
|
55
|
+
error: Error;
|
|
56
|
+
variables: CreateAccountRequest;
|
|
57
|
+
isError: true;
|
|
58
|
+
isIdle: false;
|
|
59
|
+
isPending: false;
|
|
60
|
+
isSuccess: false;
|
|
61
|
+
status: "error";
|
|
62
|
+
reset: () => void;
|
|
63
|
+
context: unknown;
|
|
64
|
+
failureCount: number;
|
|
65
|
+
failureReason: Error | null;
|
|
66
|
+
isPaused: boolean;
|
|
67
|
+
submittedAt: number;
|
|
68
|
+
createAccount: import("@tanstack/react-query").UseMutateFunction<{
|
|
69
|
+
mezoId: string;
|
|
70
|
+
hasModifiedMezoId: boolean;
|
|
71
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
72
|
+
}, Error, CreateAccountRequest, unknown>;
|
|
73
|
+
createAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
74
|
+
mezoId: string;
|
|
75
|
+
hasModifiedMezoId: boolean;
|
|
76
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
77
|
+
}, Error, CreateAccountRequest, unknown>;
|
|
78
|
+
} | {
|
|
79
|
+
data: {
|
|
80
|
+
mezoId: string;
|
|
81
|
+
hasModifiedMezoId: boolean;
|
|
82
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
83
|
+
};
|
|
84
|
+
error: null;
|
|
85
|
+
variables: CreateAccountRequest;
|
|
86
|
+
isError: false;
|
|
87
|
+
isIdle: false;
|
|
88
|
+
isPending: false;
|
|
89
|
+
isSuccess: true;
|
|
90
|
+
status: "success";
|
|
91
|
+
reset: () => void;
|
|
92
|
+
context: unknown;
|
|
93
|
+
failureCount: number;
|
|
94
|
+
failureReason: Error | null;
|
|
95
|
+
isPaused: boolean;
|
|
96
|
+
submittedAt: number;
|
|
97
|
+
createAccount: import("@tanstack/react-query").UseMutateFunction<{
|
|
98
|
+
mezoId: string;
|
|
99
|
+
hasModifiedMezoId: boolean;
|
|
100
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
101
|
+
}, Error, CreateAccountRequest, unknown>;
|
|
102
|
+
createAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
103
|
+
mezoId: string;
|
|
104
|
+
hasModifiedMezoId: boolean;
|
|
105
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
106
|
+
}, Error, CreateAccountRequest, unknown>;
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=useCreateAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCreateAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EACf,YAAY,EACb,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAA;AAEzE,wBAAgB,gBAAgB,CAC9B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,qBAAqB,EAAE,YAAY,EAAE,oBAAoB,CAAC,EAC1E,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqBP"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useQueryClient, useMutation, } from "@tanstack/react-query";
|
|
2
|
+
import { useAuthApiClient } from "./useAuthApiClient";
|
|
3
|
+
import { QUERY_KEYS } from "./constants";
|
|
4
|
+
export function useCreateAccount(mutationOptions = {}) {
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
const authApiClient = useAuthApiClient();
|
|
7
|
+
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions;
|
|
8
|
+
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
9
|
+
mutationFn: (createAccountRequest) => authApiClient.createAccount(createAccountRequest),
|
|
10
|
+
onSuccess: (data, variables, context) => {
|
|
11
|
+
queryClient.resetQueries({
|
|
12
|
+
queryKey: [QUERY_KEYS.ACCOUNT],
|
|
13
|
+
});
|
|
14
|
+
if (customOnSuccess)
|
|
15
|
+
customOnSuccess(data, variables, context);
|
|
16
|
+
},
|
|
17
|
+
...restMutationOptions,
|
|
18
|
+
});
|
|
19
|
+
return { createAccount: mutate, createAccountAsync: mutateAsync, ...rest };
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=useCreateAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateAccount.js","sourceRoot":"","sources":["../../../src/hooks/useCreateAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,WAAW,GAGZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC,MAAM,UAAU,gBAAgB,CAC9B,kBAGI,EAAE;IAEN,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,mBAAmB,EAAE,GAAG,eAAe,CAAA;IAE9E,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,WAAW,CAAC;QACnD,UAAU,EAAE,CAAC,oBAA0C,EAAE,EAAE,CACzD,aAAa,CAAC,aAAa,CAAC,oBAAoB,CAAC;QACnD,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;YACtC,WAAW,CAAC,YAAY,CAAC;gBACvB,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;aAC/B,CAAC,CAAA;YAEF,IAAI,eAAe;gBAAE,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;QAChE,CAAC;QACD,GAAG,mBAAmB;KACvB,CAAC,CAAA;IAEF,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,CAAA;AAC5E,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { MutationOptions, DefaultError } from "@tanstack/react-query";
|
|
2
|
+
import type { CreateSessionRequest, CreateSessionResponse } from "../api";
|
|
3
|
+
/**
|
|
4
|
+
* This hook is not exposed for external consumers. For creating session they
|
|
5
|
+
* should use `useSignIn` hook related to the authentication method.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useCreateSession(mutationOptions?: Omit<MutationOptions<CreateSessionResponse, DefaultError, CreateSessionRequest>, "mutationFn" | "mutationKey">): {
|
|
8
|
+
data: undefined;
|
|
9
|
+
variables: undefined;
|
|
10
|
+
error: null;
|
|
11
|
+
isError: false;
|
|
12
|
+
isIdle: true;
|
|
13
|
+
isPending: false;
|
|
14
|
+
isSuccess: false;
|
|
15
|
+
status: "idle";
|
|
16
|
+
reset: () => void;
|
|
17
|
+
context: unknown;
|
|
18
|
+
failureCount: number;
|
|
19
|
+
failureReason: Error | null;
|
|
20
|
+
isPaused: boolean;
|
|
21
|
+
submittedAt: number;
|
|
22
|
+
createSession: import("@tanstack/react-query").UseMutateFunction<CreateSessionResponse, Error, CreateSessionRequest, unknown>;
|
|
23
|
+
createSessionAsync: import("@tanstack/react-query").UseMutateAsyncFunction<CreateSessionResponse, Error, CreateSessionRequest, unknown>;
|
|
24
|
+
} | {
|
|
25
|
+
data: undefined;
|
|
26
|
+
variables: CreateSessionRequest;
|
|
27
|
+
error: null;
|
|
28
|
+
isError: false;
|
|
29
|
+
isIdle: false;
|
|
30
|
+
isPending: true;
|
|
31
|
+
isSuccess: false;
|
|
32
|
+
status: "pending";
|
|
33
|
+
reset: () => void;
|
|
34
|
+
context: unknown;
|
|
35
|
+
failureCount: number;
|
|
36
|
+
failureReason: Error | null;
|
|
37
|
+
isPaused: boolean;
|
|
38
|
+
submittedAt: number;
|
|
39
|
+
createSession: import("@tanstack/react-query").UseMutateFunction<CreateSessionResponse, Error, CreateSessionRequest, unknown>;
|
|
40
|
+
createSessionAsync: import("@tanstack/react-query").UseMutateAsyncFunction<CreateSessionResponse, Error, CreateSessionRequest, unknown>;
|
|
41
|
+
} | {
|
|
42
|
+
data: undefined;
|
|
43
|
+
error: Error;
|
|
44
|
+
variables: CreateSessionRequest;
|
|
45
|
+
isError: true;
|
|
46
|
+
isIdle: false;
|
|
47
|
+
isPending: false;
|
|
48
|
+
isSuccess: false;
|
|
49
|
+
status: "error";
|
|
50
|
+
reset: () => void;
|
|
51
|
+
context: unknown;
|
|
52
|
+
failureCount: number;
|
|
53
|
+
failureReason: Error | null;
|
|
54
|
+
isPaused: boolean;
|
|
55
|
+
submittedAt: number;
|
|
56
|
+
createSession: import("@tanstack/react-query").UseMutateFunction<CreateSessionResponse, Error, CreateSessionRequest, unknown>;
|
|
57
|
+
createSessionAsync: import("@tanstack/react-query").UseMutateAsyncFunction<CreateSessionResponse, Error, CreateSessionRequest, unknown>;
|
|
58
|
+
} | {
|
|
59
|
+
data: CreateSessionResponse;
|
|
60
|
+
error: null;
|
|
61
|
+
variables: CreateSessionRequest;
|
|
62
|
+
isError: false;
|
|
63
|
+
isIdle: false;
|
|
64
|
+
isPending: false;
|
|
65
|
+
isSuccess: true;
|
|
66
|
+
status: "success";
|
|
67
|
+
reset: () => void;
|
|
68
|
+
context: unknown;
|
|
69
|
+
failureCount: number;
|
|
70
|
+
failureReason: Error | null;
|
|
71
|
+
isPaused: boolean;
|
|
72
|
+
submittedAt: number;
|
|
73
|
+
createSession: import("@tanstack/react-query").UseMutateFunction<CreateSessionResponse, Error, CreateSessionRequest, unknown>;
|
|
74
|
+
createSessionAsync: import("@tanstack/react-query").UseMutateAsyncFunction<CreateSessionResponse, Error, CreateSessionRequest, unknown>;
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=useCreateSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateSession.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCreateSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EACf,YAAY,EACb,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAA;AAGzE;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,qBAAqB,EAAE,YAAY,EAAE,oBAAoB,CAAC,EAC1E,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBP"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useQueryClient, useMutation, } from "@tanstack/react-query";
|
|
2
|
+
import { useAuthApiClient } from "./useAuthApiClient";
|
|
3
|
+
import { QUERY_KEYS } from "./constants";
|
|
4
|
+
/**
|
|
5
|
+
* This hook is not exposed for external consumers. For creating session they
|
|
6
|
+
* should use `useSignIn` hook related to the authentication method.
|
|
7
|
+
*/
|
|
8
|
+
export function useCreateSession(mutationOptions = {}) {
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
const authApiClient = useAuthApiClient();
|
|
11
|
+
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions;
|
|
12
|
+
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
13
|
+
mutationFn: (createSessionRequest) => authApiClient.createSession(createSessionRequest),
|
|
14
|
+
onSuccess: (data, variables, context) => {
|
|
15
|
+
// Since `getSession` query also has code in its query keys we can't set
|
|
16
|
+
// query data for a specific query, because we don't know if the code was
|
|
17
|
+
// used or not. Because of that we just reset all getSession queries
|
|
18
|
+
queryClient.resetQueries({ queryKey: [QUERY_KEYS.SESSION] });
|
|
19
|
+
queryClient.resetQueries({
|
|
20
|
+
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
21
|
+
});
|
|
22
|
+
if (customOnSuccess)
|
|
23
|
+
customOnSuccess(data, variables, context);
|
|
24
|
+
},
|
|
25
|
+
...restMutationOptions,
|
|
26
|
+
});
|
|
27
|
+
return { createSession: mutate, createSessionAsync: mutateAsync, ...rest };
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=useCreateSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateSession.js","sourceRoot":"","sources":["../../../src/hooks/useCreateSession.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,WAAW,GAGZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,kBAGI,EAAE;IAEN,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,mBAAmB,EAAE,GAAG,eAAe,CAAA;IAE9E,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,WAAW,CAAC;QACnD,UAAU,EAAE,CAAC,oBAA0C,EAAE,EAAE,CACzD,aAAa,CAAC,aAAa,CAAC,oBAAoB,CAAC;QACnD,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;YACtC,wEAAwE;YACxE,yEAAyE;YACzE,oEAAoE;YACpE,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAC5D,WAAW,CAAC,YAAY,CAAC;gBACvB,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;aACnD,CAAC,CAAA;YAEF,IAAI,eAAe;gBAAE,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;QAChE,CAAC;QACD,GAAG,mBAAmB;KACvB,CAAC,CAAA;IAEF,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,CAAA;AAC5E,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CryptoAssetKey } from "../utils/cryptoAssets";
|
|
2
|
+
/**
|
|
3
|
+
* Formats crypto asset to balance details (balance in USD and decimals)
|
|
4
|
+
* @param type The type of crypto asset
|
|
5
|
+
* @param balance The balance of crypto asset
|
|
6
|
+
* @param btcUsdConversionRate The USD conversion rate
|
|
7
|
+
* @returns The balance details
|
|
8
|
+
*/
|
|
9
|
+
declare function formatCryptoAsset(type: CryptoAssetKey, balance: bigint, btcUsdConversionRate: number): {
|
|
10
|
+
type: CryptoAssetKey;
|
|
11
|
+
balance: number;
|
|
12
|
+
balanceInUsd: number;
|
|
13
|
+
decimals: number;
|
|
14
|
+
};
|
|
15
|
+
export type DropdownCryptoAsset<T = CryptoAssetKey> = {
|
|
16
|
+
type: T;
|
|
17
|
+
balance: bigint;
|
|
18
|
+
};
|
|
19
|
+
type DropdownDetailedCryptoAsset = ReturnType<typeof formatCryptoAsset>;
|
|
20
|
+
export type DropdownData = {
|
|
21
|
+
mezoId: string;
|
|
22
|
+
address: string;
|
|
23
|
+
walletType: "bitcoin" | "evm";
|
|
24
|
+
totalBalanceInUsd: number;
|
|
25
|
+
formattedNativeAssets: DropdownDetailedCryptoAsset[];
|
|
26
|
+
matsnet: {
|
|
27
|
+
mats: number;
|
|
28
|
+
formattedAssets: DropdownDetailedCryptoAsset[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
type UseDropdownDataOptions = {
|
|
32
|
+
evmNativeAssets?: DropdownCryptoAsset[];
|
|
33
|
+
matsnetAssets?: DropdownCryptoAsset[];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Aggregates dropdown data for Dropdown component.
|
|
37
|
+
* @param options - Options for the dropdown data.
|
|
38
|
+
* @param options.evmNativeAssets - Native assets for EVM wallet.
|
|
39
|
+
* @param options.matsnetAssets - Matsnet tokens. Rendered as separate section.
|
|
40
|
+
* @returns Dropdown data.
|
|
41
|
+
* @dev This hook is for internal use only.
|
|
42
|
+
*/
|
|
43
|
+
export default function useDropdownData(options?: UseDropdownDataOptions): DropdownData | null;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=useDropdownData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDropdownData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useDropdownData.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,cAAc,EAIf,MAAM,uBAAuB,CAAA;AAK9B;;;;;;GAMG;AACH,iBAAS,iBAAiB,CACxB,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,MAAM,EACf,oBAAoB,EAAE,MAAM;;;;;EAmB7B;AAED,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,cAAc,IAAI;IACpD,IAAI,EAAE,CAAC,CAAA;IACP,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,KAAK,2BAA2B,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAEvE,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,SAAS,GAAG,KAAK,CAAA;IAC7B,iBAAiB,EAAE,MAAM,CAAA;IACzB,qBAAqB,EAAE,2BAA2B,EAAE,CAAA;IACpD,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAA;QACZ,eAAe,EAAE,2BAA2B,EAAE,CAAA;KAC/C,CAAA;CACF,CAAA;AAED,KAAK,sBAAsB,GAAG;IAE5B,eAAe,CAAC,EAAE,mBAAmB,EAAE,CAAA;IACvC,aAAa,CAAC,EAAE,mBAAmB,EAAE,CAAA;CACtC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,YAAY,GAAG,IAAI,CAoDrB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useBitcoinAccount } from "@mezo-org/orangekit";
|
|
2
|
+
import { useGetCurrentAccount } from ".";
|
|
3
|
+
import { getCryptoAsset, isBitcoinLikeCryptoAsset, isUsdLikeCryptoAsset, } from "../utils/cryptoAssets";
|
|
4
|
+
import { fromFixedPoint } from "../utils/numbers";
|
|
5
|
+
import { useAssetsUsdConversion } from "./useAssetsUSDConversion";
|
|
6
|
+
import useWalletAccount from "./useWalletAccount";
|
|
7
|
+
/**
|
|
8
|
+
* Formats crypto asset to balance details (balance in USD and decimals)
|
|
9
|
+
* @param type The type of crypto asset
|
|
10
|
+
* @param balance The balance of crypto asset
|
|
11
|
+
* @param btcUsdConversionRate The USD conversion rate
|
|
12
|
+
* @returns The balance details
|
|
13
|
+
*/
|
|
14
|
+
function formatCryptoAsset(type, balance, btcUsdConversionRate) {
|
|
15
|
+
const { decimals } = getCryptoAsset(type);
|
|
16
|
+
const nativeBalance = fromFixedPoint(balance, decimals, 4);
|
|
17
|
+
let balanceInUsd = 0;
|
|
18
|
+
if (isBitcoinLikeCryptoAsset(type)) {
|
|
19
|
+
balanceInUsd = nativeBalance * btcUsdConversionRate;
|
|
20
|
+
}
|
|
21
|
+
if (isUsdLikeCryptoAsset(type)) {
|
|
22
|
+
balanceInUsd = nativeBalance;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
type,
|
|
26
|
+
balance: nativeBalance,
|
|
27
|
+
balanceInUsd,
|
|
28
|
+
decimals,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Aggregates dropdown data for Dropdown component.
|
|
33
|
+
* @param options - Options for the dropdown data.
|
|
34
|
+
* @param options.evmNativeAssets - Native assets for EVM wallet.
|
|
35
|
+
* @param options.matsnetAssets - Matsnet tokens. Rendered as separate section.
|
|
36
|
+
* @returns Dropdown data.
|
|
37
|
+
* @dev This hook is for internal use only.
|
|
38
|
+
*/
|
|
39
|
+
export default function useDropdownData(options) {
|
|
40
|
+
const { evmNativeAssets = [], matsnetAssets = [] } = options || {};
|
|
41
|
+
const { btcBalance } = useBitcoinAccount();
|
|
42
|
+
const { address, networkFamily, isConnected } = useWalletAccount();
|
|
43
|
+
const { data: passportAccount } = useGetCurrentAccount();
|
|
44
|
+
const { data: assetsUsdConversion } = useAssetsUsdConversion();
|
|
45
|
+
if (!address || !isConnected || !passportAccount) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const mezoId = passportAccount.mezoId;
|
|
49
|
+
const nativeAssets = networkFamily === "bitcoin"
|
|
50
|
+
? [
|
|
51
|
+
{
|
|
52
|
+
type: "btc",
|
|
53
|
+
balance: BigInt(btcBalance?.total ?? 0),
|
|
54
|
+
},
|
|
55
|
+
]
|
|
56
|
+
: evmNativeAssets;
|
|
57
|
+
const btcUsdConversionRate = Number(assetsUsdConversion?.btcUsd ?? 0);
|
|
58
|
+
const formattedNativeAssets = nativeAssets.map((asset) => formatCryptoAsset(asset.type, asset.balance, btcUsdConversionRate));
|
|
59
|
+
const totalBalanceInUsd = formattedNativeAssets.reduce((sum, value) => sum + value.balanceInUsd, 0);
|
|
60
|
+
const matsBalance = passportAccount.mats.totalMats;
|
|
61
|
+
const matsnetFormattedAssets = matsnetAssets.map((asset) => formatCryptoAsset(asset.type, asset.balance, btcUsdConversionRate));
|
|
62
|
+
return {
|
|
63
|
+
mezoId,
|
|
64
|
+
address,
|
|
65
|
+
walletType: networkFamily,
|
|
66
|
+
totalBalanceInUsd,
|
|
67
|
+
formattedNativeAssets,
|
|
68
|
+
matsnet: {
|
|
69
|
+
mats: matsBalance,
|
|
70
|
+
formattedAssets: matsnetFormattedAssets,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=useDropdownData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDropdownData.js","sourceRoot":"","sources":["../../../src/hooks/useDropdownData.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEnsureNoSessionAndFetchNonce.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEnsureNoSessionAndFetchNonce.ts"],"names":[],"mappings":"AAIA,iBAAS,+BAA+B;;EAuCvC;AAED,OAAO,EAAE,+BAA+B,EAAE,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { useGetSession } from "./useGetSession";
|
|
3
|
+
import { useSignOut } from "./useSignOut";
|
|
4
|
+
function useEnsureNoSessionAndFetchNonce() {
|
|
5
|
+
const { refetch: getSession } = useGetSession(undefined, {
|
|
6
|
+
enabled: false,
|
|
7
|
+
retry: false,
|
|
8
|
+
});
|
|
9
|
+
const { signOutAsync } = useSignOut();
|
|
10
|
+
const getAndValidateSession = useCallback(async () => {
|
|
11
|
+
const getSessionResult = await getSession();
|
|
12
|
+
// TODO: We should create a separate endpoint that will always return nonce
|
|
13
|
+
if (getSessionResult.error) {
|
|
14
|
+
throw new Error(`Sign in error: Failed to fetch the current session: ${getSessionResult.error}`);
|
|
15
|
+
}
|
|
16
|
+
if (!getSessionResult.data) {
|
|
17
|
+
throw new Error("Sign in error: Failed to fetch the current session; no data returned.");
|
|
18
|
+
}
|
|
19
|
+
return getSessionResult.data;
|
|
20
|
+
}, [getSession]);
|
|
21
|
+
const ensureNoSessionAndFetchNonce = useCallback(async () => {
|
|
22
|
+
let getSessionResult = await getAndValidateSession();
|
|
23
|
+
if (!("nonce" in getSessionResult)) {
|
|
24
|
+
// If there is active session we are terminating it
|
|
25
|
+
await signOutAsync();
|
|
26
|
+
// Because we've signed out we can assume nonce will be returned here
|
|
27
|
+
getSessionResult = (await getAndValidateSession());
|
|
28
|
+
}
|
|
29
|
+
return getSessionResult.nonce;
|
|
30
|
+
}, [getAndValidateSession, signOutAsync]);
|
|
31
|
+
return { ensureNoSessionAndFetchNonce };
|
|
32
|
+
}
|
|
33
|
+
export { useEnsureNoSessionAndFetchNonce };
|
|
34
|
+
//# sourceMappingURL=useEnsureNoSessionAndFetchNonce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEnsureNoSessionAndFetchNonce.js","sourceRoot":"","sources":["../../../src/hooks/useEnsureNoSessionAndFetchNonce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,SAAS,+BAA+B;IACtC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC,SAAS,EAAE;QACvD,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,KAAK;KACb,CAAC,CAAA;IACF,MAAM,EAAE,YAAY,EAAE,GAAG,UAAU,EAAE,CAAA;IAErC,MAAM,qBAAqB,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACnD,MAAM,gBAAgB,GAAG,MAAM,UAAU,EAAE,CAAA;QAE3C,2EAA2E;QAC3E,IAAI,gBAAgB,CAAC,KAAK,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CACb,uDAAuD,gBAAgB,CAAC,KAAK,EAAE,CAChF,CAAA;QACH,CAAC;QACD,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CACb,uEAAuE,CACxE,CAAA;QACH,CAAC;QAED,OAAO,gBAAgB,CAAC,IAAI,CAAA;IAC9B,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;IAEhB,MAAM,4BAA4B,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QAC1D,IAAI,gBAAgB,GAAG,MAAM,qBAAqB,EAAE,CAAA;QAEpD,IAAI,CAAC,CAAC,OAAO,IAAI,gBAAgB,CAAC,EAAE,CAAC;YACnC,mDAAmD;YACnD,MAAM,YAAY,EAAE,CAAA;YACpB,qEAAqE;YACrE,gBAAgB,GAAG,CAAC,MAAM,qBAAqB,EAAE,CAAsB,CAAA;QACzE,CAAC;QAED,OAAO,gBAAgB,CAAC,KAAK,CAAA;IAC/B,CAAC,EAAE,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC,CAAA;IAEzC,OAAO,EAAE,4BAA4B,EAAE,CAAA;AACzC,CAAC;AAED,OAAO,EAAE,+BAA+B,EAAE,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UseBaseQueryOptions } from "@tanstack/react-query";
|
|
2
|
+
import type { GetAccountByMezoIdOrAddressResponse } from "../api";
|
|
3
|
+
export declare function useGetAccountByAddress(address?: string, queryOptions?: Omit<UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse | null>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<GetAccountByMezoIdOrAddressResponse | null, Error>;
|
|
4
|
+
//# sourceMappingURL=useGetAccountByAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetAccountByAddress.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetAccountByAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAIhF,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,QAAQ,CAAA;AAEjE,wBAAgB,sBAAsB,CACpC,OAAO,CAAC,EAAE,MAAM,EAChB,YAAY,GAAE,IAAI,CAChB,mBAAmB,CAAC,mCAAmC,GAAG,IAAI,CAAC,EAC/D,UAAU,GAAG,SAAS,CAClB,qGAaP"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useQuery, skipToken } from "@tanstack/react-query";
|
|
2
|
+
import { useAuthApiClient } from "./useAuthApiClient";
|
|
3
|
+
import { QUERY_KEYS } from "./constants";
|
|
4
|
+
import { ONE_MINUTE_MS } from "../utils/time";
|
|
5
|
+
export function useGetAccountByAddress(address, queryOptions = {}) {
|
|
6
|
+
const authApiClient = useAuthApiClient();
|
|
7
|
+
return useQuery({
|
|
8
|
+
queryKey: [QUERY_KEYS.ACCOUNT, address],
|
|
9
|
+
queryFn: address
|
|
10
|
+
? () => authApiClient.getAccountByMezoIdOrAddress(address)
|
|
11
|
+
: skipToken,
|
|
12
|
+
staleTime: ONE_MINUTE_MS,
|
|
13
|
+
retry: 1,
|
|
14
|
+
...queryOptions,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=useGetAccountByAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetAccountByAddress.js","sourceRoot":"","sources":["../../../src/hooks/useGetAccountByAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAuB,MAAM,uBAAuB,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAG7C,MAAM,UAAU,sBAAsB,CACpC,OAAgB,EAChB,eAGI,EAAE;IAEN,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC;QACvC,OAAO,EAAE,OAAO;YACd,CAAC,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,2BAA2B,CAAC,OAAO,CAAC;YAC1D,CAAC,CAAC,SAAS;QACb,SAAS,EAAE,aAAa;QACxB,KAAK,EAAE,CAAC;QACR,GAAG,YAAY;KAChB,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UseBaseQueryOptions } from "@tanstack/react-query";
|
|
2
|
+
import type { GetAccountByMezoIdOrAddressResponse } from "../api";
|
|
3
|
+
export declare function useGetAccountByMezoId(mezoId?: string, queryOptions?: Omit<UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse | null>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<GetAccountByMezoIdOrAddressResponse | null, Error>;
|
|
4
|
+
//# sourceMappingURL=useGetAccountByMezoId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetAccountByMezoId.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetAccountByMezoId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAIhF,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,QAAQ,CAAA;AAEjE,wBAAgB,qBAAqB,CACnC,MAAM,CAAC,EAAE,MAAM,EACf,YAAY,GAAE,IAAI,CAChB,mBAAmB,CAAC,mCAAmC,GAAG,IAAI,CAAC,EAC/D,UAAU,GAAG,SAAS,CAClB,qGAaP"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useQuery, skipToken } from "@tanstack/react-query";
|
|
2
|
+
import { useAuthApiClient } from "./useAuthApiClient";
|
|
3
|
+
import { QUERY_KEYS } from "./constants";
|
|
4
|
+
import { ONE_MINUTE_MS } from "../utils/time";
|
|
5
|
+
export function useGetAccountByMezoId(mezoId, queryOptions = {}) {
|
|
6
|
+
const authApiClient = useAuthApiClient();
|
|
7
|
+
return useQuery({
|
|
8
|
+
queryKey: [QUERY_KEYS.ACCOUNT, mezoId],
|
|
9
|
+
queryFn: mezoId
|
|
10
|
+
? () => authApiClient.getAccountByMezoIdOrAddress(mezoId)
|
|
11
|
+
: skipToken,
|
|
12
|
+
staleTime: ONE_MINUTE_MS,
|
|
13
|
+
retry: 1,
|
|
14
|
+
...queryOptions,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=useGetAccountByMezoId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetAccountByMezoId.js","sourceRoot":"","sources":["../../../src/hooks/useGetAccountByMezoId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAuB,MAAM,uBAAuB,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAG7C,MAAM,UAAU,qBAAqB,CACnC,MAAe,EACf,eAGI,EAAE;IAEN,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC;QACtC,OAAO,EAAE,MAAM;YACb,CAAC,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,2BAA2B,CAAC,MAAM,CAAC;YACzD,CAAC,CAAC,SAAS;QACb,SAAS,EAAE,aAAa;QACxB,KAAK,EAAE,CAAC;QACR,GAAG,YAAY;KAChB,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { UseBaseQueryOptions } from "@tanstack/react-query";
|
|
2
|
+
import type { GetCurrentAccountResponse } from "../api";
|
|
3
|
+
type GetCurrentAccountResponseWithMats = GetCurrentAccountResponse & {
|
|
4
|
+
mats: {
|
|
5
|
+
totalMats: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare function useGetCurrentAccount(queryOptions?: Omit<UseBaseQueryOptions<GetCurrentAccountResponseWithMats>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<Partial<{
|
|
9
|
+
mezoId: string;
|
|
10
|
+
hasModifiedMezoId: boolean;
|
|
11
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
12
|
+
}> & {
|
|
13
|
+
mats: {
|
|
14
|
+
totalMats: number;
|
|
15
|
+
};
|
|
16
|
+
}, Error>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=useGetCurrentAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetCurrentAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetCurrentAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAY,MAAM,uBAAuB,CAAA;AAKrE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAA;AAEvD,KAAK,iCAAiC,GAAG,yBAAyB,GAAG;IACnE,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF,CAAA;AAED,wBAAgB,oBAAoB,CAClC,YAAY,GAAE,IAAI,CAChB,mBAAmB,CAAC,iCAAiC,CAAC,EACtD,UAAU,GAAG,SAAS,CAClB;;;;;UATA;QACJ,SAAS,EAAE,MAAM,CAAA;KAClB;UAmDF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { ONE_MINUTE_MS } from "../utils/time";
|
|
3
|
+
import { QUERY_KEYS } from "./constants";
|
|
4
|
+
import { useAuthApiClient } from "./useAuthApiClient";
|
|
5
|
+
import { usePortalApiClient } from "./usePortalApiClient";
|
|
6
|
+
export function useGetCurrentAccount(queryOptions = {}) {
|
|
7
|
+
const authApiClient = useAuthApiClient();
|
|
8
|
+
const portalApiClient = usePortalApiClient();
|
|
9
|
+
return useQuery({
|
|
10
|
+
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
11
|
+
queryFn: async () => {
|
|
12
|
+
const currentAccount = await authApiClient.getCurrentAccount();
|
|
13
|
+
const linkedWallets = currentAccount?.linkedAccounts?.filter((account) => account.type === "wallet");
|
|
14
|
+
if (!linkedWallets || linkedWallets.length === 0) {
|
|
15
|
+
return {
|
|
16
|
+
...currentAccount,
|
|
17
|
+
mats: {
|
|
18
|
+
totalMats: 0,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const addresses = linkedWallets.map((account) => account.btcAddress || account.evmAddress);
|
|
23
|
+
const mats = await Promise.all(addresses.map((address) => portalApiClient.getPortalMats(address)));
|
|
24
|
+
const totalMats = mats.reduce((sumMats, currentMats) => sumMats + currentMats.totalMats, 0);
|
|
25
|
+
return {
|
|
26
|
+
...currentAccount,
|
|
27
|
+
mats: {
|
|
28
|
+
totalMats,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
staleTime: ONE_MINUTE_MS,
|
|
33
|
+
retry: 1,
|
|
34
|
+
...queryOptions,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=useGetCurrentAccount.js.map
|