@b3dotfun/sdk 0.0.72 → 0.0.73-test.0
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/anyspend/react/components/AnySpendCustom.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +3 -2
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.js +3 -2
- package/dist/cjs/anyspend/react/hooks/useValidatedClientReferenceId.d.ts +3 -1
- package/dist/cjs/anyspend/react/hooks/useValidatedClientReferenceId.js +3 -3
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +3 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +3 -2
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.js +3 -2
- package/dist/esm/anyspend/react/hooks/useValidatedClientReferenceId.d.ts +3 -1
- package/dist/esm/anyspend/react/hooks/useValidatedClientReferenceId.js +4 -4
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +3 -1
- package/dist/types/anyspend/react/hooks/useValidatedClientReferenceId.d.ts +3 -1
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +3 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpendCustom.tsx +1 -0
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +4 -2
- package/src/anyspend/react/hooks/useAnyspendCreateOrder.ts +3 -2
- package/src/anyspend/react/hooks/useValidatedClientReferenceId.ts +28 -23
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +4 -2
- package/src/global-account/react/components/B3Provider/types.ts +3 -1
|
@@ -19,7 +19,7 @@ function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
19
19
|
// Get B3 context values
|
|
20
20
|
const { partnerId } = (0, react_1.useB3)();
|
|
21
21
|
// Get validated client reference ID from B3 context
|
|
22
|
-
const
|
|
22
|
+
const createValidatedClientReferenceId = (0, useValidatedClientReferenceId_1.useValidatedClientReferenceId)();
|
|
23
23
|
// Get fingerprint data
|
|
24
24
|
const { data: fpData } = (0, fingerprintjs_pro_react_1.useVisitorData)({ extendedResult: true }, { immediate: true });
|
|
25
25
|
const visitorData = fpData && {
|
|
@@ -29,6 +29,7 @@ function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
29
29
|
const { mutate: createOrder, isPending } = (0, react_query_1.useMutation)({
|
|
30
30
|
mutationFn: async (params) => {
|
|
31
31
|
const { recipientAddress, orderType, dstChain, dstToken, srcFiatAmount, onramp, creatorAddress, expectedDstAmount, nft, tournament, payload, } = params;
|
|
32
|
+
const clientReferenceId = await createValidatedClientReferenceId(params);
|
|
32
33
|
try {
|
|
33
34
|
// Validate required onramp fields
|
|
34
35
|
if (!onramp.vendor || !onramp.country) {
|
|
@@ -71,7 +72,7 @@ function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
71
72
|
}),
|
|
72
73
|
creatorAddress: creatorAddress ? (0, utils_1.normalizeAddress)(creatorAddress) : undefined,
|
|
73
74
|
partnerId,
|
|
74
|
-
clientReferenceId
|
|
75
|
+
clientReferenceId,
|
|
75
76
|
visitorData,
|
|
76
77
|
});
|
|
77
78
|
}
|
|
@@ -17,7 +17,7 @@ function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
|
|
|
17
17
|
// Get B3 context values
|
|
18
18
|
const { partnerId } = (0, react_1.useB3)();
|
|
19
19
|
// Get validated client reference ID from B3 context
|
|
20
|
-
const
|
|
20
|
+
const createValidatedClientReferenceId = (0, useValidatedClientReferenceId_1.useValidatedClientReferenceId)();
|
|
21
21
|
// Get fingerprint data
|
|
22
22
|
const { data: fpData } = (0, fingerprintjs_pro_react_1.useVisitorData)({ extendedResult: true }, { immediate: true });
|
|
23
23
|
const visitorData = fpData && {
|
|
@@ -27,6 +27,7 @@ function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
|
|
|
27
27
|
const { mutate: createOrder, isPending } = (0, react_query_1.useMutation)({
|
|
28
28
|
mutationFn: async (params) => {
|
|
29
29
|
const { recipientAddress, orderType, srcChain, dstChain, srcToken, dstToken, srcAmount, creatorAddress } = params;
|
|
30
|
+
const clientReferenceId = await createValidatedClientReferenceId(params);
|
|
30
31
|
try {
|
|
31
32
|
return await anyspend_1.anyspendService.createOrder({
|
|
32
33
|
recipientAddress: (0, utils_1.normalizeAddress)(recipientAddress),
|
|
@@ -60,7 +61,7 @@ function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
|
|
|
60
61
|
}),
|
|
61
62
|
creatorAddress: creatorAddress ? (0, utils_1.normalizeAddress)(creatorAddress) : undefined,
|
|
62
63
|
partnerId,
|
|
63
|
-
clientReferenceId
|
|
64
|
+
clientReferenceId,
|
|
64
65
|
visitorData,
|
|
65
66
|
});
|
|
66
67
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { CreateOnrampOrderParams } from "./useAnyspendCreateOnrampOrder";
|
|
2
|
+
import { CreateOrderParams } from "./useAnyspendCreateOrder";
|
|
1
3
|
/**
|
|
2
4
|
* Hook that provides a validated client reference ID
|
|
3
5
|
* Gets the createClientReferenceId function from B3 context and validates the result
|
|
4
6
|
*/
|
|
5
|
-
export declare function useValidatedClientReferenceId(): string | undefined
|
|
7
|
+
export declare function useValidatedClientReferenceId(): (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string | undefined>;
|
|
@@ -10,14 +10,14 @@ const react_2 = require("react");
|
|
|
10
10
|
*/
|
|
11
11
|
function useValidatedClientReferenceId() {
|
|
12
12
|
const { createClientReferenceId } = (0, react_1.useB3)();
|
|
13
|
-
const
|
|
13
|
+
const createValidatedClientReferenceId = (0, react_2.useCallback)(async (params) => {
|
|
14
14
|
// If no function provided, return undefined
|
|
15
15
|
if (!createClientReferenceId) {
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
|
18
18
|
try {
|
|
19
19
|
// Call the function to generate the ID
|
|
20
|
-
const generatedId = createClientReferenceId();
|
|
20
|
+
const generatedId = await createClientReferenceId(params);
|
|
21
21
|
// Validate the generated ID
|
|
22
22
|
const validation = validation_1.Validators.clientReferenceId(generatedId);
|
|
23
23
|
if (!validation.isValid) {
|
|
@@ -31,5 +31,5 @@ function useValidatedClientReferenceId() {
|
|
|
31
31
|
return undefined;
|
|
32
32
|
}
|
|
33
33
|
}, [createClientReferenceId]);
|
|
34
|
-
return
|
|
34
|
+
return createValidatedClientReferenceId;
|
|
35
35
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
|
+
import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
|
|
1
3
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
2
4
|
import "@relayprotocol/relay-kit-ui/styles.css";
|
|
3
5
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
@@ -24,7 +26,7 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
24
26
|
onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
25
27
|
connectors?: CreateConnectorFn[];
|
|
26
28
|
overrideDefaultConnectors?: boolean;
|
|
27
|
-
createClientReferenceId?: () => string
|
|
29
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
28
30
|
}): import("react/jsx-runtime").JSX.Element;
|
|
29
31
|
/**
|
|
30
32
|
* Inner provider component that provides the actual B3Context
|
|
@@ -38,5 +40,5 @@ export declare function InnerProvider({ children, accountOverride, environment,
|
|
|
38
40
|
theme: "light" | "dark";
|
|
39
41
|
clientType?: ClientType;
|
|
40
42
|
partnerId: string;
|
|
41
|
-
createClientReferenceId?: () => string
|
|
43
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
42
44
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Users } from "@b3dotfun/b3-api";
|
|
2
|
+
import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
3
|
+
import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
|
|
2
4
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
3
5
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
4
6
|
import { ClientType } from "../../../client-manager";
|
|
@@ -20,7 +22,7 @@ export interface B3ContextType {
|
|
|
20
22
|
theme: "light" | "dark";
|
|
21
23
|
clientType: ClientType;
|
|
22
24
|
partnerId: string;
|
|
23
|
-
createClientReferenceId?: () => string
|
|
25
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Context for B3 provider
|
|
@@ -16,7 +16,7 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
16
16
|
// Get B3 context values
|
|
17
17
|
const { partnerId } = useB3();
|
|
18
18
|
// Get validated client reference ID from B3 context
|
|
19
|
-
const
|
|
19
|
+
const createValidatedClientReferenceId = useValidatedClientReferenceId();
|
|
20
20
|
// Get fingerprint data
|
|
21
21
|
const { data: fpData } = useVisitorData({ extendedResult: true }, { immediate: true });
|
|
22
22
|
const visitorData = fpData && {
|
|
@@ -26,6 +26,7 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
26
26
|
const { mutate: createOrder, isPending } = useMutation({
|
|
27
27
|
mutationFn: async (params) => {
|
|
28
28
|
const { recipientAddress, orderType, dstChain, dstToken, srcFiatAmount, onramp, creatorAddress, expectedDstAmount, nft, tournament, payload, } = params;
|
|
29
|
+
const clientReferenceId = await createValidatedClientReferenceId(params);
|
|
29
30
|
try {
|
|
30
31
|
// Validate required onramp fields
|
|
31
32
|
if (!onramp.vendor || !onramp.country) {
|
|
@@ -68,7 +69,7 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
68
69
|
}),
|
|
69
70
|
creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined,
|
|
70
71
|
partnerId,
|
|
71
|
-
clientReferenceId
|
|
72
|
+
clientReferenceId,
|
|
72
73
|
visitorData,
|
|
73
74
|
});
|
|
74
75
|
}
|
|
@@ -14,7 +14,7 @@ export function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
|
|
|
14
14
|
// Get B3 context values
|
|
15
15
|
const { partnerId } = useB3();
|
|
16
16
|
// Get validated client reference ID from B3 context
|
|
17
|
-
const
|
|
17
|
+
const createValidatedClientReferenceId = useValidatedClientReferenceId();
|
|
18
18
|
// Get fingerprint data
|
|
19
19
|
const { data: fpData } = useVisitorData({ extendedResult: true }, { immediate: true });
|
|
20
20
|
const visitorData = fpData && {
|
|
@@ -24,6 +24,7 @@ export function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
|
|
|
24
24
|
const { mutate: createOrder, isPending } = useMutation({
|
|
25
25
|
mutationFn: async (params) => {
|
|
26
26
|
const { recipientAddress, orderType, srcChain, dstChain, srcToken, dstToken, srcAmount, creatorAddress } = params;
|
|
27
|
+
const clientReferenceId = await createValidatedClientReferenceId(params);
|
|
27
28
|
try {
|
|
28
29
|
return await anyspendService.createOrder({
|
|
29
30
|
recipientAddress: normalizeAddress(recipientAddress),
|
|
@@ -57,7 +58,7 @@ export function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
|
|
|
57
58
|
}),
|
|
58
59
|
creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined,
|
|
59
60
|
partnerId,
|
|
60
|
-
clientReferenceId
|
|
61
|
+
clientReferenceId,
|
|
61
62
|
visitorData,
|
|
62
63
|
});
|
|
63
64
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { CreateOnrampOrderParams } from "./useAnyspendCreateOnrampOrder";
|
|
2
|
+
import { CreateOrderParams } from "./useAnyspendCreateOrder";
|
|
1
3
|
/**
|
|
2
4
|
* Hook that provides a validated client reference ID
|
|
3
5
|
* Gets the createClientReferenceId function from B3 context and validates the result
|
|
4
6
|
*/
|
|
5
|
-
export declare function useValidatedClientReferenceId(): string | undefined
|
|
7
|
+
export declare function useValidatedClientReferenceId(): (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string | undefined>;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { Validators } from "../../../anyspend/utils/validation.js";
|
|
2
2
|
import { useB3 } from "../../../global-account/react/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { useCallback } from "react";
|
|
4
4
|
/**
|
|
5
5
|
* Hook that provides a validated client reference ID
|
|
6
6
|
* Gets the createClientReferenceId function from B3 context and validates the result
|
|
7
7
|
*/
|
|
8
8
|
export function useValidatedClientReferenceId() {
|
|
9
9
|
const { createClientReferenceId } = useB3();
|
|
10
|
-
const
|
|
10
|
+
const createValidatedClientReferenceId = useCallback(async (params) => {
|
|
11
11
|
// If no function provided, return undefined
|
|
12
12
|
if (!createClientReferenceId) {
|
|
13
13
|
return undefined;
|
|
14
14
|
}
|
|
15
15
|
try {
|
|
16
16
|
// Call the function to generate the ID
|
|
17
|
-
const generatedId = createClientReferenceId();
|
|
17
|
+
const generatedId = await createClientReferenceId(params);
|
|
18
18
|
// Validate the generated ID
|
|
19
19
|
const validation = Validators.clientReferenceId(generatedId);
|
|
20
20
|
if (!validation.isValid) {
|
|
@@ -28,5 +28,5 @@ export function useValidatedClientReferenceId() {
|
|
|
28
28
|
return undefined;
|
|
29
29
|
}
|
|
30
30
|
}, [createClientReferenceId]);
|
|
31
|
-
return
|
|
31
|
+
return createValidatedClientReferenceId;
|
|
32
32
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
|
+
import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
|
|
1
3
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
2
4
|
import "@relayprotocol/relay-kit-ui/styles.css";
|
|
3
5
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
@@ -24,7 +26,7 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
24
26
|
onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
25
27
|
connectors?: CreateConnectorFn[];
|
|
26
28
|
overrideDefaultConnectors?: boolean;
|
|
27
|
-
createClientReferenceId?: () => string
|
|
29
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
28
30
|
}): import("react/jsx-runtime").JSX.Element;
|
|
29
31
|
/**
|
|
30
32
|
* Inner provider component that provides the actual B3Context
|
|
@@ -38,5 +40,5 @@ export declare function InnerProvider({ children, accountOverride, environment,
|
|
|
38
40
|
theme: "light" | "dark";
|
|
39
41
|
clientType?: ClientType;
|
|
40
42
|
partnerId: string;
|
|
41
|
-
createClientReferenceId?: () => string
|
|
43
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
42
44
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Users } from "@b3dotfun/b3-api";
|
|
2
|
+
import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
3
|
+
import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
|
|
2
4
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
3
5
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
4
6
|
import { ClientType } from "../../../client-manager";
|
|
@@ -20,7 +22,7 @@ export interface B3ContextType {
|
|
|
20
22
|
theme: "light" | "dark";
|
|
21
23
|
clientType: ClientType;
|
|
22
24
|
partnerId: string;
|
|
23
|
-
createClientReferenceId?: () => string
|
|
25
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Context for B3 provider
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { CreateOnrampOrderParams } from "./useAnyspendCreateOnrampOrder";
|
|
2
|
+
import { CreateOrderParams } from "./useAnyspendCreateOrder";
|
|
1
3
|
/**
|
|
2
4
|
* Hook that provides a validated client reference ID
|
|
3
5
|
* Gets the createClientReferenceId function from B3 context and validates the result
|
|
4
6
|
*/
|
|
5
|
-
export declare function useValidatedClientReferenceId(): string | undefined
|
|
7
|
+
export declare function useValidatedClientReferenceId(): (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string | undefined>;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
|
+
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
1
3
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
2
4
|
import "@relayprotocol/relay-kit-ui/styles.css";
|
|
3
5
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
@@ -24,7 +26,7 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
24
26
|
onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
25
27
|
connectors?: CreateConnectorFn[];
|
|
26
28
|
overrideDefaultConnectors?: boolean;
|
|
27
|
-
createClientReferenceId?: () => string
|
|
29
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
28
30
|
}): import("react/jsx-runtime").JSX.Element;
|
|
29
31
|
/**
|
|
30
32
|
* Inner provider component that provides the actual B3Context
|
|
@@ -38,5 +40,5 @@ export declare function InnerProvider({ children, accountOverride, environment,
|
|
|
38
40
|
theme: "light" | "dark";
|
|
39
41
|
clientType?: ClientType;
|
|
40
42
|
partnerId: string;
|
|
41
|
-
createClientReferenceId?: () => string
|
|
43
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
42
44
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Users } from "@b3dotfun/b3-api";
|
|
2
|
+
import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
3
|
+
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
2
4
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
3
5
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
4
6
|
import { ClientType } from "../../../client-manager";
|
|
@@ -20,7 +22,7 @@ export interface B3ContextType {
|
|
|
20
22
|
theme: "light" | "dark";
|
|
21
23
|
clientType: ClientType;
|
|
22
24
|
partnerId: string;
|
|
23
|
-
createClientReferenceId?: () => string
|
|
25
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Context for B3 provider
|
package/package.json
CHANGED
|
@@ -39,7 +39,7 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError }: UseAnyspend
|
|
|
39
39
|
const { partnerId } = useB3();
|
|
40
40
|
|
|
41
41
|
// Get validated client reference ID from B3 context
|
|
42
|
-
const
|
|
42
|
+
const createValidatedClientReferenceId = useValidatedClientReferenceId();
|
|
43
43
|
|
|
44
44
|
// Get fingerprint data
|
|
45
45
|
const { data: fpData } = useVisitorData({ extendedResult: true }, { immediate: true });
|
|
@@ -64,6 +64,8 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError }: UseAnyspend
|
|
|
64
64
|
payload,
|
|
65
65
|
} = params;
|
|
66
66
|
|
|
67
|
+
const clientReferenceId = await createValidatedClientReferenceId(params);
|
|
68
|
+
|
|
67
69
|
try {
|
|
68
70
|
// Validate required onramp fields
|
|
69
71
|
if (!onramp.vendor || !onramp.country) {
|
|
@@ -109,7 +111,7 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError }: UseAnyspend
|
|
|
109
111
|
}),
|
|
110
112
|
creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined,
|
|
111
113
|
partnerId,
|
|
112
|
-
clientReferenceId
|
|
114
|
+
clientReferenceId,
|
|
113
115
|
visitorData,
|
|
114
116
|
});
|
|
115
117
|
} catch (error: any) {
|
|
@@ -38,7 +38,7 @@ export function useAnyspendCreateOrder({ onSuccess, onError }: UseAnyspendCreate
|
|
|
38
38
|
const { partnerId } = useB3();
|
|
39
39
|
|
|
40
40
|
// Get validated client reference ID from B3 context
|
|
41
|
-
const
|
|
41
|
+
const createValidatedClientReferenceId = useValidatedClientReferenceId();
|
|
42
42
|
|
|
43
43
|
// Get fingerprint data
|
|
44
44
|
const { data: fpData } = useVisitorData({ extendedResult: true }, { immediate: true });
|
|
@@ -49,6 +49,7 @@ export function useAnyspendCreateOrder({ onSuccess, onError }: UseAnyspendCreate
|
|
|
49
49
|
const { mutate: createOrder, isPending } = useMutation({
|
|
50
50
|
mutationFn: async (params: CreateOrderParams) => {
|
|
51
51
|
const { recipientAddress, orderType, srcChain, dstChain, srcToken, dstToken, srcAmount, creatorAddress } = params;
|
|
52
|
+
const clientReferenceId = await createValidatedClientReferenceId(params);
|
|
52
53
|
|
|
53
54
|
try {
|
|
54
55
|
return await anyspendService.createOrder({
|
|
@@ -83,7 +84,7 @@ export function useAnyspendCreateOrder({ onSuccess, onError }: UseAnyspendCreate
|
|
|
83
84
|
}),
|
|
84
85
|
creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined,
|
|
85
86
|
partnerId,
|
|
86
|
-
clientReferenceId
|
|
87
|
+
clientReferenceId,
|
|
87
88
|
visitorData,
|
|
88
89
|
});
|
|
89
90
|
} catch (error: any) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Validators } from "@b3dotfun/sdk/anyspend/utils/validation";
|
|
2
2
|
import { useB3 } from "@b3dotfun/sdk/global-account/react";
|
|
3
|
-
import {
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import { CreateOnrampOrderParams } from "./useAnyspendCreateOnrampOrder";
|
|
5
|
+
import { CreateOrderParams } from "./useAnyspendCreateOrder";
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Hook that provides a validated client reference ID
|
|
@@ -9,32 +11,35 @@ import { useMemo } from "react";
|
|
|
9
11
|
export function useValidatedClientReferenceId() {
|
|
10
12
|
const { createClientReferenceId } = useB3();
|
|
11
13
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const createValidatedClientReferenceId = useCallback(
|
|
15
|
+
async (params: CreateOrderParams | CreateOnrampOrderParams) => {
|
|
16
|
+
// If no function provided, return undefined
|
|
17
|
+
if (!createClientReferenceId) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
try {
|
|
22
|
+
// Call the function to generate the ID
|
|
23
|
+
const generatedId = await createClientReferenceId(params);
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
// Validate the generated ID
|
|
26
|
+
const validation = Validators.clientReferenceId(generatedId);
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
if (!validation.isValid) {
|
|
29
|
+
console.error(
|
|
30
|
+
`[AnySpend] Invalid clientReferenceId generated: ${validation.error || "Validation failed"}. Will be set to undefined.`,
|
|
31
|
+
);
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return validation.cleaned;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error("[AnySpend] Error generating clientReferenceId:", error);
|
|
29
38
|
return undefined;
|
|
30
39
|
}
|
|
40
|
+
},
|
|
41
|
+
[createClientReferenceId],
|
|
42
|
+
);
|
|
31
43
|
|
|
32
|
-
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error("[AnySpend] Error generating clientReferenceId:", error);
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
}, [createClientReferenceId]);
|
|
38
|
-
|
|
39
|
-
return validatedClientReferenceId;
|
|
44
|
+
return createValidatedClientReferenceId;
|
|
40
45
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
|
+
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
1
3
|
import {
|
|
2
4
|
RelayKitProviderWrapper,
|
|
3
5
|
TooltipProvider,
|
|
@@ -76,7 +78,7 @@ export function B3Provider({
|
|
|
76
78
|
onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
77
79
|
connectors?: CreateConnectorFn[];
|
|
78
80
|
overrideDefaultConnectors?: boolean;
|
|
79
|
-
createClientReferenceId?: () => string
|
|
81
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
80
82
|
}) {
|
|
81
83
|
// Initialize Google Analytics on mount
|
|
82
84
|
useEffect(() => {
|
|
@@ -141,7 +143,7 @@ export function InnerProvider({
|
|
|
141
143
|
theme: "light" | "dark";
|
|
142
144
|
clientType?: ClientType;
|
|
143
145
|
partnerId: string;
|
|
144
|
-
createClientReferenceId?: () => string
|
|
146
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
145
147
|
}) {
|
|
146
148
|
const activeAccount = useActiveAccount();
|
|
147
149
|
const [manuallySelectedWallet, setManuallySelectedWallet] = useState<Wallet | undefined>(undefined);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Users } from "@b3dotfun/b3-api";
|
|
2
|
+
import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
3
|
+
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
2
4
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
3
5
|
import { createContext } from "react";
|
|
4
6
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
@@ -22,7 +24,7 @@ export interface B3ContextType {
|
|
|
22
24
|
theme: "light" | "dark";
|
|
23
25
|
clientType: ClientType;
|
|
24
26
|
partnerId: string;
|
|
25
|
-
createClientReferenceId?: () => string
|
|
27
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
/**
|