@0xkey-io/react-wallet-kit 0.1.1 → 0.2.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.
- package/dist/components/onramp/OnRamp.d.ts +4 -2
- package/dist/components/onramp/OnRamp.d.ts.map +1 -1
- package/dist/components/onramp/OnRamp.js +6 -2
- package/dist/components/onramp/OnRamp.js.map +1 -1
- package/dist/components/onramp/OnRamp.mjs +7 -2
- package/dist/components/onramp/OnRamp.mjs.map +1 -1
- package/dist/providers/client/Provider.d.ts.map +1 -1
- package/dist/providers/client/Provider.js +83 -85
- package/dist/providers/client/Provider.js.map +1 -1
- package/dist/providers/client/Provider.mjs +210 -229
- package/dist/providers/client/Provider.mjs.map +1 -1
- package/dist/providers/client/Types.d.ts +4 -4
- package/dist/providers/client/Types.d.ts.map +1 -1
- package/dist/providers/client/Types.js.map +1 -1
- package/dist/providers/client/Types.mjs.map +1 -1
- package/dist/types/method-types.d.ts +16 -2
- package/dist/types/method-types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -11,9 +11,9 @@ import { generateChallengePair, exchangeFacebookCodeForToken } from '../../utils
|
|
|
11
11
|
import { capitalizeProviderName, getProviderIcon } from '../../utils/oauth/helpers.mjs';
|
|
12
12
|
import { useWalletProviderState, useDebouncedCallback, isValidSession, withZeroXKeyErrorHandling, SESSION_WARNING_THRESHOLD_MS, mergeWalletsWithoutDuplicates } from '../../utils/utils.mjs';
|
|
13
13
|
import { setCappedTimeoutInMap, clearKey, setTimeoutInMap, clearKeys, clearAll } from '../../utils/timers.mjs';
|
|
14
|
-
import { DEFAULT_SESSION_EXPIRATION_IN_SECONDS, OtpType, ZeroXKeyClient, Chain, WalletInterfaceType, getAuthProxyConfig, WalletSource } from '@0xkey-io/core';
|
|
14
|
+
import { DEFAULT_SESSION_EXPIRATION_IN_SECONDS, OtpType, OnRampError, OnRampErrorCode, inferOnRampAssetFromWalletAccount, assertOnRampProviderSupported, pollOnRampTransactionStatus, initOnRampFlow, ZeroXKeyClient, Chain, WalletInterfaceType, getAuthProxyConfig, WalletSource } from '@0xkey-io/core';
|
|
15
15
|
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
16
|
-
import { ZeroXKeyError, ZeroXKeyErrorCodes, ZeroXKeyNetworkError, AuthAction, OAuthProviders
|
|
16
|
+
import { ZeroXKeyError, ZeroXKeyErrorCodes, ZeroXKeyNetworkError, AuthAction, OAuthProviders } from '@0xkey-io/sdk-types';
|
|
17
17
|
import { useModal } from '../modal/Hook.mjs';
|
|
18
18
|
import { AuthState, ClientState, AuthMethod, ExportType, ImportType } from '../../types/base.mjs';
|
|
19
19
|
import { AuthComponent } from '../../components/auth/index.mjs';
|
|
@@ -865,11 +865,11 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
865
865
|
* @throws {ZeroXKeyError} If an error occurs while clearing the timers.
|
|
866
866
|
*/
|
|
867
867
|
function _initializeWalletProviderListeners() {
|
|
868
|
-
_initializeWalletProviderListeners = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
868
|
+
_initializeWalletProviderListeners = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee138(walletProviders, onUpdateState) {
|
|
869
869
|
var _masterConfig$walletC0, _masterConfig$walletC1, _masterConfig$walletC10, _masterConfig$walletC11;
|
|
870
870
|
var cleanups, nativeOnly, ethProviders, solProviders, wcProviders, wcProvider, attachEthereumListeners, attachSolanaListeners, _wcProvider$provider, _wcProvider$provider$, standardEvents, unsubscribe;
|
|
871
|
-
return _regenerator().w(function (
|
|
872
|
-
while (1) switch (
|
|
871
|
+
return _regenerator().w(function (_context138) {
|
|
872
|
+
while (1) switch (_context138.n) {
|
|
873
873
|
case 0:
|
|
874
874
|
attachSolanaListeners = function _attachSolanaListener(provider, onUpdateState) {
|
|
875
875
|
var _provider$features;
|
|
@@ -877,19 +877,19 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
877
877
|
var walletEvents = provider === null || provider === void 0 ? void 0 : (_provider$features = provider.features) === null || _provider$features === void 0 ? void 0 : _provider$features["standard:events"];
|
|
878
878
|
if (walletEvents !== null && walletEvents !== void 0 && walletEvents.on) {
|
|
879
879
|
var offChange = walletEvents.on("change", /*#__PURE__*/function () {
|
|
880
|
-
var
|
|
881
|
-
return _regenerator().w(function (
|
|
882
|
-
while (1) switch (
|
|
880
|
+
var _ref159 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee136(_evt) {
|
|
881
|
+
return _regenerator().w(function (_context136) {
|
|
882
|
+
while (1) switch (_context136.n) {
|
|
883
883
|
case 0:
|
|
884
|
-
|
|
884
|
+
_context136.n = 1;
|
|
885
885
|
return onUpdateState();
|
|
886
886
|
case 1:
|
|
887
|
-
return
|
|
887
|
+
return _context136.a(2);
|
|
888
888
|
}
|
|
889
|
-
},
|
|
889
|
+
}, _callee136);
|
|
890
890
|
}));
|
|
891
891
|
return function (_x114) {
|
|
892
|
-
return
|
|
892
|
+
return _ref159.apply(this, arguments);
|
|
893
893
|
};
|
|
894
894
|
}());
|
|
895
895
|
cleanups.push(offChange);
|
|
@@ -903,31 +903,31 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
903
903
|
attachEthereumListeners = function _attachEthereumListen(provider, onUpdateState) {
|
|
904
904
|
if (typeof provider.on !== "function") return;
|
|
905
905
|
var handleChainChanged = /*#__PURE__*/function () {
|
|
906
|
-
var
|
|
907
|
-
return _regenerator().w(function (
|
|
908
|
-
while (1) switch (
|
|
906
|
+
var _ref157 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(_chainId) {
|
|
907
|
+
return _regenerator().w(function (_context134) {
|
|
908
|
+
while (1) switch (_context134.n) {
|
|
909
909
|
case 0:
|
|
910
|
-
return
|
|
910
|
+
return _context134.a(2, onUpdateState());
|
|
911
911
|
}
|
|
912
|
-
},
|
|
912
|
+
}, _callee134);
|
|
913
913
|
}));
|
|
914
914
|
return function handleChainChanged(_x112) {
|
|
915
|
-
return
|
|
915
|
+
return _ref157.apply(this, arguments);
|
|
916
916
|
};
|
|
917
917
|
}();
|
|
918
918
|
var handleAccountsChanged = /*#__PURE__*/function () {
|
|
919
|
-
var
|
|
920
|
-
return _regenerator().w(function (
|
|
921
|
-
while (1) switch (
|
|
919
|
+
var _ref158 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee135(accounts) {
|
|
920
|
+
return _regenerator().w(function (_context135) {
|
|
921
|
+
while (1) switch (_context135.n) {
|
|
922
922
|
case 0:
|
|
923
923
|
if (accounts.length === 0) onUpdateState();
|
|
924
924
|
case 1:
|
|
925
|
-
return
|
|
925
|
+
return _context135.a(2);
|
|
926
926
|
}
|
|
927
|
-
},
|
|
927
|
+
}, _callee135);
|
|
928
928
|
}));
|
|
929
929
|
return function handleAccountsChanged(_x113) {
|
|
930
|
-
return
|
|
930
|
+
return _ref158.apply(this, arguments);
|
|
931
931
|
};
|
|
932
932
|
}();
|
|
933
933
|
var handleDisconnect = function handleDisconnect() {
|
|
@@ -943,10 +943,10 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
943
943
|
};
|
|
944
944
|
};
|
|
945
945
|
if (!(walletProviders.length === 0)) {
|
|
946
|
-
|
|
946
|
+
_context138.n = 1;
|
|
947
947
|
break;
|
|
948
948
|
}
|
|
949
|
-
return
|
|
949
|
+
return _context138.a(2, function () {});
|
|
950
950
|
case 1:
|
|
951
951
|
cleanups = []; // we only want to initialize these listeners for connected walletProviders
|
|
952
952
|
nativeOnly = function nativeOnly(provider) {
|
|
@@ -984,82 +984,82 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
984
984
|
if (standardEvents !== null && standardEvents !== void 0 && standardEvents.on) {
|
|
985
985
|
if (standardEvents !== null && standardEvents !== void 0 && standardEvents.on) {
|
|
986
986
|
unsubscribe = standardEvents.on("change", /*#__PURE__*/function () {
|
|
987
|
-
var
|
|
987
|
+
var _ref160 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(evt) {
|
|
988
988
|
var _callbacks$onError10, providers, currentSession, _wcProviders, wcWallets;
|
|
989
|
-
return _regenerator().w(function (
|
|
990
|
-
while (1) switch (
|
|
989
|
+
return _regenerator().w(function (_context137) {
|
|
990
|
+
while (1) switch (_context137.n) {
|
|
991
991
|
case 0:
|
|
992
992
|
if (!((evt === null || evt === void 0 ? void 0 : evt.type) === "pairingExpired")) {
|
|
993
|
-
|
|
993
|
+
_context137.n = 1;
|
|
994
994
|
break;
|
|
995
995
|
}
|
|
996
996
|
debouncedFetchWalletProviders();
|
|
997
|
-
return
|
|
997
|
+
return _context137.a(2);
|
|
998
998
|
case 1:
|
|
999
999
|
if (!((evt === null || evt === void 0 ? void 0 : evt.type) === "failed")) {
|
|
1000
|
-
|
|
1000
|
+
_context137.n = 2;
|
|
1001
1001
|
break;
|
|
1002
1002
|
}
|
|
1003
1003
|
debouncedFetchWalletProviders();
|
|
1004
1004
|
callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError10 = callbacks.onError) === null || _callbacks$onError10 === void 0 ? void 0 : _callbacks$onError10.call(callbacks, new ZeroXKeyError("WalletConnect initialization failed: ".concat(evt.error || "Unknown error"), ZeroXKeyErrorCodes.WALLET_CONNECT_INITIALIZATION_ERROR, evt.error));
|
|
1005
|
-
return
|
|
1005
|
+
return _context137.a(2);
|
|
1006
1006
|
case 2:
|
|
1007
1007
|
if (!((evt === null || evt === void 0 ? void 0 : evt.type) === "initialized")) {
|
|
1008
|
-
|
|
1008
|
+
_context137.n = 7;
|
|
1009
1009
|
break;
|
|
1010
1010
|
}
|
|
1011
|
-
|
|
1011
|
+
_context137.n = 3;
|
|
1012
1012
|
return debouncedFetchWalletProviders();
|
|
1013
1013
|
case 3:
|
|
1014
|
-
providers =
|
|
1015
|
-
|
|
1014
|
+
providers = _context137.v;
|
|
1015
|
+
_context137.n = 4;
|
|
1016
1016
|
return getSession();
|
|
1017
1017
|
case 4:
|
|
1018
|
-
currentSession =
|
|
1018
|
+
currentSession = _context137.v;
|
|
1019
1019
|
if (!currentSession) {
|
|
1020
|
-
|
|
1020
|
+
_context137.n = 6;
|
|
1021
1021
|
break;
|
|
1022
1022
|
}
|
|
1023
1023
|
_wcProviders = providers === null || providers === void 0 ? void 0 : providers.filter(function (p) {
|
|
1024
1024
|
return p.interfaceType === WalletInterfaceType.WalletConnect;
|
|
1025
1025
|
});
|
|
1026
|
-
|
|
1026
|
+
_context137.n = 5;
|
|
1027
1027
|
return fetchWallets({
|
|
1028
1028
|
walletProviders: _wcProviders,
|
|
1029
1029
|
connectedOnly: true
|
|
1030
1030
|
});
|
|
1031
1031
|
case 5:
|
|
1032
|
-
wcWallets =
|
|
1032
|
+
wcWallets = _context137.v;
|
|
1033
1033
|
if (wcWallets.length > 0) {
|
|
1034
1034
|
setWallets(function (prev) {
|
|
1035
1035
|
return mergeWalletsWithoutDuplicates(prev, wcWallets);
|
|
1036
1036
|
});
|
|
1037
1037
|
}
|
|
1038
1038
|
case 6:
|
|
1039
|
-
return
|
|
1039
|
+
return _context137.a(2);
|
|
1040
1040
|
case 7:
|
|
1041
|
-
|
|
1041
|
+
_context137.n = 8;
|
|
1042
1042
|
return onUpdateState();
|
|
1043
1043
|
case 8:
|
|
1044
|
-
return
|
|
1044
|
+
return _context137.a(2);
|
|
1045
1045
|
}
|
|
1046
|
-
},
|
|
1046
|
+
}, _callee137);
|
|
1047
1047
|
}));
|
|
1048
1048
|
return function (_x115) {
|
|
1049
|
-
return
|
|
1049
|
+
return _ref160.apply(this, arguments);
|
|
1050
1050
|
};
|
|
1051
1051
|
}());
|
|
1052
1052
|
cleanups.push(unsubscribe);
|
|
1053
1053
|
}
|
|
1054
1054
|
}
|
|
1055
1055
|
}
|
|
1056
|
-
return
|
|
1056
|
+
return _context138.a(2, function () {
|
|
1057
1057
|
cleanups.forEach(function (remove) {
|
|
1058
1058
|
return remove();
|
|
1059
1059
|
});
|
|
1060
1060
|
});
|
|
1061
1061
|
}
|
|
1062
|
-
},
|
|
1062
|
+
}, _callee138);
|
|
1063
1063
|
}));
|
|
1064
1064
|
return _initializeWalletProviderListeners.apply(this, arguments);
|
|
1065
1065
|
}
|
|
@@ -6340,59 +6340,63 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
6340
6340
|
};
|
|
6341
6341
|
}(), [ethSendErc20Transfer, getSession, pollTransactionStatus, pushPage]);
|
|
6342
6342
|
var handleOnRamp = useCallback(/*#__PURE__*/function () {
|
|
6343
|
-
var _ref151 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
6344
|
-
var
|
|
6345
|
-
var walletAccount, fiatCurrencyAmount, fiatCurrencyCode, paymentMethod, countrySubdivisionCode, urlForSignature, countryCode, _params$onrampProvide, onrampProvider, _params$
|
|
6346
|
-
return _regenerator().w(function (
|
|
6347
|
-
while (1) switch (
|
|
6343
|
+
var _ref151 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee130(params) {
|
|
6344
|
+
var _params$cryptoCurrenc, _params$network;
|
|
6345
|
+
var walletAccount, fiatCurrencyAmount, fiatCurrencyCode, paymentMethod, countrySubdivisionCode, urlForSignature, countryCode, _params$onrampProvide, onrampProvider, _params$successPageDu7, successPageDuration, _params$openInNewTab, openInNewTab, openMode, polling, onStatusChange, s, organizationId, inferredAsset, cryptoCurrencyCode, network, resolvedOpenMode;
|
|
6346
|
+
return _regenerator().w(function (_context130) {
|
|
6347
|
+
while (1) switch (_context130.n) {
|
|
6348
6348
|
case 0:
|
|
6349
|
-
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$
|
|
6350
|
-
|
|
6351
|
-
|
|
6349
|
+
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$successPageDu7 = params.successPageDuration, successPageDuration = _params$successPageDu7 === void 0 ? 2000 : _params$successPageDu7, _params$openInNewTab = params.openInNewTab, openInNewTab = _params$openInNewTab === void 0 ? false : _params$openInNewTab, openMode = params.openMode, polling = params.polling, onStatusChange = params.onStatusChange;
|
|
6350
|
+
if (!(params.sandboxMode === undefined)) {
|
|
6351
|
+
_context130.n = 1;
|
|
6352
|
+
break;
|
|
6353
|
+
}
|
|
6354
|
+
throw new OnRampError(OnRampErrorCode.SANDBOX_MODE_REQUIRED, "sandboxMode must be explicitly set for on-ramp flows.");
|
|
6352
6355
|
case 1:
|
|
6353
|
-
|
|
6356
|
+
// Fail fast (before opening any modal/window) when the provider has no
|
|
6357
|
+
// supported runtime, so callers get a typed error instead of a popup.
|
|
6358
|
+
assertOnRampProviderSupported(onrampProvider);
|
|
6359
|
+
if (client !== null && client !== void 0 && client.httpClient) {
|
|
6360
|
+
_context130.n = 2;
|
|
6361
|
+
break;
|
|
6362
|
+
}
|
|
6363
|
+
throw new ZeroXKeyError("Client is not initialized.", ZeroXKeyErrorCodes.CLIENT_NOT_INITIALIZED);
|
|
6364
|
+
case 2:
|
|
6365
|
+
_context130.n = 3;
|
|
6366
|
+
return getSession();
|
|
6367
|
+
case 3:
|
|
6368
|
+
s = _context130.v;
|
|
6354
6369
|
organizationId = (params === null || params === void 0 ? void 0 : params.organizationId) || (s === null || s === void 0 ? void 0 : s.organizationId);
|
|
6355
6370
|
if (organizationId) {
|
|
6356
|
-
|
|
6371
|
+
_context130.n = 4;
|
|
6357
6372
|
break;
|
|
6358
6373
|
}
|
|
6359
6374
|
throw new ZeroXKeyError("A session or passed in organization ID is required.", ZeroXKeyErrorCodes.INVALID_REQUEST);
|
|
6360
|
-
case 2:
|
|
6361
|
-
_t30 = true;
|
|
6362
|
-
_context131.n = _t30 === (walletAccount.addressFormat === "ADDRESS_FORMAT_ETHEREUM") ? 3 : _t30 === ((_walletAccount$addres = walletAccount.addressFormat) === null || _walletAccount$addres === void 0 ? void 0 : _walletAccount$addres.includes("ADDRESS_FORMAT_BITCOIN")) ? 4 : _t30 === (walletAccount.addressFormat === "ADDRESS_FORMAT_SOLANA") ? 5 : 6;
|
|
6363
|
-
break;
|
|
6364
|
-
case 3:
|
|
6365
|
-
cryptoCurrencyCode = FiatOnRampCryptoCurrency.ETHEREUM;
|
|
6366
|
-
network = FiatOnRampBlockchainNetwork.ETHEREUM;
|
|
6367
|
-
return _context131.a(3, 7);
|
|
6368
6375
|
case 4:
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6376
|
+
inferredAsset = params.network && params.cryptoCurrencyCode ? undefined : inferOnRampAssetFromWalletAccount(walletAccount);
|
|
6377
|
+
cryptoCurrencyCode = (_params$cryptoCurrenc = params.cryptoCurrencyCode) !== null && _params$cryptoCurrenc !== void 0 ? _params$cryptoCurrenc : inferredAsset === null || inferredAsset === void 0 ? void 0 : inferredAsset.cryptoCurrencyCode;
|
|
6378
|
+
network = (_params$network = params.network) !== null && _params$network !== void 0 ? _params$network : inferredAsset === null || inferredAsset === void 0 ? void 0 : inferredAsset.network;
|
|
6379
|
+
if (!(!cryptoCurrencyCode || !network)) {
|
|
6380
|
+
_context130.n = 5;
|
|
6381
|
+
break;
|
|
6382
|
+
}
|
|
6383
|
+
throw new OnRampError(OnRampErrorCode.ASSET_REQUIRED, "network and cryptoCurrencyCode are required for on-ramp flows.");
|
|
6372
6384
|
case 5:
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
return _context131.a(3, 7);
|
|
6376
|
-
case 6:
|
|
6377
|
-
cryptoCurrencyCode = FiatOnRampCryptoCurrency.ETHEREUM;
|
|
6378
|
-
network = FiatOnRampBlockchainNetwork.ETHEREUM;
|
|
6379
|
-
return _context131.a(3, 7);
|
|
6380
|
-
case 7:
|
|
6381
|
-
openNewTab = openInNewTab || isMobile;
|
|
6382
|
-
cryptoCurrencyCode = params.cryptoCurrencyCode || cryptoCurrencyCode;
|
|
6383
|
-
network = params.network || network;
|
|
6384
|
-
return _context131.a(2, new Promise(function (resolve, reject) {
|
|
6385
|
+
resolvedOpenMode = openMode !== null && openMode !== void 0 ? openMode : openInNewTab || isMobile ? "newTab" : "popup";
|
|
6386
|
+
return _context130.a(2, new Promise(function (resolve, reject) {
|
|
6385
6387
|
var OnRampContainer = function OnRampContainer() {
|
|
6386
6388
|
var _useState15 = useState(false),
|
|
6387
6389
|
_useState16 = _slicedToArray(_useState15, 2),
|
|
6388
6390
|
completed = _useState16[0],
|
|
6389
6391
|
setCompleted = _useState16[1];
|
|
6390
|
-
var
|
|
6392
|
+
var _useState17 = useState(),
|
|
6393
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
6394
|
+
result = _useState18[0],
|
|
6395
|
+
setResult = _useState18[1];
|
|
6396
|
+
var abortRef = useRef(null);
|
|
6391
6397
|
var cleanup = function cleanup() {
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
pollingRef.current = null;
|
|
6395
|
-
}
|
|
6398
|
+
var _abortRef$current;
|
|
6399
|
+
return (_abortRef$current = abortRef.current) === null || _abortRef$current === void 0 ? void 0 : _abortRef$current.abort();
|
|
6396
6400
|
};
|
|
6397
6401
|
useEffect(function () {
|
|
6398
6402
|
return function () {
|
|
@@ -6400,33 +6404,36 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
6400
6404
|
};
|
|
6401
6405
|
}, []);
|
|
6402
6406
|
var action = /*#__PURE__*/function () {
|
|
6403
|
-
var _ref152 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
6404
|
-
var
|
|
6405
|
-
return _regenerator().w(function (
|
|
6406
|
-
while (1) switch (
|
|
6407
|
+
var _ref152 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee129() {
|
|
6408
|
+
var _initResult$signedUrl, _polling$refresh, onRampWindow, initResult, providerUrl, popupWidth, popupHeight, left, top, status, _onRampWindow, _t28;
|
|
6409
|
+
return _regenerator().w(function (_context129) {
|
|
6410
|
+
while (1) switch (_context129.p = _context129.n) {
|
|
6407
6411
|
case 0:
|
|
6408
|
-
|
|
6412
|
+
_context129.p = 0;
|
|
6409
6413
|
onRampWindow = null;
|
|
6410
|
-
if (!
|
|
6411
|
-
|
|
6414
|
+
if (!(resolvedOpenMode === "newTab")) {
|
|
6415
|
+
_context129.n = 1;
|
|
6412
6416
|
break;
|
|
6413
6417
|
}
|
|
6414
6418
|
onRampWindow = window.open("", "_blank");
|
|
6415
6419
|
if (onRampWindow) {
|
|
6416
|
-
|
|
6420
|
+
_context129.n = 1;
|
|
6417
6421
|
break;
|
|
6418
6422
|
}
|
|
6419
|
-
throw new
|
|
6423
|
+
throw new OnRampError(OnRampErrorCode.POPUP_BLOCKED, "Failed to open On Ramp tab.");
|
|
6420
6424
|
case 1:
|
|
6421
|
-
|
|
6422
|
-
return
|
|
6425
|
+
_context129.n = 2;
|
|
6426
|
+
return initOnRampFlow(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
6427
|
+
runtimeClient: client.httpClient,
|
|
6423
6428
|
onrampProvider: onrampProvider,
|
|
6424
6429
|
walletAddress: walletAccount.address,
|
|
6425
6430
|
network: network,
|
|
6426
6431
|
cryptoCurrencyCode: cryptoCurrencyCode,
|
|
6427
|
-
|
|
6428
|
-
|
|
6429
|
-
},
|
|
6432
|
+
organizationId: organizationId,
|
|
6433
|
+
sandboxMode: params.sandboxMode
|
|
6434
|
+
}, params.stampWith ? {
|
|
6435
|
+
stampWith: params.stampWith
|
|
6436
|
+
} : {}), fiatCurrencyCode ? {
|
|
6430
6437
|
fiatCurrencyCode: fiatCurrencyCode
|
|
6431
6438
|
} : {}), fiatCurrencyAmount ? {
|
|
6432
6439
|
fiatCurrencyAmount: fiatCurrencyAmount
|
|
@@ -6436,111 +6443,84 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
6436
6443
|
countryCode: countryCode
|
|
6437
6444
|
} : {}), countrySubdivisionCode ? {
|
|
6438
6445
|
countrySubdivisionCode: countrySubdivisionCode
|
|
6439
|
-
} : {}), sandboxMode !== undefined ? {
|
|
6440
|
-
sandboxMode: sandboxMode
|
|
6441
6446
|
} : {}), urlForSignature ? {
|
|
6442
6447
|
urlForSignature: urlForSignature
|
|
6443
6448
|
} : {}));
|
|
6444
6449
|
case 2:
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
6450
|
+
initResult = _context129.v;
|
|
6451
|
+
onStatusChange === null || onStatusChange === void 0 ? void 0 : onStatusChange(initResult);
|
|
6452
|
+
if (!(resolvedOpenMode === "returnUrl")) {
|
|
6453
|
+
_context129.n = 3;
|
|
6448
6454
|
break;
|
|
6449
6455
|
}
|
|
6450
|
-
|
|
6456
|
+
setResult(initResult);
|
|
6457
|
+
setCompleted(true);
|
|
6458
|
+
return _context129.a(2);
|
|
6451
6459
|
case 3:
|
|
6452
|
-
|
|
6453
|
-
|
|
6460
|
+
providerUrl = (_initResult$signedUrl = initResult.signedUrl) !== null && _initResult$signedUrl !== void 0 ? _initResult$signedUrl : initResult.onRampUrl;
|
|
6461
|
+
if (!(resolvedOpenMode === "newTab" && onRampWindow)) {
|
|
6462
|
+
_context129.n = 4;
|
|
6454
6463
|
break;
|
|
6455
6464
|
}
|
|
6456
|
-
onRampWindow.location.href =
|
|
6457
|
-
|
|
6465
|
+
onRampWindow.location.href = providerUrl;
|
|
6466
|
+
_context129.n = 5;
|
|
6458
6467
|
break;
|
|
6459
6468
|
case 4:
|
|
6460
6469
|
popupWidth = 500;
|
|
6461
6470
|
popupHeight = 600;
|
|
6462
6471
|
left = window.screenX + (window.innerWidth - popupWidth) / 2;
|
|
6463
6472
|
top = window.screenY + (window.innerHeight - popupHeight) / 2;
|
|
6464
|
-
onRampWindow = window.open(
|
|
6473
|
+
onRampWindow = window.open(providerUrl, "_blank", "width=".concat(popupWidth, ",height=").concat(popupHeight, ",top=").concat(top, ",left=").concat(left, ",scrollbars=yes,resizable=yes"));
|
|
6465
6474
|
if (onRampWindow) {
|
|
6466
|
-
|
|
6475
|
+
_context129.n = 5;
|
|
6467
6476
|
break;
|
|
6468
6477
|
}
|
|
6469
|
-
throw new
|
|
6478
|
+
throw new OnRampError(OnRampErrorCode.POPUP_BLOCKED, "Failed to open On Ramp window.");
|
|
6470
6479
|
case 5:
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6480
|
+
abortRef.current = new AbortController();
|
|
6481
|
+
_context129.n = 6;
|
|
6482
|
+
return pollOnRampTransactionStatus(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
6483
|
+
runtimeClient: client.httpClient,
|
|
6484
|
+
organizationId: organizationId,
|
|
6485
|
+
transactionId: initResult.onRampTransactionId,
|
|
6486
|
+
refresh: (_polling$refresh = polling === null || polling === void 0 ? void 0 : polling.refresh) !== null && _polling$refresh !== void 0 ? _polling$refresh : true,
|
|
6487
|
+
signal: abortRef.current.signal,
|
|
6488
|
+
onStatusUpdate: function onStatusUpdate(polledStatus) {
|
|
6489
|
+
onStatusChange === null || onStatusChange === void 0 ? void 0 : onStatusChange(_objectSpread2(_objectSpread2({}, initResult), {}, {
|
|
6490
|
+
status: polledStatus
|
|
6491
|
+
}));
|
|
6492
|
+
}
|
|
6493
|
+
}, params.stampWith ? {
|
|
6494
|
+
stampWith: params.stampWith
|
|
6495
|
+
} : {}), polling !== null && polling !== void 0 && polling.intervalMs ? {
|
|
6496
|
+
intervalMs: polling.intervalMs
|
|
6497
|
+
} : {}), polling !== null && polling !== void 0 && polling.timeoutMs ? {
|
|
6498
|
+
timeoutMs: polling.timeoutMs
|
|
6499
|
+
} : {}), polling !== null && polling !== void 0 && polling.maxConsecutiveErrors ? {
|
|
6500
|
+
maxConsecutiveErrors: polling.maxConsecutiveErrors
|
|
6501
|
+
} : {}));
|
|
6477
6502
|
case 6:
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
_context129.n = 1;
|
|
6487
|
-
break;
|
|
6488
|
-
}
|
|
6489
|
-
cleanup();
|
|
6490
|
-
rejectAction(new Error("On-ramp popup closed by user"));
|
|
6491
|
-
return _context129.a(2);
|
|
6492
|
-
case 1:
|
|
6493
|
-
currentUrl = "";
|
|
6494
|
-
try {
|
|
6495
|
-
currentUrl = ((_onRampWindow2 = onRampWindow) === null || _onRampWindow2 === void 0 ? void 0 : _onRampWindow2.location.href) || "";
|
|
6496
|
-
} catch (_unused6) {}
|
|
6497
|
-
if (!(currentUrl && currentUrl.startsWith(window.location.origin))) {
|
|
6498
|
-
_context129.n = 2;
|
|
6499
|
-
break;
|
|
6500
|
-
}
|
|
6501
|
-
cleanup();
|
|
6502
|
-
(_onRampWindow3 = onRampWindow) === null || _onRampWindow3 === void 0 ? void 0 : _onRampWindow3.close();
|
|
6503
|
-
setCompleted(true);
|
|
6504
|
-
resolveAction();
|
|
6505
|
-
return _context129.a(2);
|
|
6506
|
-
case 2:
|
|
6507
|
-
_context129.n = 3;
|
|
6508
|
-
return client === null || client === void 0 ? void 0 : (_client$httpClient2 = client.httpClient) === null || _client$httpClient2 === void 0 ? void 0 : _client$httpClient2.getOnRampTransactionStatus({
|
|
6509
|
-
transactionId: onRampTransactionId,
|
|
6510
|
-
refresh: true
|
|
6511
|
-
});
|
|
6512
|
-
case 3:
|
|
6513
|
-
resp = _context129.v;
|
|
6514
|
-
status = resp === null || resp === void 0 ? void 0 : resp.transactionStatus;
|
|
6515
|
-
if (["COMPLETED", "FAILED", "CANCELLED"].includes(status !== null && status !== void 0 ? status : "")) {
|
|
6516
|
-
cleanup();
|
|
6517
|
-
try {
|
|
6518
|
-
(_onRampWindow4 = onRampWindow) === null || _onRampWindow4 === void 0 ? void 0 : _onRampWindow4.close();
|
|
6519
|
-
} catch (_unused7) {}
|
|
6520
|
-
setCompleted(true);
|
|
6521
|
-
resolveAction();
|
|
6522
|
-
}
|
|
6523
|
-
_context129.n = 5;
|
|
6524
|
-
break;
|
|
6525
|
-
case 4:
|
|
6526
|
-
_context129.p = 4;
|
|
6527
|
-
_t28 = _context129.v;
|
|
6528
|
-
console.warn("Polling error (ignored):", _t28);
|
|
6529
|
-
case 5:
|
|
6530
|
-
return _context129.a(2);
|
|
6531
|
-
}
|
|
6532
|
-
}, _callee129, null, [[0, 4]]);
|
|
6533
|
-
})), 3000);
|
|
6503
|
+
status = _context129.v;
|
|
6504
|
+
try {
|
|
6505
|
+
(_onRampWindow = onRampWindow) === null || _onRampWindow === void 0 ? void 0 : _onRampWindow.close();
|
|
6506
|
+
} catch (_unused6) {}
|
|
6507
|
+
// The terminal status was already emitted via onStatusUpdate
|
|
6508
|
+
// inside pollOnRampTransactionStatus; avoid a duplicate callback.
|
|
6509
|
+
setResult(_objectSpread2(_objectSpread2({}, initResult), {}, {
|
|
6510
|
+
status: status
|
|
6534
6511
|
}));
|
|
6512
|
+
setCompleted(true);
|
|
6513
|
+
_context129.n = 8;
|
|
6514
|
+
break;
|
|
6535
6515
|
case 7:
|
|
6536
|
-
|
|
6537
|
-
|
|
6516
|
+
_context129.p = 7;
|
|
6517
|
+
_t28 = _context129.v;
|
|
6538
6518
|
cleanup();
|
|
6539
|
-
throw
|
|
6519
|
+
throw _t28;
|
|
6540
6520
|
case 8:
|
|
6541
|
-
return
|
|
6521
|
+
return _context129.a(2);
|
|
6542
6522
|
}
|
|
6543
|
-
},
|
|
6523
|
+
}, _callee129, null, [[0, 7]]);
|
|
6544
6524
|
}));
|
|
6545
6525
|
return function action() {
|
|
6546
6526
|
return _ref152.apply(this, arguments);
|
|
@@ -6554,11 +6534,12 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
6554
6534
|
}),
|
|
6555
6535
|
onrampProvider: onrampProvider,
|
|
6556
6536
|
action: action,
|
|
6557
|
-
sandboxMode: sandboxMode,
|
|
6537
|
+
sandboxMode: params.sandboxMode,
|
|
6558
6538
|
completed: completed,
|
|
6539
|
+
result: result,
|
|
6559
6540
|
successPageDuration: successPageDuration,
|
|
6560
|
-
onSuccess: function onSuccess() {
|
|
6561
|
-
return resolve();
|
|
6541
|
+
onSuccess: function onSuccess(resolvedResult) {
|
|
6542
|
+
return resolve(resolvedResult);
|
|
6562
6543
|
},
|
|
6563
6544
|
onError: function onError(err) {
|
|
6564
6545
|
return reject(err);
|
|
@@ -6571,37 +6552,37 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
6571
6552
|
showTitle: false,
|
|
6572
6553
|
preventBack: true,
|
|
6573
6554
|
onClose: function onClose() {
|
|
6574
|
-
|
|
6555
|
+
reject(new OnRampError(OnRampErrorCode.USER_ABORTED, "User canceled the onramp process."));
|
|
6575
6556
|
}
|
|
6576
6557
|
});
|
|
6577
6558
|
}));
|
|
6578
6559
|
}
|
|
6579
|
-
},
|
|
6560
|
+
}, _callee130);
|
|
6580
6561
|
}));
|
|
6581
6562
|
return function (_x110) {
|
|
6582
6563
|
return _ref151.apply(this, arguments);
|
|
6583
6564
|
};
|
|
6584
6565
|
}(), [getSession, client, pushPage]);
|
|
6585
6566
|
var handleVerifyAppProofs = useCallback(/*#__PURE__*/function () {
|
|
6586
|
-
var
|
|
6587
|
-
var
|
|
6588
|
-
return _regenerator().w(function (
|
|
6589
|
-
while (1) switch (
|
|
6567
|
+
var _ref153 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee131(params) {
|
|
6568
|
+
var _ref154, appProofs, _ref154$successPageDu, successPageDuration, stampWith, s, organizationId, _t29;
|
|
6569
|
+
return _regenerator().w(function (_context131) {
|
|
6570
|
+
while (1) switch (_context131.p = _context131.n) {
|
|
6590
6571
|
case 0:
|
|
6591
|
-
|
|
6592
|
-
|
|
6572
|
+
_ref154 = params || {}, appProofs = _ref154.appProofs, _ref154$successPageDu = _ref154.successPageDuration, successPageDuration = _ref154$successPageDu === void 0 ? 3000 : _ref154$successPageDu, stampWith = _ref154.stampWith;
|
|
6573
|
+
_context131.n = 1;
|
|
6593
6574
|
return getSession();
|
|
6594
6575
|
case 1:
|
|
6595
|
-
s =
|
|
6576
|
+
s = _context131.v;
|
|
6596
6577
|
organizationId = (params === null || params === void 0 ? void 0 : params.organizationId) || (s === null || s === void 0 ? void 0 : s.organizationId);
|
|
6597
6578
|
if (organizationId) {
|
|
6598
|
-
|
|
6579
|
+
_context131.n = 2;
|
|
6599
6580
|
break;
|
|
6600
6581
|
}
|
|
6601
6582
|
throw new ZeroXKeyError("A session or passed in organization ID is required.", ZeroXKeyErrorCodes.INVALID_REQUEST);
|
|
6602
6583
|
case 2:
|
|
6603
|
-
|
|
6604
|
-
return
|
|
6584
|
+
_context131.p = 2;
|
|
6585
|
+
return _context131.a(2, new Promise(function (resolve, reject) {
|
|
6605
6586
|
pushPage({
|
|
6606
6587
|
key: "Verify app proofs",
|
|
6607
6588
|
content: jsx(VerifyPage, _objectSpread2(_objectSpread2({
|
|
@@ -6626,60 +6607,60 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
6626
6607
|
});
|
|
6627
6608
|
}));
|
|
6628
6609
|
case 3:
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
if (!(
|
|
6632
|
-
|
|
6610
|
+
_context131.p = 3;
|
|
6611
|
+
_t29 = _context131.v;
|
|
6612
|
+
if (!(_t29 instanceof ZeroXKeyError)) {
|
|
6613
|
+
_context131.n = 4;
|
|
6633
6614
|
break;
|
|
6634
6615
|
}
|
|
6635
|
-
throw
|
|
6616
|
+
throw _t29;
|
|
6636
6617
|
case 4:
|
|
6637
|
-
throw new ZeroXKeyError("Failed to verify app proofs.", ZeroXKeyErrorCodes.VERIFY_APP_PROOFS_ERROR,
|
|
6618
|
+
throw new ZeroXKeyError("Failed to verify app proofs.", ZeroXKeyErrorCodes.VERIFY_APP_PROOFS_ERROR, _t29);
|
|
6638
6619
|
case 5:
|
|
6639
|
-
return
|
|
6620
|
+
return _context131.a(2);
|
|
6640
6621
|
}
|
|
6641
|
-
},
|
|
6622
|
+
}, _callee131, null, [[2, 3]]);
|
|
6642
6623
|
}));
|
|
6643
6624
|
return function (_x111) {
|
|
6644
|
-
return
|
|
6625
|
+
return _ref153.apply(this, arguments);
|
|
6645
6626
|
};
|
|
6646
6627
|
}(), [getSession, pushPage]);
|
|
6647
6628
|
useEffect(function () {
|
|
6648
6629
|
if (proxyAuthConfigRef.current) return;
|
|
6649
6630
|
// Only fetch the proxy auth config once. Use that to build the master config.
|
|
6650
6631
|
var fetchProxyAuthConfig = /*#__PURE__*/function () {
|
|
6651
|
-
var
|
|
6632
|
+
var _ref155 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee132() {
|
|
6652
6633
|
var proxyAuthConfig;
|
|
6653
|
-
return _regenerator().w(function (
|
|
6654
|
-
while (1) switch (
|
|
6634
|
+
return _regenerator().w(function (_context132) {
|
|
6635
|
+
while (1) switch (_context132.p = _context132.n) {
|
|
6655
6636
|
case 0:
|
|
6656
|
-
|
|
6637
|
+
_context132.p = 0;
|
|
6657
6638
|
if (!shouldFetchWalletKitConfig) {
|
|
6658
|
-
|
|
6639
|
+
_context132.n = 2;
|
|
6659
6640
|
break;
|
|
6660
6641
|
}
|
|
6661
|
-
|
|
6642
|
+
_context132.n = 1;
|
|
6662
6643
|
return getAuthProxyConfig(config.authProxyConfigId,
|
|
6663
6644
|
// Can assert safely. See shouldFetchWalletKitConfig definition.
|
|
6664
6645
|
config.authProxyUrl);
|
|
6665
6646
|
case 1:
|
|
6666
|
-
proxyAuthConfig =
|
|
6647
|
+
proxyAuthConfig = _context132.v;
|
|
6667
6648
|
proxyAuthConfigRef.current = proxyAuthConfig;
|
|
6668
6649
|
case 2:
|
|
6669
6650
|
setMasterConfig(buildConfig(proxyAuthConfig));
|
|
6670
|
-
|
|
6651
|
+
_context132.n = 4;
|
|
6671
6652
|
break;
|
|
6672
6653
|
case 3:
|
|
6673
|
-
|
|
6674
|
-
|
|
6654
|
+
_context132.p = 3;
|
|
6655
|
+
_context132.v;
|
|
6675
6656
|
setClientState(ClientState.Error);
|
|
6676
6657
|
case 4:
|
|
6677
|
-
return
|
|
6658
|
+
return _context132.a(2);
|
|
6678
6659
|
}
|
|
6679
|
-
},
|
|
6660
|
+
}, _callee132, null, [[0, 3]]);
|
|
6680
6661
|
}));
|
|
6681
6662
|
return function fetchProxyAuthConfig() {
|
|
6682
|
-
return
|
|
6663
|
+
return _ref155.apply(this, arguments);
|
|
6683
6664
|
};
|
|
6684
6665
|
}();
|
|
6685
6666
|
fetchProxyAuthConfig();
|
|
@@ -6712,34 +6693,34 @@ var ClientProvider = function ClientProvider(_ref) {
|
|
|
6712
6693
|
var debouncedFetchWalletProviders = useDebouncedCallback(fetchWalletProviders, 100);
|
|
6713
6694
|
useEffect(function () {
|
|
6714
6695
|
var handleUpdateState = /*#__PURE__*/function () {
|
|
6715
|
-
var
|
|
6696
|
+
var _ref156 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133() {
|
|
6716
6697
|
var currentSession;
|
|
6717
|
-
return _regenerator().w(function (
|
|
6718
|
-
while (1) switch (
|
|
6698
|
+
return _regenerator().w(function (_context133) {
|
|
6699
|
+
while (1) switch (_context133.n) {
|
|
6719
6700
|
case 0:
|
|
6720
|
-
|
|
6701
|
+
_context133.n = 1;
|
|
6721
6702
|
return getSession();
|
|
6722
6703
|
case 1:
|
|
6723
|
-
currentSession =
|
|
6704
|
+
currentSession = _context133.v;
|
|
6724
6705
|
if (!currentSession) {
|
|
6725
|
-
|
|
6706
|
+
_context133.n = 3;
|
|
6726
6707
|
break;
|
|
6727
6708
|
}
|
|
6728
|
-
|
|
6709
|
+
_context133.n = 2;
|
|
6729
6710
|
return debouncedRefreshWallets();
|
|
6730
6711
|
case 2:
|
|
6731
|
-
|
|
6712
|
+
_context133.n = 4;
|
|
6732
6713
|
break;
|
|
6733
6714
|
case 3:
|
|
6734
|
-
|
|
6715
|
+
_context133.n = 4;
|
|
6735
6716
|
return debouncedFetchWalletProviders();
|
|
6736
6717
|
case 4:
|
|
6737
|
-
return
|
|
6718
|
+
return _context133.a(2);
|
|
6738
6719
|
}
|
|
6739
|
-
},
|
|
6720
|
+
}, _callee133);
|
|
6740
6721
|
}));
|
|
6741
6722
|
return function handleUpdateState() {
|
|
6742
|
-
return
|
|
6723
|
+
return _ref156.apply(this, arguments);
|
|
6743
6724
|
};
|
|
6744
6725
|
}();
|
|
6745
6726
|
var cleanup = function cleanup() {};
|