@b3dotfun/sdk 0.0.33-alpha.1 → 0.0.33

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.
Files changed (28) hide show
  1. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +25 -26
  2. package/dist/cjs/global-account/react/components/B3DynamicModal.js +4 -1
  3. package/dist/cjs/global-account/react/components/Transak/TransakModal.d.ts +1 -0
  4. package/dist/cjs/global-account/react/components/Transak/TransakModal.js +110 -0
  5. package/dist/cjs/global-account/react/components/index.d.ts +9 -8
  6. package/dist/cjs/global-account/react/components/index.js +28 -25
  7. package/dist/cjs/global-account/react/stores/index.d.ts +1 -1
  8. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +19 -1
  9. package/dist/esm/anyspend/react/components/common/OrderDetails.js +3 -4
  10. package/dist/esm/global-account/react/components/B3DynamicModal.js +4 -1
  11. package/dist/esm/global-account/react/components/Transak/TransakModal.d.ts +1 -0
  12. package/dist/esm/global-account/react/components/Transak/TransakModal.js +104 -0
  13. package/dist/esm/global-account/react/components/index.d.ts +9 -8
  14. package/dist/esm/global-account/react/components/index.js +10 -8
  15. package/dist/esm/global-account/react/stores/index.d.ts +1 -1
  16. package/dist/esm/global-account/react/stores/useModalStore.d.ts +19 -1
  17. package/dist/styles/index.css +1 -1
  18. package/dist/types/global-account/react/components/Transak/TransakModal.d.ts +1 -0
  19. package/dist/types/global-account/react/components/index.d.ts +9 -8
  20. package/dist/types/global-account/react/stores/index.d.ts +1 -1
  21. package/dist/types/global-account/react/stores/useModalStore.d.ts +19 -1
  22. package/package.json +3 -1
  23. package/src/anyspend/react/components/common/OrderDetails.tsx +3 -6
  24. package/src/global-account/react/components/B3DynamicModal.tsx +4 -0
  25. package/src/global-account/react/components/Transak/TransakModal.tsx +131 -0
  26. package/src/global-account/react/components/index.ts +16 -13
  27. package/src/global-account/react/stores/index.ts +2 -1
  28. package/src/global-account/react/stores/useModalStore.ts +20 -0
