@dynamic-labs/utils 3.0.0-alpha.4 → 3.0.0-alpha.40

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 (53) hide show
  1. package/CHANGELOG.md +371 -0
  2. package/_virtual/_tslib.cjs +15 -0
  3. package/_virtual/_tslib.js +14 -1
  4. package/package.json +7 -8
  5. package/src/eip6963/eip6963Provider.cjs +40 -0
  6. package/src/eip6963/eip6963Provider.d.ts +34 -0
  7. package/src/eip6963/eip6963Provider.js +35 -0
  8. package/src/eip6963/index.d.ts +1 -0
  9. package/src/errors/ExternalAuthError.cjs +14 -0
  10. package/src/errors/ExternalAuthError.d.ts +4 -0
  11. package/src/errors/ExternalAuthError.js +10 -0
  12. package/src/errors/MfaInvalidOtpError.cjs +1 -1
  13. package/src/errors/MfaInvalidOtpError.js +1 -1
  14. package/src/errors/NoAccessError.cjs +3 -1
  15. package/src/errors/NoAccessError.d.ts +5 -1
  16. package/src/errors/NoAccessError.js +3 -1
  17. package/src/errors/SandboxMaximumThresholdReachedError.cjs +15 -0
  18. package/src/errors/SandboxMaximumThresholdReachedError.d.ts +5 -0
  19. package/src/errors/SandboxMaximumThresholdReachedError.js +11 -0
  20. package/src/errors/WalletAddressMismatchError.cjs +17 -0
  21. package/src/errors/WalletAddressMismatchError.d.ts +11 -0
  22. package/src/errors/WalletAddressMismatchError.js +13 -0
  23. package/src/errors/index.d.ts +3 -0
  24. package/src/handleMobileWalletRedirect/handleMobileWalletRedirect.cjs +0 -7
  25. package/src/handleMobileWalletRedirect/handleMobileWalletRedirect.js +0 -7
  26. package/src/index.cjs +15 -4
  27. package/src/index.d.ts +3 -1
  28. package/src/index.js +7 -1
  29. package/src/nativeMobileOauthStateParam.cjs +13 -0
  30. package/src/nativeMobileOauthStateParam.d.ts +14 -0
  31. package/src/nativeMobileOauthStateParam.js +9 -0
  32. package/src/retryableFn.cjs +1 -6
  33. package/src/retryableFn.js +1 -6
  34. package/src/services/FetchService/FetchService.cjs +10 -5
  35. package/src/services/FetchService/FetchService.d.ts +2 -2
  36. package/src/services/FetchService/FetchService.js +10 -5
  37. package/src/services/Oauth2Service/Oauth2Service.cjs +38 -0
  38. package/src/services/Oauth2Service/Oauth2Service.d.ts +35 -0
  39. package/src/services/Oauth2Service/Oauth2Service.js +34 -0
  40. package/src/services/Oauth2Service/createWindowOauth2Service/createWindowOauth2Service.cjs +203 -0
  41. package/src/services/Oauth2Service/createWindowOauth2Service/createWindowOauth2Service.d.ts +2 -0
  42. package/src/services/Oauth2Service/createWindowOauth2Service/createWindowOauth2Service.js +199 -0
  43. package/src/services/Oauth2Service/createWindowOauth2Service/index.d.ts +1 -0
  44. package/src/services/Oauth2Service/index.d.ts +2 -0
  45. package/src/services/PlatformService/PlatformService.cjs +13 -12
  46. package/src/services/PlatformService/PlatformService.d.ts +2 -3
  47. package/src/services/PlatformService/PlatformService.js +13 -12
  48. package/src/services/PlatformService/createBrowserPlatformService/createBrowserPlatformService.cjs +0 -3
  49. package/src/services/PlatformService/createBrowserPlatformService/createBrowserPlatformService.js +0 -3
  50. package/src/services/PlatformService/types.d.ts +0 -4
  51. package/src/getOrMapViemChain.cjs +0 -77
  52. package/src/getOrMapViemChain.d.ts +0 -11
  53. package/src/getOrMapViemChain.js +0 -51
