@mezo-org/passport 0.4.0-dev.79 → 0.4.0-dev.80
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/hooks/index.d.ts +0 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +0 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts +13 -13
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +4 -20
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.d.ts +13 -13
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.d.ts +13 -13
- package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
- package/dist/src/provider.d.ts +2 -2
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +1 -1
- package/dist/src/provider.js.map +1 -1
- package/package.json +2 -2
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useAuthenticateWithWallet.ts +9 -22
- package/src/hooks/useSignInWithWallet.ts +2 -2
- package/src/hooks/useSignUpWithWallet.ts +2 -2
- package/src/provider.ts +3 -3
- package/dist/src/hooks/useAddMezoChainToWallet.d.ts +0 -5
- package/dist/src/hooks/useAddMezoChainToWallet.d.ts.map +0 -1
- package/dist/src/hooks/useAddMezoChainToWallet.js +0 -57
- package/dist/src/hooks/useAddMezoChainToWallet.js.map +0 -1
- package/src/hooks/useAddMezoChainToWallet.ts +0 -68
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { useBitcoinAccount, useSendBitcoin, useSendTransaction, useSubscribeToConnectedToUnsupportedBitcoinAddress, useSubscribeToConnectorEvent, useSubscribeToWalletNetworkDoesNotMatchProviderChain, } from "@mezo-org/orangekit";
|
|
2
|
-
export * from "./useAddMezoChainToWallet";
|
|
3
2
|
export { useInvalidateBorrowData, useResetBorrowData } from "./useBorrowData";
|
|
4
3
|
export * from "./useGetAccountByAddress";
|
|
5
4
|
export * from "./useGetAccountByMezoId";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kDAAkD,EAClD,4BAA4B,EAC5B,oDAAoD,GACrD,MAAM,qBAAqB,CAAA;AAC5B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kDAAkD,EAClD,4BAA4B,EAC5B,oDAAoD,GACrD,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC7E,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA"}
|
package/dist/src/hooks/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { useBitcoinAccount, useSendBitcoin, useSendTransaction, useSubscribeToConnectedToUnsupportedBitcoinAddress, useSubscribeToConnectorEvent, useSubscribeToWalletNetworkDoesNotMatchProviderChain, } from "@mezo-org/orangekit";
|
|
2
|
-
export * from "./useAddMezoChainToWallet";
|
|
3
2
|
export { useInvalidateBorrowData, useResetBorrowData } from "./useBorrowData";
|
|
4
3
|
export * from "./useGetAccountByAddress";
|
|
5
4
|
export * from "./useGetAccountByMezoId";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kDAAkD,EAClD,4BAA4B,EAC5B,oDAAoD,GACrD,MAAM,qBAAqB,CAAA;AAC5B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kDAAkD,EAClD,4BAA4B,EAC5B,oDAAoD,GACrD,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC7E,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MutationOptions } from "@tanstack/react-query";
|
|
1
|
+
import { DefaultError, MutationOptions } from "@tanstack/react-query";
|
|
2
2
|
import type { Session } from "../api";
|
|
3
|
-
declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutationOptions?: Omit<MutationOptions<Session>, "mutationFn" | "mutationKey">): {
|
|
3
|
+
declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutationOptions?: Omit<MutationOptions<Session, DefaultError, number | void>, "mutationFn" | "mutationKey">): {
|
|
4
4
|
data: undefined;
|
|
5
5
|
variables: undefined;
|
|
6
6
|
error: null;
|
|
@@ -15,11 +15,11 @@ declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutati
|
|
|
15
15
|
failureReason: Error | null;
|
|
16
16
|
isPaused: boolean;
|
|
17
17
|
submittedAt: number;
|
|
18
|
-
authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
19
|
-
authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
18
|
+
authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
19
|
+
authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
20
20
|
} | {
|
|
21
21
|
data: undefined;
|
|
22
|
-
variables: void;
|
|
22
|
+
variables: number | void | undefined;
|
|
23
23
|
error: null;
|
|
24
24
|
isError: false;
|
|
25
25
|
isIdle: false;
|
|
@@ -32,12 +32,12 @@ declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutati
|
|
|
32
32
|
failureReason: Error | null;
|
|
33
33
|
isPaused: boolean;
|
|
34
34
|
submittedAt: number;
|
|
35
|
-
authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
36
|
-
authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
35
|
+
authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
36
|
+
authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
37
37
|
} | {
|
|
38
38
|
data: undefined;
|
|
39
39
|
error: Error;
|
|
40
|
-
variables: void;
|
|
40
|
+
variables: number | void | undefined;
|
|
41
41
|
isError: true;
|
|
42
42
|
isIdle: false;
|
|
43
43
|
isPending: false;
|
|
@@ -49,12 +49,12 @@ declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutati
|
|
|
49
49
|
failureReason: Error | null;
|
|
50
50
|
isPaused: boolean;
|
|
51
51
|
submittedAt: number;
|
|
52
|
-
authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
53
|
-
authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
52
|
+
authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
53
|
+
authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
54
54
|
} | {
|
|
55
55
|
data: Session;
|
|
56
56
|
error: null;
|
|
57
|
-
variables: void;
|
|
57
|
+
variables: number | void | undefined;
|
|
58
58
|
isError: false;
|
|
59
59
|
isIdle: false;
|
|
60
60
|
isPending: false;
|
|
@@ -66,8 +66,8 @@ declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutati
|
|
|
66
66
|
failureReason: Error | null;
|
|
67
67
|
isPaused: boolean;
|
|
68
68
|
submittedAt: number;
|
|
69
|
-
authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
70
|
-
authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
69
|
+
authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
70
|
+
authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
71
71
|
};
|
|
72
72
|
export { useAuthenticateWithWallet };
|
|
73
73
|
//# sourceMappingURL=useAuthenticateWithWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticateWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"useAuthenticateWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,eAAe,EAEhB,MAAM,uBAAuB,CAAA;AAS9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAGrC,iBAAS,yBAAyB,CAChC,mBAAmB,UAAQ,EAC3B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC,EACrD,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8FP;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAA"}
|
|
@@ -1,44 +1,28 @@
|
|
|
1
|
-
import { useSignMessage
|
|
2
|
-
import { useMutation } from "@tanstack/react-query";
|
|
3
|
-
import { mezoMainnet, mezoTestnet } from "@mezo-org/orangekit";
|
|
1
|
+
import { useSignMessage } from "wagmi";
|
|
2
|
+
import { useMutation, } from "@tanstack/react-query";
|
|
4
3
|
import { useCreateAccount } from "./useCreateAccount";
|
|
5
4
|
import { useCreateSession } from "./useCreateSession";
|
|
6
5
|
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce";
|
|
7
6
|
import { createSignInWithWalletMessage, verifyDomainInSignInWithWalletMessage, } from "../utils/siww";
|
|
8
7
|
import { useGetAccountByAddress } from "./useGetAccountByAddress";
|
|
9
8
|
import useWalletAccount from "./useWalletAccount";
|
|
10
|
-
import { useAddMezoChainToWallet } from "./useAddMezoChainToWallet";
|
|
11
|
-
import { usePassportContext } from "./usePassportContext";
|
|
12
9
|
function useAuthenticateWithWallet(shouldCreateAccount = false, mutationOptions = {}) {
|
|
13
10
|
const { walletAddress, chainId: walletChainId, connector, networkFamily, } = useWalletAccount();
|
|
14
11
|
const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce();
|
|
15
12
|
const { createSessionAsync } = useCreateSession();
|
|
16
13
|
const { createAccountAsync } = useCreateAccount();
|
|
17
14
|
const { signMessageAsync } = useSignMessage();
|
|
18
|
-
const { environment } = usePassportContext();
|
|
19
|
-
const { isMezoChain, addMezoChain } = useAddMezoChainToWallet(environment);
|
|
20
|
-
const MEZO_CHAIN = environment === "mainnet" ? mezoMainnet : mezoTestnet;
|
|
21
|
-
const { switchChainAsync } = useSwitchChain();
|
|
22
15
|
const { refetch: getAccountByAddress } = useGetAccountByAddress(walletAddress, {
|
|
23
16
|
enabled: false,
|
|
24
17
|
retry: false,
|
|
25
18
|
});
|
|
26
19
|
const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
|
|
27
|
-
mutationFn: async () => {
|
|
20
|
+
mutationFn: async (chainId) => {
|
|
28
21
|
if (!walletAddress) {
|
|
29
22
|
throw new Error("Sign in error: Wallet not connected!");
|
|
30
23
|
}
|
|
31
|
-
let chainId = walletChainId;
|
|
32
|
-
console.log("before adding chain...");
|
|
33
|
-
if (connector?.type !== "orangekit" && !isMezoChain) {
|
|
34
|
-
console.log("ading mezo chain");
|
|
35
|
-
await addMezoChain();
|
|
36
|
-
console.log("switching chain...");
|
|
37
|
-
const newChain = await switchChainAsync({ chainId: MEZO_CHAIN.id });
|
|
38
|
-
chainId = newChain.id;
|
|
39
|
-
}
|
|
40
24
|
const nonce = await ensureNoSessionAndFetchNonce();
|
|
41
|
-
const messageResult = createSignInWithWalletMessage(walletAddress, nonce, networkFamily, chainId);
|
|
25
|
+
const messageResult = createSignInWithWalletMessage(walletAddress, nonce, networkFamily, chainId ?? walletChainId);
|
|
42
26
|
const signatureResult = await signMessageAsync({
|
|
43
27
|
message: messageResult,
|
|
44
28
|
connector,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticateWithWallet.js","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"useAuthenticateWithWallet.js","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAGL,WAAW,GACZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAA;AACnF,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,GACtC,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAEjE,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AAEjD,SAAS,yBAAyB,CAChC,mBAAmB,GAAG,KAAK,EAC3B,kBAGI,EAAE;IAEN,MAAM,EACJ,aAAa,EACb,OAAO,EAAE,aAAa,EACtB,SAAS,EACT,aAAa,GACd,GAAG,gBAAgB,EAAE,CAAA;IACtB,MAAM,EAAE,4BAA4B,EAAE,GAAG,+BAA+B,EAAE,CAAA;IAC1E,MAAM,EAAE,kBAAkB,EAAE,GAAG,gBAAgB,EAAE,CAAA;IACjD,MAAM,EAAE,kBAAkB,EAAE,GAAG,gBAAgB,EAAE,CAAA;IACjD,MAAM,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,CAAA;IAE7C,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,GAAG,sBAAsB,CAC7D,aAAa,EACb;QACE,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,KAAK;KACb,CACF,CAAA;IAED,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,4BAA4B,EAAE,GAAG,WAAW,CAAC;QAC3E,UAAU,EAAE,KAAK,EAAE,OAAuB,EAAE,EAAE;YAC5C,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;YACzD,CAAC;YAED,MAAM,KAAK,GAAG,MAAM,4BAA4B,EAAE,CAAA;YAElD,MAAM,aAAa,GAAG,6BAA6B,CACjD,aAAa,EACb,KAAK,EACL,aAAa,EACb,OAAO,IAAI,aAAa,CACzB,CAAA;YACD,MAAM,eAAe,GAAG,MAAM,gBAAgB,CAAC;gBAC7C,OAAO,EAAE,aAAa;gBACtB,SAAS;aACV,CAAC,CAAA;YAEF,MAAM,qCAAqC,CACzC,aAAa,EACb,eAAe,EACf,KAAK,CACN,CAAA;YAED,IAAI,mBAAmB,EAAE,CAAC;gBACxB,MAAM,yBAAyB,GAAG,MAAM,mBAAmB,EAAE,CAAA;gBAE7D,IAAI,yBAAyB,CAAC,IAAI,EAAE,CAAC;oBACnC,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAA;gBACH,CAAC;gBAED,IAAI,yBAAyB,CAAC,KAAK,EAAE,CAAC;oBACpC,MAAM,IAAI,KAAK,CACb,sGAAsG,yBAAyB,CAAC,KAAK,EAAE,CACxI,CAAA;gBACH,CAAC;gBAED,iDAAiD;gBACjD,IAAI,CAAC;oBACH,MAAM,mBAAmB,GAAG,MAAM,kBAAkB,CAAC;wBACnD,IAAI,EAAE,QAAQ;wBACd,OAAO,EAAE,aAAa;wBACtB,SAAS,EAAE,eAAe;qBAC3B,CAAC,CAAA;oBAEF,IAAI,CAAC,mBAAmB,EAAE,CAAC;wBACzB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;oBACjD,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,IAAI,KAAK,CACb,0DAA0D,KAAK,EAAE,CAClE,CAAA;gBACH,CAAC;YACH,CAAC;YAED,OAAO,CAAC,MAAM,kBAAkB,CAAC;gBAC/B,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,aAAa;gBACtB,SAAS,EAAE,eAAe;aAC3B,CAAC,CAAY,CAAA;YACd,0EAA0E;QAC5E,CAAC;QACD,GAAG,eAAe;KACnB,CAAC,CAAA;IAEF,OAAO;QACL,sBAAsB,EAAE,MAAM;QAC9B,2BAA2B,EAAE,WAAW;QACxC,GAAG,4BAA4B;KAChC,CAAA;AACH,CAAC;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MutationOptions } from "@tanstack/react-query";
|
|
1
|
+
import { DefaultError, MutationOptions } from "@tanstack/react-query";
|
|
2
2
|
import type { Session } from "../api";
|
|
3
|
-
declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Session>, "mutationFn" | "mutationKey">): {
|
|
3
|
+
declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Session, DefaultError, number | void>, "mutationFn" | "mutationKey">): {
|
|
4
4
|
data: undefined;
|
|
5
5
|
variables: undefined;
|
|
6
6
|
error: null;
|
|
@@ -15,11 +15,11 @@ declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
15
15
|
failureReason: Error | null;
|
|
16
16
|
isPaused: boolean;
|
|
17
17
|
submittedAt: number;
|
|
18
|
-
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
19
|
-
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
18
|
+
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
19
|
+
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
20
20
|
} | {
|
|
21
21
|
data: undefined;
|
|
22
|
-
variables: void;
|
|
22
|
+
variables: number | void | undefined;
|
|
23
23
|
error: null;
|
|
24
24
|
isError: false;
|
|
25
25
|
isIdle: false;
|
|
@@ -32,12 +32,12 @@ declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
32
32
|
failureReason: Error | null;
|
|
33
33
|
isPaused: boolean;
|
|
34
34
|
submittedAt: number;
|
|
35
|
-
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
36
|
-
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
35
|
+
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
36
|
+
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
37
37
|
} | {
|
|
38
38
|
data: undefined;
|
|
39
39
|
error: Error;
|
|
40
|
-
variables: void;
|
|
40
|
+
variables: number | void | undefined;
|
|
41
41
|
isError: true;
|
|
42
42
|
isIdle: false;
|
|
43
43
|
isPending: false;
|
|
@@ -49,12 +49,12 @@ declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
49
49
|
failureReason: Error | null;
|
|
50
50
|
isPaused: boolean;
|
|
51
51
|
submittedAt: number;
|
|
52
|
-
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
53
|
-
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
52
|
+
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
53
|
+
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
54
54
|
} | {
|
|
55
55
|
data: Session;
|
|
56
56
|
error: null;
|
|
57
|
-
variables: void;
|
|
57
|
+
variables: number | void | undefined;
|
|
58
58
|
isError: false;
|
|
59
59
|
isIdle: false;
|
|
60
60
|
isPending: false;
|
|
@@ -66,8 +66,8 @@ declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
66
66
|
failureReason: Error | null;
|
|
67
67
|
isPaused: boolean;
|
|
68
68
|
submittedAt: number;
|
|
69
|
-
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
70
|
-
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
69
|
+
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
70
|
+
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
71
71
|
};
|
|
72
72
|
export { useSignInWithWallet };
|
|
73
73
|
//# sourceMappingURL=useSignInWithWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignInWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignInWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"useSignInWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignInWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAErE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,iBAAS,mBAAmB,CAC1B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC,EACrD,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUP;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MutationOptions } from "@tanstack/react-query";
|
|
1
|
+
import { DefaultError, MutationOptions } from "@tanstack/react-query";
|
|
2
2
|
import type { Session } from "../api";
|
|
3
|
-
declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Session>, "mutationFn" | "mutationKey">): {
|
|
3
|
+
declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Session, DefaultError, number | void>, "mutationFn" | "mutationKey">): {
|
|
4
4
|
data: undefined;
|
|
5
5
|
variables: undefined;
|
|
6
6
|
error: null;
|
|
@@ -15,11 +15,11 @@ declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
15
15
|
failureReason: Error | null;
|
|
16
16
|
isPaused: boolean;
|
|
17
17
|
submittedAt: number;
|
|
18
|
-
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
19
|
-
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
18
|
+
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
19
|
+
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
20
20
|
} | {
|
|
21
21
|
data: undefined;
|
|
22
|
-
variables: void;
|
|
22
|
+
variables: number | void | undefined;
|
|
23
23
|
error: null;
|
|
24
24
|
isError: false;
|
|
25
25
|
isIdle: false;
|
|
@@ -32,12 +32,12 @@ declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
32
32
|
failureReason: Error | null;
|
|
33
33
|
isPaused: boolean;
|
|
34
34
|
submittedAt: number;
|
|
35
|
-
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
36
|
-
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
35
|
+
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
36
|
+
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
37
37
|
} | {
|
|
38
38
|
data: undefined;
|
|
39
39
|
error: Error;
|
|
40
|
-
variables: void;
|
|
40
|
+
variables: number | void | undefined;
|
|
41
41
|
isError: true;
|
|
42
42
|
isIdle: false;
|
|
43
43
|
isPending: false;
|
|
@@ -49,12 +49,12 @@ declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
49
49
|
failureReason: Error | null;
|
|
50
50
|
isPaused: boolean;
|
|
51
51
|
submittedAt: number;
|
|
52
|
-
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
53
|
-
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
52
|
+
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
53
|
+
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
54
54
|
} | {
|
|
55
55
|
data: Session;
|
|
56
56
|
error: null;
|
|
57
|
-
variables: void;
|
|
57
|
+
variables: number | void | undefined;
|
|
58
58
|
isError: false;
|
|
59
59
|
isIdle: false;
|
|
60
60
|
isPending: false;
|
|
@@ -66,8 +66,8 @@ declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
66
66
|
failureReason: Error | null;
|
|
67
67
|
isPaused: boolean;
|
|
68
68
|
submittedAt: number;
|
|
69
|
-
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
70
|
-
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
69
|
+
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
70
|
+
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
71
71
|
};
|
|
72
72
|
export { useSignUpWithWallet };
|
|
73
73
|
//# sourceMappingURL=useSignUpWithWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignUpWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignUpWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"useSignUpWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignUpWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAErE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,iBAAS,mBAAmB,CAC1B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC,EACrD,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUP;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
package/dist/src/provider.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { AuthApiClient, PortalApiClient } from "./api";
|
|
|
2
2
|
export interface PassportContextValue {
|
|
3
3
|
authApiClient: AuthApiClient;
|
|
4
4
|
portalApiClient: PortalApiClient;
|
|
5
|
-
environment
|
|
5
|
+
environment?: Environment;
|
|
6
6
|
}
|
|
7
7
|
export declare const PassportContext: import("react").Context<PassportContextValue | undefined>;
|
|
8
8
|
type Environment = "mainnet" | "testnet";
|
|
9
9
|
type PassportProviderProps = {
|
|
10
10
|
children: React.ReactNode;
|
|
11
|
-
environment
|
|
11
|
+
environment?: Environment;
|
|
12
12
|
authApiUrl?: string;
|
|
13
13
|
portalApiUrl?: string;
|
|
14
14
|
};
|
|
@@ -1 +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,EAAE,WAAW,CAAA;
|
|
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"}
|
package/dist/src/provider.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createContext, createElement } from "react";
|
|
|
2
2
|
import { AuthApiClient, PortalApiClient } from "./api";
|
|
3
3
|
export const PassportContext = createContext(undefined);
|
|
4
4
|
export function PassportProvider({ environment, authApiUrl, portalApiUrl, children, }) {
|
|
5
|
-
if (
|
|
5
|
+
if (environment && !["mainnet", "testnet"].includes(environment)) {
|
|
6
6
|
throw new Error("Wrong environment passed to PassportProvider.");
|
|
7
7
|
}
|
|
8
8
|
return createElement(PassportContext.Provider, {
|
package/dist/src/provider.js.map
CHANGED
|
@@ -1 +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,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezo-org/passport",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.80",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"scripts": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"typescript": "^5.4.3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@mezo-org/mezo-clay": "0.1.0-dev.
|
|
40
|
+
"@mezo-org/mezo-clay": "0.1.0-dev.30",
|
|
41
41
|
"@mezo-org/mezod-contracts": "^1.0.0",
|
|
42
42
|
"@mezo-org/musd-contracts": "^1.0.1",
|
|
43
43
|
"@mezo-org/orangekit": "1.0.0-beta.40-dev.19",
|
package/src/hooks/index.ts
CHANGED
|
@@ -6,7 +6,6 @@ export {
|
|
|
6
6
|
useSubscribeToConnectorEvent,
|
|
7
7
|
useSubscribeToWalletNetworkDoesNotMatchProviderChain,
|
|
8
8
|
} from "@mezo-org/orangekit"
|
|
9
|
-
export * from "./useAddMezoChainToWallet"
|
|
10
9
|
export { useInvalidateBorrowData, useResetBorrowData } from "./useBorrowData"
|
|
11
10
|
export * from "./useGetAccountByAddress"
|
|
12
11
|
export * from "./useGetAccountByMezoId"
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { useSignMessage
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { useSignMessage } from "wagmi"
|
|
2
|
+
import {
|
|
3
|
+
DefaultError,
|
|
4
|
+
MutationOptions,
|
|
5
|
+
useMutation,
|
|
6
|
+
} from "@tanstack/react-query"
|
|
4
7
|
import { useCreateAccount } from "./useCreateAccount"
|
|
5
8
|
import { useCreateSession } from "./useCreateSession"
|
|
6
9
|
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce"
|
|
@@ -11,13 +14,11 @@ import {
|
|
|
11
14
|
import { useGetAccountByAddress } from "./useGetAccountByAddress"
|
|
12
15
|
import type { Session } from "../api"
|
|
13
16
|
import useWalletAccount from "./useWalletAccount"
|
|
14
|
-
import { useAddMezoChainToWallet } from "./useAddMezoChainToWallet"
|
|
15
|
-
import { usePassportContext } from "./usePassportContext"
|
|
16
17
|
|
|
17
18
|
function useAuthenticateWithWallet(
|
|
18
19
|
shouldCreateAccount = false,
|
|
19
20
|
mutationOptions: Omit<
|
|
20
|
-
MutationOptions<Session>,
|
|
21
|
+
MutationOptions<Session, DefaultError, number | void>,
|
|
21
22
|
"mutationFn" | "mutationKey"
|
|
22
23
|
> = {},
|
|
23
24
|
) {
|
|
@@ -31,10 +32,6 @@ function useAuthenticateWithWallet(
|
|
|
31
32
|
const { createSessionAsync } = useCreateSession()
|
|
32
33
|
const { createAccountAsync } = useCreateAccount()
|
|
33
34
|
const { signMessageAsync } = useSignMessage()
|
|
34
|
-
const { environment } = usePassportContext()
|
|
35
|
-
const { isMezoChain, addMezoChain } = useAddMezoChainToWallet(environment)
|
|
36
|
-
const MEZO_CHAIN = environment === "mainnet" ? mezoMainnet : mezoTestnet
|
|
37
|
-
const { switchChainAsync } = useSwitchChain()
|
|
38
35
|
|
|
39
36
|
const { refetch: getAccountByAddress } = useGetAccountByAddress(
|
|
40
37
|
walletAddress,
|
|
@@ -45,28 +42,18 @@ function useAuthenticateWithWallet(
|
|
|
45
42
|
)
|
|
46
43
|
|
|
47
44
|
const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
|
|
48
|
-
mutationFn: async () => {
|
|
45
|
+
mutationFn: async (chainId?: number | void) => {
|
|
49
46
|
if (!walletAddress) {
|
|
50
47
|
throw new Error("Sign in error: Wallet not connected!")
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
let chainId = walletChainId
|
|
54
|
-
console.log("before adding chain...")
|
|
55
|
-
if (connector?.type !== "orangekit" && !isMezoChain) {
|
|
56
|
-
console.log("ading mezo chain")
|
|
57
|
-
await addMezoChain()
|
|
58
|
-
console.log("switching chain...")
|
|
59
|
-
const newChain = await switchChainAsync({ chainId: MEZO_CHAIN.id })
|
|
60
|
-
chainId = newChain.id
|
|
61
|
-
}
|
|
62
|
-
|
|
63
50
|
const nonce = await ensureNoSessionAndFetchNonce()
|
|
64
51
|
|
|
65
52
|
const messageResult = createSignInWithWalletMessage(
|
|
66
53
|
walletAddress,
|
|
67
54
|
nonce,
|
|
68
55
|
networkFamily,
|
|
69
|
-
chainId,
|
|
56
|
+
chainId ?? walletChainId,
|
|
70
57
|
)
|
|
71
58
|
const signatureResult = await signMessageAsync({
|
|
72
59
|
message: messageResult,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { MutationOptions } from "@tanstack/react-query"
|
|
1
|
+
import { DefaultError, MutationOptions } from "@tanstack/react-query"
|
|
2
2
|
import { useAuthenticateWithWallet } from "./useAuthenticateWithWallet"
|
|
3
3
|
import type { Session } from "../api"
|
|
4
4
|
|
|
5
5
|
function useSignInWithWallet(
|
|
6
6
|
mutationOptions: Omit<
|
|
7
|
-
MutationOptions<Session>,
|
|
7
|
+
MutationOptions<Session, DefaultError, number | void>,
|
|
8
8
|
"mutationFn" | "mutationKey"
|
|
9
9
|
> = {},
|
|
10
10
|
) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { MutationOptions } from "@tanstack/react-query"
|
|
1
|
+
import { DefaultError, MutationOptions } from "@tanstack/react-query"
|
|
2
2
|
import { useAuthenticateWithWallet } from "./useAuthenticateWithWallet"
|
|
3
3
|
import type { Session } from "../api"
|
|
4
4
|
|
|
5
5
|
function useSignUpWithWallet(
|
|
6
6
|
mutationOptions: Omit<
|
|
7
|
-
MutationOptions<Session>,
|
|
7
|
+
MutationOptions<Session, DefaultError, number | void>,
|
|
8
8
|
"mutationFn" | "mutationKey"
|
|
9
9
|
> = {},
|
|
10
10
|
) {
|
package/src/provider.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { AuthApiClient, PortalApiClient } from "./api"
|
|
|
4
4
|
export interface PassportContextValue {
|
|
5
5
|
authApiClient: AuthApiClient
|
|
6
6
|
portalApiClient: PortalApiClient
|
|
7
|
-
environment
|
|
7
|
+
environment?: Environment
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const PassportContext = createContext<PassportContextValue | undefined>(
|
|
@@ -16,7 +16,7 @@ type Environment = "mainnet" | "testnet"
|
|
|
16
16
|
type PassportProviderProps = {
|
|
17
17
|
children: React.ReactNode
|
|
18
18
|
// eslint-disable-next-line react/require-default-props
|
|
19
|
-
environment
|
|
19
|
+
environment?: Environment
|
|
20
20
|
// eslint-disable-next-line react/require-default-props
|
|
21
21
|
authApiUrl?: string
|
|
22
22
|
// eslint-disable-next-line react/require-default-props
|
|
@@ -29,7 +29,7 @@ export function PassportProvider({
|
|
|
29
29
|
portalApiUrl,
|
|
30
30
|
children,
|
|
31
31
|
}: PassportProviderProps) {
|
|
32
|
-
if (
|
|
32
|
+
if (environment && !["mainnet", "testnet"].includes(environment)) {
|
|
33
33
|
throw new Error("Wrong environment passed to PassportProvider.")
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAddMezoChainToWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAddMezoChainToWallet.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,GAClC,aAAa,SAAS,GAAG,SAAS,EAClC,mBAAmB,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;;;CA6D7D,CAAA"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { mezoMainnet, mezoTestnet } from "@mezo-org/orangekit";
|
|
2
|
-
import { useCallback, useEffect, useState } from "react";
|
|
3
|
-
import { useAccount } from "wagmi";
|
|
4
|
-
export const useAddMezoChainToWallet = (mezoNetwork, onMezoChainAdded) => {
|
|
5
|
-
const [isMezoChain, setIsMezoChain] = useState(false);
|
|
6
|
-
const MEZO_CHAIN = mezoNetwork === "mainnet" ? mezoMainnet : mezoTestnet;
|
|
7
|
-
const hexadecimalMezoChainId = `0x${MEZO_CHAIN.id.toString(16)}`;
|
|
8
|
-
const { connector } = useAccount();
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
const getCurrentChainId = async () => {
|
|
11
|
-
console.log("getCurrentChainId useEffect");
|
|
12
|
-
if (!window.ethereum || connector?.type === "orangekit")
|
|
13
|
-
return;
|
|
14
|
-
const currentChainId = await window.ethereum.request({
|
|
15
|
-
method: "eth_chainId",
|
|
16
|
-
});
|
|
17
|
-
console.log("setting current chain Id: ", currentChainId);
|
|
18
|
-
setIsMezoChain(currentChainId === hexadecimalMezoChainId);
|
|
19
|
-
};
|
|
20
|
-
getCurrentChainId();
|
|
21
|
-
}, [connector, hexadecimalMezoChainId]);
|
|
22
|
-
const addMezoChain = useCallback(async () => {
|
|
23
|
-
if (!window.ethereum || connector?.type === "orangekit")
|
|
24
|
-
return;
|
|
25
|
-
const mezoChainParams = {
|
|
26
|
-
chainId: hexadecimalMezoChainId,
|
|
27
|
-
chainName: MEZO_CHAIN.name,
|
|
28
|
-
nativeCurrency: MEZO_CHAIN.nativeCurrency,
|
|
29
|
-
rpcUrls: [MEZO_CHAIN.rpcUrls.default.http[0]],
|
|
30
|
-
blockExplorerUrls: [MEZO_CHAIN.blockExplorers?.default.url],
|
|
31
|
-
};
|
|
32
|
-
try {
|
|
33
|
-
await window.ethereum.request({
|
|
34
|
-
method: "wallet_addEthereumChain",
|
|
35
|
-
params: [mezoChainParams],
|
|
36
|
-
});
|
|
37
|
-
setIsMezoChain(true);
|
|
38
|
-
if (onMezoChainAdded)
|
|
39
|
-
onMezoChainAdded(MEZO_CHAIN.id);
|
|
40
|
-
// setConnectedChainId(MEZO_CHAIN.id)
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
setIsMezoChain(false);
|
|
44
|
-
}
|
|
45
|
-
}, [
|
|
46
|
-
connector?.type,
|
|
47
|
-
hexadecimalMezoChainId,
|
|
48
|
-
MEZO_CHAIN.name,
|
|
49
|
-
MEZO_CHAIN.nativeCurrency,
|
|
50
|
-
MEZO_CHAIN.rpcUrls.default.http,
|
|
51
|
-
MEZO_CHAIN.blockExplorers?.default.url,
|
|
52
|
-
MEZO_CHAIN.id,
|
|
53
|
-
onMezoChainAdded,
|
|
54
|
-
]);
|
|
55
|
-
return { isMezoChain, addMezoChain };
|
|
56
|
-
};
|
|
57
|
-
//# sourceMappingURL=useAddMezoChainToWallet.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAddMezoChainToWallet.js","sourceRoot":"","sources":["../../../src/hooks/useAddMezoChainToWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAElC,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,WAAkC,EAClC,gBAA4D,EAC5D,EAAE;IACF,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAErD,MAAM,UAAU,GAAG,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAA;IAExE,MAAM,sBAAsB,GAAG,KAAK,UAAU,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAA;IAEhE,MAAM,EAAE,SAAS,EAAE,GAAG,UAAU,EAAE,CAAA;IAElC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,iBAAiB,GAAG,KAAK,IAAI,EAAE;YACnC,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAA;YAC1C,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,SAAS,EAAE,IAAI,KAAK,WAAW;gBAAE,OAAM;YAE/D,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;gBACnD,MAAM,EAAE,aAAa;aACtB,CAAC,CAAA;YAEF,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,cAAc,CAAC,CAAA;YACzD,cAAc,CAAC,cAAc,KAAK,sBAAsB,CAAC,CAAA;QAC3D,CAAC,CAAA;QAED,iBAAiB,EAAE,CAAA;IACrB,CAAC,EAAE,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAA;IAEvC,MAAM,YAAY,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QAC1C,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,SAAS,EAAE,IAAI,KAAK,WAAW;YAAE,OAAM;QAE/D,MAAM,eAAe,GAAG;YACtB,OAAO,EAAE,sBAAsB;YAC/B,SAAS,EAAE,UAAU,CAAC,IAAI;YAC1B,cAAc,EAAE,UAAU,CAAC,cAAc;YACzC,OAAO,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC7C,iBAAiB,EAAE,CAAC,UAAU,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC;SAC5D,CAAA;QAED,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAC5B,MAAM,EAAE,yBAAyB;gBACjC,MAAM,EAAE,CAAC,eAAe,CAAC;aAC1B,CAAC,CAAA;YAEF,cAAc,CAAC,IAAI,CAAC,CAAA;YACpB,IAAI,gBAAgB;gBAAE,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;YACrD,qCAAqC;QACvC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,cAAc,CAAC,KAAK,CAAC,CAAA;QACvB,CAAC;IACH,CAAC,EAAE;QACD,SAAS,EAAE,IAAI;QACf,sBAAsB;QACtB,UAAU,CAAC,IAAI;QACf,UAAU,CAAC,cAAc;QACzB,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI;QAC/B,UAAU,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG;QACtC,UAAU,CAAC,EAAE;QACb,gBAAgB;KACjB,CAAC,CAAA;IAEF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAA;AACtC,CAAC,CAAA"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { mezoMainnet, mezoTestnet } from "@mezo-org/orangekit"
|
|
2
|
-
import { useCallback, useEffect, useState } from "react"
|
|
3
|
-
import { useAccount } from "wagmi"
|
|
4
|
-
|
|
5
|
-
export const useAddMezoChainToWallet = (
|
|
6
|
-
mezoNetwork: "mainnet" | "testnet",
|
|
7
|
-
onMezoChainAdded?: (chainId: number) => void | Promise<void>,
|
|
8
|
-
) => {
|
|
9
|
-
const [isMezoChain, setIsMezoChain] = useState(false)
|
|
10
|
-
|
|
11
|
-
const MEZO_CHAIN = mezoNetwork === "mainnet" ? mezoMainnet : mezoTestnet
|
|
12
|
-
|
|
13
|
-
const hexadecimalMezoChainId = `0x${MEZO_CHAIN.id.toString(16)}`
|
|
14
|
-
|
|
15
|
-
const { connector } = useAccount()
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const getCurrentChainId = async () => {
|
|
19
|
-
console.log("getCurrentChainId useEffect")
|
|
20
|
-
if (!window.ethereum || connector?.type === "orangekit") return
|
|
21
|
-
|
|
22
|
-
const currentChainId = await window.ethereum.request({
|
|
23
|
-
method: "eth_chainId",
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
console.log("setting current chain Id: ", currentChainId)
|
|
27
|
-
setIsMezoChain(currentChainId === hexadecimalMezoChainId)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getCurrentChainId()
|
|
31
|
-
}, [connector, hexadecimalMezoChainId])
|
|
32
|
-
|
|
33
|
-
const addMezoChain = useCallback(async () => {
|
|
34
|
-
if (!window.ethereum || connector?.type === "orangekit") return
|
|
35
|
-
|
|
36
|
-
const mezoChainParams = {
|
|
37
|
-
chainId: hexadecimalMezoChainId,
|
|
38
|
-
chainName: MEZO_CHAIN.name,
|
|
39
|
-
nativeCurrency: MEZO_CHAIN.nativeCurrency,
|
|
40
|
-
rpcUrls: [MEZO_CHAIN.rpcUrls.default.http[0]],
|
|
41
|
-
blockExplorerUrls: [MEZO_CHAIN.blockExplorers?.default.url],
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
await window.ethereum.request({
|
|
46
|
-
method: "wallet_addEthereumChain",
|
|
47
|
-
params: [mezoChainParams],
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
setIsMezoChain(true)
|
|
51
|
-
if (onMezoChainAdded) onMezoChainAdded(MEZO_CHAIN.id)
|
|
52
|
-
// setConnectedChainId(MEZO_CHAIN.id)
|
|
53
|
-
} catch (err) {
|
|
54
|
-
setIsMezoChain(false)
|
|
55
|
-
}
|
|
56
|
-
}, [
|
|
57
|
-
connector?.type,
|
|
58
|
-
hexadecimalMezoChainId,
|
|
59
|
-
MEZO_CHAIN.name,
|
|
60
|
-
MEZO_CHAIN.nativeCurrency,
|
|
61
|
-
MEZO_CHAIN.rpcUrls.default.http,
|
|
62
|
-
MEZO_CHAIN.blockExplorers?.default.url,
|
|
63
|
-
MEZO_CHAIN.id,
|
|
64
|
-
onMezoChainAdded,
|
|
65
|
-
])
|
|
66
|
-
|
|
67
|
-
return { isMezoChain, addMezoChain }
|
|
68
|
-
}
|