@turnkey/react-wallet-kit 1.4.3 → 1.5.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.
Files changed (32) hide show
  1. package/dist/components/design/Svg.d.ts +2 -0
  2. package/dist/components/design/Svg.d.ts.map +1 -1
  3. package/dist/components/design/Svg.js +45 -0
  4. package/dist/components/design/Svg.js.map +1 -1
  5. package/dist/components/design/Svg.mjs +44 -1
  6. package/dist/components/design/Svg.mjs.map +1 -1
  7. package/dist/components/import/Import.d.ts +1 -0
  8. package/dist/components/import/Import.d.ts.map +1 -1
  9. package/dist/components/import/Import.js +3 -1
  10. package/dist/components/import/Import.js.map +1 -1
  11. package/dist/components/import/Import.mjs +3 -1
  12. package/dist/components/import/Import.mjs.map +1 -1
  13. package/dist/components/onramp/OnRamp.d.ts +14 -0
  14. package/dist/components/onramp/OnRamp.d.ts.map +1 -0
  15. package/dist/components/onramp/OnRamp.js +61 -0
  16. package/dist/components/onramp/OnRamp.js.map +1 -0
  17. package/dist/components/onramp/OnRamp.mjs +79 -0
  18. package/dist/components/onramp/OnRamp.mjs.map +1 -0
  19. package/dist/providers/client/Provider.d.ts.map +1 -1
  20. package/dist/providers/client/Provider.js +184 -1
  21. package/dist/providers/client/Provider.js.map +1 -1
  22. package/dist/providers/client/Provider.mjs +388 -138
  23. package/dist/providers/client/Provider.mjs.map +1 -1
  24. package/dist/providers/client/Types.d.ts +30 -1
  25. package/dist/providers/client/Types.d.ts.map +1 -1
  26. package/dist/providers/client/Types.js.map +1 -1
  27. package/dist/providers/client/Types.mjs.map +1 -1
  28. package/dist/types/method-types.d.ts +21 -1
  29. package/dist/types/method-types.d.ts.map +1 -1
  30. package/dist/utils/utils.js +1 -1
  31. package/dist/utils/utils.mjs +1 -1
  32. package/package.json +4 -4
@@ -30,6 +30,8 @@ var OTP = require('../../components/auth/OTP.js');
30
30
  var RemoveEmail = require('../../components/user/RemoveEmail.js');
31
31
  var RemovePhoneNumber = require('../../components/user/RemovePhoneNumber.js');
32
32
  var Verify = require('../../components/verify/Verify.js');
33
+ var OnRamp = require('../../components/onramp/OnRamp.js');
34
+ var Svg = require('../../components/design/Svg.js');
33
35
 