@@ -0,0 +1,131 @@
1
+ "use client";
2
+
3
+ import { TextShimmer, useAccountWallet, useB3, useModalStore } from "@b3dotfun/sdk/global-account/react";
4
+ import debug from "@b3dotfun/sdk/shared/utils/debug";
5
+ import { Transak, TransakConfig } from "@transak/transak-sdk";
6
+ import { Loader2 } from "lucide-react";
7
+ import { useEffect, useMemo, useState } from "react";
8
+ import { toast } from "sonner";
9
+
10
+ export function TransakModal() {
11
+ const [isLoading, setIsLoading] = useState(true);
12
+ const [_error, setError] = useState<Error | null>(null);
13
+
14
+ const account = useAccountWallet();
15
+ const { environment } = useB3();
16
+
17
+ console.log(`process.env.NEXT_PUBLIC_TRANSAK_API_KEY`, process.env.NEXT_PUBLIC_TRANSAK_API_KEY); // d1f4e8be-cacb-4cfa-b2cd-c591084b5ef6
18
+
19
+ const transakConfig = useMemo((): TransakConfig => {
20
+ return {
21
+ apiKey: process.env.NEXT_PUBLIC_TRANSAK_API_KEY || "", // (Required)
22
+ // Yes, I know it looks weird to use isDevelopment for staging, but this is how this was done on Basement. Leaving till confirming difference
23
+ environment: environment === "development" ? Transak.ENVIRONMENTS.STAGING : Transak.ENVIRONMENTS.PRODUCTION, // (Required)
24
+ containerId: "transakMount", // Id of the element where you want to initialize the iframe
25
+ themeColor: "0c68e9",
26
+ widgetHeight: "650px",
27
+ productsAvailed: "BUY",
28
+ hideMenu: true,
29
+ colorMode: "DARK",
30
+ backgroundColors: "000000", // TODO: figure out why this doesn't work
31
+ exchangeScreenTitle: "Buy ETH on B3",
32
+ isFeeCalculationHidden: true,
33
+ cryptoCurrencyCode: "ETH",
34
+ network: "b3",
35
+ };
36
+ }, [environment]);
37
+
38
+ const { ready } = useB3();
39
+ const modalOptions = useModalStore(state => state.contentType);
40
+ const isOnRamp = modalOptions?.type === "transak";
41
+ const destinationWalletAddress = isOnRamp ? modalOptions?.destinationWalletAddress : undefined;
42
+ const defaultCryptoAmount = isOnRamp ? modalOptions?.defaultCryptoAmount : undefined;
43
+ const onSuccess = isOnRamp ? modalOptions?.onSuccess : undefined;
44
+ const fiatAmount = isOnRamp ? modalOptions?.fiatAmount : undefined;
45
+ const countryCode = isOnRamp ? modalOptions?.countryCode : undefined;
46
+
47
+ useEffect(() => {
48
+ if (!ready || !isOnRamp) return;
49
+
50
+ const config = {
51
+ ...transakConfig,
52
+ walletAddress: destinationWalletAddress || account?.address, // In the future, this should be set to the new global B3 SCW address
53
+ defaultCryptoAmount,
54
+ disableWalletAddressForm: !!destinationWalletAddress || !!account?.address, // Only disable the form if we have an address
55
+ fiatAmount: fiatAmount,
56
+ countryCode: countryCode,
57
+ };
58
+
59
+ const transak = new Transak(config);
60
+
61
+ try {
62
+ transak.init();
63
+
64
+ // Add event listeners
65
+ Transak.on("*", data => {
66
+ debug("@@transak", data);
67
+ });
68
+
69
+ Transak.on(Transak.EVENTS.TRANSAK_WIDGET_CLOSE, () => {
70
+ setIsLoading(false);
71
+ debug("@@transak", "Transak SDK closed!");
72
+ });
73
+
74
+ Transak.on(Transak.EVENTS.TRANSAK_WIDGET_INITIALISED, () => {
75
+ debug("@@transak", "Transak SDK initialized!");
76
+ setIsLoading(false);
77
+ });
78
+
79
+ Transak.on(Transak.EVENTS.TRANSAK_ORDER_FAILED, orderData => {
80
+ debug("@@transak", orderData);
81
+ toast.error("Oh no! Something went wrong. Please try again.");
82
+ });
83
+
84
+ Transak.on(Transak.EVENTS.TRANSAK_ORDER_SUCCESSFUL, orderData => {
85
+ debug("@@transak", orderData);
86
+ toast.success("Successfully purchased ETH with credit card!");
87
+ onSuccess?.();
88
+ });
89
+ } catch (err) {
90
+ setError(err instanceof Error ? err : new Error("Failed to initialize Transak"));
91
+ toast.error("Oh no! Something went wrong. Please try again.");
92
+ setIsLoading(false);
93
+ }
94
+
95
+ // Cleanup code
96
+ return () => {
97
+ transak.close();
98
+ };
99
+ }, [
100
+ ready,
101
+ account?.address,
102
+ destinationWalletAddress,
103
+ defaultCryptoAmount,
104
+ isOnRamp,
105
+ onSuccess,
106
+ fiatAmount,
107
+ transakConfig,
108
+ countryCode,
109
+ ]);
110
+
111
+ return (
112
+ <>
113
+ {isLoading && (
114
+ <div className="flex h-full min-h-[650px] flex-col items-center justify-center gap-4">
115
+ <Loader2 className="h-24 w-24 animate-spin opacity-10" />
116
+ <TextShimmer>Powering up our credit card processor...</TextShimmer>
117
+ </div>
118
+ )}
119
+ <div
120
+ id="transakMount"
121
+ style={{
122
+ display: isLoading ? "none" : "block",
123
+ width: "100%",
124
+ height: "650px",
125
+ borderRadius: "25px",
126
+ overflow: "hidden",
127
+ }}
128
+ />
129
+ </>
130
+ );
131
+ }
@@ -1,18 +1,18 @@
1
1
  // Core Components
2
+ export { RelayKitProviderWrapper } from "./B3Provider/RelayKitProviderWrapper";
2
3
  export { B3DynamicModal } from "./B3DynamicModal";
3
4
  export { B3Provider, InnerProvider } from "./B3Provider/B3Provider";
4
- export { RelayKitProviderWrapper } from "./B3Provider/RelayKitProviderWrapper";
5
5
  export { B3Context, type B3ContextType } from "./B3Provider/types";
6
6
  export { useB3 } from "./B3Provider/useB3";
7
7
  export { StyleRoot } from "./StyleRoot";
8
8
 
9
9
  // SignInWithB3 Components
10
- export { SignInWithB3 } from "./SignInWithB3/SignInWithB3";
11
- export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
12
- export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy";
13
10
  export { AuthButton } from "./SignInWithB3/components/AuthButton";
14
11
  export { PermissionItem } from "./SignInWithB3/components/PermissionItem";
15
12
  export { WalletRow } from "./SignInWithB3/components/WalletRow";
13
+ export { SignInWithB3 } from "./SignInWithB3/SignInWithB3";
14
+ export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
15
+ export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy";
16
16
  export { LoginStepContainer } from "./SignInWithB3/steps/LoginStep";