@@ -0,0 +1,203 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../_virtual/_tslib.cjs');
7
+ var types = require('@dynamic-labs/types');
8
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
9
+ var logger = require('../../../logger/logger.cjs');
10
+
11
+ const providersWithoutWindowOpenerReference = ['twitter'];
12
+ let authWindowInterval;
13
+ const createWindowOauth2Service = () => ({
14
+ getOauthCode: ({ apiProvider, provider, setIsProcessing, state, oauthLoginUrl, getOAuthResultFromApi, sessionTimeout, isMobile, onSettled, initWebAuth, }) => new Promise((resolve, _reject) => {
15
+ /**
16
+ * Use redirect flow on mobile for all providers except Telegram
17
+ */
18
+ if (isMobile && provider !== types.ProviderEnum.Telegram) {
19
+ initWebAuth().then(() => {
20
+ window.location.assign(oauthLoginUrl);
21
+ });
22
+ return;
23
+ }
24
+ // When we catch this error we assume it follows this type, so we must enforce it
25
+ // here to ensure the assumption is correct
26
+ const typedReject = (params) => _reject(params);
27
+ // Clear any potential pending timeouts and intervals
28
+ clearInterval(authWindowInterval);
29
+ const providersWaitingOauthMessage = {};
30
+ let shouldPool = false;
31
+ const authWindow = window.open('', '_blank', 'width=500,height=600');
32
+ const clearListeners = () => {
33
+ window.removeEventListener('message', handleWindowMessage);
34
+ providersWaitingOauthMessage[provider] = false;
35
+ };
36
+ const handleWindowMessage = (event) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
37
+ const message = event.data;
38
+ const expectedOrigin = getExpectedOrigin(apiProvider, provider);
39
+ if (!expectedOrigin) {
40
+ return;
41
+ }
42
+ if ((message === null || message === void 0 ? void 0 : message.type) === 'origin_check' && authWindow) {
43
+ logger.logger.debug('Origin check message received. Sending response now.', {
44
+ data: message,
45
+ expectedOrigin,
46
+ });
47
+ authWindow.postMessage('origin_check_response', expectedOrigin);
48
+ return;
49
+ }
50
+ const isTelegramCompletedMessage = (message === null || message === void 0 ? void 0 : message.type) === 'telegram_completed';
51
+ const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
52
+ if (isAuthorizationMessage || isTelegramCompletedMessage) {
53
+ logger.logger.debug('Message received', { data: message });
54
+ }
55
+ const isExpectedOrigin = event.origin === expectedOrigin;
56
+ const isValidMessage = ((isAuthorizationMessage && (message === null || message === void 0 ? void 0 : message.provider) === provider) ||
57
+ isTelegramCompletedMessage) &&
58
+ isExpectedOrigin;
59
+ // don't process invalid messages for provider
60
+ if (!isValidMessage) {
61
+ return;
62
+ }
63
+ setIsProcessing(true);
64
+ if (!providersWaitingOauthMessage[provider]) {
65
+ typedReject({
66
+ code: types.SocialOAuthErrorCode.SESSION_TIMEOUT,
67
+ message: `Connecting ${provider} account session timeout.`,
68
+ });
69
+ return;
70
+ }
71
+ clearListeners();
72
+ if (isTelegramCompletedMessage) {
73
+ handleTelegramCompletionMessage(message);
74
+ return;
75
+ }
76
+ handleAuthorizationMessage(message, provider, state);
77
+ });
78
+ const getExpectedOrigin = (apiProvider, provider) => {
79
+ if (!(apiProvider === null || apiProvider === void 0 ? void 0 : apiProvider.redirectUrl)) {
80
+ return;
81
+ }
82
+ let expectedOrigin = window.location.origin;
83
+ if (!providersWithoutWindowOpenerReference.includes(provider)) {
84
+ try {
85
+ const redirectUri = new URL(apiProvider.redirectUrl);
86
+ expectedOrigin = redirectUri.origin;
87
+ }
88
+ catch (e) {
89
+ logger.logger.error('Failed to parse social provider redirect url', {
90
+ error: e,
91
+ });
92
+ return;
93
+ }
94
+ }
95
+ return expectedOrigin;
96
+ };
97
+ const handleTelegramCompletionMessage = (message) => {
98
+ logger.logger.debug('Telegram completion message received', {
99
+ data: message,
100
+ });
101
+ resolve('telegram_completed');
102
+ setIsProcessing(false);
103
+ };
104
+ const handleAuthorizationMessage = (message, provider, state) => {
105
+ const { code, error, state: authState } = message;
106
+ if (error && error !== 'undefined') {
107
+ typedReject({
108
+ code: types.SocialOAuthErrorCode.OAUTH_ERROR,
109
+ message: `Failed to connect ${provider} social account: ${error}`,
110
+ });
111
+ return;
112
+ }
113
+ // check that the state we receive from message is the same state we calculated earlier
114
+ // this could be an attack
115
+ // this state check is used only by providers with an open window opener reference (eg, not twitter)
116
+ if (!providersWithoutWindowOpenerReference.includes(provider) &&
117
+ state !== authState) {
118
+ typedReject({
119
+ code: types.SocialOAuthErrorCode.OAUTH_ERROR,
120
+ message: `Failed to connect ${provider} social account: Invalid random state`,
121
+ });
122
+ return;
123
+ }
124
+ if (!code) {
125
+ typedReject({
126
+ code: types.SocialOAuthErrorCode.NO_AUTH_CODE,
127
+ message: `Failed to connect ${provider} social account: no authorization code`,
128
+ });
129
+ return;
130
+ }
131
+ resolve(code);
132
+ setIsProcessing(false);
133
+ };
134
+ if (!providersWaitingOauthMessage[provider]) {
135
+ window.addEventListener('message', handleWindowMessage);
136
+ providersWaitingOauthMessage[provider] = true;
137
+ }
138
+ // First we store the state in backend
139
+ initWebAuth().then(() => {
140
+ authWindow === null || authWindow === void 0 ? void 0 : authWindow.location.assign(oauthLoginUrl);
141
+ if (!providersWithoutWindowOpenerReference.includes(provider)) {
142
+ // For provider that support window.opener, we need to clear all states/listeners when the window is closed
143
+ authWindowInterval = setInterval(() => {
144
+ if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed))
145
+ return;
146
+ clearInterval(authWindowInterval);
147
+ setIsProcessing(false);
148
+ // user didn't complete oauth
149
+ if (providersWaitingOauthMessage[provider])
150
+ typedReject('user-cancelled');
151
+ }, 2000);
152
+ return;
153
+ }
154
+ // For provider that don't support window.opener, we need to use a timeout to pool the oauth result
155
+ // If we don't get a valid result in {async sessionTimeout} ms, we'll assume the user closed the window
156
+ // and we'll clear all states/listeners
157
+ const poolOauthResult = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
158
+ if (!shouldPool)
159
+ return;
160
+ const result = yield getOAuthResultFromApi();
161
+ if (!shouldPool)
162
+ return;
163
+ if ((result === null || result === void 0 ? void 0 : result.status) !== sdkApiCore.OauthResultStatus.Completed) {
164
+ authWindowInterval = setTimeout(() => {
165
+ poolOauthResult();
166
+ }, 1000);
167
+ return;
168
+ }
169
+ shouldPool = false;
170
+ const authMessage = {
171
+ code: result === null || result === void 0 ? void 0 : result.code,
172
+ error: result === null || result === void 0 ? void 0 : result.error,
173
+ provider,
174
+ type: 'authorization_response',
175
+ };
176
+ window.postMessage(authMessage, '*');
177
+ });
178
+ // start pooling oauth result
179
+ shouldPool = true;
180
+ poolOauthResult();
181
+ // if this is mobile, set a longer timeout to allow the user to login to the provider in the browser
182
+ let authWindowTimeout = sessionTimeout;
183
+ if (isMobile) {
184
+ authWindowTimeout = authWindowTimeout * 3;
185
+ }
186
+ authWindowInterval = setTimeout(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
187
+ shouldPool = false;
188
+ // clear all states/listeners, assuming user closed the window before completing oauth
189
+ if (providersWaitingOauthMessage[provider]) {
190
+ clearListeners();
191
+ typedReject({
192
+ code: types.SocialOAuthErrorCode.OAUTH_WINDOW_TIMEOUT,
193
+ message: `Connecting ${provider} account window timeout.`,
194
+ });
195
+ }
196
+ setIsProcessing(false);
197
+ onSettled === null || onSettled === void 0 ? void 0 : onSettled();
198
+ }), authWindowTimeout);
199
+ });
200
+ }),
201
+ });
202
+
203
+ exports.createWindowOauth2Service = createWindowOauth2Service;
@@ -0,0 +1,2 @@
1
+ import { IOauth2Service } from '../Oauth2Service';
2
+ export declare const createWindowOauth2Service: () => IOauth2Service;
@@ -0,0 +1,199 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../_virtual/_tslib.js';
3
+ import { ProviderEnum, SocialOAuthErrorCode } from '@dynamic-labs/types';
4
+ import { OauthResultStatus } from '@dynamic-labs/sdk-api-core';
5
+ import { logger } from '../../../logger/logger.js';
6
+
7
+ const providersWithoutWindowOpenerReference = ['twitter'];
8
+ let authWindowInterval;
9
+ const createWindowOauth2Service = () => ({
10
+ getOauthCode: ({ apiProvider, provider, setIsProcessing, state, oauthLoginUrl, getOAuthResultFromApi, sessionTimeout, isMobile, onSettled, initWebAuth, }) => new Promise((resolve, _reject) => {
11
+ /**
12
+ * Use redirect flow on mobile for all providers except Telegram
13
+ */
14
+ if (isMobile && provider !== ProviderEnum.Telegram) {
15
+ initWebAuth().then(() => {
16
+ window.location.assign(oauthLoginUrl);
17
+ });
18
+ return;
19
+ }
20
+ // When we catch this error we assume it follows this type, so we must enforce it
21
+ // here to ensure the assumption is correct
22
+ const typedReject = (params) => _reject(params);
23
+ // Clear any potential pending timeouts and intervals
24
+ clearInterval(authWindowInterval);
25
+ const providersWaitingOauthMessage = {};
26
+ let shouldPool = false;
27
+ const authWindow = window.open('', '_blank', 'width=500,height=600');
28
+ const clearListeners = () => {
29
+ window.removeEventListener('message', handleWindowMessage);
30
+ providersWaitingOauthMessage[provider] = false;
31
+ };
32
+ const handleWindowMessage = (event) => __awaiter(void 0, void 0, void 0, function* () {
33
+ const message = event.data;
34
+ const expectedOrigin = getExpectedOrigin(apiProvider, provider);
35
+ if (!expectedOrigin) {
36
+ return;
37
+ }
38
+ if ((message === null || message === void 0 ? void 0 : message.type) === 'origin_check' && authWindow) {
39
+ logger.debug('Origin check message received. Sending response now.', {
40
+ data: message,
41
+ expectedOrigin,
42
+ });
43
+ authWindow.postMessage('origin_check_response', expectedOrigin);
44
+ return;
45
+ }
46
+ const isTelegramCompletedMessage = (message === null || message === void 0 ? void 0 : message.type) === 'telegram_completed';
47
+ const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
48
+ if (isAuthorizationMessage || isTelegramCompletedMessage) {
49
+ logger.debug('Message received', { data: message });
50
+ }
51
+ const isExpectedOrigin = event.origin === expectedOrigin;
52
+ const isValidMessage = ((isAuthorizationMessage && (message === null || message === void 0 ? void 0 : message.provider) === provider) ||
53
+ isTelegramCompletedMessage) &&
54
+ isExpectedOrigin;
55
+ // don't process invalid messages for provider
56
+ if (!isValidMessage) {
57
+ return;
58
+ }
59
+ setIsProcessing(true);
60
+ if (!providersWaitingOauthMessage[provider]) {
61
+ typedReject({
62
+ code: SocialOAuthErrorCode.SESSION_TIMEOUT,
63
+ message: `Connecting ${provider} account session timeout.`,
64
+ });
65
+ return;
66
+ }
67
+ clearListeners();
68
+ if (isTelegramCompletedMessage) {
69
+ handleTelegramCompletionMessage(message);
70
+ return;
71
+ }
72
+ handleAuthorizationMessage(message, provider, state);
73
+ });
74
+ const getExpectedOrigin = (apiProvider, provider) => {
75
+ if (!(apiProvider === null || apiProvider === void 0 ? void 0 : apiProvider.redirectUrl)) {
76
+ return;
77
+ }
78
+ let expectedOrigin = window.location.origin;
79
+ if (!providersWithoutWindowOpenerReference.includes(provider)) {
80
+ try {
81
+ const redirectUri = new URL(apiProvider.redirectUrl);
82
+ expectedOrigin = redirectUri.origin;
83
+ }
84
+ catch (e) {
85
+ logger.error('Failed to parse social provider redirect url', {
86
+ error: e,
87
+ });
88
+ return;
89
+ }
90
+ }
91
+ return expectedOrigin;
92
+ };
93
+ const handleTelegramCompletionMessage = (message) => {
94
+ logger.debug('Telegram completion message received', {
95
+ data: message,
96
+ });
97
+ resolve('telegram_completed');
98
+ setIsProcessing(false);
99
+ };
100
+ const handleAuthorizationMessage = (message, provider, state) => {
101
+ const { code, error, state: authState } = message;
102
+ if (error && error !== 'undefined') {
103
+ typedReject({
104
+ code: SocialOAuthErrorCode.OAUTH_ERROR,
105
+ message: `Failed to connect ${provider} social account: ${error}`,
106
+ });
107
+ return;
108
+ }
109
+ // check that the state we receive from message is the same state we calculated earlier
110
+ // this could be an attack
111
+ // this state check is used only by providers with an open window opener reference (eg, not twitter)
112
+ if (!providersWithoutWindowOpenerReference.includes(provider) &&
113
+ state !== authState) {
114
+ typedReject({
115
+ code: SocialOAuthErrorCode.OAUTH_ERROR,
116
+ message: `Failed to connect ${provider} social account: Invalid random state`,
117
+ });
118
+ return;
119
+ }
120
+ if (!code) {
121
+ typedReject({
122
+ code: SocialOAuthErrorCode.NO_AUTH_CODE,
123
+ message: `Failed to connect ${provider} social account: no authorization code`,
124
+ });
125
+ return;
126
+ }
127
+ resolve(code);
128
+ setIsProcessing(false);
129
+ };
130
+ if (!providersWaitingOauthMessage[provider]) {
131
+ window.addEventListener('message', handleWindowMessage);
132
+ providersWaitingOauthMessage[provider] = true;
133
+ }
134
+ // First we store the state in backend
135
+ initWebAuth().then(() => {
136
+ authWindow === null || authWindow === void 0 ? void 0 : authWindow.location.assign(oauthLoginUrl);
137
+ if (!providersWithoutWindowOpenerReference.includes(provider)) {
138
+ // For provider that support window.opener, we need to clear all states/listeners when the window is closed
139
+ authWindowInterval = setInterval(() => {
140
+ if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed))
141
+ return;
142
+ clearInterval(authWindowInterval);
143
+ setIsProcessing(false);
144
+ // user didn't complete oauth
145
+ if (providersWaitingOauthMessage[provider])
146
+ typedReject('user-cancelled');
147
+ }, 2000);
148
+ return;
149
+ }
150
+ // For provider that don't support window.opener, we need to use a timeout to pool the oauth result
151
+ // If we don't get a valid result in {async sessionTimeout} ms, we'll assume the user closed the window
152
+ // and we'll clear all states/listeners
153
+ const poolOauthResult = () => __awaiter(void 0, void 0, void 0, function* () {
154
+ if (!shouldPool)
155
+ return;
156
+ const result = yield getOAuthResultFromApi();
157
+ if (!shouldPool)
158
+ return;
159
+ if ((result === null || result === void 0 ? void 0 : result.status) !== OauthResultStatus.Completed) {
160
+ authWindowInterval = setTimeout(() => {
161
+ poolOauthResult();
162
+ }, 1000);
163
+ return;
164
+ }
165
+ shouldPool = false;
166
+ const authMessage = {
167
+ code: result === null || result === void 0 ? void 0 : result.code,
168
+ error: result === null || result === void 0 ? void 0 : result.error,
169
+ provider,
170
+ type: 'authorization_response',
171
+ };
172
+ window.postMessage(authMessage, '*');
173
+ });
174
+ // start pooling oauth result
175
+ shouldPool = true;
176
+ poolOauthResult();
177
+ // if this is mobile, set a longer timeout to allow the user to login to the provider in the browser
178
+ let authWindowTimeout = sessionTimeout;
179
+ if (isMobile) {
180
+ authWindowTimeout = authWindowTimeout * 3;
181
+ }
182
+ authWindowInterval = setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
183
+ shouldPool = false;
184
+ // clear all states/listeners, assuming user closed the window before completing oauth
185
+ if (providersWaitingOauthMessage[provider]) {
186
+ clearListeners();
187
+ typedReject({
188
+ code: SocialOAuthErrorCode.OAUTH_WINDOW_TIMEOUT,
189
+ message: `Connecting ${provider} account window timeout.`,
190
+ });
191
+ }
192
+ setIsProcessing(false);
193
+ onSettled === null || onSettled === void 0 ? void 0 : onSettled();
194
+ }), authWindowTimeout);
195
+ });
196
+ }),
197
+ });
198
+
199
+ export { createWindowOauth2Service };
@@ -0,0 +1 @@
1
+ export * from './createWindowOauth2Service';
@@ -0,0 +1,2 @@
1
+ export * from './Oauth2Service';
2
+ export * from './createWindowOauth2Service';
@@ -3,37 +3,38 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
6
7
  var createBrowserPlatformService = require('./createBrowserPlatformService/createBrowserPlatformService.cjs');
