@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,108 @@
|
|
|
1
|
+
import { MutationOptions, DefaultError } from "@tanstack/react-query";
|
|
2
|
+
import type { UpdateMezoIdResponse } from "../api";
|
|
3
|
+
export declare function useUpdateMezoId(mutationOptions?: Omit<MutationOptions<UpdateMezoIdResponse, DefaultError, string>, "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
|
+
updateMezoId: import("@tanstack/react-query").UseMutateFunction<{
|
|
19
|
+
mezoId: string;
|
|
20
|
+
hasModifiedMezoId: boolean;
|
|
21
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
22
|
+
}, Error, string, unknown>;
|
|
23
|
+
updateMezoIdAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
24
|
+
mezoId: string;
|
|
25
|
+
hasModifiedMezoId: boolean;
|
|
26
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
27
|
+
}, Error, string, unknown>;
|
|
28
|
+
} | {
|
|
29
|
+
data: undefined;
|
|
30
|
+
variables: string;
|
|
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
|
+
updateMezoId: import("@tanstack/react-query").UseMutateFunction<{
|
|
44
|
+
mezoId: string;
|
|
45
|
+
hasModifiedMezoId: boolean;
|
|
46
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
47
|
+
}, Error, string, unknown>;
|
|
48
|
+
updateMezoIdAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
49
|
+
mezoId: string;
|
|
50
|
+
hasModifiedMezoId: boolean;
|
|
51
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
52
|
+
}, Error, string, unknown>;
|
|
53
|
+
} | {
|
|
54
|
+
data: undefined;
|
|
55
|
+
error: Error;
|
|
56
|
+
variables: string;
|
|
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
|
+
updateMezoId: import("@tanstack/react-query").UseMutateFunction<{
|
|
69
|
+
mezoId: string;
|
|
70
|
+
hasModifiedMezoId: boolean;
|
|
71
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
72
|
+
}, Error, string, unknown>;
|
|
73
|
+
updateMezoIdAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
74
|
+
mezoId: string;
|
|
75
|
+
hasModifiedMezoId: boolean;
|
|
76
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
77
|
+
}, Error, string, unknown>;
|
|
78
|
+
} | {
|
|
79
|
+
data: {
|
|
80
|
+
mezoId: string;
|
|
81
|
+
hasModifiedMezoId: boolean;
|
|
82
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
83
|
+
};
|
|
84
|
+
error: null;
|
|
85
|
+
variables: string;
|
|
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
|
+
updateMezoId: import("@tanstack/react-query").UseMutateFunction<{
|
|
98
|
+
mezoId: string;
|
|
99
|
+
hasModifiedMezoId: boolean;
|
|
100
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
101
|
+
}, Error, string, unknown>;
|
|
102
|
+
updateMezoIdAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
103
|
+
mezoId: string;
|
|
104
|
+
hasModifiedMezoId: boolean;
|
|
105
|
+
linkedAccounts: import("../api").LinkedAccount[];
|
|
106
|
+
}, Error, string, unknown>;
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=useUpdateMezoId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUpdateMezoId.d.ts","sourceRoot":"","sources":["../../../src/hooks/useUpdateMezoId.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EACf,YAAY,EACb,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAElD,wBAAgB,eAAe,CAC7B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,oBAAoB,EAAE,YAAY,EAAE,MAAM,CAAC,EAC3D,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBP"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useQueryClient, useMutation, } from "@tanstack/react-query";
|
|
2
|
+
import { useAuthApiClient } from "./useAuthApiClient";
|
|
3
|
+
import { QUERY_KEYS } from "./constants";
|
|
4
|
+
export function useUpdateMezoId(mutationOptions = {}) {
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
const authApiClient = useAuthApiClient();
|
|
7
|
+
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions;
|
|
8
|
+
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
9
|
+
mutationFn: (newMezoId) => authApiClient.updateMezoId(newMezoId),
|
|
10
|
+
onSuccess: (data, variables, context) => {
|
|
11
|
+
queryClient.resetQueries({ queryKey: [QUERY_KEYS.ACCOUNT] });
|
|
12
|
+
if (customOnSuccess)
|
|
13
|
+
customOnSuccess(data, variables, context);
|
|
14
|
+
},
|
|
15
|
+
...restMutationOptions,
|
|
16
|
+
});
|
|
17
|
+
return { updateMezoId: mutate, updateMezoIdAsync: mutateAsync, ...rest };
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=useUpdateMezoId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUpdateMezoId.js","sourceRoot":"","sources":["../../../src/hooks/useUpdateMezoId.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,eAAe,CAC7B,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,SAAiB,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,CAAC,SAAS,CAAC;QACxE,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;YACtC,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAE5D,IAAI,eAAe;gBAAE,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;QAChE,CAAC;QACD,GAAG,mBAAmB;KACvB,CAAC,CAAA;IAEF,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,CAAA;AAC1E,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Address } from "viem";
|
|
2
|
+
import { Connector } from "wagmi";
|
|
3
|
+
type UseWalletAccountReturn = {
|
|
4
|
+
address?: string | Address;
|
|
5
|
+
isConnected: boolean;
|
|
6
|
+
networkFamily: "bitcoin" | "evm";
|
|
7
|
+
connector?: Connector;
|
|
8
|
+
chainId?: number;
|
|
9
|
+
};
|
|
10
|
+
export default function useWalletAccount(): UseWalletAccountReturn;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=useWalletAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWalletAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWalletAccount.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAc,MAAM,OAAO,CAAA;AAE7C,KAAK,sBAAsB,GAAG;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC1B,WAAW,EAAE,OAAO,CAAA;IACpB,aAAa,EAAE,SAAS,GAAG,KAAK,CAAA;IAChC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAMD,MAAM,CAAC,OAAO,UAAU,gBAAgB,IAAI,sBAAsB,CAkCjE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { useAccount } from "wagmi";
|
|
4
|
+
export default function useWalletAccount() {
|
|
5
|
+
const { address: evmAddress, connector, chainId } = useAccount();
|
|
6
|
+
const networkFamily = useMemo(() => (connector?.type !== "orangekit" ? "evm" : "bitcoin"), [connector]);
|
|
7
|
+
const { data: btcData } = useQuery({
|
|
8
|
+
queryKey: [connector?.id],
|
|
9
|
+
queryFn: async () => {
|
|
10
|
+
const bitcoinProvider = connector.getBitcoinProvider();
|
|
11
|
+
const address = await bitcoinProvider.getAddress();
|
|
12
|
+
const balance = await bitcoinProvider.getBalance();
|
|
13
|
+
return {
|
|
14
|
+
address,
|
|
15
|
+
balance,
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const { address: btcAddress } = btcData || {};
|
|
20
|
+
return {
|
|
21
|
+
address: networkFamily === "bitcoin" ? btcAddress : evmAddress,
|
|
22
|
+
isConnected: networkFamily === "bitcoin" ? !!btcAddress : !!evmAddress,
|
|
23
|
+
networkFamily,
|
|
24
|
+
connector,
|
|
25
|
+
chainId,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=useWalletAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWalletAccount.js","sourceRoot":"","sources":["../../../src/hooks/useWalletAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAa,UAAU,EAAE,MAAM,OAAO,CAAA;AAc7C,MAAM,CAAC,OAAO,UAAU,gBAAgB;IACtC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,UAAU,EAAE,CAAA;IAEhE,MAAM,aAAa,GAAG,OAAO,CAC3B,GAAG,EAAE,CAAC,CAAC,SAAS,EAAE,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,EAC3D,CAAC,SAAS,CAAC,CACZ,CAAA;IAED,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;QACjC,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC;QACzB,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,eAAe,GACnB,SACD,CAAC,kBAAkB,EAAE,CAAA;YAEtB,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC,UAAU,EAAE,CAAA;YAClD,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC,UAAU,EAAE,CAAA;YAElD,OAAO;gBACL,OAAO;gBACP,OAAO;aACR,CAAA;QACH,CAAC;KACF,CAAC,CAAA;IAEF,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,IAAI,EAAE,CAAA;IAE7C,OAAO;QACL,OAAO,EAAE,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU;QAC9D,WAAW,EAAE,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU;QACtE,aAAa;QACb,SAAS;QACT,OAAO;KACC,CAAA;AACZ,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
package/dist/src/index.js
CHANGED
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AuthApiClient, PortalApiClient } from "./api";
|
|
2
|
+
export interface PassportContextValue {
|
|
3
|
+
authApiClient: AuthApiClient;
|
|
4
|
+
portalApiClient: PortalApiClient;
|
|
5
|
+
environment?: Environment;
|
|
6
|
+
}
|
|
7
|
+
export declare const PassportContext: import("react").Context<PassportContextValue | undefined>;
|
|
8
|
+
type Environment = "mainnet" | "testnet";
|
|
9
|
+
type PassportProviderProps = {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
environment?: Environment;
|
|
12
|
+
authApiUrl?: string;
|
|
13
|
+
portalApiUrl?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function PassportProvider({ environment, authApiUrl, portalApiUrl, children, }: PassportProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<PassportContextValue | undefined>>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AAEtD,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,aAAa,CAAA;IAC5B,eAAe,EAAE,eAAe,CAAA;IAChC,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B;AAED,eAAO,MAAM,eAAe,2DAE3B,CAAA;AAED,KAAK,WAAW,GAAG,SAAS,GAAG,SAAS,CAAA;AAExC,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IAEzB,WAAW,CAAC,EAAE,WAAW,CAAA;IAEzB,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,WAAW,EACX,UAAU,EACV,YAAY,EACZ,QAAQ,GACT,EAAE,qBAAqB,6GAmBvB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createContext, createElement } from "react";
|
|
2
|
+
import { AuthApiClient, PortalApiClient } from "./api";
|
|
3
|
+
export const PassportContext = createContext(undefined);
|
|
4
|
+
export function PassportProvider({ environment, authApiUrl, portalApiUrl, children, }) {
|
|
5
|
+
if (environment && !["mainnet", "testnet"].includes(environment)) {
|
|
6
|
+
throw new Error("Wrong environment passed to PassportProvider.");
|
|
7
|
+
}
|
|
8
|
+
return createElement(PassportContext.Provider, {
|
|
9
|
+
value: {
|
|
10
|
+
authApiClient: new AuthApiClient(environment ?? "mainnet", authApiUrl),
|
|
11
|
+
portalApiClient: new PortalApiClient(environment ?? "mainnet", portalApiUrl),
|
|
12
|
+
environment,
|
|
13
|
+
},
|
|
14
|
+
}, children);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AAQtD,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAC1C,SAAS,CACV,CAAA;AAcD,MAAM,UAAU,gBAAgB,CAAC,EAC/B,WAAW,EACX,UAAU,EACV,YAAY,EACZ,QAAQ,GACc;IACtB,IAAI,WAAW,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;IAClE,CAAC;IAED,OAAO,aAAa,CAClB,eAAe,CAAC,QAAQ,EACxB;QACE,KAAK,EAAE;YACL,aAAa,EAAE,IAAI,aAAa,CAAC,WAAW,IAAI,SAAS,EAAE,UAAU,CAAC;YACtE,eAAe,EAAE,IAAI,eAAe,CAClC,WAAW,IAAI,SAAS,EACxB,YAAY,CACb;YACD,WAAW;SACZ;KACF,EACD,QAAQ,CACT,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trims the address to the first 5 and last 5 characters.
|
|
3
|
+
* @param address The address to trim.
|
|
4
|
+
* @returns The trimmed address.
|
|
5
|
+
*/
|
|
6
|
+
export declare function trimAddress(address: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Get the URL of the block explorer page for an address.
|
|
9
|
+
* @param address - The address to link to.
|
|
10
|
+
* @param chainType - The chain type of the address.
|
|
11
|
+
* @param isTestnet - Whether the address is on testnet.
|
|
12
|
+
* @returns The URL of the block explorer page for the address.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAddressExplorerUrl(address: string, chainType: "bitcoin" | "evm", isTestnet: boolean): string;
|
|
15
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src/utils/address.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMnD;AAYD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,GAAG,KAAK,EAC5B,SAAS,EAAE,OAAO,UASnB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trims the address to the first 5 and last 5 characters.
|
|
3
|
+
* @param address The address to trim.
|
|
4
|
+
* @returns The trimmed address.
|
|
5
|
+
*/
|
|
6
|
+
export function trimAddress(address) {
|
|
7
|
+
if (address.length < 11)
|
|
8
|
+
return address;
|
|
9
|
+
const trimmedAddress = `${address.slice(0, 5)}...${address.slice(-5)}`;
|
|
10
|
+
return trimmedAddress;
|
|
11
|
+
}
|
|
12
|
+
const MAINNET_EXPLORER_URLS = {
|
|
13
|
+
bitcoin: "https://mempool.space",
|
|
14
|
+
evm: "https://etherscan.io",
|
|
15
|
+
};
|
|
16
|
+
const TESTNET_EXPLORER_URLS = {
|
|
17
|
+
bitcoin: "https://mempool.space/testnet",
|
|
18
|
+
evm: "https://sepolia.etherscan.io",
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Get the URL of the block explorer page for an address.
|
|
22
|
+
* @param address - The address to link to.
|
|
23
|
+
* @param chainType - The chain type of the address.
|
|
24
|
+
* @param isTestnet - Whether the address is on testnet.
|
|
25
|
+
* @returns The URL of the block explorer page for the address.
|
|
26
|
+
*/
|
|
27
|
+
export function getAddressExplorerUrl(address, chainType, isTestnet) {
|
|
28
|
+
const EXPLORER_URLS = isTestnet
|
|
29
|
+
? TESTNET_EXPLORER_URLS
|
|
30
|
+
: MAINNET_EXPLORER_URLS;
|
|
31
|
+
const baseUrl = EXPLORER_URLS[chainType];
|
|
32
|
+
const endpoint = `address/${address}`;
|
|
33
|
+
return `${baseUrl}/${endpoint}`;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/utils/address.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,OAAO,CAAA;IAEvC,MAAM,cAAc,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAEtE,OAAO,cAAc,CAAA;AACvB,CAAC;AAED,MAAM,qBAAqB,GAAsC;IAC/D,OAAO,EAAE,uBAAuB;IAChC,GAAG,EAAE,sBAAsB;CAC5B,CAAA;AAED,MAAM,qBAAqB,GAAsC;IAC/D,OAAO,EAAE,+BAA+B;IACxC,GAAG,EAAE,8BAA8B;CACpC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAe,EACf,SAA4B,EAC5B,SAAkB;IAElB,MAAM,aAAa,GAAG,SAAS;QAC7B,CAAC,CAAC,qBAAqB;QACvB,CAAC,CAAC,qBAAqB,CAAA;IACzB,MAAM,OAAO,GAAG,aAAa,CAAC,SAAS,CAAC,CAAA;IACxC,MAAM,QAAQ,GAAG,WAAW,OAAO,EAAE,CAAA;IAErC,OAAO,GAAG,OAAO,IAAI,QAAQ,EAAE,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.test.d.ts","sourceRoot":"","sources":["../../../src/utils/address.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getAddressExplorerUrl, trimAddress } from "./address";
|
|
2
|
+
describe("trimAddress", () => {
|
|
3
|
+
it("returns full address if length is less than 11", () => {
|
|
4
|
+
expect(trimAddress("0x12345")).toBe("0x12345");
|
|
5
|
+
});
|
|
6
|
+
it("returns trimmed address if length is 11 or more", () => {
|
|
7
|
+
const input = "0x123456789abcdef";
|
|
8
|
+
const expected = "0x123...bcdef";
|
|
9
|
+
expect(trimAddress(input)).toBe(expected);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
describe("getAddressExplorerUrl", () => {
|
|
13
|
+
const btcAddress = "bc1qxyz123";
|
|
14
|
+
const evmAddress = "0x1234567890abcdef";
|
|
15
|
+
it("returns correct mainnet Bitcoin explorer URL", () => {
|
|
16
|
+
const url = getAddressExplorerUrl(btcAddress, "bitcoin", false);
|
|
17
|
+
expect(url).toBe(`https://mempool.space/address/${btcAddress}`);
|
|
18
|
+
});
|
|
19
|
+
it("returns correct testnet Bitcoin explorer URL", () => {
|
|
20
|
+
const url = getAddressExplorerUrl(btcAddress, "bitcoin", true);
|
|
21
|
+
expect(url).toBe(`https://mempool.space/testnet/address/${btcAddress}`);
|
|
22
|
+
});
|
|
23
|
+
it("returns correct mainnet EVM explorer URL", () => {
|
|
24
|
+
const url = getAddressExplorerUrl(evmAddress, "evm", false);
|
|
25
|
+
expect(url).toBe(`https://etherscan.io/address/${evmAddress}`);
|
|
26
|
+
});
|
|
27
|
+
it("returns correct testnet EVM explorer URL", () => {
|
|
28
|
+
const url = getAddressExplorerUrl(evmAddress, "evm", true);
|
|
29
|
+
expect(url).toBe(`https://sepolia.etherscan.io/address/${evmAddress}`);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=address.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.test.js","sourceRoot":"","sources":["../../../src/utils/address.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAE9D,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,iDAAiD,EAAE,GAAG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C,CAAA;IACxE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IconProps } from "@mezo-org/mezo-clay";
|
|
2
|
+
import { FC } from "react";
|
|
3
|
+
export type CryptoAssetKey = "btc" | "eth" | "tbtc" | "wbtc" | "mbtc" | "musd";
|
|
4
|
+
export type CryptoAsset = {
|
|
5
|
+
name: string;
|
|
6
|
+
symbol: string;
|
|
7
|
+
icon: FC<IconProps>;
|
|
8
|
+
decimals: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Gets details of given crypto asset
|
|
12
|
+
* @param key The key of crypto asset
|
|
13
|
+
* @returns The crypto asset details
|
|
14
|
+
*/
|
|
15
|
+
export declare function getCryptoAsset(key: CryptoAssetKey): CryptoAsset;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if given crypto asset is Bitcoin-like
|
|
18
|
+
* @param key The key of crypto asset
|
|
19
|
+
* @returns True if crypto asset is Bitcoin-like
|
|
20
|
+
*/
|
|
21
|
+
export declare function isBitcoinLikeCryptoAsset(key: CryptoAssetKey): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if given crypto asset is USD-like
|
|
24
|
+
* @param key The key of crypto asset
|
|
25
|
+
* @returns True if crypto asset is USD-like
|
|
26
|
+
*/
|
|
27
|
+
export declare function isUsdLikeCryptoAsset(key: CryptoAssetKey): boolean;
|
|
28
|
+
//# sourceMappingURL=cryptoAssets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cryptoAssets.d.ts","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EAGV,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAiB,EAAE,EAAE,MAAM,OAAO,CAAA;AAEzC,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AAE9E,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAmDD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,eAEjD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,cAAc,WAE3D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,cAAc,WAEvD"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BitcoinCircle, EthCircle, MUsdCircle, TBtcCircle, } from "@mezo-org/mezo-clay";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
const CRYPTO_ASSETS = {
|
|
4
|
+
btc: {
|
|
5
|
+
name: "Bitcoin",
|
|
6
|
+
symbol: "BTC",
|
|
7
|
+
icon: BitcoinCircle,
|
|
8
|
+
decimals: 8,
|
|
9
|
+
},
|
|
10
|
+
eth: {
|
|
11
|
+
name: "Ethereum",
|
|
12
|
+
symbol: "ETH",
|
|
13
|
+
icon: EthCircle,
|
|
14
|
+
decimals: 18,
|
|
15
|
+
},
|
|
16
|
+
tbtc: {
|
|
17
|
+
name: "Threshold Bitcoin",
|
|
18
|
+
symbol: "tBTC",
|
|
19
|
+
icon: TBtcCircle,
|
|
20
|
+
decimals: 18,
|
|
21
|
+
},
|
|
22
|
+
wbtc: {
|
|
23
|
+
name: "Wrapped Bitcoin",
|
|
24
|
+
symbol: "wBTC",
|
|
25
|
+
icon: (props) => createElement(BitcoinCircle, {
|
|
26
|
+
...props,
|
|
27
|
+
symbolColor: "#FF8A00",
|
|
28
|
+
color: "#000000",
|
|
29
|
+
}),
|
|
30
|
+
decimals: 8,
|
|
31
|
+
},
|
|
32
|
+
mbtc: {
|
|
33
|
+
name: "Matsnet Bitcoin",
|
|
34
|
+
symbol: "BTC",
|
|
35
|
+
icon: (props) => createElement(BitcoinCircle, {
|
|
36
|
+
...props,
|
|
37
|
+
symbolColor: "#000000",
|
|
38
|
+
color: "#FFC907",
|
|
39
|
+
}),
|
|
40
|
+
decimals: 18,
|
|
41
|
+
},
|
|
42
|
+
musd: {
|
|
43
|
+
name: "Mezo USD",
|
|
44
|
+
symbol: "MUSD",
|
|
45
|
+
icon: MUsdCircle,
|
|
46
|
+
decimals: 18,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Gets details of given crypto asset
|
|
51
|
+
* @param key The key of crypto asset
|
|
52
|
+
* @returns The crypto asset details
|
|
53
|
+
*/
|
|
54
|
+
export function getCryptoAsset(key) {
|
|
55
|
+
return CRYPTO_ASSETS[key];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Checks if given crypto asset is Bitcoin-like
|
|
59
|
+
* @param key The key of crypto asset
|
|
60
|
+
* @returns True if crypto asset is Bitcoin-like
|
|
61
|
+
*/
|
|
62
|
+
export function isBitcoinLikeCryptoAsset(key) {
|
|
63
|
+
return ["btc", "tbtc", "wbtc", "mbtc"].includes(key);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Checks if given crypto asset is USD-like
|
|
67
|
+
* @param key The key of crypto asset
|
|
68
|
+
* @returns True if crypto asset is USD-like
|
|
69
|
+
*/
|
|
70
|
+
export function isUsdLikeCryptoAsset(key) {
|
|
71
|
+
return ["musd"].includes(key);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=cryptoAssets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cryptoAssets.js","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EAET,UAAU,EACV,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAM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E,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AACtD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAmB;IACtD,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cryptoAssets.test.d.ts","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BitcoinCircle, EthCircle, MUsdCircle, TBtcCircle, } from "@mezo-org/mezo-clay";
|
|
2
|
+
import { getCryptoAsset } from "./cryptoAssets";
|
|
3
|
+
// FIXME: Test fails if run in full suite (pnpm test) but works when run in isolation (pnpm test cryptoAssets)
|
|
4
|
+
describe("getCryptoAsset", () => {
|
|
5
|
+
it("returns the correct asset for 'btc'", () => {
|
|
6
|
+
const asset = getCryptoAsset("btc");
|
|
7
|
+
expect(asset.name).toBe("Bitcoin");
|
|
8
|
+
expect(asset.symbol).toBe("BTC");
|
|
9
|
+
expect(asset.decimals).toBe(8);
|
|
10
|
+
expect(asset.icon).toBe(BitcoinCircle);
|
|
11
|
+
});
|
|
12
|
+
it("returns the correct asset for 'eth'", () => {
|
|
13
|
+
const asset = getCryptoAsset("eth");
|
|
14
|
+
expect(asset.name).toBe("Ethereum");
|
|
15
|
+
expect(asset.symbol).toBe("ETH");
|
|
16
|
+
expect(asset.decimals).toBe(18);
|
|
17
|
+
expect(asset.icon).toBe(EthCircle);
|
|
18
|
+
});
|
|
19
|
+
it("returns the correct asset for 'tbtc'", () => {
|
|
20
|
+
const asset = getCryptoAsset("tbtc");
|
|
21
|
+
expect(asset.name).toBe("Threshold Bitcoin");
|
|
22
|
+
expect(asset.symbol).toBe("tBTC");
|
|
23
|
+
expect(asset.decimals).toBe(18);
|
|
24
|
+
expect(asset.icon).toBe(TBtcCircle);
|
|
25
|
+
});
|
|
26
|
+
it("returns the correct asset for 'wbtc'", () => {
|
|
27
|
+
const asset = getCryptoAsset("wbtc");
|
|
28
|
+
expect(asset.name).toBe("Wrapped Bitcoin");
|
|
29
|
+
expect(asset.symbol).toBe("wBTC");
|
|
30
|
+
expect(asset.decimals).toBe(8);
|
|
31
|
+
// FIXME: Test should expect the exact icon component
|
|
32
|
+
expect(asset.icon).toEqual(expect.any(Function));
|
|
33
|
+
});
|
|
34
|
+
it("returns the correct asset for 'mbtc'", () => {
|
|
35
|
+
const asset = getCryptoAsset("mbtc");
|
|
36
|
+
expect(asset.name).toBe("Matsnet Bitcoin");
|
|
37
|
+
expect(asset.symbol).toBe("BTC");
|
|
38
|
+
expect(asset.decimals).toBe(18);
|
|
39
|
+
// FIXME: Test should expect the exact icon component
|
|
40
|
+
expect(asset.icon).toEqual(expect.any(Function));
|
|
41
|
+
});
|
|
42
|
+
it("returns the correct asset for 'musd'", () => {
|
|
43
|
+
const asset = getCryptoAsset("musd");
|
|
44
|
+
expect(asset.name).toBe("Mezo USD");
|
|
45
|
+
expect(asset.symbol).toBe("MUSD");
|
|
46
|
+
expect(asset.decimals).toBe(18);
|
|
47
|
+
expect(asset.icon).toBe(MUsdCircle);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=cryptoAssets.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cryptoAssets.test.js","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EACT,UAAU,EACV,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,8GAA8G;AAE9G,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,KAAK,GAAG,cAAc,CAA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AAC,CAAA;QACjC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC/B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a number as a currency
|
|
3
|
+
* @param value The value to format
|
|
4
|
+
* @param options The options to pass to the formatter
|
|
5
|
+
* @returns The formatted currency
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatCurrency(value: number, options?: Omit<Intl.NumberFormatOptions, "style">): string;
|
|
8
|
+
/**
|
|
9
|
+
* Formats a number as a USD currency
|
|
10
|
+
* @param value The value to format
|
|
11
|
+
* @returns The formatted currency
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatUsd(value: number): string;
|
|
14
|
+
//# sourceMappingURL=currency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/utils/currency.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAM,GACpD,MAAM,CAOR;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const DEFAULT_FORMAT_OPTIONS = {
|
|
2
|
+
style: "currency",
|
|
3
|
+
minimumFractionDigits: 2,
|
|
4
|
+
maximumFractionDigits: 2,
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Formats a number as a currency
|
|
8
|
+
* @param value The value to format
|
|
9
|
+
* @param options The options to pass to the formatter
|
|
10
|
+
* @returns The formatted currency
|
|
11
|
+
*/
|
|
12
|
+
export function formatCurrency(value, options = {}) {
|
|
13
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
14
|
+
...DEFAULT_FORMAT_OPTIONS,
|
|
15
|
+
...options,
|
|
16
|
+
});
|
|
17
|
+
return formatter.format(value);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Formats a number as a USD currency
|
|
21
|
+
* @param value The value to format
|
|
22
|
+
* @returns The formatted currency
|
|
23
|
+
*/
|
|
24
|
+
export function formatUsd(value) {
|
|
25
|
+
return formatCurrency(value, { currency: "USD" });
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=currency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/utils/currency.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAA6B;IACvD,KAAK,EAAE,UAAU;IACjB,qBAAqB,EAAE,CAAC;IACxB,qBAAqB,EAAE,CAAC;CACzB,CAAA;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAa,EACb,UAAmD,EAAE;IAErD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;QAC/C,GAAG,sBAAsB;QACzB,GAAG,OAAO;KACX,CAAC,CAAA;IAEF,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,cAAc,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;AACnD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.test.d.ts","sourceRoot":"","sources":["../../../src/utils/currency.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { formatCurrency, formatUsd } from "./currency";
|
|
2
|
+
describe("formatCurrency", () => {
|
|
3
|
+
it("formats a number as currency with default options", () => {
|
|
4
|
+
const result = formatCurrency(1234.5, { currency: "EUR" });
|
|
5
|
+
expect(result).toBe("€1,234.50");
|
|
6
|
+
});
|
|
7
|
+
it("respects minimumFractionDigits (min = 3, max = 3)", () => {
|
|
8
|
+
const result = formatCurrency(1.2, {
|
|
9
|
+
currency: "USD",
|
|
10
|
+
minimumFractionDigits: 3,
|
|
11
|
+
maximumFractionDigits: 3,
|
|
12
|
+
});
|
|
13
|
+
expect(result).toBe("$1.200");
|
|
14
|
+
});
|
|
15
|
+
it("respects maximumFractionDigits (min = 0, max = 1)", () => {
|
|
16
|
+
const result = formatCurrency(1.234567, {
|
|
17
|
+
currency: "USD",
|
|
18
|
+
minimumFractionDigits: 0,
|
|
19
|
+
maximumFractionDigits: 1,
|
|
20
|
+
});
|
|
21
|
+
expect(result).toBe("$1.2");
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe("formatUsd", () => {
|
|
25
|
+
it("formats a number as USD", () => {
|
|
26
|
+
const result = formatUsd(99.99);
|
|
27
|
+
expect(result).toBe("$99.99");
|
|
28
|
+
});
|
|
29
|
+
it("formats zero", () => {
|
|
30
|
+
const result = formatUsd(0);
|
|
31
|
+
expect(result).toBe("$0.00");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=currency.test.js.map
|