@b3dotfun/sdk 0.1.70-alpha.3 → 0.1.70-alpha.5
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/cjs/app.shared.d.ts +8 -0
- package/dist/cjs/app.shared.js +19 -0
- package/dist/cjs/global-account/better-auth-client.d.ts +8 -0
- package/dist/cjs/global-account/better-auth-client.js +26 -3
- package/dist/cjs/global-account/client-manager.d.ts +2 -0
- package/dist/cjs/global-account/client-manager.js +19 -4
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +10 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -1
- package/dist/cjs/global-account/react/components/B3Provider/BetterAuthProvider.js +45 -4
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +1 -5
- package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +3 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.js +1 -3
- package/dist/cjs/global-account/react/components/index.d.ts +0 -1
- package/dist/cjs/global-account/react/components/index.js +3 -5
- package/dist/cjs/global-account/react/hooks/index.d.ts +0 -1
- package/dist/cjs/global-account/react/hooks/index.js +2 -4
- package/dist/cjs/global-account/react/hooks/useBetterAuth.js +7 -7
- package/dist/cjs/global-account/types/b3-api.types.d.ts +5 -0
- package/dist/esm/app.shared.d.ts +8 -0
- package/dist/esm/app.shared.js +17 -0
- package/dist/esm/global-account/better-auth-client.d.ts +8 -0
- package/dist/esm/global-account/better-auth-client.js +25 -4
- package/dist/esm/global-account/client-manager.d.ts +2 -0
- package/dist/esm/global-account/client-manager.js +19 -5
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +10 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +16 -2
- package/dist/esm/global-account/react/components/B3Provider/BetterAuthProvider.js +46 -5
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +1 -5
- package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +3 -2
- package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.js +1 -3
- package/dist/esm/global-account/react/components/index.d.ts +0 -1
- package/dist/esm/global-account/react/components/index.js +0 -1
- package/dist/esm/global-account/react/hooks/index.d.ts +0 -1
- package/dist/esm/global-account/react/hooks/index.js +0 -1
- package/dist/esm/global-account/react/hooks/useBetterAuth.js +8 -8
- package/dist/esm/global-account/types/b3-api.types.d.ts +5 -0
- package/dist/types/app.shared.d.ts +8 -0
- package/dist/types/global-account/better-auth-client.d.ts +8 -0
- package/dist/types/global-account/client-manager.d.ts +2 -0
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +10 -1
- package/dist/types/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +3 -2
- package/dist/types/global-account/react/components/index.d.ts +0 -1
- package/dist/types/global-account/react/hooks/index.d.ts +0 -1
- package/dist/types/global-account/types/b3-api.types.d.ts +5 -0
- package/package.json +2 -2
- package/src/app.shared.ts +20 -0
- package/src/global-account/better-auth-client.ts +28 -4
- package/src/global-account/client-manager.ts +20 -5
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +26 -1
- package/src/global-account/react/components/B3Provider/BetterAuthProvider.tsx +51 -5
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +1 -4
- package/src/global-account/react/components/SignInWithB3/utils/signInUtils.ts +2 -4
- package/src/global-account/react/components/index.ts +0 -1
- package/src/global-account/react/hooks/index.ts +0 -1
- package/src/global-account/react/hooks/useBetterAuth.ts +8 -8
- package/src/global-account/types/b3-api.types.ts +5 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +0 -10
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +0 -46
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +0 -11
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +0 -70
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +0 -10
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +0 -43
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +0 -11
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +0 -67
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +0 -10
- package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +0 -11
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +0 -63
- package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +0 -79
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Loading,
|
|
3
|
-
useAuthentication,
|
|
4
|
-
useAuthStore,
|
|
5
|
-
useB3Config,
|
|
6
|
-
useHandleConnectWithPrivy,
|
|
7
|
-
} from "@b3dotfun/sdk/global-account/react";
|
|
8
|
-
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
9
|
-
import { useEffect } from "react";
|
|
10
|
-
import type { Chain } from "thirdweb";
|
|
11
|
-
import { Account } from "thirdweb/wallets";
|
|
12
|
-
|
|
13
|
-
const debug = debugB3React("SignInWithB3Privy");
|
|
14
|
-
interface SignInWithB3PrivyProps {
|
|
15
|
-
onError?: (error: Error) => Promise<void>;
|
|
16
|
-
onSuccess: (account: Account) => Promise<void>;
|
|
17
|
-
accessToken?: string;
|
|
18
|
-
chain: Chain;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3PrivyProps) {
|
|
22
|
-
const { partnerId } = useB3Config();
|
|
23
|
-
const { isLoading, connectTw, fullToken } = useHandleConnectWithPrivy(chain, onSuccess);
|
|
24
|
-
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
25
|
-
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
26
|
-
const { logout } = useAuthentication(partnerId, { skipAutoConnect: true });
|
|
27
|
-
|
|
28
|
-
debug("@@SignInWithB3Privy", {
|
|
29
|
-
isLoading,
|
|
30
|
-
fullToken,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
async function autoConnect() {
|
|
35
|
-
try {
|
|
36
|
-
const connectResult = await connectTw();
|
|
37
|
-
const account = connectResult?.getAccount();
|
|
38
|
-
if (!account) {
|
|
39
|
-
setIsAuthenticated(false);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
await onSuccess(account);
|
|
43
|
-
setIsAuthenticated(true);
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.error("Failed to connect:", error);
|
|
46
|
-
await onError?.(error as Error);
|
|
47
|
-
await logout();
|
|
48
|
-
setIsAuthenticated(false);
|
|
49
|
-
} finally {
|
|
50
|
-
debug("setIsAuthenticating:false:7");
|
|
51
|
-
setIsAuthenticating(false);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
autoConnect();
|
|
55
|
-
}, [connectTw, onSuccess, onError, setIsAuthenticated, logout, setIsAuthenticating]);
|
|
56
|
-
|
|
57
|
-
// Currently we auto login, so we can show loading immediately and the onSuccess will proceed to the next modal
|
|
58
|
-
return (
|
|
59
|
-
<div className="flex aspect-square items-center justify-center p-6">
|
|
60
|
-
<Loading variant="white" size="lg" />
|
|
61
|
-
</div>
|
|
62
|
-
);
|
|
63
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { useB3Config, useConnect } from "@b3dotfun/sdk/global-account/react";
|
|
2
|
-
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
|
-
import { useIdentityToken, usePrivy } from "@privy-io/react-auth";
|
|
4
|
-
import { useCallback, useRef, useState } from "react";
|
|
5
|
-
import { Chain } from "thirdweb";
|
|
6
|
-
import { Account } from "thirdweb/wallets";
|
|
7
|
-
const debug = debugB3React("@@b3:useHandleConnectWithPrivy");
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* This essentially wraps our useConnect hook to handle the Privy auth flow.
|
|
11
|
-
* Currently, this is for the basement-privy strategy
|
|
12
|
-
*/
|
|
13
|
-
export function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void) {
|
|
14
|
-
const { partnerId } = useB3Config();
|
|
15
|
-
if (!chain) {
|
|
16
|
-
throw new Error("Chain is required");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const { connect } = useConnect(partnerId, chain);
|
|
20
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
21
|
-
const isConnecting = useRef(false);
|
|
22
|
-
const { identityToken } = useIdentityToken();
|
|
23
|
-
const { getAccessToken } = usePrivy();
|
|
24
|
-
const [fullToken, setFullToken] = useState<string | null>(null);
|
|
25
|
-
|
|
26
|
-
const connectTw = useCallback(async () => {
|
|
27
|
-
if (isConnecting.current) {
|
|
28
|
-
debug("@@connectTw:skipping:isConnecting", isConnecting.current);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
setIsLoading(true);
|
|
32
|
-
isConnecting.current = true;
|
|
33
|
-
|
|
34
|
-
// Form token
|
|
35
|
-
const accessToken = await getAccessToken();
|
|
36
|
-
const fullToken = `${accessToken}+${identityToken}`;
|
|
37
|
-
setFullToken(fullToken);
|
|
38
|
-
debug("@@connectTw:fullToken", fullToken);
|
|
39
|
-
if (!fullToken) throw new Error("Token is not set");
|
|
40
|
-
|
|
41
|
-
// Connect to TW via privy
|
|
42
|
-
const wallet = await connect({
|
|
43
|
-
strategy: "auth_endpoint",
|
|
44
|
-
payload: JSON.stringify({
|
|
45
|
-
strategy: "basement",
|
|
46
|
-
accessToken: fullToken,
|
|
47
|
-
}),
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
debug("@@useHandleConnectWithPrivy:connect:return", wallet);
|
|
51
|
-
setIsLoading(false);
|
|
52
|
-
|
|
53
|
-
// Handle onsuccess & more
|
|
54
|
-
try {
|
|
55
|
-
debug("@@autoLogin:starting", fullToken);
|
|
56
|
-
|
|
57
|
-
const account = wallet?.getAccount();
|
|
58
|
-
|
|
59
|
-
if (!account) {
|
|
60
|
-
throw new Error("Failed to connect");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
onSuccess?.(account);
|
|
64
|
-
|
|
65
|
-
if (!account) {
|
|
66
|
-
throw new Error("Failed to connect");
|
|
67
|
-
}
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error("@@Error signing in with Privy", error);
|
|
70
|
-
} finally {
|
|
71
|
-
isConnecting.current = false;
|
|
72
|
-
setIsLoading(false);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return wallet;
|
|
76
|
-
}, [connect, getAccessToken, identityToken, onSuccess]);
|
|
77
|
-
|
|
78
|
-
return { connectTw, isLoading, fullToken };
|
|
79
|
-
}
|