@mezo-org/passport 0.4.0-dev.6 → 0.4.0-dev.8
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/components/Dropdown/Content.d.ts +1 -0
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Content.js +6 -2
- package/dist/src/components/Dropdown/Content.js.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.d.ts +4 -2
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.js +6 -3
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +5 -6
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/utils/cryptoAssets.js +1 -1
- package/package.json +2 -2
- package/src/components/Dropdown/Content.tsx +8 -2
- package/src/components/Dropdown/Dropdown.tsx +12 -5
- package/src/components/Dropdown/README.md +6 -3
- package/src/hooks/useAuthenticateWithWallet.ts +5 -12
- package/src/utils/cryptoAssets.ts +1 -1
|
@@ -2,6 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { DropdownData } from "../../hooks/useDropdownData";
|
|
3
3
|
type DropdownContentProps = {
|
|
4
4
|
data: DropdownData;
|
|
5
|
+
onSignOut?: () => void;
|
|
5
6
|
};
|
|
6
7
|
export default function DropdownContent(props: DropdownContentProps): React.JSX.Element;
|
|
7
8
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Content.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/Content.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAsB,MAAM,OAAO,CAAA;AAG1C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AA0B1D,KAAK,oBAAoB,GAAG;IAC1B,IAAI,EAAE,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"Content.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/Content.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAsB,MAAM,OAAO,CAAA;AAG1C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AA0B1D,KAAK,oBAAoB,GAAG;IAC1B,IAAI,EAAE,YAAY,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;CACvB,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,KAAK,EAAE,oBAAoB,qBAyGlE"}
|
|
@@ -19,15 +19,19 @@ function MatsnetLabel() {
|
|
|
19
19
|
"Matsnet Assets"));
|
|
20
20
|
}
|
|
21
21
|
export default function DropdownContent(props) {
|
|
22
|
-
const { data } = props;
|
|
22
|
+
const { data, onSignOut } = props;
|
|
23
23
|
const [, theme] = useStyletron();
|
|
24
24
|
const { mezoId, address, walletType, totalBalanceInUsd, formattedNativeAssets, matsnet, } = data;
|
|
25
25
|
const { disconnect } = useDisconnect();
|
|
26
26
|
const { signOut } = useSignOut();
|
|
27
27
|
const handleLogOut = useCallback(() => {
|
|
28
|
+
if (onSignOut) {
|
|
29
|
+
onSignOut();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
28
32
|
signOut();
|
|
29
33
|
disconnect();
|
|
30
|
-
}, [signOut, disconnect]);
|
|
34
|
+
}, [signOut, disconnect, onSignOut]);
|
|
31
35
|
return (React.createElement(Block, { display: "inline-flex", flexDirection: "column", backgroundColor: theme.colors.backgroundPrimary, padding: theme.sizing.scale500, width: "100%", overrides: {
|
|
32
36
|
Block: {
|
|
33
37
|
style: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Content.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/Content.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,cAAc,EACd,YAAY,GACb,MAAM,qBAAqB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C,oBAAC,MAAM,IACL,IAAI,EAAC,OAAO,EACZ,IAAI,EAAC,UAAU,EACf,aAAa,EAAE,oBAAC,QAAQ,IAAC,KAAK,EAAC,cAAc,EAAC,IAAI,EAAE,EAAE,GAAI,EAC1D,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,EAC7B,SAAS,EAAE;oBACT,IAAI,EAAE;wBACJ,KAAK,EAAE;4BACL,QAAQ,EAAE;gCACR,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,mBAAmB;gCACjD,SAAS,EAAE,MAAM;6BAClB;4BACD,SAAS,EAAE;gCACT,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,mBAAmB;gCACjD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,cAAc;6BACnC;yBACF;qBACF;iBACF,cAGM,CACH,CACF,CACT,CAAA;AACH,CAAC"}
|
|
@@ -2,8 +2,10 @@ import { StatefulPopoverProps } from "@mezo-org/mezo-clay";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { DropdownCryptoAsset } from "../../hooks/useDropdownData";
|
|
4
4
|
export type DropdownProps = {
|
|
5
|
-
/** The callback to be called when the user clicks
|
|
6
|
-
|
|
5
|
+
/** The callback to be called when the user clicks the sign-out button */
|
|
6
|
+
onSignOut?: () => void;
|
|
7
|
+
/** The callback to be called when the user clicks the button in sign-in state */
|
|
8
|
+
onSignIn?: () => void;
|
|
7
9
|
/** The set of EVM native assets to be displayed in the dropdown */
|
|
8
10
|
evmNativeAssets?: DropdownCryptoAsset<"tbtc" | "wbtc">[];
|
|
9
11
|
/** The set of Matsnet assets to be displayed in the dropdown */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/Dropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EAErB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAwB,EACtB,mBAAmB,EACpB,MAAM,6BAA6B,CAAA;AAMpC,MAAM,MAAM,aAAa,GAAG;IAC1B,
|
|
1
|
+
{"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/Dropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EAErB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAwB,EACtB,mBAAmB,EACpB,MAAM,6BAA6B,CAAA;AAMpC,MAAM,MAAM,aAAa,GAAG;IAC1B,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,mEAAmE;IACnE,eAAe,CAAC,EAAE,mBAAmB,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACxD,gEAAgE;IAChE,aAAa,CAAC,EAAE,mBAAmB,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;CACvD,GAAG,IAAI,CAAC,oBAAoB,EAAE,UAAU,GAAG,SAAS,CAAC,CAAA;AAEtD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,qBAuD5C"}
|
|
@@ -13,7 +13,7 @@ import DisconnectedTrigger from "./DisconnectedTrigger";
|
|
|
13
13
|
* @returns {JSX.Element}
|
|
14
14
|
*/
|
|
15
15
|
export function Dropdown(props) {
|
|
16
|
-
const { placement = "bottomRight", animateOutTime = 120,
|
|
16
|
+
const { placement = "bottomRight", animateOutTime = 120, onSignIn, onSignOut, evmNativeAssets, matsnetAssets, overrides, ...restProps } = props;
|
|
17
17
|
const [, theme] = useStyletron();
|
|
18
18
|
const dropdownData = useDropdownData({ evmNativeAssets, matsnetAssets });
|
|
19
19
|
const { openConnectModal } = useConnectModal();
|
|
@@ -25,15 +25,18 @@ export function Dropdown(props) {
|
|
|
25
25
|
, {
|
|
26
26
|
// If connect wallet flow is not provided it fallbacks to RainbowKit's
|
|
27
27
|
// connect modal
|
|
28
|
-
onClick:
|
|
28
|
+
onClick: onSignIn || openConnectModal }, "Sign in"));
|
|
29
29
|
}
|
|
30
|
-
return (React.createElement(StatefulPopover, { content: React.createElement(Content, { data: dropdownData }), placement: placement, animateOutTime: animateOutTime, overrides: {
|
|
30
|
+
return (React.createElement(StatefulPopover, { content: React.createElement(Content, { data: dropdownData, onSignOut: onSignOut }), placement: placement, animateOutTime: animateOutTime, overrides: {
|
|
31
|
+
...overrides,
|
|
31
32
|
Body: {
|
|
33
|
+
...overrides?.Body,
|
|
32
34
|
style: {
|
|
33
35
|
minWidth: "378px",
|
|
34
36
|
borderRadius: theme.borders.radius500,
|
|
35
37
|
boxShadow: theme.lighting.shadow500,
|
|
36
38
|
overflow: "hidden",
|
|
39
|
+
...overrides?.Body?.style,
|
|
37
40
|
},
|
|
38
41
|
},
|
|
39
42
|
}, ...restProps },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dropdown.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/Dropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,YAAY,GACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,aAAa,MAAM,4BAA4B,CAAA;AACtD,OAAO,eAEN,MAAM,6BAA6B,CAAA;AACpC,OAAO,gBAAgB,MAAM,8BAA8B,CAAA;AAC3D,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,mBAAmB,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"Dropdown.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/Dropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,YAAY,GACb,MAAM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EAAE;gBACJ,GAAG,SAAS,EAAE,IAAI;gBAClB,KAAK,EAAE;oBACL,QAAQ,EAAE,OAAO;oBACjB,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS;oBACrC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS;oBACnC,QAAQ,EAAE,QAAQ;oBAClB,GAAG,SAAS,EAAE,IAAI,EAAE,KAAK;iBAC1B;aACF;SACF,KACG,SAAS;QAEb,oBAAC,gBAAgB,IAAC,MAAM,EAAE,oBAAC,aAAa,OAAG,GAAI,CAC/B,CACnB,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticateWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAuthenticateWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAe,MAAM,uBAAuB,CAAA;AAMpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAGrC,iBAAS,yBAAyB,CAChC,mBAAmB,UAAQ,EAC3B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,OAAO,CAAC,EACxB,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgFP;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAA"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { useSignMessage } from "wagmi";
|
|
2
|
-
import { useBitcoinAccount } from "@mezo-org/orangekit";
|
|
3
2
|
import { useMutation } from "@tanstack/react-query";
|
|
4
|
-
import { useMemo } from "react";
|
|
5
3
|
import { useCreateAccount } from "./useCreateAccount";
|
|
6
4
|
import { useCreateSession } from "./useCreateSession";
|
|
7
5
|
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce";
|
|
@@ -10,20 +8,21 @@ import { useGetAccountByAddress } from "./useGetAccountByAddress";
|
|
|
10
8
|
import useWalletAccount from "./useWalletAccount";
|
|
11
9
|
function useAuthenticateWithWallet(shouldCreateAccount = false, mutationOptions = {}) {
|
|
12
10
|
const { address, chainId, connector, networkFamily } = useWalletAccount();
|
|
13
|
-
const { btcAddress } = useBitcoinAccount();
|
|
14
11
|
const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce();
|
|
15
12
|
const { createSessionAsync } = useCreateSession();
|
|
16
13
|
const { createAccountAsync } = useCreateAccount();
|
|
17
14
|
const { signMessageAsync } = useSignMessage();
|
|
18
|
-
const
|
|
19
|
-
|
|
15
|
+
const { refetch: getAccountByAddress } = useGetAccountByAddress(address, {
|
|
16
|
+
enabled: false,
|
|
17
|
+
retry: false,
|
|
18
|
+
});
|
|
20
19
|
const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
|
|
21
20
|
mutationFn: async () => {
|
|
22
21
|
if (!address) {
|
|
23
22
|
throw new Error("Sign in error: Wallet not connected!");
|
|
24
23
|
}
|
|
25
24
|
const nonce = await ensureNoSessionAndFetchNonce();
|
|
26
|
-
const messageResult = createSignInWithWalletMessage(
|
|
25
|
+
const messageResult = createSignInWithWalletMessage(address, nonce, networkFamily, chainId);
|
|
27
26
|
const signatureResult = await signMessageAsync({
|
|
28
27
|
message: messageResult,
|
|
29
28
|
connector,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticateWithWallet.js","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,
|
|
1
|
+
{"version":3,"file":"useAuthenticateWithWallet.js","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"AAAA,OAA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E,CAAA"}
|
package/package.json
CHANGED
|
@@ -37,10 +37,11 @@ function MatsnetLabel() {
|
|
|
37
37
|
|
|
38
38
|
type DropdownContentProps = {
|
|
39
39
|
data: DropdownData
|
|
40
|
+
onSignOut?: () => void
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
export default function DropdownContent(props: DropdownContentProps) {
|
|
43
|
-
const { data } = props
|
|
44
|
+
const { data, onSignOut } = props
|
|
44
45
|
|
|
45
46
|
const [, theme] = useStyletron()
|
|
46
47
|
|
|
@@ -57,9 +58,14 @@ export default function DropdownContent(props: DropdownContentProps) {
|
|
|
57
58
|
const { signOut } = useSignOut()
|
|
58
59
|
|
|
59
60
|
const handleLogOut = useCallback(() => {
|
|
61
|
+
if (onSignOut) {
|
|
62
|
+
onSignOut()
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
60
66
|
signOut()
|
|
61
67
|
disconnect()
|
|
62
|
-
}, [signOut, disconnect])
|
|
68
|
+
}, [signOut, disconnect, onSignOut])
|
|
63
69
|
|
|
64
70
|
return (
|
|
65
71
|
<Block
|
|
@@ -15,8 +15,10 @@ import Content from "./Content"
|
|
|
15
15
|
import DisconnectedTrigger from "./DisconnectedTrigger"
|
|
16
16
|
|
|
17
17
|
export type DropdownProps = {
|
|
18
|
-
/** The callback to be called when the user clicks
|
|
19
|
-
|
|
18
|
+
/** The callback to be called when the user clicks the sign-out button */
|
|
19
|
+
onSignOut?: () => void
|
|
20
|
+
/** The callback to be called when the user clicks the button in sign-in state */
|
|
21
|
+
onSignIn?: () => void
|
|
20
22
|
/** The set of EVM native assets to be displayed in the dropdown */
|
|
21
23
|
evmNativeAssets?: DropdownCryptoAsset<"tbtc" | "wbtc">[]
|
|
22
24
|
/** The set of Matsnet assets to be displayed in the dropdown */
|
|
@@ -32,9 +34,11 @@ export function Dropdown(props: DropdownProps) {
|
|
|
32
34
|
const {
|
|
33
35
|
placement = "bottomRight",
|
|
34
36
|
animateOutTime = 120,
|
|
35
|
-
|
|
37
|
+
onSignIn,
|
|
38
|
+
onSignOut,
|
|
36
39
|
evmNativeAssets,
|
|
37
40
|
matsnetAssets,
|
|
41
|
+
overrides,
|
|
38
42
|
...restProps
|
|
39
43
|
} = props
|
|
40
44
|
|
|
@@ -51,7 +55,7 @@ export function Dropdown(props: DropdownProps) {
|
|
|
51
55
|
<DisconnectedTrigger
|
|
52
56
|
// If connect wallet flow is not provided it fallbacks to RainbowKit's
|
|
53
57
|
// connect modal
|
|
54
|
-
onClick={
|
|
58
|
+
onClick={onSignIn || openConnectModal}
|
|
55
59
|
>
|
|
56
60
|
Sign in
|
|
57
61
|
</DisconnectedTrigger>
|
|
@@ -60,16 +64,19 @@ export function Dropdown(props: DropdownProps) {
|
|
|
60
64
|
|
|
61
65
|
return (
|
|
62
66
|
<StatefulPopover
|
|
63
|
-
content={<Content data={dropdownData} />}
|
|
67
|
+
content={<Content data={dropdownData} onSignOut={onSignOut} />}
|
|
64
68
|
placement={placement}
|
|
65
69
|
animateOutTime={animateOutTime}
|
|
66
70
|
overrides={{
|
|
71
|
+
...overrides,
|
|
67
72
|
Body: {
|
|
73
|
+
...overrides?.Body,
|
|
68
74
|
style: {
|
|
69
75
|
minWidth: "378px",
|
|
70
76
|
borderRadius: theme.borders.radius500,
|
|
71
77
|
boxShadow: theme.lighting.shadow500,
|
|
72
78
|
overflow: "hidden",
|
|
79
|
+
...overrides?.Body?.style,
|
|
73
80
|
},
|
|
74
81
|
},
|
|
75
82
|
}}
|
|
@@ -5,10 +5,13 @@ component. It allows to establish the session and interact with the API.
|
|
|
5
5
|
|
|
6
6
|
## Props
|
|
7
7
|
|
|
8
|
-
- `
|
|
9
|
-
|
|
10
|
-
[Rainbow Kit's wallet connection modal](https://www.rainbowkit.com/docs/modal-hooks) -
|
|
8
|
+
- `onSignIn` (`() => void`) - The callback to be executed on trigger click when
|
|
9
|
+
the state is disconnected, it's optional since by default it triggers the
|
|
10
|
+
[Rainbow Kit's wallet connection modal](https://www.rainbowkit.com/docs/modal-hooks). -
|
|
11
11
|
**optional**
|
|
12
|
+
- `onSignOut` (`() => void`) - The callback to be executed on click of the
|
|
13
|
+
**Sign out** button, it's optional since by default it disconnects the current
|
|
14
|
+
wallet connector and closes the Passport session. - **optional**
|
|
12
15
|
- `evmNativeAssets` (`Asset<"tbtc" | "wbtc">[]`) - Array of Matsnet assets. -
|
|
13
16
|
**optional**
|
|
14
17
|
- `matsnetAssets` (`Asset<"mbtc" | "musd">[]`) - Array of Matsnet assets. -
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { useSignMessage } from "wagmi"
|
|
2
|
-
import { useBitcoinAccount } from "@mezo-org/orangekit"
|
|
3
2
|
import { MutationOptions, useMutation } from "@tanstack/react-query"
|
|
4
|
-
import { useMemo } from "react"
|
|
5
3
|
import { useCreateAccount } from "./useCreateAccount"
|
|
6
4
|
import { useCreateSession } from "./useCreateSession"
|
|
7
5
|
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce"
|
|
@@ -18,20 +16,15 @@ function useAuthenticateWithWallet(
|
|
|
18
16
|
> = {},
|
|
19
17
|
) {
|
|
20
18
|
const { address, chainId, connector, networkFamily } = useWalletAccount()
|
|
21
|
-
const { btcAddress } = useBitcoinAccount()
|
|
22
19
|
const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce()
|
|
23
20
|
const { createSessionAsync } = useCreateSession()
|
|
24
21
|
const { createAccountAsync } = useCreateAccount()
|
|
25
22
|
const { signMessageAsync } = useSignMessage()
|
|
26
|
-
const walletAddress = useMemo(
|
|
27
|
-
() => (connector?.type === "orangekit" ? btcAddress : address),
|
|
28
|
-
[btcAddress, address, connector],
|
|
29
|
-
)
|
|
30
23
|
|
|
31
|
-
const { refetch: getAccountByAddress } = useGetAccountByAddress(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
24
|
+
const { refetch: getAccountByAddress } = useGetAccountByAddress(address, {
|
|
25
|
+
enabled: false,
|
|
26
|
+
retry: false,
|
|
27
|
+
})
|
|
35
28
|
|
|
36
29
|
const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
|
|
37
30
|
mutationFn: async () => {
|
|
@@ -42,7 +35,7 @@ function useAuthenticateWithWallet(
|
|
|
42
35
|
const nonce = await ensureNoSessionAndFetchNonce()
|
|
43
36
|
|
|
44
37
|
const messageResult = createSignInWithWalletMessage(
|
|
45
|
-
|
|
38
|
+
address,
|
|
46
39
|
nonce,
|
|
47
40
|
networkFamily,
|
|
48
41
|
chainId,
|