17
17
  export { getConnectOptionsFromStrategy, isWalletType, type AllowedStrategy } from "./SignInWithB3/utils/signInUtils";
18
18
 
@@ -35,6 +35,9 @@ export { SendETHButton } from "./SendETHButton/SendETHButton";
35
35
  // SendERC20Button Components
36
36
  export { SendERC20Button } from "./SendERC20Button/SendERC20Button";
37
37
 
38
+ // Transak Components
39
+ export { TransakModal } from "./Transak/TransakModal";
40
+
38
41
  // Custom Components
39
42
  export { Button as CustomButton, buttonVariants as customButtonVariants } from "./custom/Button";
40
43
  export { ClientOnly } from "./custom/ClientOnly";
@@ -43,15 +46,6 @@ export { StaggeredFadeLoader } from "./custom/StaggeredFadeLoader";
43
46
  export { WalletConnectorIcon } from "./custom/WalletConnectorIcon";
44
47
 
45
48
  // UI Components
46
- export { Loading } from "./ui/Loading";
47
- export { ShinyButton } from "./ui/ShinyButton";
48
- export { TabTrigger, Tabs, TabsContent, TabsList, TabsTransitionWrapper } from "./ui/TabSystem";
49
- export {
50
- TabTrigger as TabTriggerPrimitive,
51
- TabsContent as TabsContentPrimitive,
52
- TabsList as TabsListPrimitive,
53
- Tabs as TabsPrimitive,
54
- } from "./ui/Tabs";
55
49
  export { Badge, badgeVariants } from "./ui/badge";
56
50
  export { Button, buttonVariants } from "./ui/button";
57
51
  export {
@@ -92,9 +86,18 @@ export {
92
86
  export { GlareCard } from "./ui/glare-card";
93
87
  export { GlareCardRounded } from "./ui/glare-card-rounded";
94
88
  export { Input } from "./ui/input";
89
+ export { Loading } from "./ui/Loading";
95
90
  export { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
96
91
  export { ScrollArea, ScrollBar } from "./ui/scroll-area";
92
+ export { ShinyButton } from "./ui/ShinyButton";
97
93
  export { Skeleton } from "./ui/skeleton";
94
+ export {
95
+ TabsContent as TabsContentPrimitive,
96
+ TabsList as TabsListPrimitive,
97
+ Tabs as TabsPrimitive,
98
+ TabTrigger as TabTriggerPrimitive,
99
+ } from "./ui/Tabs";
100
+ export { Tabs, TabsContent, TabsList, TabsTransitionWrapper, TabTrigger } from "./ui/TabSystem";
98
101
  export { TextLoop } from "./ui/text-loop";
99
102
  export { TextShimmer } from "./ui/text-shimmer";
100
103
  export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip";
@@ -7,11 +7,12 @@ export type {
7
7
  AnySpendJoinTournamentProps,
8
8
  AnySpendModalProps,
9
9
  AnySpendNftProps,
10
+ AnyspendOrderDetailsProps,
10
11
  AnySpendOrderHistoryProps,
11
12
  AnySpendStakeB3Props,
12
- AnyspendOrderDetailsProps,
13
13
  ManageAccountModalProps,
14
14
  ModalContentType,
15
15
  RequestPermissionsModalProps,
16
16
  SignInWithB3ModalProps,
17
+ TransakProps,
17
18
  } from "./useModalStore";
@@ -194,6 +194,25 @@ export interface AnyspendOrderDetailsProps extends BaseModalProps {
194
194
  showBackButton?: boolean;
195
195
  }
196
196
 
197
+ /**
198
+ * Props for the Transak modal
199
+ * Handles Transak-specific on-ramping
200
+ */
201
+ export interface TransakProps extends BaseModalProps {
202
+ /** Modal type identifier */
203
+ type: "transak";
204
+ /** Wallet address to receive the purchased crypto */
205
+ destinationWalletAddress?: string;
206
+ /** Default amount of crypto to purchase */
207
+ defaultCryptoAmount?: number;
208
+ /** Amount of fiat currency to spend */
209
+ fiatAmount?: number;
210
+ /** ISO country code for KYC and available payment methods */
211
+ countryCode?: string;
212
+ /** Callback function called when the purchase is successful */
213
+ onSuccess?: () => void;
214
+ }
215
+
197
216
  /**
198
217
  * Props for the AnySpend order history modal
199
218
  */
@@ -317,6 +336,7 @@ export type ModalContentType =
317
336
  | AnySpendNftProps
318
337
  | AnySpendJoinTournamentProps
319
338
  | AnySpendFundTournamentProps
339
+ | TransakProps
320
340
  | AnySpendOrderHistoryProps
321
341
  | AnySpendStakeB3Props
322
342
  | AnySpendBuySpinProps