7
8
 
9
+ var _a, _PlatformService_implementation;
8
10
  class PlatformService {
9
11
  static get implementation() {
10
- if (!PlatformService._implementation) {
12
+ if (!_tslib.__classPrivateFieldGet(_a, _a, "f", _PlatformService_implementation)) {
11
13
  return createBrowserPlatformService.createBrowserPlatformService(window);
12
14
  }
13
- return PlatformService._implementation;
15
+ return _tslib.__classPrivateFieldGet(_a, _a, "f", _PlatformService_implementation);
14
16
  }
15
- static setImplementation(implementation) {
16
- PlatformService._implementation = implementation;
17
+ static set implementation(implementation) {
18
+ _tslib.__classPrivateFieldSet(_a, _a, implementation, "f", _PlatformService_implementation);
17
19
  }
18
20
  static get getOrigin() {
19
- return PlatformService.implementation.getOrigin;
21
+ return _a.implementation.getOrigin;
20
22
  }
21
23
  static get getHost() {
22
- return PlatformService.implementation.getHost;
24
+ return _a.implementation.getHost;
23
25
  }
24
26
  static get getHostname() {
25
- return PlatformService.implementation.getHostname;
27
+ return _a.implementation.getHostname;
26
28
  }
27
29
  static get getTLD() {
28
- return PlatformService.implementation.getTLD;
30
+ return _a.implementation.getTLD;
29
31
  }
30
32
  // Deeplink handling
31
33
  static get openURL() {
32
- return PlatformService.implementation.openURL;
33
- }
34
- static get openNewWindow() {
35
- return PlatformService.implementation.openNewWindow;
34
+ return _a.implementation.openURL;
36
35
  }
37
36
  }
37
+ _a = PlatformService;
38
+ _PlatformService_implementation = { value: void 0 };
38
39
 
39
40
  exports.PlatformService = PlatformService;
@@ -1,12 +1,11 @@
1
1
  import { IPlatformService } from './types';
2
2
  export declare class PlatformService {
3
- static _implementation: IPlatformService;
3
+ #private;
4
4
  static get implementation(): IPlatformService;
5
- static setImplementation(implementation: IPlatformService): void;
5
+ static set implementation(implementation: IPlatformService);
6
6
  static get getOrigin(): () => string;
7
7
  static get getHost(): () => string;
8
8
  static get getHostname(): () => string;
9
9
  static get getTLD(): () => string | undefined;
10
10
  static get openURL(): (url: string) => Promise<void>;
11
- static get openNewWindow(): (url: string) => Promise<void>;
12
11
  }
@@ -1,35 +1,36 @@
1
1
  'use client'
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from '../../../_virtual/_tslib.js';
2
3
  import { createBrowserPlatformService } from './createBrowserPlatformService/createBrowserPlatformService.js';
3
4
 
5
+ var _a, _PlatformService_implementation;
4
6
  class PlatformService {
5
7
  static get implementation() {
6
- if (!PlatformService._implementation) {
8
+ if (!__classPrivateFieldGet(_a, _a, "f", _PlatformService_implementation)) {
7
9
  return createBrowserPlatformService(window);
8
10
  }
9
- return PlatformService._implementation;
11
+ return __classPrivateFieldGet(_a, _a, "f", _PlatformService_implementation);
10
12
  }
11
- static setImplementation(implementation) {
12
- PlatformService._implementation = implementation;
13
+ static set implementation(implementation) {
14
+ __classPrivateFieldSet(_a, _a, implementation, "f", _PlatformService_implementation);
13
15
  }
14
16
  static get getOrigin() {
15
- return PlatformService.implementation.getOrigin;
17
+ return _a.implementation.getOrigin;
16
18
  }
17
19
  static get getHost() {
18
- return PlatformService.implementation.getHost;
20
+ return _a.implementation.getHost;
19
21
  }
20
22
  static get getHostname() {
21
- return PlatformService.implementation.getHostname;
23
+ return _a.implementation.getHostname;
22
24
  }
23
25
  static get getTLD() {
24
- return PlatformService.implementation.getTLD;
26
+ return _a.implementation.getTLD;
25
27
  }
26
28
  // Deeplink handling
27
29
  static get openURL() {
28
- return PlatformService.implementation.openURL;
29
- }
30
- static get openNewWindow() {
31
- return PlatformService.implementation.openNewWindow;
30
+ return _a.implementation.openURL;
32
31
  }
33
32
  }
33
+ _a = PlatformService;
34
+ _PlatformService_implementation = { value: void 0 };
34
35
 
35
36
  export { PlatformService };
@@ -22,9 +22,6 @@ const createBrowserPlatformService = (window) => ({
22
22
  });
23
23
  return data.domain || undefined;
24
24
  },
25
- openNewWindow: (url) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
26
- window.open(url);
27
- }),
28
25
  openURL: (url) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
29
26
  window.location.assign(url);
30
27
  }),