34
36
  /**
35
37
  * Provides Turnkey client authentication, session management, wallet operations, and user profile management
@@ -2458,6 +2460,7 @@ const ClientProvider = ({
2458
2460
  successPageDuration = 2000,
2459
2461
  stampWith,
2460
2462
  walletName,
2463
+ clearClipboardOnPaste,
2461
2464
  organizationId,
2462
2465
  userId
2463
2466
  } = params || {};
@@ -2476,6 +2479,9 @@ const ClientProvider = ({
2476
2479
  ...(successPageDuration !== undefined && {
2477
2480
  successPageDuration
2478
2481
  }),
2482
+ ...(clearClipboardOnPaste !== undefined && {
2483
+ clearClipboardOnPaste // Note: This is defaulted to true in the IframeStamper
2484
+ }),
2479
2485
  ...(stampWith !== undefined && {
2480
2486
  stampWith
2481
2487
  }),
@@ -2504,6 +2510,7 @@ const ClientProvider = ({
2504
2510
  successPageDuration = 2000,
2505
2511
  stampWith,
2506
2512
  keyName,
2513
+ clearClipboardOnPaste,
2507
2514
  organizationId
2508
2515
  } = params || {};
2509
2516
  try {
@@ -2520,6 +2527,9 @@ const ClientProvider = ({
2520
2527
  ...(successPageDuration !== undefined && {
2521
2528
  successPageDuration
2522
2529
  }),
2530
+ ...(clearClipboardOnPaste !== undefined && {
2531
+ clearClipboardOnPaste // Note: This is defaulted to true in the IframeStamper
2532
+ }),
2523
2533
  ...(stampWith !== undefined && {
2524
2534
  stampWith
2525
2535
  }),
@@ -3438,6 +3448,178 @@ const ClientProvider = ({
3438
3448
  throw new sdkTypes.TurnkeyError("Failed to remove user phone number.", sdkTypes.TurnkeyErrorCodes.UPDATE_USER_PHONE_NUMBER_ERROR, error);
3439
3449
  }
3440
3450
  }, [pushPage, masterConfig, client, session, user]);
3451
+ const handleOnRamp = react.useCallback(async params => {
3452
+ const {
3453
+ walletAccount,
3454
+ fiatCurrencyAmount,
3455
+ fiatCurrencyCode,
3456
+ paymentMethod,
3457
+ countrySubdivisionCode,
3458
+ urlForSignature,
3459
+ countryCode,
3460
+ onrampProvider = "FIAT_ON_RAMP_PROVIDER_MOONPAY",
3461
+ sandboxMode = true,
3462
+ successPageDuration = 2000,
3463
+ openInNewTab = false
3464
+ } = params;
3465
+ const s = await getSession();
3466
+ const organizationId = params?.organizationId || s?.organizationId;
3467
+ if (!organizationId) {
3468
+ throw new sdkTypes.TurnkeyError("A session or passed in organization ID is required.", sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
3469
+ }
3470
+ let cryptoCurrencyCode;
3471
+ let network;
3472
+ switch (true) {
3473
+ case walletAccount.addressFormat === "ADDRESS_FORMAT_ETHEREUM":
3474
+ cryptoCurrencyCode = sdkTypes.FiatOnRampCryptoCurrency.ETHEREUM;
3475
+ network = sdkTypes.FiatOnRampBlockchainNetwork.ETHEREUM;
3476
+ break;
3477
+ case walletAccount.addressFormat?.includes("ADDRESS_FORMAT_BITCOIN"):
3478
+ cryptoCurrencyCode = sdkTypes.FiatOnRampCryptoCurrency.BITCOIN;
3479
+ network = sdkTypes.FiatOnRampBlockchainNetwork.BITCOIN;
3480
+ break;
3481
+ case walletAccount.addressFormat === "ADDRESS_FORMAT_SOLANA":
3482
+ cryptoCurrencyCode = sdkTypes.FiatOnRampCryptoCurrency.SOLANA;
3483
+ network = sdkTypes.FiatOnRampBlockchainNetwork.SOLANA;
3484
+ break;
3485
+ default:
3486
+ cryptoCurrencyCode = sdkTypes.FiatOnRampCryptoCurrency.ETHEREUM;
3487
+ network = sdkTypes.FiatOnRampBlockchainNetwork.ETHEREUM;
3488
+ break;
3489
+ }
3490
+ const openNewTab = openInNewTab || isMobile;
3491
+ cryptoCurrencyCode = params.cryptoCurrencyCode || cryptoCurrencyCode;
3492
+ network = params.network || network;
3493
+ return new Promise((resolve, reject) => {
3494
+ const OnRampContainer = () => {
3495
+ const [completed, setCompleted] = react.useState(false);
3496
+ const pollingRef = react.useRef(null);
3497
+ const cleanup = () => {
3498
+ if (pollingRef.current) {
3499
+ clearInterval(pollingRef.current);
3500
+ pollingRef.current = null;
3501
+ }
3502
+ };
3503
+ react.useEffect(() => {
3504
+ return () => {
3505
+ cleanup();
3506
+ };
3507
+ }, []);
3508
+ const action = async () => {
3509
+ try {
3510
+ let onRampWindow = null;
3511
+ if (openNewTab) {
3512
+ onRampWindow = window.open("", "_blank");
3513
+ if (!onRampWindow) throw new Error("Failed to open On Ramp tab.");
3514
+ }
3515
+ const result = await client?.httpClient?.initFiatOnRamp({
3516
+ onrampProvider,
3517
+ walletAddress: walletAccount.address,
3518
+ network,
3519
+ cryptoCurrencyCode,
3520
+ sandboxMode,
3521
+ organizationId,
3522
+ ...(fiatCurrencyCode ? {
3523
+ fiatCurrencyCode
3524
+ } : {}),
3525
+ ...(fiatCurrencyAmount ? {
3526
+ fiatCurrencyAmount
3527
+ } : {}),
3528
+ ...(paymentMethod ? {
3529
+ paymentMethod
3530
+ } : {}),
3531
+ ...(countryCode ? {
3532
+ countryCode
3533
+ } : {}),
3534
+ ...(countrySubdivisionCode ? {
3535
+ countrySubdivisionCode
3536
+ } : {}),
3537
+ ...(sandboxMode !== undefined ? {
3538
+ sandboxMode
3539
+ } : {}),
3540
+ ...(urlForSignature ? {
3541
+ urlForSignature
3542
+ } : {})
3543
+ });
3544
+ if (!result?.onRampUrl) throw new Error("Missing onRampUrl");
3545
+ if (openNewTab && onRampWindow) {
3546
+ onRampWindow.location.href = result.onRampUrl.toString();
3547
+ } else {
3548
+ const popupWidth = 500;
3549
+ const popupHeight = 600;
3550
+ const left = window.screenX + (window.innerWidth - popupWidth) / 2;
3551
+ const top = window.screenY + (window.innerHeight - popupHeight) / 2;
3552
+ onRampWindow = window.open(result.onRampUrl.toString(), "_blank", `width=${popupWidth},height=${popupHeight},top=${top},left=${left},scrollbars=yes,resizable=yes`);
3553
+ if (!onRampWindow) throw new Error("Failed to open On Ramp window.");
3554
+ }
3555
+ const onRampTransactionId = result.onRampTransactionId;
3556
+ if (!onRampTransactionId) throw new Error("No onRampTransactionId returned");
3557
+ return new Promise((resolveAction, rejectAction) => {
3558
+ pollingRef.current = setInterval(async () => {
3559
+ try {
3560
+ if (onrampProvider === "FIAT_ON_RAMP_PROVIDER_COINBASE" && onRampWindow?.closed) {
3561
+ cleanup();
3562
+ rejectAction(new Error("On-ramp popup closed by user"));
3563
+ return;
3564
+ }
3565
+ let currentUrl = "";
3566
+ try {
3567
+ currentUrl = onRampWindow?.location.href || "";
3568
+ } catch {}
3569
+ if (currentUrl && currentUrl.startsWith(window.location.origin)) {
3570
+ cleanup();
3571
+ onRampWindow?.close();
3572
+ setCompleted(true);
3573
+ resolveAction();
3574
+ return;
3575
+ }
3576
+ const resp = await client?.httpClient?.getOnRampTransactionStatus({
3577
+ transactionId: onRampTransactionId,
3578
+ refresh: true
3579
+ });
3580
+ const status = resp?.transactionStatus;
3581
+ if (["COMPLETED", "FAILED", "CANCELLED"].includes(status ?? "")) {
3582
+ cleanup();
3583
+ try {
3584
+ onRampWindow?.close();
3585
+ } catch {}
3586
+ setCompleted(true);
3587
+ resolveAction();
3588
+ }
3589
+ } catch (error) {
3590
+ console.warn("Polling error (ignored):", error);
3591
+ }
3592
+ }, 3000);
3593
+ });
3594
+ } catch (err) {
3595
+ cleanup();
3596
+ throw err;
3597
+ }
3598
+ };
3599
+ return jsxRuntime.jsx(OnRamp.OnRampPage, {
3600
+ icon: onrampProvider === "FIAT_ON_RAMP_PROVIDER_COINBASE" ? jsxRuntime.jsx(Svg.CoinbaseLogo, {
3601
+ className: "w-12 h-12"
3602
+ }) : jsxRuntime.jsx(Svg.MoonPayLogo, {
3603
+ className: "w-12 h-12"
3604
+ }),
3605
+ onrampProvider: onrampProvider,
3606
+ action: action,
3607
+ sandboxMode: sandboxMode,
3608
+ completed: completed,
3609
+ successPageDuration: successPageDuration,
3610
+ onSuccess: () => resolve(),
3611
+ onError: err => reject(err)
3612
+ });
3613
+ };
3614
+ pushPage({
3615
+ key: "Fiat OnRamp",
3616
+ content: jsxRuntime.jsx(OnRampContainer, {}),
3617
+ showTitle: false,
3618
+ preventBack: true,
3619
+ onClose: () => reject(new sdkTypes.TurnkeyError("User canceled the onramp process.", sdkTypes.TurnkeyErrorCodes.USER_CANCELED))
3620
+ });
3621
+ });
3622
+ }, [pushPage, client]);
3441
3623
  const handleVerifyAppProofs = react.useCallback(async params => {
3442
3624
  const {
3443
3625
  appProofs,
@@ -3674,7 +3856,8 @@ const ClientProvider = ({
3674
3856
  handleConnectExternalWallet,
3675
3857
  handleRemoveUserEmail,
3676
3858
  handleRemoveUserPhoneNumber,
3677
- handleVerifyAppProofs
3859
+ handleVerifyAppProofs,
3860
+ handleOnRamp
3678
3861
  },
3679
3862
  children: children
3680
3863
  });