@turnkey/react-wallet-kit 1.4.2 → 1.5.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.
@@ -7,7 +7,7 @@ import { useWalletProviderState, useDebouncedCallback, isValidSession, withTurnk
7
7
  import { clearKeys, clearAll, setCappedTimeoutInMap, clearKey, setTimeoutInMap } from '../../utils/timers.mjs';
8
8
  import { DEFAULT_SESSION_EXPIRATION_IN_SECONDS, WalletSource, OtpType, TurnkeyClient, Chain, WalletInterfaceType, getAuthProxyConfig } from '@turnkey/core';
9
9
  import { useState, useRef, useCallback, useEffect } from 'react';
10
- import { TurnkeyError, TurnkeyErrorCodes, AuthAction, OAuthProviders, TurnkeyNetworkError } from '@turnkey/sdk-types';
10
+ import { TurnkeyError, TurnkeyErrorCodes, AuthAction, OAuthProviders, FiatOnRampCryptoCurrency, FiatOnRampBlockchainNetwork, TurnkeyNetworkError } from '@turnkey/sdk-types';
11
11
  import { useModal } from '../modal/Hook.mjs';
12
12
  import { AuthState, ClientState, AuthMethod, ExportType, ImportType } from '../../types/base.mjs';
13
13
  import { AuthComponent } from '../../components/auth/index.mjs';
@@ -29,6 +29,8 @@ import { OtpVerification } from '../../components/auth/OTP.mjs';
29
29
  import { RemoveEmail } from '../../components/user/RemoveEmail.mjs';
30
30
  import { RemovePhoneNumber } from '../../components/user/RemovePhoneNumber.mjs';
31
31
  import { VerifyPage } from '../../components/verify/Verify.mjs';
32
+ import { OnRampPage } from '../../components/onramp/OnRamp.mjs';
33
+ import { CoinbaseLogo, MoonPayLogo } from '../../components/design/Svg.mjs';
32
34
 
33
35
  /**
34
36
  * Provides Turnkey client authentication, session management, wallet operations, and user profile management
@@ -789,11 +791,11 @@ var ClientProvider = function ClientProvider(_ref) {
789
791
  * @throws {TurnkeyError} If an error occurs while scheduling the session expiration.
790
792
  */
791
793
  function _initializeWalletProviderListeners() {
792
- _initializeWalletProviderListeners = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(walletProviders, onUpdateState) {
794
+ _initializeWalletProviderListeners = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee112(walletProviders, onUpdateState) {
793
795
  var _masterConfig$walletC0, _masterConfig$walletC1, _masterConfig$walletC10, _masterConfig$walletC11;
794
796
  var cleanups, nativeOnly, ethProviders, solProviders, wcProviders, wcProvider, attachEthereumListeners, attachSolanaListeners, _wcProvider$provider, _wcProvider$provider$, standardEvents, unsubscribe;
795
- return _regenerator().w(function (_context109) {
796
- while (1) switch (_context109.n) {
797
+ return _regenerator().w(function (_context112) {
798
+ while (1) switch (_context112.n) {
797
799
  case 0:
798
800
  attachSolanaListeners = function _attachSolanaListener(provider, onUpdateState) {
799
801
  var _provider$features;
@@ -801,19 +803,19 @@ var ClientProvider = function ClientProvider(_ref) {
801
803
  var walletEvents = provider === null || provider === void 0 ? void 0 : (_provider$features = provider.features) === null || _provider$features === void 0 ? void 0 : _provider$features["standard:events"];
802
804
  if (walletEvents !== null && walletEvents !== void 0 && walletEvents.on) {
803
805
  var offChange = walletEvents.on("change", /*#__PURE__*/function () {
804
- var _ref137 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107(_evt) {
805
- return _regenerator().w(function (_context107) {
806
- while (1) switch (_context107.n) {
806
+ var _ref140 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee110(_evt) {
807
+ return _regenerator().w(function (_context110) {
808
+ while (1) switch (_context110.n) {
807
809
  case 0:
808
- _context107.n = 1;
810
+ _context110.n = 1;
809
811
  return onUpdateState();
810
812
  case 1:
811
- return _context107.a(2);
813
+ return _context110.a(2);
812
814
  }
813
- }, _callee107);
815
+ }, _callee110);
814
816
  }));
815
- return function (_x94) {
816
- return _ref137.apply(this, arguments);
817
+ return function (_x95) {
818
+ return _ref140.apply(this, arguments);
817
819
  };
818
820
  }());
819
821
  cleanups.push(offChange);
@@ -827,31 +829,31 @@ var ClientProvider = function ClientProvider(_ref) {
827
829
  attachEthereumListeners = function _attachEthereumListen(provider, onUpdateState) {
828
830
  if (typeof provider.on !== "function") return;
829
831
  var handleChainChanged = /*#__PURE__*/function () {
830
- var _ref135 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(_chainId) {
831
- return _regenerator().w(function (_context105) {
832
- while (1) switch (_context105.n) {
832
+ var _ref138 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee108(_chainId) {
833
+ return _regenerator().w(function (_context108) {
834
+ while (1) switch (_context108.n) {
833
835
  case 0:
834
- return _context105.a(2, onUpdateState());
836
+ return _context108.a(2, onUpdateState());
835
837
  }
836
- }, _callee105);
838
+ }, _callee108);
837
839
  }));
838
- return function handleChainChanged(_x92) {
839
- return _ref135.apply(this, arguments);
840
+ return function handleChainChanged(_x93) {
841
+ return _ref138.apply(this, arguments);
840
842
  };
841
843
  }();
842
844
  var handleAccountsChanged = /*#__PURE__*/function () {
843
- var _ref136 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee106(accounts) {
844
- return _regenerator().w(function (_context106) {
845
- while (1) switch (_context106.n) {
845
+ var _ref139 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(accounts) {
846
+ return _regenerator().w(function (_context109) {
847
+ while (1) switch (_context109.n) {
846
848
  case 0:
847
849
  if (accounts.length === 0) onUpdateState();
848
850
  case 1:
849
- return _context106.a(2);
851
+ return _context109.a(2);
850
852
  }
851
- }, _callee106);
853
+ }, _callee109);
852
854
  }));
853
- return function handleAccountsChanged(_x93) {
854
- return _ref136.apply(this, arguments);
855
+ return function handleAccountsChanged(_x94) {
856
+ return _ref139.apply(this, arguments);
855
857
  };
856
858
  }();
857
859
  var handleDisconnect = function handleDisconnect() {
@@ -867,10 +869,10 @@ var ClientProvider = function ClientProvider(_ref) {
867
869
  };
868
870
  };
869
871
  if (!(walletProviders.length === 0)) {
870
- _context109.n = 1;
872
+ _context112.n = 1;
871
873
  break;
872
874
  }
873
- return _context109.a(2, function () {});
875
+ return _context112.a(2, function () {});
874
876
  case 1:
875
877
  cleanups = []; // we only want to initialize these listeners for connected walletProviders
876
878
  nativeOnly = function nativeOnly(provider) {
@@ -908,9 +910,9 @@ var ClientProvider = function ClientProvider(_ref) {
908
910
  if (standardEvents !== null && standardEvents !== void 0 && standardEvents.on) {
909
911
  if (standardEvents !== null && standardEvents !== void 0 && standardEvents.on) {
910
912
  unsubscribe = standardEvents.on("change", /*#__PURE__*/function () {
911
- var _ref138 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee108(evt) {
912
- return _regenerator().w(function (_context108) {
913
- while (1) switch (_context108.n) {
913
+ var _ref141 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111(evt) {
914
+ return _regenerator().w(function (_context111) {
915
+ while (1) switch (_context111.n) {
914
916
  case 0:
915
917
  // if the event is a proposalExpired, we want to re-fetch the providers
916
918
  // to refresh the uri, there is no need to refresh the wallets state
@@ -919,28 +921,28 @@ var ClientProvider = function ClientProvider(_ref) {
919
921
  }
920
922
  // any other event (disconnect, chain switch, accounts changed)
921
923
  // we refresh the wallets state
922
- _context108.n = 1;
924
+ _context111.n = 1;
923
925
  return onUpdateState();
924
926
  case 1:
925
- return _context108.a(2);
927
+ return _context111.a(2);
926
928
  }
927
- }, _callee108);
929
+ }, _callee111);
928
930
  }));
929
- return function (_x95) {
930
- return _ref138.apply(this, arguments);
931
+ return function (_x96) {
932
+ return _ref141.apply(this, arguments);
931
933
  };
932
934
  }());
933
935
  cleanups.push(unsubscribe);
934
936
  }
935
937
  }
936
938
  }
937
- return _context109.a(2, function () {
939
+ return _context112.a(2, function () {
938
940
  cleanups.forEach(function (remove) {
939
941
  return remove();
940
942
  });
941
943
  });
942
944
  }
943
- }, _callee109);
945
+ }, _callee112);
944
946
  }));
945
947
  return _initializeWalletProviderListeners.apply(this, arguments);
946
948
  }
@@ -956,13 +958,13 @@ var ClientProvider = function ClientProvider(_ref) {
956
958
  * @throws {TurnkeyError} If an error occurs while clearing the timers.
957
959
  */
958
960
  function _scheduleSessionExpiration() {
959
- _scheduleSessionExpiration = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee112(params) {
960
- var sessionKey, expiry, warnKey, now, expiryMs, timeUntilExpiry, _beforeExpiry, expireSession, warnAt, _callbacks$onError0, _callbacks$onError1, _t35;
961
- return _regenerator().w(function (_context112) {
962
- while (1) switch (_context112.p = _context112.n) {
961
+ _scheduleSessionExpiration = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee115(params) {
962
+ var sessionKey, expiry, warnKey, now, expiryMs, timeUntilExpiry, _beforeExpiry, expireSession, warnAt, _callbacks$onError0, _callbacks$onError1, _t38;
963
+ return _regenerator().w(function (_context115) {
964
+ while (1) switch (_context115.p = _context115.n) {
963
965
  case 0:
964
966
  sessionKey = params.sessionKey, expiry = params.expiry;
965
- _context112.p = 1;
967
+ _context115.p = 1;
966
968
  warnKey = "".concat(sessionKey, "-warning"); // Replace any prior timers for this session
967
969
  clearKey(expiryTimeoutsRef.current, sessionKey);
968
970
  clearKey(expiryTimeoutsRef.current, warnKey);
@@ -970,86 +972,86 @@ var ClientProvider = function ClientProvider(_ref) {
970
972
  expiryMs = expiry * 1000;
971
973
  timeUntilExpiry = expiryMs - now;
972
974
  _beforeExpiry = /*#__PURE__*/function () {
973
- var _ref139 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee110() {
975
+ var _ref142 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee113() {
974
976
  var _callbacks$beforeSess, _masterConfig$auth50;
975
977
  var activeSession, session;
976
- return _regenerator().w(function (_context110) {
977
- while (1) switch (_context110.n) {
978
+ return _regenerator().w(function (_context113) {
979
+ while (1) switch (_context113.n) {
978
980
  case 0:
979
- _context110.n = 1;
981
+ _context113.n = 1;
980
982
  return getSession();
981
983
  case 1:
982
- activeSession = _context110.v;
984
+ activeSession = _context113.v;
983
985
  if (!(!activeSession && expiryTimeoutsRef.current[warnKey])) {
984
- _context110.n = 2;
986
+ _context113.n = 2;
985
987
  break;
986
988
  }
987
989
  // Keep nudging until session materializes (short 10s timer is fine)
988
990
  setTimeoutInMap(expiryTimeoutsRef.current, warnKey, _beforeExpiry, 10000);
989
- return _context110.a(2);
991
+ return _context113.a(2);
990
992
  case 2:
991
- _context110.n = 3;
993
+ _context113.n = 3;
992
994
  return getSession({
993
995
  sessionKey: sessionKey
994
996
  });
995
997
  case 3:
996
- session = _context110.v;
998
+ session = _context113.v;
997
999
  if (session) {
998
- _context110.n = 4;
1000
+ _context113.n = 4;
999
1001
  break;
1000
1002
  }
1001
- return _context110.a(2);
1003
+ return _context113.a(2);
1002
1004
  case 4:
1003
1005
  callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$beforeSess = callbacks.beforeSessionExpiry) === null || _callbacks$beforeSess === void 0 ? void 0 : _callbacks$beforeSess.call(callbacks, {
1004
1006
  sessionKey: sessionKey
1005
1007
  });
1006
1008
  if (!(masterConfig !== null && masterConfig !== void 0 && (_masterConfig$auth50 = masterConfig.auth) !== null && _masterConfig$auth50 !== void 0 && _masterConfig$auth50.autoRefreshSession)) {
1007
- _context110.n = 5;
1009
+ _context113.n = 5;
1008
1010
  break;
1009
1011
  }
1010
- _context110.n = 5;
1012
+ _context113.n = 5;
1011
1013
  return refreshSession({
1012
1014
  expirationSeconds: session.expirationSeconds,
1013
1015
  sessionKey: sessionKey
1014
1016
  });
1015
1017
  case 5:
1016
- return _context110.a(2);
1018
+ return _context113.a(2);
1017
1019
  }
1018
- }, _callee110);
1020
+ }, _callee113);
1019
1021
  }));
1020
1022
  return function beforeExpiry() {
1021
- return _ref139.apply(this, arguments);
1023
+ return _ref142.apply(this, arguments);
1022
1024
  };
1023
1025
  }();
1024
1026
  expireSession = /*#__PURE__*/function () {
1025
- var _ref140 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111() {
1027
+ var _ref143 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee114() {
1026
1028
  var _callbacks$onSessionE;
1027
- var expiredSession, _t33, _t34;
1028
- return _regenerator().w(function (_context111) {
1029
- while (1) switch (_context111.n) {
1029
+ var expiredSession, _t36, _t37;
1030
+ return _regenerator().w(function (_context114) {
1031
+ while (1) switch (_context114.n) {
1030
1032
  case 0:
1031
- _context111.n = 1;
1033
+ _context114.n = 1;
1032
1034
  return getSession({
1033
1035
  sessionKey: sessionKey
1034
1036
  });
1035
1037
  case 1:
1036
- expiredSession = _context111.v;
1038
+ expiredSession = _context114.v;
1037
1039
  if (expiredSession) {
1038
- _context111.n = 2;
1040
+ _context114.n = 2;
1039
1041
  break;
1040
1042
  }
1041
- return _context111.a(2);
1043
+ return _context114.a(2);
1042
1044
  case 2:
1043
1045
  callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onSessionE = callbacks.onSessionExpired) === null || _callbacks$onSessionE === void 0 ? void 0 : _callbacks$onSessionE.call(callbacks, {
1044
1046
  sessionKey: sessionKey
1045
1047
  });
1046
- _context111.n = 3;
1048
+ _context114.n = 3;
1047
1049
  return getActiveSessionKey();
1048
1050
  case 3:
1049
- _t33 = _context111.v;
1050
- _t34 = sessionKey;
1051
- if (!(_t33 === _t34)) {
1052
- _context111.n = 4;
1051
+ _t36 = _context114.v;
1052
+ _t37 = sessionKey;
1053
+ if (!(_t36 === _t37)) {
1054
+ _context114.n = 4;
1053
1055
  break;
1054
1056
  }
1055
1057
  setSession(undefined);
@@ -1060,7 +1062,7 @@ var ClientProvider = function ClientProvider(_ref) {
1060
1062
  delete next[sessionKey];
1061
1063
  return next;
1062
1064
  });
1063
- _context111.n = 5;
1065
+ _context114.n = 5;
1064
1066
  return clearSession({
1065
1067
  sessionKey: sessionKey
1066
1068
  });
@@ -1068,25 +1070,25 @@ var ClientProvider = function ClientProvider(_ref) {
1068
1070
  // Remove timers for this session
1069
1071
  clearKey(expiryTimeoutsRef.current, sessionKey);
1070
1072
  clearKey(expiryTimeoutsRef.current, warnKey);
1071
- _context111.n = 6;
1073
+ _context114.n = 6;
1072
1074
  return logout();
1073
1075
  case 6:
1074
- return _context111.a(2);
1076
+ return _context114.a(2);
1075
1077
  }
1076
- }, _callee111);
1078
+ }, _callee114);
1077
1079
  }));
1078
1080
  return function expireSession() {
1079
- return _ref140.apply(this, arguments);
1081
+ return _ref143.apply(this, arguments);
1080
1082
  };
1081
1083
  }(); // Already expired → expire immediately
1082
1084
  if (!(timeUntilExpiry <= 0)) {
1083
- _context112.n = 3;
1085
+ _context115.n = 3;
1084
1086
  break;
1085
1087
  }
1086
- _context112.n = 2;
1088
+ _context115.n = 2;
1087
1089
  return expireSession();
1088
1090
  case 2:
1089
- return _context112.a(2);
1091
+ return _context115.a(2);
1090
1092
  case 3:
1091
1093
  // Warning timer (if threshold is in the future)
1092
1094
  warnAt = expiryMs - SESSION_WARNING_THRESHOLD_MS;
@@ -1097,20 +1099,20 @@ var ClientProvider = function ClientProvider(_ref) {
1097
1099
  }
1098
1100
  // Actual expiry timer (safe for long delays)
1099
1101
  setCappedTimeoutInMap(expiryTimeoutsRef.current, sessionKey, expireSession, timeUntilExpiry);
1100
- _context112.n = 5;
1102
+ _context115.n = 5;
1101
1103
  break;
1102
1104
  case 4:
1103
- _context112.p = 4;
1104
- _t35 = _context112.v;
1105
- if (_t35 instanceof TurnkeyError || _t35 instanceof TurnkeyNetworkError) {
1106
- callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError0 = callbacks.onError) === null || _callbacks$onError0 === void 0 ? void 0 : _callbacks$onError0.call(callbacks, _t35);
1105
+ _context115.p = 4;
1106
+ _t38 = _context115.v;
1107
+ if (_t38 instanceof TurnkeyError || _t38 instanceof TurnkeyNetworkError) {
1108
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError0 = callbacks.onError) === null || _callbacks$onError0 === void 0 ? void 0 : _callbacks$onError0.call(callbacks, _t38);
1107
1109
  } else {
1108
- callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError1 = callbacks.onError) === null || _callbacks$onError1 === void 0 ? void 0 : _callbacks$onError1.call(callbacks, new TurnkeyError("Failed to schedule session expiration for ".concat(sessionKey), TurnkeyErrorCodes.SCHEDULE_SESSION_EXPIRY_ERROR, _t35));
1110
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError1 = callbacks.onError) === null || _callbacks$onError1 === void 0 ? void 0 : _callbacks$onError1.call(callbacks, new TurnkeyError("Failed to schedule session expiration for ".concat(sessionKey), TurnkeyErrorCodes.SCHEDULE_SESSION_EXPIRY_ERROR, _t38));
1109
1111
  }
1110
1112
  case 5:
1111
- return _context112.a(2);
1113
+ return _context115.a(2);
1112
1114
  }
1113
- }, _callee112, null, [[1, 4]]);
1115
+ }, _callee115, null, [[1, 4]]);
1114
1116
  }));
1115
1117
  return _scheduleSessionExpiration.apply(this, arguments);
1116
1118
  }
@@ -3072,6 +3074,12 @@ var ClientProvider = function ClientProvider(_ref) {
3072
3074
  allSessions = _context56.v;
3073
3075
  setSession(session);
3074
3076
  setAllSessions(allSessions);
3077
+ _context56.n = 7;
3078
+ return refreshWallets();
3079
+ case 7:
3080
+ _context56.n = 8;
3081
+ return refreshUser();
3082
+ case 8:
3075
3083
  return _context56.a(2);
3076
3084
  }
3077
3085
  }, _callee56);
@@ -6081,26 +6089,269 @@ var ClientProvider = function ClientProvider(_ref) {
6081
6089
  return _ref129.apply(this, arguments);
6082
6090
  };
6083
6091
  }(), [pushPage, masterConfig, client, session, user]);
6092
+ var handleOnRamp = useCallback(/*#__PURE__*/function () {
6093
+ var _ref131 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee104(params) {
6094
+ var _walletAccount$addres;
6095
+ var walletAccount, fiatCurrencyAmount, fiatCurrencyCode, paymentMethod, countrySubdivisionCode, urlForSignature, countryCode, _params$onrampProvide, onrampProvider, _params$sandboxMode, sandboxMode, _params$successPageDu5, successPageDuration, _params$openInNewTab, openInNewTab, s, organizationId, cryptoCurrencyCode, network, openNewTab, _t33;
6096
+ return _regenerator().w(function (_context104) {
6097
+ while (1) switch (_context104.n) {
6098
+ case 0:
6099
+ walletAccount = params.walletAccount, fiatCurrencyAmount = params.fiatCurrencyAmount, fiatCurrencyCode = params.fiatCurrencyCode, paymentMethod = params.paymentMethod, countrySubdivisionCode = params.countrySubdivisionCode, urlForSignature = params.urlForSignature, countryCode = params.countryCode, _params$onrampProvide = params.onrampProvider, onrampProvider = _params$onrampProvide === void 0 ? "FIAT_ON_RAMP_PROVIDER_MOONPAY" : _params$onrampProvide, _params$sandboxMode = params.sandboxMode, sandboxMode = _params$sandboxMode === void 0 ? true : _params$sandboxMode, _params$successPageDu5 = params.successPageDuration, successPageDuration = _params$successPageDu5 === void 0 ? 2000 : _params$successPageDu5, _params$openInNewTab = params.openInNewTab, openInNewTab = _params$openInNewTab === void 0 ? false : _params$openInNewTab;
6100
+ _context104.n = 1;
6101
+ return getSession();
6102
+ case 1:
6103
+ s = _context104.v;
6104
+ organizationId = (params === null || params === void 0 ? void 0 : params.organizationId) || (s === null || s === void 0 ? void 0 : s.organizationId);
6105
+ if (organizationId) {
6106
+ _context104.n = 2;
6107
+ break;
6108
+ }
6109
+ throw new TurnkeyError("A session or passed in organization ID is required.", TurnkeyErrorCodes.INVALID_REQUEST);
6110
+ case 2:
6111
+ _t33 = true;
6112
+ _context104.n = _t33 === (walletAccount.addressFormat === "ADDRESS_FORMAT_ETHEREUM") ? 3 : _t33 === ((_walletAccount$addres = walletAccount.addressFormat) === null || _walletAccount$addres === void 0 ? void 0 : _walletAccount$addres.includes("ADDRESS_FORMAT_BITCOIN")) ? 4 : _t33 === (walletAccount.addressFormat === "ADDRESS_FORMAT_SOLANA") ? 5 : 6;
6113
+ break;
6114
+ case 3:
6115
+ cryptoCurrencyCode = FiatOnRampCryptoCurrency.ETHEREUM;
6116
+ network = FiatOnRampBlockchainNetwork.ETHEREUM;
6117
+ return _context104.a(3, 7);
6118
+ case 4:
6119
+ cryptoCurrencyCode = FiatOnRampCryptoCurrency.BITCOIN;
6120
+ network = FiatOnRampBlockchainNetwork.BITCOIN;
6121
+ return _context104.a(3, 7);
6122
+ case 5:
6123
+ cryptoCurrencyCode = FiatOnRampCryptoCurrency.SOLANA;
6124
+ network = FiatOnRampBlockchainNetwork.SOLANA;
6125
+ return _context104.a(3, 7);
6126
+ case 6:
6127
+ cryptoCurrencyCode = FiatOnRampCryptoCurrency.ETHEREUM;
6128
+ network = FiatOnRampBlockchainNetwork.ETHEREUM;
6129
+ return _context104.a(3, 7);
6130
+ case 7:
6131
+ openNewTab = openInNewTab || isMobile;
6132
+ cryptoCurrencyCode = params.cryptoCurrencyCode || cryptoCurrencyCode;
6133
+ network = params.network || network;
6134
+ return _context104.a(2, new Promise(function (resolve, reject) {
6135
+ var OnRampContainer = function OnRampContainer() {
6136
+ var _useState15 = useState(false),
6137
+ _useState16 = _slicedToArray(_useState15, 2),
6138
+ completed = _useState16[0],
6139
+ setCompleted = _useState16[1];
6140
+ var pollingRef = useRef(null);
6141
+ var cleanup = function cleanup() {
6142
+ if (pollingRef.current) {
6143
+ clearInterval(pollingRef.current);
6144
+ pollingRef.current = null;
6145
+ }
6146
+ };
6147
+ useEffect(function () {
6148
+ return function () {
6149
+ cleanup();
6150
+ };
6151
+ }, []);
6152
+ var action = /*#__PURE__*/function () {
6153
+ var _ref132 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee103() {
6154
+ var _client$httpClient, onRampWindow, result, _popupWidth, _popupHeight, left, top, onRampTransactionId, _t32;
6155
+ return _regenerator().w(function (_context103) {
6156
+ while (1) switch (_context103.p = _context103.n) {
6157
+ case 0:
6158
+ _context103.p = 0;
6159
+ onRampWindow = null;
6160
+ if (!openNewTab) {
6161
+ _context103.n = 1;
6162
+ break;
6163
+ }
6164
+ onRampWindow = window.open("", "_blank");
6165
+ if (onRampWindow) {
6166
+ _context103.n = 1;
6167
+ break;
6168
+ }
6169
+ throw new Error("Failed to open On Ramp tab.");
6170
+ case 1:
6171
+ _context103.n = 2;
6172
+ return client === null || client === void 0 ? void 0 : (_client$httpClient = client.httpClient) === null || _client$httpClient === void 0 ? void 0 : _client$httpClient.initFiatOnRamp(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
6173
+ onrampProvider: onrampProvider,
6174
+ walletAddress: walletAccount.address,
6175
+ network: network,
6176
+ cryptoCurrencyCode: cryptoCurrencyCode,
6177
+ sandboxMode: sandboxMode,
6178
+ organizationId: organizationId
6179
+ }, fiatCurrencyCode ? {
6180
+ fiatCurrencyCode: fiatCurrencyCode
6181
+ } : {}), fiatCurrencyAmount ? {
6182
+ fiatCurrencyAmount: fiatCurrencyAmount
6183
+ } : {}), paymentMethod ? {
6184
+ paymentMethod: paymentMethod
6185
+ } : {}), countryCode ? {
6186
+ countryCode: countryCode
6187
+ } : {}), countrySubdivisionCode ? {
6188
+ countrySubdivisionCode: countrySubdivisionCode
6189
+ } : {}), sandboxMode !== undefined ? {
6190
+ sandboxMode: sandboxMode
6191
+ } : {}), urlForSignature ? {
6192
+ urlForSignature: urlForSignature
6193
+ } : {}));
6194
+ case 2:
6195
+ result = _context103.v;
6196
+ if (result !== null && result !== void 0 && result.onRampUrl) {
6197
+ _context103.n = 3;
6198
+ break;
6199
+ }
6200
+ throw new Error("Missing onRampUrl");
6201
+ case 3:
6202
+ if (!(openNewTab && onRampWindow)) {
6203
+ _context103.n = 4;
6204
+ break;
6205
+ }
6206
+ onRampWindow.location.href = result.onRampUrl.toString();
6207
+ _context103.n = 5;
6208
+ break;
6209
+ case 4:
6210
+ _popupWidth = 500;
6211
+ _popupHeight = 600;
6212
+ left = window.screenX + (window.innerWidth - _popupWidth) / 2;
6213
+ top = window.screenY + (window.innerHeight - _popupHeight) / 2;
6214
+ onRampWindow = window.open(result.onRampUrl.toString(), "_blank", "width=".concat(_popupWidth, ",height=").concat(_popupHeight, ",top=").concat(top, ",left=").concat(left, ",scrollbars=yes,resizable=yes"));
6215
+ if (onRampWindow) {
6216
+ _context103.n = 5;
6217
+ break;
6218
+ }
6219
+ throw new Error("Failed to open On Ramp window.");
6220
+ case 5:
6221
+ onRampTransactionId = result.onRampTransactionId;
6222
+ if (onRampTransactionId) {
6223
+ _context103.n = 6;
6224
+ break;
6225
+ }
6226
+ throw new Error("No onRampTransactionId returned");
6227
+ case 6:
6228
+ return _context103.a(2, new Promise(function (resolveAction, rejectAction) {
6229
+ pollingRef.current = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102() {
6230
+ var _onRampWindow, _client$httpClient2, currentUrl, _onRampWindow2, _onRampWindow3, resp, status, _onRampWindow4, _t31;
6231
+ return _regenerator().w(function (_context102) {
6232
+ while (1) switch (_context102.p = _context102.n) {
6233
+ case 0:
6234
+ _context102.p = 0;
6235
+ if (!(onrampProvider === "FIAT_ON_RAMP_PROVIDER_COINBASE" && (_onRampWindow = onRampWindow) !== null && _onRampWindow !== void 0 && _onRampWindow.closed)) {
6236
+ _context102.n = 1;
6237
+ break;
6238
+ }
6239
+ cleanup();
6240
+ rejectAction(new Error("On-ramp popup closed by user"));
6241
+ return _context102.a(2);
6242
+ case 1:
6243
+ currentUrl = "";
6244
+ try {
6245
+ currentUrl = ((_onRampWindow2 = onRampWindow) === null || _onRampWindow2 === void 0 ? void 0 : _onRampWindow2.location.href) || "";
6246
+ } catch (_unused3) {}
6247
+ if (!(currentUrl && currentUrl.startsWith(window.location.origin))) {
6248
+ _context102.n = 2;
6249
+ break;
6250
+ }
6251
+ cleanup();
6252
+ (_onRampWindow3 = onRampWindow) === null || _onRampWindow3 === void 0 ? void 0 : _onRampWindow3.close();
6253
+ setCompleted(true);
6254
+ resolveAction();
6255
+ return _context102.a(2);
6256
+ case 2:
6257
+ _context102.n = 3;
6258
+ return client === null || client === void 0 ? void 0 : (_client$httpClient2 = client.httpClient) === null || _client$httpClient2 === void 0 ? void 0 : _client$httpClient2.getOnRampTransactionStatus({
6259
+ transactionId: onRampTransactionId,
6260
+ refresh: true
6261
+ });
6262
+ case 3:
6263
+ resp = _context102.v;
6264
+ status = resp === null || resp === void 0 ? void 0 : resp.transactionStatus;
6265
+ if (["COMPLETED", "FAILED", "CANCELLED"].includes(status !== null && status !== void 0 ? status : "")) {
6266
+ cleanup();
6267
+ try {
6268
+ (_onRampWindow4 = onRampWindow) === null || _onRampWindow4 === void 0 ? void 0 : _onRampWindow4.close();
6269
+ } catch (_unused4) {}
6270
+ setCompleted(true);
6271
+ resolveAction();
6272
+ }
6273
+ _context102.n = 5;
6274
+ break;
6275
+ case 4:
6276
+ _context102.p = 4;
6277
+ _t31 = _context102.v;
6278
+ console.warn("Polling error (ignored):", _t31);
6279
+ case 5:
6280
+ return _context102.a(2);
6281
+ }
6282
+ }, _callee102, null, [[0, 4]]);
6283
+ })), 3000);
6284
+ }));
6285
+ case 7:
6286
+ _context103.p = 7;
6287
+ _t32 = _context103.v;
6288
+ cleanup();
6289
+ throw _t32;
6290
+ case 8:
6291
+ return _context103.a(2);
6292
+ }
6293
+ }, _callee103, null, [[0, 7]]);
6294
+ }));
6295
+ return function action() {
6296
+ return _ref132.apply(this, arguments);
6297
+ };
6298
+ }();
6299
+ return jsx(OnRampPage, {
6300
+ icon: onrampProvider === "FIAT_ON_RAMP_PROVIDER_COINBASE" ? jsx(CoinbaseLogo, {
6301
+ className: "w-12 h-12"
6302
+ }) : jsx(MoonPayLogo, {
6303
+ className: "w-12 h-12"
6304
+ }),
6305
+ onrampProvider: onrampProvider,
6306
+ action: action,
6307
+ sandboxMode: sandboxMode,
6308
+ completed: completed,
6309
+ successPageDuration: successPageDuration,
6310
+ onSuccess: function onSuccess() {
6311
+ return resolve();
6312
+ },
6313
+ onError: function onError(err) {
6314
+ return reject(err);
6315
+ }
6316
+ });
6317
+ };
6318
+ pushPage({
6319
+ key: "Fiat On-Ramp",
6320
+ content: jsx(OnRampContainer, {}),
6321
+ showTitle: false,
6322
+ preventBack: true,
6323
+ onClose: function onClose() {
6324
+ return reject(new TurnkeyError("User canceled the on-ramp process.", TurnkeyErrorCodes.USER_CANCELED));
6325
+ }
6326
+ });
6327
+ }));
6328
+ }
6329
+ }, _callee104);
6330
+ }));
6331
+ return function (_x91) {
6332
+ return _ref131.apply(this, arguments);
6333
+ };
6334
+ }(), [pushPage, client]);
6084
6335
  var handleVerifyAppProofs = useCallback(/*#__PURE__*/function () {
6085
- var _ref131 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102(params) {
6086
- var _ref132, appProofs, _ref132$successPageDu, successPageDuration, stampWith, s, organizationId, _t31;
6087
- return _regenerator().w(function (_context102) {
6088
- while (1) switch (_context102.p = _context102.n) {
6336
+ var _ref134 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(params) {
6337
+ var _ref135, appProofs, _ref135$successPageDu, successPageDuration, stampWith, s, organizationId, _t34;
6338
+ return _regenerator().w(function (_context105) {
6339
+ while (1) switch (_context105.p = _context105.n) {
6089
6340
  case 0:
6090
- _ref132 = params || {}, appProofs = _ref132.appProofs, _ref132$successPageDu = _ref132.successPageDuration, successPageDuration = _ref132$successPageDu === void 0 ? 3000 : _ref132$successPageDu, stampWith = _ref132.stampWith;
6091
- _context102.n = 1;
6341
+ _ref135 = params || {}, appProofs = _ref135.appProofs, _ref135$successPageDu = _ref135.successPageDuration, successPageDuration = _ref135$successPageDu === void 0 ? 3000 : _ref135$successPageDu, stampWith = _ref135.stampWith;
6342
+ _context105.n = 1;
6092
6343
  return getSession();
6093
6344
  case 1:
6094
- s = _context102.v;
6345
+ s = _context105.v;
6095
6346
  organizationId = (params === null || params === void 0 ? void 0 : params.organizationId) || (s === null || s === void 0 ? void 0 : s.organizationId);
6096
6347
  if (organizationId) {
6097
- _context102.n = 2;
6348
+ _context105.n = 2;
6098
6349
  break;
6099
6350
  }
6100
6351
  throw new TurnkeyError("A session or passed in organization ID is required.", TurnkeyErrorCodes.INVALID_REQUEST);
6101
6352
  case 2:
6102
- _context102.p = 2;
6103
- return _context102.a(2, new Promise(function (resolve, reject) {
6353
+ _context105.p = 2;
6354
+ return _context105.a(2, new Promise(function (resolve, reject) {
6104
6355
  pushPage({
6105
6356
  key: "Verify app proofs",
6106
6357
  showTurnkeyBranding: false,
@@ -6126,58 +6377,58 @@ var ClientProvider = function ClientProvider(_ref) {
6126
6377
  });
6127
6378
  }));
6128
6379
  case 3:
6129
- _context102.p = 3;
6130
- _t31 = _context102.v;
6131
- if (!(_t31 instanceof TurnkeyError)) {
6132
- _context102.n = 4;
6380
+ _context105.p = 3;
6381
+ _t34 = _context105.v;
6382
+ if (!(_t34 instanceof TurnkeyError)) {
6383
+ _context105.n = 4;
6133
6384
  break;
6134
6385
  }
6135
- throw _t31;
6386
+ throw _t34;
6136
6387
  case 4:
6137
- throw new TurnkeyError("Failed to verify app proofs.", TurnkeyErrorCodes.VERIFY_APP_PROOFS_ERROR, _t31);
6388
+ throw new TurnkeyError("Failed to verify app proofs.", TurnkeyErrorCodes.VERIFY_APP_PROOFS_ERROR, _t34);
6138
6389
  case 5:
6139
- return _context102.a(2);
6390
+ return _context105.a(2);
6140
6391
  }
6141
- }, _callee102, null, [[2, 3]]);
6392
+ }, _callee105, null, [[2, 3]]);
6142
6393
  }));
6143
- return function (_x91) {
6144
- return _ref131.apply(this, arguments);
6394
+ return function (_x92) {
6395
+ return _ref134.apply(this, arguments);
6145
6396
  };
6146
6397
  }(), [pushPage, client]);
6147
6398
  useEffect(function () {
6148
6399
  if (proxyAuthConfigRef.current) return;
6149
6400
  // Only fetch the proxy auth config once. Use that to build the master config.
6150
6401
  var fetchProxyAuthConfig = /*#__PURE__*/function () {
6151
- var _ref133 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee103() {
6402
+ var _ref136 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee106() {
6152
6403
  var proxyAuthConfig;
6153
- return _regenerator().w(function (_context103) {
6154
- while (1) switch (_context103.p = _context103.n) {
6404
+ return _regenerator().w(function (_context106) {
6405
+ while (1) switch (_context106.p = _context106.n) {
6155
6406
  case 0:
6156
- _context103.p = 0;
6407
+ _context106.p = 0;
6157
6408
  if (!config.authProxyConfigId) {
6158
- _context103.n = 2;
6409
+ _context106.n = 2;
6159
6410
  break;
6160
6411
  }
6161
- _context103.n = 1;
6412
+ _context106.n = 1;
6162
6413
  return getAuthProxyConfig(config.authProxyConfigId, config.authProxyUrl);
6163
6414
  case 1:
6164
- proxyAuthConfig = _context103.v;
6415
+ proxyAuthConfig = _context106.v;
6165
6416
  proxyAuthConfigRef.current = proxyAuthConfig;
6166
6417
  case 2:
6167
6418
  setMasterConfig(buildConfig(proxyAuthConfig));
6168
- _context103.n = 4;
6419
+ _context106.n = 4;
6169
6420
  break;
6170
6421
  case 3:
6171
- _context103.p = 3;
6172
- _context103.v;
6422
+ _context106.p = 3;
6423
+ _context106.v;
6173
6424
  setClientState(ClientState.Error);
6174
6425
  case 4:
6175
- return _context103.a(2);
6426
+ return _context106.a(2);
6176
6427
  }
6177
- }, _callee103, null, [[0, 3]]);
6428
+ }, _callee106, null, [[0, 3]]);
6178
6429
  }));
6179
6430
  return function fetchProxyAuthConfig() {
6180
- return _ref133.apply(this, arguments);
6431
+ return _ref136.apply(this, arguments);
6181
6432
  };
6182
6433
  }();
6183
6434
  fetchProxyAuthConfig();
@@ -6209,29 +6460,29 @@ var ClientProvider = function ClientProvider(_ref) {
6209
6460
  useEffect(function () {
6210
6461
  if (!client) return;
6211
6462
  var handleUpdateState = /*#__PURE__*/function () {
6212
- var _ref134 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee104() {
6213
- return _regenerator().w(function (_context104) {
6214
- while (1) switch (_context104.n) {
6463
+ var _ref137 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107() {
6464
+ return _regenerator().w(function (_context107) {
6465
+ while (1) switch (_context107.n) {
6215
6466
  case 0:
6216
6467
  if (!session) {
6217
- _context104.n = 2;
6468
+ _context107.n = 2;
6218
6469
  break;
6219
6470
  }
6220
- _context104.n = 1;
6471
+ _context107.n = 1;
6221
6472
  return debouncedRefreshWallets();
6222
6473
  case 1:
6223
- _context104.n = 3;
6474
+ _context107.n = 3;
6224
6475
  break;
6225
6476
  case 2:
6226
- _context104.n = 3;
6477
+ _context107.n = 3;
6227
6478
  return debouncedFetchWalletProviders();
6228
6479
  case 3:
6229
- return _context104.a(2);
6480
+ return _context107.a(2);
6230
6481
  }
6231
- }, _callee104);
6482
+ }, _callee107);
6232
6483
  }));
6233
6484
  return function handleUpdateState() {
6234
- return _ref134.apply(this, arguments);
6485
+ return _ref137.apply(this, arguments);
6235
6486
  };
6236
6487
  }();
6237
6488
  var cleanup = function cleanup() {};
@@ -6370,7 +6621,8 @@ var ClientProvider = function ClientProvider(_ref) {
6370
6621
  handleConnectExternalWallet: handleConnectExternalWallet,
6371
6622
  handleRemoveUserEmail: handleRemoveUserEmail,
6372
6623
  handleRemoveUserPhoneNumber: handleRemoveUserPhoneNumber,
6373
- handleVerifyAppProofs: handleVerifyAppProofs
6624
+ handleVerifyAppProofs: handleVerifyAppProofs,
6625
+ handleOnRamp: handleOnRamp
6374
6626
  },
6375
6627
  children: children
6376
6628
  });