@@ -18,9 +18,6 @@ const createBrowserPlatformService = (window) => ({
18
18
  });
19
19
  return data.domain || undefined;
20
20
  },
21
- openNewWindow: (url) => __awaiter(void 0, void 0, void 0, function* () {
22
- window.open(url);
23
- }),
24
21
  openURL: (url) => __awaiter(void 0, void 0, void 0, function* () {
25
22
  window.location.assign(url);
26
23
  }),
@@ -22,8 +22,4 @@ export interface IPlatformService {
22
22
  * Opens a URL. If possible, should avoid new windows.
23
23
  */
24
24
  openURL(url: string): Promise<void>;
25
- /**
26
- * Opens a given URL in a new window.
27
- */
28
- openNewWindow(url: string): Promise<void>;
29
25
  }
@@ -1,77 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var chains = require('viem/chains');
7
-
8
- function _interopNamespace(e) {
9
- if (e && e.__esModule) return e;
10
- var n = Object.create(null);
11
- if (e) {
12
- Object.keys(e).forEach(function (k) {
13
- if (k !== 'default') {
14
- var d = Object.getOwnPropertyDescriptor(e, k);
15
- Object.defineProperty(n, k, d.get ? d : {
16
- enumerable: true,
17
- get: function () { return e[k]; }
18
- });
19
- }
20
- });
21
- }
22
- n["default"] = e;
23
- return Object.freeze(n);
24
- }
25
-
26
- var chains__namespace = /*#__PURE__*/_interopNamespace(chains);
27
-
28
- // eslint-disable-next-line import/no-namespace
29
- /**
30
- * Gets the chain object for the given chain id.
31
- * @param chainId - Chain id of the target EVM chain.
32
- * @returns Viem's chain object.
33
- */
34
- const getChain = (chainId) => {
35
- for (const chain of Object.values(chains__namespace)) {
36
- if ('id' in chain) {
37
- if (chain.id === chainId) {
38
- return chain;
39
- }
40
- }
41
- }
42
- throw new Error(`Chain with id ${chainId} not found`);
43
- };
44
- const mapChain = (network) => {
45
- var _a;
46
- return ({
47
- blockExplorers: ((_a = network.blockExplorerUrls) === null || _a === void 0 ? void 0 : _a[0])
48
- ? {
49
- default: {
50
- name: network.blockExplorerUrls[0],
51
- url: network.blockExplorerUrls[0],
52
- },
53
- }
54
- : undefined,
55
- id: network.chainId,
56
- name: network.vanityName || network.name || network.chainName,
57
- nativeCurrency: network.nativeCurrency,
58
- rpcUrls: {
59
- default: { http: network.rpcUrls },
60
- public: { http: network.rpcUrls },
61
- },
62
- });
63
- };
64
- const getOrMapViemChain = (network) => {
65
- let chain;
66
- try {
67
- chain = getChain(network.chainId);
68
- }
69
- catch (_a) {
70
- chain = mapChain(network);
71
- }
72
- return chain;
73
- };
74
-
75
- exports.getChain = getChain;
76
- exports.getOrMapViemChain = getOrMapViemChain;
77
- exports.mapChain = mapChain;
@@ -1,11 +0,0 @@
1
- import { Chain } from 'viem';
2
- import * as chains from 'viem/chains';
3
- import { EvmNetwork } from '@dynamic-labs/types';
4
- /**
5
- * Gets the chain object for the given chain id.
6
- * @param chainId - Chain id of the target EVM chain.
7
- * @returns Viem's chain object.
8
- */
9
- export declare const getChain: (chainId: number) => chains.Chain;
10
- export declare const mapChain: (network: EvmNetwork) => Chain;
11
- export declare const getOrMapViemChain: (network: EvmNetwork) => Chain;