@b3dotfun/sdk 0.0.33-alpha.0 → 0.0.33-alpha.1
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/common/OrderDetails.js +26 -25
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +1 -4
- package/dist/cjs/global-account/react/components/index.d.ts +8 -9
- package/dist/cjs/global-account/react/components/index.js +25 -28
- package/dist/cjs/global-account/react/stores/index.d.ts +1 -1
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +1 -19
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +4 -3
- package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -4
- package/dist/esm/global-account/react/components/index.d.ts +8 -9
- package/dist/esm/global-account/react/components/index.js +8 -10
- package/dist/esm/global-account/react/stores/index.d.ts +1 -1
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +1 -19
- package/dist/styles/index.css +1 -1
- package/dist/types/global-account/react/components/index.d.ts +8 -9
- package/dist/types/global-account/react/stores/index.d.ts +1 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +1 -19
- package/package.json +1 -3
- package/src/anyspend/react/components/common/OrderDetails.tsx +6 -3
- package/src/global-account/react/components/B3DynamicModal.tsx +0 -4
- package/src/global-account/react/components/index.ts +13 -16
- package/src/global-account/react/stores/index.ts +1 -2
- package/src/global-account/react/stores/useModalStore.ts +0 -20
- package/dist/cjs/global-account/react/components/Transak/TransakModal.d.ts +0 -1
- package/dist/cjs/global-account/react/components/Transak/TransakModal.js +0 -110
- package/dist/esm/global-account/react/components/Transak/TransakModal.d.ts +0 -1
- package/dist/esm/global-account/react/components/Transak/TransakModal.js +0 -104
- package/dist/types/global-account/react/components/Transak/TransakModal.d.ts +0 -1
- package/src/global-account/react/components/Transak/TransakModal.tsx +0 -131
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b3dotfun/sdk",
|
|
3
|
-
"version": "0.0.33-alpha.
|
|
3
|
+
"version": "0.0.33-alpha.1",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"react-native": "./dist/cjs/index.native.js",
|
|
@@ -239,7 +239,6 @@
|
|
|
239
239
|
"dependencies": {
|
|
240
240
|
"@b3dotfun/b3-api": "0.0.45",
|
|
241
241
|
"@b3dotfun/basement-api": "0.0.11",
|
|
242
|
-
"@chakra-ui/react": "2.10.7",
|
|
243
242
|
"@feathersjs/authentication-client": "5.0.33",
|
|
244
243
|
"@feathersjs/feathers": "5.0.33",
|
|
245
244
|
"@feathersjs/socketio-client": "5.0.33",
|
|
@@ -261,7 +260,6 @@
|
|
|
261
260
|
"@solana/web3.js": "^1.98.2",
|
|
262
261
|
"@stripe/react-stripe-js": "^3.7.0",
|
|
263
262
|
"@stripe/stripe-js": "^7.3.1",
|
|
264
|
-
"@transak/transak-sdk": "3.1.3",
|
|
265
263
|
"@web3icons/react": "3.16.0",
|
|
266
264
|
"big.js": "^7.0.1",
|
|
267
265
|
"class-variance-authority": "0.7.0",
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
TextLoop,
|
|
23
23
|
TextShimmer,
|
|
24
24
|
useAccountWallet,
|
|
25
|
+
useB3,
|
|
25
26
|
useModalStore,
|
|
26
27
|
useProfile,
|
|
27
28
|
useUnifiedChainSwitchAndExecute,
|
|
@@ -30,7 +31,7 @@ import { useRouter, useSearchParams } from "@b3dotfun/sdk/shared/react/hooks";
|
|
|
30
31
|
import { cn } from "@b3dotfun/sdk/shared/utils";
|
|
31
32
|
import centerTruncate from "@b3dotfun/sdk/shared/utils/centerTruncate";
|
|
32
33
|
import { formatTokenAmount } from "@b3dotfun/sdk/shared/utils/number";
|
|
33
|
-
|
|
34
|
+
|
|
34
35
|
import {
|
|
35
36
|
createAssociatedTokenAccountInstruction,
|
|
36
37
|
createTransferCheckedInstruction,
|
|
@@ -208,6 +209,10 @@ export const OrderDetails = memo(function OrderDetails({
|
|
|
208
209
|
const router = useRouter();
|
|
209
210
|
const searchParams = useSearchParams();
|
|
210
211
|
|
|
212
|
+
// Get theme from B3Provider context
|
|
213
|
+
const { theme } = useB3();
|
|
214
|
+
const colorMode = theme || "light";
|
|
215
|
+
|
|
211
216
|
// Read crypto payment method from URL parameters
|
|
212
217
|
const cryptoPaymentMethodFromUrl = searchParams.get("cryptoPaymentMethod") as CryptoPaymentMethodType | null;
|
|
213
218
|
const effectiveCryptoPaymentMethod =
|
|
@@ -233,8 +238,6 @@ export const OrderDetails = memo(function OrderDetails({
|
|
|
233
238
|
|
|
234
239
|
const { switchChainAndExecuteWithEOA, isSwitchingOrExecuting } = useUnifiedChainSwitchAndExecute();
|
|
235
240
|
|
|
236
|
-
const { colorMode } = useColorMode();
|
|
237
|
-
|
|
238
241
|
const roundedUpSrcAmount = useMemo(() => {
|
|
239
242
|
// Display the full transfer amount without rounding since users need to see the exact value they're transferring.
|
|
240
243
|
// Use 21 significant digits (max allowed by Intl.NumberFormat)
|
|
@@ -17,7 +17,6 @@ import { LinkAccount } from "./LinkAccount/LinkAccount";
|
|
|
17
17
|
import { ManageAccount } from "./ManageAccount/ManageAccount";
|
|
18
18
|
import { RequestPermissions } from "./RequestPermissions/RequestPermissions";
|
|
19
19
|
import { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
|
|
20
|
-
import { TransakModal } from "./Transak/TransakModal";
|
|
21
20
|
import { Dialog, DialogContent, DialogDescription, DialogTitle } from "./ui/dialog";
|
|
22
21
|
import { Drawer, DrawerContent, DrawerDescription, DrawerTitle } from "./ui/drawer";
|
|
23
22
|
|
|
@@ -66,7 +65,6 @@ export function B3DynamicModal() {
|
|
|
66
65
|
isFreestyleType && "b3-modal-freestyle",
|
|
67
66
|
contentType?.type === "signInWithB3" && "p-0",
|
|
68
67
|
contentType?.type === "anySpend" && "md:px-6",
|
|
69
|
-
contentType?.type === "transak" && "transak-modal",
|
|
70
68
|
);
|
|
71
69
|
|
|
72
70
|
debug("contentType", contentType);
|
|
@@ -90,8 +88,6 @@ export function B3DynamicModal() {
|
|
|
90
88
|
return <AnySpendTournament {...contentType} mode="modal" action="join" />;
|
|
91
89
|
case "anySpendFundTournament":
|
|
92
90
|
return <AnySpendTournament {...contentType} mode="modal" action="fund" />;
|
|
93
|
-
case "transak":
|
|
94
|
-
return <TransakModal />;
|
|
95
91
|
case "anySpendOrderHistory":
|
|
96
92
|
return <OrderHistory onBack={() => {}} mode="modal" />;
|
|
97
93
|
case "anySpendStakeB3":
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// Core Components
|
|
2
|
-
export { RelayKitProviderWrapper } from "./B3Provider/RelayKitProviderWrapper";
|
|
3
2
|
export { B3DynamicModal } from "./B3DynamicModal";
|
|
4
3
|
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 { AuthButton } from "./SignInWithB3/components/AuthButton";
|
|
11
|
-
export { PermissionItem } from "./SignInWithB3/components/PermissionItem";
|
|
12
|
-
export { WalletRow } from "./SignInWithB3/components/WalletRow";
|
|
13
10
|
export { SignInWithB3 } from "./SignInWithB3/SignInWithB3";
|
|
14
11
|
export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
|
|
15
12
|
export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy";
|
|
13
|
+
export { AuthButton } from "./SignInWithB3/components/AuthButton";
|
|
14
|
+
export { PermissionItem } from "./SignInWithB3/components/PermissionItem";
|
|
15
|
+
export { WalletRow } from "./SignInWithB3/components/WalletRow";
|
|
16
16
|
export { LoginStepContainer } from "./SignInWithB3/steps/LoginStep";
|
|
17
17
|
export { getConnectOptionsFromStrategy, isWalletType, type AllowedStrategy } from "./SignInWithB3/utils/signInUtils";
|
|
18
18
|
|
|
@@ -35,9 +35,6 @@ 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
|
-
|
|
41
38
|
// Custom Components
|
|
42
39
|
export { Button as CustomButton, buttonVariants as customButtonVariants } from "./custom/Button";
|
|
43
40
|
export { ClientOnly } from "./custom/ClientOnly";
|
|
@@ -46,6 +43,15 @@ export { StaggeredFadeLoader } from "./custom/StaggeredFadeLoader";
|
|
|
46
43
|
export { WalletConnectorIcon } from "./custom/WalletConnectorIcon";
|
|
47
44
|
|
|
48
45
|
// 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";
|
|
49
55
|
export { Badge, badgeVariants } from "./ui/badge";
|
|
50
56
|
export { Button, buttonVariants } from "./ui/button";
|
|
51
57
|
export {
|
|
@@ -86,18 +92,9 @@ export {
|
|
|
86
92
|
export { GlareCard } from "./ui/glare-card";
|
|
87
93
|
export { GlareCardRounded } from "./ui/glare-card-rounded";
|
|
88
94
|
export { Input } from "./ui/input";
|
|
89
|
-
export { Loading } from "./ui/Loading";
|
|
90
95
|
export { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
|
|
91
96
|
export { ScrollArea, ScrollBar } from "./ui/scroll-area";
|
|
92
|
-
export { ShinyButton } from "./ui/ShinyButton";
|
|
93
97
|
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";
|
|
101
98
|
export { TextLoop } from "./ui/text-loop";
|
|
102
99
|
export { TextShimmer } from "./ui/text-shimmer";
|
|
103
100
|
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip";
|
|
@@ -7,12 +7,11 @@ export type {
|
|
|
7
7
|
AnySpendJoinTournamentProps,
|
|
8
8
|
AnySpendModalProps,
|
|
9
9
|
AnySpendNftProps,
|
|
10
|
-
AnyspendOrderDetailsProps,
|
|
11
10
|
AnySpendOrderHistoryProps,
|
|
12
11
|
AnySpendStakeB3Props,
|
|
12
|
+
AnyspendOrderDetailsProps,
|
|
13
13
|
ManageAccountModalProps,
|
|
14
14
|
ModalContentType,
|
|
15
15
|
RequestPermissionsModalProps,
|
|
16
16
|
SignInWithB3ModalProps,
|
|
17
|
-
TransakProps,
|
|
18
17
|
} from "./useModalStore";
|
|
@@ -194,25 +194,6 @@ 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
|
-
|
|
216
197
|
/**
|
|
217
198
|
* Props for the AnySpend order history modal
|
|
218
199
|
*/
|
|
@@ -336,7 +317,6 @@ export type ModalContentType =
|
|
|
336
317
|
| AnySpendNftProps
|
|
337
318
|
| AnySpendJoinTournamentProps
|
|
338
319
|
| AnySpendFundTournamentProps
|
|
339
|
-
| TransakProps
|
|
340
320
|
| AnySpendOrderHistoryProps
|
|
341
321
|
| AnySpendStakeB3Props
|
|
342
322
|
| AnySpendBuySpinProps
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function TransakModal(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.TransakModal = TransakModal;
|
|
8
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
-
const react_1 = require("../../../../global-account/react");
|
|
10
|
-
const debug_1 = __importDefault(require("../../../../shared/utils/debug"));
|
|
11
|
-
const transak_sdk_1 = require("@transak/transak-sdk");
|
|
12
|
-
const lucide_react_1 = require("lucide-react");
|
|
13
|
-
const react_2 = require("react");
|
|
14
|
-
const sonner_1 = require("sonner");
|
|
15
|
-
function TransakModal() {
|
|
16
|
-
const [isLoading, setIsLoading] = (0, react_2.useState)(true);
|
|
17
|
-
const [_error, setError] = (0, react_2.useState)(null);
|
|
18
|
-
const account = (0, react_1.useAccountWallet)();
|
|
19
|
-
const { environment } = (0, react_1.useB3)();
|
|
20
|
-
console.log(`process.env.NEXT_PUBLIC_TRANSAK_API_KEY`, process.env.NEXT_PUBLIC_TRANSAK_API_KEY); // d1f4e8be-cacb-4cfa-b2cd-c591084b5ef6
|
|
21
|
-
const transakConfig = (0, react_2.useMemo)(() => {
|
|
22
|
-
return {
|
|
23
|
-
apiKey: process.env.NEXT_PUBLIC_TRANSAK_API_KEY || "", // (Required)
|
|
24
|
-
// Yes, I know it looks weird to use isDevelopment for staging, but this is how this was done on Basement. Leaving till confirming difference
|
|
25
|
-
environment: environment === "development" ? transak_sdk_1.Transak.ENVIRONMENTS.STAGING : transak_sdk_1.Transak.ENVIRONMENTS.PRODUCTION, // (Required)
|
|
26
|
-
containerId: "transakMount", // Id of the element where you want to initialize the iframe
|
|
27
|
-
themeColor: "0c68e9",
|
|
28
|
-
widgetHeight: "650px",
|
|
29
|
-
productsAvailed: "BUY",
|
|
30
|
-
hideMenu: true,
|
|
31
|
-
colorMode: "DARK",
|
|
32
|
-
backgroundColors: "000000", // TODO: figure out why this doesn't work
|
|
33
|
-
exchangeScreenTitle: "Buy ETH on B3",
|
|
34
|
-
isFeeCalculationHidden: true,
|
|
35
|
-
cryptoCurrencyCode: "ETH",
|
|
36
|
-
network: "b3",
|
|
37
|
-
};
|
|
38
|
-
}, [environment]);
|
|
39
|
-
const { ready } = (0, react_1.useB3)();
|
|
40
|
-
const modalOptions = (0, react_1.useModalStore)(state => state.contentType);
|
|
41
|
-
const isOnRamp = modalOptions?.type === "transak";
|
|
42
|
-
const destinationWalletAddress = isOnRamp ? modalOptions?.destinationWalletAddress : undefined;
|
|
43
|
-
const defaultCryptoAmount = isOnRamp ? modalOptions?.defaultCryptoAmount : undefined;
|
|
44
|
-
const onSuccess = isOnRamp ? modalOptions?.onSuccess : undefined;
|
|
45
|
-
const fiatAmount = isOnRamp ? modalOptions?.fiatAmount : undefined;
|
|
46
|
-
const countryCode = isOnRamp ? modalOptions?.countryCode : undefined;
|
|
47
|
-
(0, react_2.useEffect)(() => {
|
|
48
|
-
if (!ready || !isOnRamp)
|
|
49
|
-
return;
|
|
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
|
-
const transak = new transak_sdk_1.Transak(config);
|
|
59
|
-
try {
|
|
60
|
-
transak.init();
|
|
61
|
-
// Add event listeners
|
|
62
|
-
transak_sdk_1.Transak.on("*", data => {
|
|
63
|
-
(0, debug_1.default)("@@transak", data);
|
|
64
|
-
});
|
|
65
|
-
transak_sdk_1.Transak.on(transak_sdk_1.Transak.EVENTS.TRANSAK_WIDGET_CLOSE, () => {
|
|
66
|
-
setIsLoading(false);
|
|
67
|
-
(0, debug_1.default)("@@transak", "Transak SDK closed!");
|
|
68
|
-
});
|
|
69
|
-
transak_sdk_1.Transak.on(transak_sdk_1.Transak.EVENTS.TRANSAK_WIDGET_INITIALISED, () => {
|
|
70
|
-
(0, debug_1.default)("@@transak", "Transak SDK initialized!");
|
|
71
|
-
setIsLoading(false);
|
|
72
|
-
});
|
|
73
|
-
transak_sdk_1.Transak.on(transak_sdk_1.Transak.EVENTS.TRANSAK_ORDER_FAILED, orderData => {
|
|
74
|
-
(0, debug_1.default)("@@transak", orderData);
|
|
75
|
-
sonner_1.toast.error("Oh no! Something went wrong. Please try again.");
|
|
76
|
-
});
|
|
77
|
-
transak_sdk_1.Transak.on(transak_sdk_1.Transak.EVENTS.TRANSAK_ORDER_SUCCESSFUL, orderData => {
|
|
78
|
-
(0, debug_1.default)("@@transak", orderData);
|
|
79
|
-
sonner_1.toast.success("Successfully purchased ETH with credit card!");
|
|
80
|
-
onSuccess?.();
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
setError(err instanceof Error ? err : new Error("Failed to initialize Transak"));
|
|
85
|
-
sonner_1.toast.error("Oh no! Something went wrong. Please try again.");
|
|
86
|
-
setIsLoading(false);
|
|
87
|
-
}
|
|
88
|
-
// Cleanup code
|
|
89
|
-
return () => {
|
|
90
|
-
transak.close();
|
|
91
|
-
};
|
|
92
|
-
}, [
|
|
93
|
-
ready,
|
|
94
|
-
account?.address,
|
|
95
|
-
destinationWalletAddress,
|
|
96
|
-
defaultCryptoAmount,
|
|
97
|
-
isOnRamp,
|
|
98
|
-
onSuccess,
|
|
99
|
-
fiatAmount,
|
|
100
|
-
transakConfig,
|
|
101
|
-
countryCode,
|
|
102
|
-
]);
|
|
103
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [isLoading && ((0, jsx_runtime_1.jsxs)("div", { className: "flex h-full min-h-[650px] flex-col items-center justify-center gap-4", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-24 w-24 animate-spin opacity-10" }), (0, jsx_runtime_1.jsx)(react_1.TextShimmer, { children: "Powering up our credit card processor..." })] })), (0, jsx_runtime_1.jsx)("div", { id: "transakMount", style: {
|
|
104
|
-
display: isLoading ? "none" : "block",
|
|
105
|
-
width: "100%",
|
|
106
|
-
height: "650px",
|
|
107
|
-
borderRadius: "25px",
|
|
108
|
-
overflow: "hidden",
|
|
109
|
-
} })] }));
|
|
110
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function TransakModal(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { TextShimmer, useAccountWallet, useB3, useModalStore } from "../../../../global-account/react/index.js";
|
|
4
|
-
import debug from "../../../../shared/utils/debug.js";
|
|
5
|
-
import { Transak } from "@transak/transak-sdk";
|
|
6
|
-
import { Loader2 } from "lucide-react";
|
|
7
|
-
import { useEffect, useMemo, useState } from "react";
|
|
8
|
-
import { toast } from "sonner";
|
|
9
|
-
export function TransakModal() {
|
|
10
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
11
|
-
const [_error, setError] = useState(null);
|
|
12
|
-
const account = useAccountWallet();
|
|
13
|
-
const { environment } = useB3();
|
|
14
|
-
console.log(`process.env.NEXT_PUBLIC_TRANSAK_API_KEY`, process.env.NEXT_PUBLIC_TRANSAK_API_KEY); // d1f4e8be-cacb-4cfa-b2cd-c591084b5ef6
|
|
15
|
-
const transakConfig = useMemo(() => {
|
|
16
|
-
return {
|
|
17
|
-
apiKey: process.env.NEXT_PUBLIC_TRANSAK_API_KEY || "", // (Required)
|
|
18
|
-
// Yes, I know it looks weird to use isDevelopment for staging, but this is how this was done on Basement. Leaving till confirming difference
|
|
19
|
-
environment: environment === "development" ? Transak.ENVIRONMENTS.STAGING : Transak.ENVIRONMENTS.PRODUCTION, // (Required)
|
|
20
|
-
containerId: "transakMount", // Id of the element where you want to initialize the iframe
|
|
21
|
-
themeColor: "0c68e9",
|
|
22
|
-
widgetHeight: "650px",
|
|
23
|
-
productsAvailed: "BUY",
|
|
24
|
-
hideMenu: true,
|
|
25
|
-
colorMode: "DARK",
|
|
26
|
-
backgroundColors: "000000", // TODO: figure out why this doesn't work
|
|
27
|
-
exchangeScreenTitle: "Buy ETH on B3",
|
|
28
|
-
isFeeCalculationHidden: true,
|
|
29
|
-
cryptoCurrencyCode: "ETH",
|
|
30
|
-
network: "b3",
|
|
31
|
-
};
|
|
32
|
-
}, [environment]);
|
|
33
|
-
const { ready } = useB3();
|
|
34
|
-
const modalOptions = useModalStore(state => state.contentType);
|
|
35
|
-
const isOnRamp = modalOptions?.type === "transak";
|
|
36
|
-
const destinationWalletAddress = isOnRamp ? modalOptions?.destinationWalletAddress : undefined;
|
|
37
|
-
const defaultCryptoAmount = isOnRamp ? modalOptions?.defaultCryptoAmount : undefined;
|
|
38
|
-
const onSuccess = isOnRamp ? modalOptions?.onSuccess : undefined;
|
|
39
|
-
const fiatAmount = isOnRamp ? modalOptions?.fiatAmount : undefined;
|
|
40
|
-
const countryCode = isOnRamp ? modalOptions?.countryCode : undefined;
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (!ready || !isOnRamp)
|
|
43
|
-
return;
|
|
44
|
-
const config = {
|
|
45
|
-
...transakConfig,
|
|
46
|
-
walletAddress: destinationWalletAddress || account?.address, // In the future, this should be set to the new global B3 SCW address
|
|
47
|
-
defaultCryptoAmount,
|
|
48
|
-
disableWalletAddressForm: !!destinationWalletAddress || !!account?.address, // Only disable the form if we have an address
|
|
49
|
-
fiatAmount: fiatAmount,
|
|
50
|
-
countryCode: countryCode,
|
|
51
|
-
};
|
|
52
|
-
const transak = new Transak(config);
|
|
53
|
-
try {
|
|
54
|
-
transak.init();
|
|
55
|
-
// Add event listeners
|
|
56
|
-
Transak.on("*", data => {
|
|
57
|
-
debug("@@transak", data);
|
|
58
|
-
});
|
|
59
|
-
Transak.on(Transak.EVENTS.TRANSAK_WIDGET_CLOSE, () => {
|
|
60
|
-
setIsLoading(false);
|
|
61
|
-
debug("@@transak", "Transak SDK closed!");
|
|
62
|
-
});
|
|
63
|
-
Transak.on(Transak.EVENTS.TRANSAK_WIDGET_INITIALISED, () => {
|
|
64
|
-
debug("@@transak", "Transak SDK initialized!");
|
|
65
|
-
setIsLoading(false);
|
|
66
|
-
});
|
|
67
|
-
Transak.on(Transak.EVENTS.TRANSAK_ORDER_FAILED, orderData => {
|
|
68
|
-
debug("@@transak", orderData);
|
|
69
|
-
toast.error("Oh no! Something went wrong. Please try again.");
|
|
70
|
-
});
|
|
71
|
-
Transak.on(Transak.EVENTS.TRANSAK_ORDER_SUCCESSFUL, orderData => {
|
|
72
|
-
debug("@@transak", orderData);
|
|
73
|
-
toast.success("Successfully purchased ETH with credit card!");
|
|
74
|
-
onSuccess?.();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
setError(err instanceof Error ? err : new Error("Failed to initialize Transak"));
|
|
79
|
-
toast.error("Oh no! Something went wrong. Please try again.");
|
|
80
|
-
setIsLoading(false);
|
|
81
|
-
}
|
|
82
|
-
// Cleanup code
|
|
83
|
-
return () => {
|
|
84
|
-
transak.close();
|
|
85
|
-
};
|
|
86
|
-
}, [
|
|
87
|
-
ready,
|
|
88
|
-
account?.address,
|
|
89
|
-
destinationWalletAddress,
|
|
90
|
-
defaultCryptoAmount,
|
|
91
|
-
isOnRamp,
|
|
92
|
-
onSuccess,
|
|
93
|
-
fiatAmount,
|
|
94
|
-
transakConfig,
|
|
95
|
-
countryCode,
|
|
96
|
-
]);
|
|
97
|
-
return (_jsxs(_Fragment, { children: [isLoading && (_jsxs("div", { className: "flex h-full min-h-[650px] flex-col items-center justify-center gap-4", children: [_jsx(Loader2, { className: "h-24 w-24 animate-spin opacity-10" }), _jsx(TextShimmer, { children: "Powering up our credit card processor..." })] })), _jsx("div", { id: "transakMount", style: {
|
|
98
|
-
display: isLoading ? "none" : "block",
|
|
99
|
-
width: "100%",
|
|
100
|
-
height: "650px",
|
|
101
|
-
borderRadius: "25px",
|
|
102
|
-
overflow: "hidden",
|
|
103
|
-
} })] }));
|
|
104
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function TransakModal(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,131 +0,0 @@
|
|
|
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
|
-
}
|