@turnkey/sdk-react 3.0.6 → 3.1.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.
@@ -63,6 +63,7 @@ var Auth = function Auth(_ref) {
63
63
  var _useTurnkey = useTurnkey(),
64
64
  passkeyClient = _useTurnkey.passkeyClient,
65
65
  authIframeClient = _useTurnkey.authIframeClient,
66
+ walletClient = _useTurnkey.walletClient,
66
67
  turnkey = _useTurnkey.turnkey;
67
68
  var _useState = useState(""),
68
69
  _useState2 = _slicedToArray(_useState, 2),
@@ -108,6 +109,10 @@ var Auth = function Auth(_ref) {
108
109
  _useState22 = _slicedToArray(_useState21, 2),
109
110
  passkeyCreated = _useState22[0],
110
111
  setPasskeyCreated = _useState22[1];
112
+ var _useState23 = useState(false),
113
+ _useState24 = _slicedToArray(_useState23, 2),
114
+ walletLoading = _useState24[0],
115
+ setWalletLoading = _useState24[1];
111
116
  var handleResendCode = /*#__PURE__*/function () {
112
117
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
113
118
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -457,6 +462,95 @@ var Auth = function Auth(_ref) {
457
462
  return _ref8.apply(this, arguments);
458
463
  };
459
464
  }();
465
+ var handleLoginWithWallet = /*#__PURE__*/function () {
466
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
467
+ var publicKey, _walletClient$getWall, type, resp, suborgIds, _suborgId, sessionResponse, _authConfig$sessionLe4;
468
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
469
+ while (1) switch (_context7.prev = _context7.next) {
470
+ case 0:
471
+ setWalletLoading(true);
472
+ _context7.prev = 1;
473
+ if (walletClient) {
474
+ _context7.next = 4;
475
+ break;
476
+ }
477
+ throw new Error("Wallet client not initialized");
478
+ case 4:
479
+ _context7.next = 6;
480
+ return walletClient.getPublicKey();
481
+ case 6:
482
+ publicKey = _context7.sent;
483
+ if (publicKey) {
484
+ _context7.next = 9;
485
+ break;
486
+ }
487
+ throw new Error(authErrors.wallet.noPublicKey);
488
+ case 9:
489
+ _walletClient$getWall = walletClient.getWalletInterface(), type = _walletClient$getWall.type;
490
+ _context7.next = 12;
491
+ return server.getOrCreateSuborg({
492
+ filterType: FilterType.PublicKey,
493
+ filterValue: publicKey,
494
+ additionalData: {
495
+ wallet: {
496
+ publicKey: publicKey,
497
+ type: type
498
+ }
499
+ }
500
+ });
501
+ case 12:
502
+ resp = _context7.sent;
503
+ suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
504
+ if (!(!suborgIds || suborgIds.length === 0)) {
505
+ _context7.next = 17;
506
+ break;
507
+ }
508
+ onError(authErrors.wallet.loginFailed);
509
+ return _context7.abrupt("return");
510
+ case 17:
511
+ _suborgId = suborgIds[0];
512
+ _context7.next = 20;
513
+ return walletClient.createReadWriteSession(_objectSpread2(_objectSpread2({
514
+ targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey
515
+ }, _suborgId && {
516
+ organizationId: _suborgId
517
+ }), authConfig.sessionLengthSeconds !== undefined && {
518
+ expirationSeconds: authConfig.sessionLengthSeconds.toString()
519
+ }));
520
+ case 20:
521
+ sessionResponse = _context7.sent;
522
+ if (!(sessionResponse !== null && sessionResponse !== void 0 && sessionResponse.credentialBundle)) {
523
+ _context7.next = 26;
524
+ break;
525
+ }
526
+ _context7.next = 24;
527
+ return handleAuthSuccess(sessionResponse.credentialBundle, (_authConfig$sessionLe4 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe4 === void 0 ? void 0 : _authConfig$sessionLe4.toString());
528
+ case 24:
529
+ _context7.next = 27;
530
+ break;
531
+ case 26:
532
+ throw new Error(authErrors.wallet.loginFailed);
533
+ case 27:
534
+ _context7.next = 32;
535
+ break;
536
+ case 29:
537
+ _context7.prev = 29;
538
+ _context7.t0 = _context7["catch"](1);
539
+ onError(_context7.t0.message || authErrors.wallet.loginFailed);
540
+ case 32:
541
+ _context7.prev = 32;
542
+ setWalletLoading(false);
543
+ return _context7.finish(32);
544
+ case 35:
545
+ case "end":
546
+ return _context7.stop();
547
+ }
548
+ }, _callee7, null, [[1, 29, 32, 35]]);
549
+ }));
550
+ return function handleLoginWithWallet() {
551
+ return _ref9.apply(this, arguments);
552
+ };
553
+ }();
460
554
  var renderBackButton = function renderBackButton() {
461
555
  return jsx(ChevronLeftIcon, {
462
556
  onClick: function onClick() {
@@ -595,6 +689,21 @@ var Auth = function Auth(_ref) {
595
689
  children: "Sign up with passkey"
596
690
  })]
597
691
  }) : null;
692
+ case "wallet":
693
+ return authConfig.walletEnabled && !otpId ? jsx("div", {
694
+ className: styles.passkeyContainer,
695
+ children: jsx("button", {
696
+ className: styles.authButton,
697
+ type: "button",
698
+ onClick: handleLoginWithWallet,
699
+ disabled: walletLoading,
700
+ children: walletLoading ? jsx(CircularProgress, {
701
+ size: 24,
702
+ thickness: 4,
703
+ className: styles.buttonProgress || ""
704
+ }) : "Continue with Wallet"
705
+ })
706
+ }) : null;
598
707
  case "socials":
599
708
  return authConfig.googleEnabled || authConfig.appleEnabled || authConfig.facebookEnabled ? renderSocialButtons() : null;
600
709
  default: