@b3dotfun/sdk 0.0.37 → 0.0.38
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 +17 -0
- package/dist/cjs/app.shared.js +54 -0
- package/dist/cjs/global-account/app.d.ts +4 -3
- package/dist/cjs/global-account/app.js +17 -60
- package/dist/cjs/global-account/app.rest.d.ts +2 -0
- package/dist/cjs/global-account/app.rest.js +11 -0
- package/dist/cjs/global-account/client-manager.d.ts +44 -0
- package/dist/cjs/global-account/client-manager.js +136 -0
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +5 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +9 -3
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +5 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +4 -3
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/cjs/global-account/react/components/B3Provider/types.js +1 -0
- package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/index.js +3 -1
- package/dist/cjs/global-account/react/hooks/useClient.d.ts +16 -0
- package/dist/cjs/global-account/react/hooks/useClient.js +38 -0
- package/dist/esm/app.shared.d.ts +17 -0
- package/dist/esm/app.shared.js +46 -0
- package/dist/esm/global-account/app.d.ts +4 -3
- package/dist/esm/global-account/app.js +14 -54
- package/dist/esm/global-account/app.rest.d.ts +2 -0
- package/dist/esm/global-account/app.rest.js +3 -0
- package/dist/esm/global-account/client-manager.d.ts +44 -0
- package/dist/esm/global-account/client-manager.js +121 -0
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +5 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +9 -3
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +5 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +4 -3
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/esm/global-account/react/components/B3Provider/types.js +1 -0
- package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/index.js +1 -0
- package/dist/esm/global-account/react/hooks/useClient.d.ts +16 -0
- package/dist/esm/global-account/react/hooks/useClient.js +35 -0
- package/dist/types/app.shared.d.ts +17 -0
- package/dist/types/global-account/app.d.ts +4 -3
- package/dist/types/global-account/app.rest.d.ts +2 -0
- package/dist/types/global-account/client-manager.d.ts +44 -0
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +5 -2
- package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +5 -2
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/types/global-account/react/hooks/index.d.ts +1 -0
- package/dist/types/global-account/react/hooks/useClient.d.ts +16 -0
- package/package.json +2 -1
- package/src/app.shared.ts +61 -0
- package/src/global-account/app.rest.ts +4 -0
- package/src/global-account/app.ts +17 -63
- package/src/global-account/client-manager.ts +141 -0
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +13 -1
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +12 -0
- package/src/global-account/react/components/B3Provider/types.ts +3 -0
- package/src/global-account/react/hooks/index.ts +1 -0
- package/src/global-account/react/hooks/useClient.ts +57 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AuthenticationClient } from "@feathersjs/authentication-client";
|
|
2
|
+
import Cookies from "js-cookie";
|
|
3
|
+
import { B3_AUTH_COOKIE_NAME } from "./shared/constants/index.js";
|
|
4
|
+
export const B3_API_URL = process.env.EXPO_PUBLIC_B3_API || process.env.NEXT_PUBLIC_B3_API || process.env.PUBLIC_B3_API || "https://api.b3.fun";
|
|
5
|
+
export const authenticate = async (app, accessToken, identityToken, params) => {
|
|
6
|
+
const fullToken = `${accessToken}+${identityToken}`;
|
|
7
|
+
// Do not authenticate if there is no token
|
|
8
|
+
if (!fullToken) {
|
|
9
|
+
console.log("No token found, not authenticating");
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const response = await app.authenticate({
|
|
14
|
+
strategy: "jwt",
|
|
15
|
+
accessToken: fullToken,
|
|
16
|
+
}, {
|
|
17
|
+
query: params || {},
|
|
18
|
+
});
|
|
19
|
+
return response;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export class MyAuthenticationClient extends AuthenticationClient {
|
|
26
|
+
getFromLocation(location) {
|
|
27
|
+
// Do custom location things here
|
|
28
|
+
return super.getFromLocation(location);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export const clientOptions = {
|
|
32
|
+
Authentication: MyAuthenticationClient,
|
|
33
|
+
jwtStrategy: "jwt",
|
|
34
|
+
storage: {
|
|
35
|
+
getItem: (key) => {
|
|
36
|
+
return Cookies.get(key);
|
|
37
|
+
},
|
|
38
|
+
setItem: (key, value) => {
|
|
39
|
+
Cookies.set(key, value);
|
|
40
|
+
},
|
|
41
|
+
removeItem: (key) => {
|
|
42
|
+
Cookies.remove(key);
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
storageKey: B3_AUTH_COOKIE_NAME,
|
|
46
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { ClientApplication } from "@b3dotfun/b3-api";
|
|
2
|
+
import { authenticate, getClient, getClientByType, setClientType } from "./client-manager";
|
|
3
|
+
declare const app: ClientApplication;
|
|
4
4
|
export default app;
|
|
5
|
+
export { authenticate, getClient, getClientByType, setClientType };
|
|
@@ -1,57 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const app = createClient(socketio(socket), {
|
|
16
|
-
Authentication: MyAuthenticationClient,
|
|
17
|
-
jwtStrategy: "jwt",
|
|
18
|
-
storage: {
|
|
19
|
-
getItem: (key) => {
|
|
20
|
-
return Cookies.get(key);
|
|
21
|
-
},
|
|
22
|
-
setItem: (key, value) => {
|
|
23
|
-
Cookies.set(key, value);
|
|
24
|
-
},
|
|
25
|
-
removeItem: (key) => {
|
|
26
|
-
Cookies.remove(key);
|
|
27
|
-
},
|
|
1
|
+
import { authenticate, getClient, getClientByType, setClientType } from "./client-manager.js";
|
|
2
|
+
// Default to rest
|
|
3
|
+
setClientType("rest");
|
|
4
|
+
// Default export that *looks like* a Feathers app and auto-forwards
|
|
5
|
+
const app = new Proxy({}, {
|
|
6
|
+
get(_t, prop, receiver) {
|
|
7
|
+
const target = getClient();
|
|
8
|
+
return Reflect.get(target, prop, receiver);
|
|
9
|
+
},
|
|
10
|
+
set(_t, prop, value) {
|
|
11
|
+
const target = getClient();
|
|
12
|
+
return Reflect.set(target, prop, value);
|
|
28
13
|
},
|
|
29
|
-
storageKey: B3_AUTH_COOKIE_NAME,
|
|
30
14
|
});
|
|
31
|
-
export const authenticate = async (accessToken, identityToken, params) => {
|
|
32
|
-
const fullToken = `${accessToken}+${identityToken}`;
|
|
33
|
-
// Do not authenticate if there is no token
|
|
34
|
-
if (!fullToken) {
|
|
35
|
-
console.log("No token found, not authenticating");
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
const response = await app.authenticate({
|
|
40
|
-
strategy: "jwt",
|
|
41
|
-
accessToken: fullToken,
|
|
42
|
-
}, {
|
|
43
|
-
query: params || {},
|
|
44
|
-
});
|
|
45
|
-
return response;
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
export const resetSocket = () => {
|
|
52
|
-
if (socket.connected)
|
|
53
|
-
socket.disconnect();
|
|
54
|
-
socket.connect();
|
|
55
|
-
// reset the socket connection
|
|
56
|
-
};
|
|
57
15
|
export default app;
|
|
16
|
+
// Power-user helpers (named exports)
|
|
17
|
+
export { authenticate, getClient, getClientByType, setClientType };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ClientApplication } from "@b3dotfun/b3-api";
|
|
2
|
+
export type ClientType = "socket" | "rest";
|
|
3
|
+
/**
|
|
4
|
+
* Sets the active client type and creates the appropriate client
|
|
5
|
+
*
|
|
6
|
+
* Note: When using, be sure to avoid race conditions between different clients
|
|
7
|
+
*/
|
|
8
|
+
export declare function setClientType(t: ClientType): void;
|
|
9
|
+
/**
|
|
10
|
+
* Gets the current active client
|
|
11
|
+
*/
|
|
12
|
+
export declare function getClient(): ClientApplication;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the current client type
|
|
15
|
+
*/
|
|
16
|
+
export declare function getClientType(): ClientType;
|
|
17
|
+
/**
|
|
18
|
+
* Gets a specific client type (useful for parallel operations)
|
|
19
|
+
*/
|
|
20
|
+
export declare function getClientByType(clientType: ClientType): ClientApplication;
|
|
21
|
+
/**
|
|
22
|
+
* Resets the socket connection (only applicable for socket client)
|
|
23
|
+
*/
|
|
24
|
+
export declare function resetSocket(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Authenticates with the current active client
|
|
27
|
+
*/
|
|
28
|
+
export declare const authenticate: (accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<import("@feathersjs/authentication").AuthenticationResult | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Authenticates with a specific client type
|
|
31
|
+
*/
|
|
32
|
+
export declare const authenticateWithClient: (clientType: ClientType, accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<import("@feathersjs/authentication").AuthenticationResult | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Authenticates with both clients in parallel (useful for migration scenarios)
|
|
35
|
+
*/
|
|
36
|
+
export declare const authenticateBoth: (accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<{
|
|
37
|
+
socket: import("@feathersjs/authentication").AuthenticationResult | null;
|
|
38
|
+
rest: import("@feathersjs/authentication").AuthenticationResult | null;
|
|
39
|
+
success: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Switches the client type and authenticates
|
|
43
|
+
*/
|
|
44
|
+
export declare function switchClientAndAuth(type: ClientType, access: string, id: string, params?: any): Promise<import("@feathersjs/authentication").AuthenticationResult | null>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { createClient } from "@b3dotfun/b3-api";
|
|
2
|
+
import rest from "@feathersjs/rest-client";
|
|
3
|
+
import socketio from "@feathersjs/socketio-client";
|
|
4
|
+
import io from "socket.io-client";
|
|
5
|
+
import { authenticate as authenticateB3, B3_API_URL, clientOptions } from "../app.shared.js";
|
|
6
|
+
// Global state to track which client type is active
|
|
7
|
+
let currentClientType = "rest";
|
|
8
|
+
let currentClient = null;
|
|
9
|
+
// Socket client instance
|
|
10
|
+
let socketClient = null;
|
|
11
|
+
let socketInstance = null;
|
|
12
|
+
// REST client instance
|
|
13
|
+
let restClient = null;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a socket client
|
|
16
|
+
*/
|
|
17
|
+
function createSocketClient() {
|
|
18
|
+
if (!socketClient) {
|
|
19
|
+
socketInstance = io(B3_API_URL, { transports: ["websocket"] });
|
|
20
|
+
socketClient = createClient(socketio(socketInstance), clientOptions);
|
|
21
|
+
}
|
|
22
|
+
return socketClient;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates a REST client
|
|
26
|
+
*/
|
|
27
|
+
function resolveFetch() {
|
|
28
|
+
const f = globalThis.fetch;
|
|
29
|
+
if (typeof f === "function")
|
|
30
|
+
return f.bind(globalThis);
|
|
31
|
+
// lazy-require for Node environments
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
33
|
+
return require("cross-fetch").fetch;
|
|
34
|
+
}
|
|
35
|
+
function createRestClient() {
|
|
36
|
+
if (!restClient) {
|
|
37
|
+
const connection = rest(B3_API_URL).fetch(resolveFetch());
|
|
38
|
+
restClient = createClient(connection, clientOptions);
|
|
39
|
+
}
|
|
40
|
+
return restClient;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sets the active client type and creates the appropriate client
|
|
44
|
+
*
|
|
45
|
+
* Note: When using, be sure to avoid race conditions between different clients
|
|
46
|
+
*/
|
|
47
|
+
export function setClientType(t) {
|
|
48
|
+
if (currentClientType === t && currentClient)
|
|
49
|
+
return;
|
|
50
|
+
currentClientType = t;
|
|
51
|
+
currentClient = t === "socket" ? createSocketClient() : createRestClient();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the current active client
|
|
55
|
+
*/
|
|
56
|
+
export function getClient() {
|
|
57
|
+
if (!currentClient) {
|
|
58
|
+
currentClient = currentClientType === "socket" ? createSocketClient() : createRestClient();
|
|
59
|
+
}
|
|
60
|
+
return currentClient;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets the current client type
|
|
64
|
+
*/
|
|
65
|
+
export function getClientType() {
|
|
66
|
+
return currentClientType;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets a specific client type (useful for parallel operations)
|
|
70
|
+
*/
|
|
71
|
+
export function getClientByType(clientType) {
|
|
72
|
+
if (clientType === "socket") {
|
|
73
|
+
return createSocketClient();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
return createRestClient();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resets the socket connection (only applicable for socket client)
|
|
81
|
+
*/
|
|
82
|
+
export function resetSocket() {
|
|
83
|
+
if (socketInstance && socketInstance.connected) {
|
|
84
|
+
socketInstance.disconnect();
|
|
85
|
+
socketInstance.connect();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Authenticates with the current active client
|
|
90
|
+
*/
|
|
91
|
+
export const authenticate = async (accessToken, identityToken, params) => {
|
|
92
|
+
return authenticateB3(getClient(), accessToken, identityToken, params);
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Authenticates with a specific client type
|
|
96
|
+
*/
|
|
97
|
+
export const authenticateWithClient = async (clientType, accessToken, identityToken, params) => {
|
|
98
|
+
const client = getClientByType(clientType);
|
|
99
|
+
return authenticateB3(client, accessToken, identityToken, params);
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Authenticates with both clients in parallel (useful for migration scenarios)
|
|
103
|
+
*/
|
|
104
|
+
export const authenticateBoth = async (accessToken, identityToken, params) => {
|
|
105
|
+
const [socketResult, restResult] = await Promise.allSettled([
|
|
106
|
+
authenticateWithClient("socket", accessToken, identityToken, params),
|
|
107
|
+
authenticateWithClient("rest", accessToken, identityToken, params),
|
|
108
|
+
]);
|
|
109
|
+
return {
|
|
110
|
+
socket: socketResult.status === "fulfilled" ? socketResult.value : null,
|
|
111
|
+
rest: restResult.status === "fulfilled" ? restResult.value : null,
|
|
112
|
+
success: socketResult.status === "fulfilled" || restResult.status === "fulfilled",
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Switches the client type and authenticates
|
|
117
|
+
*/
|
|
118
|
+
export async function switchClientAndAuth(type, access, id, params) {
|
|
119
|
+
setClientType(type);
|
|
120
|
+
return authenticateWithClient(type, access, id, params);
|
|
121
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
2
2
|
import { Account } from "thirdweb/wallets";
|
|
3
|
+
import { ClientType } from "../../../client-manager";
|
|
3
4
|
import { B3ContextType } from "./types";
|
|
4
5
|
import "@reservoir0x/relay-kit-ui/styles.css";
|
|
5
6
|
export declare const wagmiConfig: import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], any, readonly import("wagmi").CreateConnectorFn[]>;
|
|
6
7
|
/**
|
|
7
8
|
* Main B3Provider component
|
|
8
9
|
*/
|
|
9
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, }: {
|
|
10
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, }: {
|
|
10
11
|
theme: "light" | "dark";
|
|
11
12
|
children: React.ReactNode;
|
|
12
13
|
accountOverride?: Account;
|
|
@@ -17,15 +18,17 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
17
18
|
position?: "top-center" | "top-right" | "bottom-center" | "bottom-right";
|
|
18
19
|
style?: React.CSSProperties;
|
|
19
20
|
};
|
|
21
|
+
clientType?: ClientType;
|
|
20
22
|
}): import("react/jsx-runtime").JSX.Element;
|
|
21
23
|
/**
|
|
22
24
|
* Inner provider component that provides the actual B3Context
|
|
23
25
|
*/
|
|
24
|
-
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, }: {
|
|
26
|
+
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, }: {
|
|
25
27
|
children: React.ReactNode;
|
|
26
28
|
accountOverride?: Account;
|
|
27
29
|
environment: B3ContextType["environment"];
|
|
28
30
|
defaultPermissions?: PermissionsConfig;
|
|
29
31
|
automaticallySetFirstEoa: boolean;
|
|
30
32
|
theme: "light" | "dark";
|
|
33
|
+
clientType?: ClientType;
|
|
31
34
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -7,6 +7,7 @@ import { useCallback, useEffect, useState } from "react";
|
|
|
7
7
|
import { Toaster } from "sonner";
|
|
8
8
|
import { getLastAuthProvider, ThirdwebProvider, useActiveAccount, useConnectedWallets, useSetActiveWallet, } from "thirdweb/react";
|
|
9
9
|
import { createConfig, http, WagmiProvider } from "wagmi";
|
|
10
|
+
import { setClientType } from "../../../client-manager.js";
|
|
10
11
|
import { StyleRoot } from "../StyleRoot.js";
|
|
11
12
|
import { B3Context } from "./types.js";
|
|
12
13
|
import "@reservoir0x/relay-kit-ui/styles.css";
|
|
@@ -28,17 +29,21 @@ const queryClient = new QueryClient();
|
|
|
28
29
|
/**
|
|
29
30
|
* Main B3Provider component
|
|
30
31
|
*/
|
|
31
|
-
export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, }) {
|
|
32
|
+
export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", }) {
|
|
32
33
|
// Initialize Google Analytics on mount
|
|
33
34
|
useEffect(() => {
|
|
34
35
|
loadGA4Script();
|
|
35
36
|
}, []);
|
|
36
|
-
|
|
37
|
+
// Set the client type when provider mounts
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
setClientType(clientType);
|
|
40
|
+
}, [clientType]);
|
|
41
|
+
return (_jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(ThirdwebProvider, { children: _jsx(TooltipProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, children: _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" }), _jsx(Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }));
|
|
37
42
|
}
|
|
38
43
|
/**
|
|
39
44
|
* Inner provider component that provides the actual B3Context
|
|
40
45
|
*/
|
|
41
|
-
export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", }) {
|
|
46
|
+
export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", clientType = "socket", }) {
|
|
42
47
|
const activeAccount = useActiveAccount();
|
|
43
48
|
const [manuallySelectedWallet, setManuallySelectedWallet] = useState(undefined);
|
|
44
49
|
const wallets = useConnectedWallets();
|
|
@@ -109,5 +114,6 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
|
|
|
109
114
|
environment,
|
|
110
115
|
defaultPermissions,
|
|
111
116
|
theme,
|
|
117
|
+
clientType,
|
|
112
118
|
}, children: children }));
|
|
113
119
|
}
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
2
2
|
import { Account } from "thirdweb/wallets";
|
|
3
|
+
import { ClientType } from "../../../client-manager";
|
|
3
4
|
import { B3ContextType } from "./types";
|
|
4
5
|
/**
|
|
5
6
|
* Main B3Provider component
|
|
6
7
|
*/
|
|
7
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, }: {
|
|
8
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, clientType, }: {
|
|
8
9
|
theme: "light" | "dark";
|
|
9
10
|
children: React.ReactNode;
|
|
10
11
|
accountOverride?: Account;
|
|
11
12
|
environment: B3ContextType["environment"];
|
|
13
|
+
clientType?: ClientType;
|
|
12
14
|
}): import("react/jsx-runtime").JSX.Element;
|
|
13
15
|
/**
|
|
14
16
|
* Inner provider component that provides the actual B3Context
|
|
15
17
|
*/
|
|
16
|
-
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme, }: {
|
|
18
|
+
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme, clientType, }: {
|
|
17
19
|
children: React.ReactNode;
|
|
18
20
|
accountOverride?: Account;
|
|
19
21
|
environment: B3ContextType["environment"];
|
|
20
22
|
defaultPermissions?: PermissionsConfig;
|
|
21
23
|
theme: "light" | "dark";
|
|
24
|
+
clientType?: ClientType;
|
|
22
25
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -17,13 +17,13 @@ const queryClient = new QueryClient();
|
|
|
17
17
|
/**
|
|
18
18
|
* Main B3Provider component
|
|
19
19
|
*/
|
|
20
|
-
export function B3Provider({ theme = "light", children, accountOverride, environment, }) {
|
|
21
|
-
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(ThirdwebProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, children: children }) }) }));
|
|
20
|
+
export function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", }) {
|
|
21
|
+
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(ThirdwebProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, clientType: clientType, children: children }) }) }));
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Inner provider component that provides the actual B3Context
|
|
25
25
|
*/
|
|
26
|
-
export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, theme = "light", }) {
|
|
26
|
+
export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, theme = "light", clientType = "socket", }) {
|
|
27
27
|
const activeAccount = useActiveAccount();
|
|
28
28
|
const [user, setUser] = useState(undefined);
|
|
29
29
|
// Use given accountOverride or activeAccount from thirdweb
|
|
@@ -40,5 +40,6 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
|
|
|
40
40
|
environment,
|
|
41
41
|
defaultPermissions,
|
|
42
42
|
theme,
|
|
43
|
+
clientType,
|
|
43
44
|
}, children: children }));
|
|
44
45
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Users } from "@b3dotfun/b3-api";
|
|
2
2
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
3
3
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
4
|
+
import { ClientType } from "../../../client-manager";
|
|
4
5
|
/**
|
|
5
6
|
* Context type for B3Provider
|
|
6
7
|
*/
|
|
@@ -16,6 +17,7 @@ export interface B3ContextType {
|
|
|
16
17
|
environment?: "development" | "production";
|
|
17
18
|
defaultPermissions?: PermissionsConfig;
|
|
18
19
|
theme: "light" | "dark";
|
|
20
|
+
clientType: ClientType;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Context for B3 provider
|
|
@@ -8,6 +8,7 @@ export { useB3EnsName } from "./useB3EnsName";
|
|
|
8
8
|
export { useBestTransactionPath } from "./useBestTransactionPath";
|
|
9
9
|
export { useChainSwitchWithAction } from "./useChainSwitchWithAction";
|
|
10
10
|
export * from "./useClaim";
|
|
11
|
+
export { useClient } from "./useClient";
|
|
11
12
|
export { useConnect } from "./useConnect";
|
|
12
13
|
export { useExchangeRate } from "./useExchangeRate";
|
|
13
14
|
export { useFirstEOA } from "./useFirstEOA";
|
|
@@ -8,6 +8,7 @@ export { useB3EnsName } from "./useB3EnsName.js";
|
|
|
8
8
|
export { useBestTransactionPath } from "./useBestTransactionPath.js";
|
|
9
9
|
export { useChainSwitchWithAction } from "./useChainSwitchWithAction.js";
|
|
10
10
|
export * from "./useClaim.js";
|
|
11
|
+
export { useClient } from "./useClient.js";
|
|
11
12
|
export { useConnect } from "./useConnect.js";
|
|
12
13
|
export { useExchangeRate } from "./useExchangeRate.js";
|
|
13
14
|
export { useFirstEOA } from "./useFirstEOA.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ClientType } from "../../client-manager";
|
|
2
|
+
/**
|
|
3
|
+
* Hook to access the current FeathersJS client and client management utilities
|
|
4
|
+
*/
|
|
5
|
+
export declare function useClient(): {
|
|
6
|
+
clientType: ClientType;
|
|
7
|
+
getCurrentClient: () => import("@b3dotfun/b3-api").ClientApplication;
|
|
8
|
+
getClientByType: (type: ClientType) => import("@b3dotfun/b3-api").ClientApplication;
|
|
9
|
+
switchClientType: (type: ClientType) => void;
|
|
10
|
+
authenticateWithType: (type: ClientType, accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<import("@feathersjs/authentication").AuthenticationResult | null>;
|
|
11
|
+
authenticateWithBoth: (accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<{
|
|
12
|
+
socket: import("@feathersjs/authentication").AuthenticationResult | null;
|
|
13
|
+
rest: import("@feathersjs/authentication").AuthenticationResult | null;
|
|
14
|
+
success: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useB3 } from "../../../global-account/react/index.js";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { authenticateBoth, authenticateWithClient, getClient, getClientByType, setClientType, } from "../../client-manager.js";
|
|
4
|
+
/**
|
|
5
|
+
* Hook to access the current FeathersJS client and client management utilities
|
|
6
|
+
*/
|
|
7
|
+
export function useClient() {
|
|
8
|
+
const { clientType } = useB3();
|
|
9
|
+
const getCurrentClient = useCallback(() => {
|
|
10
|
+
return getClient();
|
|
11
|
+
}, []);
|
|
12
|
+
const getClientByTypeCallback = useCallback((type) => {
|
|
13
|
+
return getClientByType(type);
|
|
14
|
+
}, []);
|
|
15
|
+
const switchClientType = useCallback((type) => {
|
|
16
|
+
setClientType(type);
|
|
17
|
+
}, []);
|
|
18
|
+
const authenticateWithType = useCallback(async (type, accessToken, identityToken, params) => {
|
|
19
|
+
return authenticateWithClient(type, accessToken, identityToken, params);
|
|
20
|
+
}, []);
|
|
21
|
+
const authenticateWithBoth = useCallback(async (accessToken, identityToken, params) => {
|
|
22
|
+
return authenticateBoth(accessToken, identityToken, params);
|
|
23
|
+
}, []);
|
|
24
|
+
return {
|
|
25
|
+
// Current client info
|
|
26
|
+
clientType,
|
|
27
|
+
getCurrentClient,
|
|
28
|
+
// Client management
|
|
29
|
+
getClientByType: getClientByTypeCallback,
|
|
30
|
+
switchClientType,
|
|
31
|
+
// Authentication utilities
|
|
32
|
+
authenticateWithType,
|
|
33
|
+
authenticateWithBoth,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ClientApplication } from "@b3dotfun/b3-api";
|
|
2
|
+
import { AuthenticationClient } from "@feathersjs/authentication-client";
|
|
3
|
+
export declare const B3_API_URL: string;
|
|
4
|
+
export declare const authenticate: (app: ClientApplication, accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<import("@feathersjs/authentication").AuthenticationResult | null>;
|
|
5
|
+
export declare class MyAuthenticationClient extends AuthenticationClient {
|
|
6
|
+
getFromLocation(location: any): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
export declare const clientOptions: {
|
|
9
|
+
Authentication: typeof MyAuthenticationClient;
|
|
10
|
+
jwtStrategy: string;
|
|
11
|
+
storage: {
|
|
12
|
+
getItem: (key: string) => string | undefined;
|
|
13
|
+
setItem: (key: string, value: string) => void;
|
|
14
|
+
removeItem: (key: string) => void;
|
|
15
|
+
};
|
|
16
|
+
storageKey: string;
|
|
17
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { ClientApplication } from "@b3dotfun/b3-api";
|
|
2
|
+
import { authenticate, getClient, getClientByType, setClientType } from "./client-manager";
|
|
3
|
+
declare const app: ClientApplication;
|
|
4
4
|
export default app;
|
|
5
|
+
export { authenticate, getClient, getClientByType, setClientType };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ClientApplication } from "@b3dotfun/b3-api";
|
|
2
|
+
export type ClientType = "socket" | "rest";
|
|
3
|
+
/**
|
|
4
|
+
* Sets the active client type and creates the appropriate client
|
|
5
|
+
*
|
|
6
|
+
* Note: When using, be sure to avoid race conditions between different clients
|
|
7
|
+
*/
|
|
8
|
+
export declare function setClientType(t: ClientType): void;
|
|
9
|
+
/**
|
|
10
|
+
* Gets the current active client
|
|
11
|
+
*/
|
|
12
|
+
export declare function getClient(): ClientApplication;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the current client type
|
|
15
|
+
*/
|
|
16
|
+
export declare function getClientType(): ClientType;
|
|
17
|
+
/**
|
|
18
|
+
* Gets a specific client type (useful for parallel operations)
|
|
19
|
+
*/
|
|
20
|
+
export declare function getClientByType(clientType: ClientType): ClientApplication;
|
|
21
|
+
/**
|
|
22
|
+
* Resets the socket connection (only applicable for socket client)
|
|
23
|
+
*/
|
|
24
|
+
export declare function resetSocket(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Authenticates with the current active client
|
|
27
|
+
*/
|
|
28
|
+
export declare const authenticate: (accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<import("@feathersjs/authentication").AuthenticationResult | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Authenticates with a specific client type
|
|
31
|
+
*/
|
|
32
|
+
export declare const authenticateWithClient: (clientType: ClientType, accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<import("@feathersjs/authentication").AuthenticationResult | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Authenticates with both clients in parallel (useful for migration scenarios)
|
|
35
|
+
*/
|
|
36
|
+
export declare const authenticateBoth: (accessToken: string, identityToken: string, params?: Record<string, any>) => Promise<{
|
|
37
|
+
socket: import("@feathersjs/authentication").AuthenticationResult | null;
|
|
38
|
+
rest: import("@feathersjs/authentication").AuthenticationResult | null;
|
|
39
|
+
success: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Switches the client type and authenticates
|
|
43
|
+
*/
|
|
44
|
+
export declare function switchClientAndAuth(type: ClientType, access: string, id: string, params?: any): Promise<import("@feathersjs/authentication").AuthenticationResult | null>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
2
2
|
import { Account } from "thirdweb/wallets";
|
|
3
|
+
import { ClientType } from "../../../client-manager";
|
|
3
4
|
import { B3ContextType } from "./types";
|
|
4
5
|
import "@reservoir0x/relay-kit-ui/styles.css";
|
|
5
6
|
export declare const wagmiConfig: import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], any, readonly import("wagmi").CreateConnectorFn[]>;
|
|
6
7
|
/**
|
|
7
8
|
* Main B3Provider component
|
|
8
9
|
*/
|
|
9
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, }: {
|
|
10
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, }: {
|
|
10
11
|
theme: "light" | "dark";
|
|
11
12
|
children: React.ReactNode;
|
|
12
13
|
accountOverride?: Account;
|
|
@@ -17,15 +18,17 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
17
18
|
position?: "top-center" | "top-right" | "bottom-center" | "bottom-right";
|
|
18
19
|
style?: React.CSSProperties;
|
|
19
20
|
};
|
|
21
|
+
clientType?: ClientType;
|
|
20
22
|
}): import("react/jsx-runtime").JSX.Element;
|
|
21
23
|
/**
|
|
22
24
|
* Inner provider component that provides the actual B3Context
|
|
23
25
|
*/
|
|
24
|
-
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, }: {
|
|
26
|
+
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, }: {
|
|
25
27
|
children: React.ReactNode;
|
|
26
28
|
accountOverride?: Account;
|
|
27
29
|
environment: B3ContextType["environment"];
|
|
28
30
|
defaultPermissions?: PermissionsConfig;
|
|
29
31
|
automaticallySetFirstEoa: boolean;
|
|
30
32
|
theme: "light" | "dark";
|
|
33
|
+
clientType?: ClientType;
|
|
31
34
|
}): import("react/jsx-runtime").JSX.Element;
|