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