@meshconnect/web-link-sdk 2.1.0 → 3.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@meshconnect/web-link-sdk",
3
- "version": "2.1.0",
3
+ "version": "3.0.0-rc.1",
4
4
  "description": "A client-side JS library for integrating with Mesh Connect",
5
+ "exports": "./index.js",
5
6
  "license": "MIT",
6
7
  "repository": "https://github.com/FrontFin/mesh-web-sdk.git",
7
8
  "homepage": "https://github.com/FrontFin/mesh-web-sdk",
@@ -55,7 +56,7 @@
55
56
  "url": "http://localhost/"
56
57
  }
57
58
  },
58
- "main": "./cjs/index.js",
59
59
  "module": "./index.js",
60
+ "main": "./index.js",
60
61
  "types": "./index.d.ts"
61
62
  }
@@ -1 +1 @@
1
- export declare const sdkVersion = "2.1.0";
1
+ export declare const sdkVersion = "3.0.0-rc.1";
package/utils/version.js CHANGED
@@ -1 +1 @@
1
- export var sdkVersion = '2.1.0';
1
+ export var sdkVersion = '3.0.0-rc.1';
package/cjs/Link.js DELETED
@@ -1,441 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.createLink = void 0;
51
- var popup_1 = require("./utils/popup");
52
- var event_types_1 = require("./utils/event-types");
53
- var wallet_browser_event_types_1 = require("./utils/wallet-browser-event-types");
54
- var sdk_specs_1 = require("./utils/sdk-specs");
55
- var wagmiCoreConnectorsUtils_1 = require("./utils/wagmiCoreConnectorsUtils");
56
- var currentOptions;
57
- var possibleOrigins = new Set([
58
- 'https://web.meshconnect.com',
59
- 'https://web.getfront.com'
60
- ]);
61
- var iframeElement = function () {
62
- return document.getElementById(popup_1.iframeId);
63
- };
64
- function sendMessageToIframe(message) {
65
- possibleOrigins.forEach(function (origin) {
66
- var _a;
67
- try {
68
- (_a = iframeElement().contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(message, origin);
69
- }
70
- catch (e) {
71
- console.error('Mesh SDK: Failed to deliver message to the iframe');
72
- console.error(e);
73
- }
74
- });
75
- }
76
- function handleLinkEvent(event) {
77
- return __awaiter(this, void 0, void 0, function () {
78
- var _a, payload, payload, payload, payload, w, h, left, top_1, injectedConnectors;
79
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
80
- return __generator(this, function (_o) {
81
- switch (_o.label) {
82
- case 0:
83
- _a = event.data.type;
84
- switch (_a) {
85
- case 'brokerageAccountAccessToken': return [3 /*break*/, 1];
86
- case 'delayedAuthentication': return [3 /*break*/, 2];
87
- case 'transferFinished': return [3 /*break*/, 3];
88
- case 'close': return [3 /*break*/, 4];
89
- case 'done': return [3 /*break*/, 4];
90
- case 'oauthLinkOpen': return [3 /*break*/, 5];
91
- case 'loaded': return [3 /*break*/, 6];
92
- }
93
- return [3 /*break*/, 8];
94
- case 1:
95
- {
96
- payload = {
97
- accessToken: event.data.payload
98
- };
99
- (_b = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _b === void 0 ? void 0 : _b.call(currentOptions, {
100
- type: 'integrationConnected',
101
- payload: payload
102
- });
103
- (_c = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onIntegrationConnected) === null || _c === void 0 ? void 0 : _c.call(currentOptions, payload);
104
- return [3 /*break*/, 9];
105
- }
106
- _o.label = 2;
107
- case 2:
108
- {
109
- payload = {
110
- delayedAuth: event.data.payload
111
- };
112
- (_d = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _d === void 0 ? void 0 : _d.call(currentOptions, {
113
- type: 'integrationConnected',
114
- payload: payload
115
- });
116
- (_e = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onIntegrationConnected) === null || _e === void 0 ? void 0 : _e.call(currentOptions, payload);
117
- return [3 /*break*/, 9];
118
- }
119
- _o.label = 3;
120
- case 3:
121
- {
122
- payload = event.data.payload;
123
- (_f = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _f === void 0 ? void 0 : _f.call(currentOptions, {
124
- type: 'transferCompleted',
125
- payload: payload
126
- });
127
- (_g = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onTransferFinished) === null || _g === void 0 ? void 0 : _g.call(currentOptions, payload);
128
- return [3 /*break*/, 9];
129
- }
130
- _o.label = 4;
131
- case 4:
132
- {
133
- payload = (_h = event.data) === null || _h === void 0 ? void 0 : _h.payload;
134
- (_j = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onExit) === null || _j === void 0 ? void 0 : _j.call(currentOptions, payload === null || payload === void 0 ? void 0 : payload.errorMessage, payload);
135
- (0, popup_1.removePopup)();
136
- return [3 /*break*/, 9];
137
- }
138
- _o.label = 5;
139
- case 5:
140
- {
141
- if (event.data.link) {
142
- w = 700;
143
- h = 800;
144
- left = screen.width / 2 - w / 2;
145
- top_1 = screen.height / 2 - h / 2;
146
- (_k = window
147
- .open(event.data.link, '_blank', "popup,noopener,noreferrer,resizable,scrollbars,width=".concat(w, ",height=").concat(h, ",top=").concat(top_1, ",left=").concat(left))) === null || _k === void 0 ? void 0 : _k.focus();
148
- }
149
- return [3 /*break*/, 9];
150
- }
151
- _o.label = 6;
152
- case 6:
153
- sendMessageToIframe({
154
- type: 'meshSDKSpecs',
155
- payload: __assign({}, sdk_specs_1.sdkSpecs)
156
- });
157
- if (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.accessTokens) {
158
- sendMessageToIframe({
159
- type: 'frontAccessTokens',
160
- payload: currentOptions.accessTokens
161
- });
162
- }
163
- if (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.transferDestinationTokens) {
164
- sendMessageToIframe({
165
- type: 'frontTransferDestinationTokens',
166
- payload: currentOptions.transferDestinationTokens
167
- });
168
- }
169
- return [4 /*yield*/, (0, wagmiCoreConnectorsUtils_1.getWagmiCoreInjectedData)()];
170
- case 7:
171
- injectedConnectors = _o.sent();
172
- if (injectedConnectors) {
173
- sendMessageToIframe({
174
- type: 'SDKinjectedWagmiConnectorsData',
175
- payload: injectedConnectors
176
- });
177
- }
178
- (_l = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _l === void 0 ? void 0 : _l.call(currentOptions, { type: 'pageLoaded' });
179
- return [3 /*break*/, 9];
180
- case 8:
181
- {
182
- if ((0, event_types_1.isLinkEventTypeKey)(event.data.type)) {
183
- (_m = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _m === void 0 ? void 0 : _m.call(currentOptions, event.data);
184
- }
185
- return [3 /*break*/, 9];
186
- }
187
- _o.label = 9;
188
- case 9: return [2 /*return*/];
189
- }
190
- });
191
- });
192
- }
193
- function handleWalletBrowserEvent(event) {
194
- return __awaiter(this, void 0, void 0, function () {
195
- var _a, payload, result, error_1, payload, result, error_2, payload, result, error_3, payload, result, error_4, payload, result, error_5, payload, result, error_6, payload, result, error_7;
196
- return __generator(this, function (_b) {
197
- switch (_b.label) {
198
- case 0:
199
- _a = event.data.type;
200
- switch (_a) {
201
- case 'walletBrowserInjectedWalletSelected': return [3 /*break*/, 1];
202
- case 'walletBrowserSignRequest': return [3 /*break*/, 6];
203
- case 'walletBrowserChainSwitchRequest': return [3 /*break*/, 11];
204
- case 'walletBrowserNativeTransferRequest': return [3 /*break*/, 16];
205
- case 'walletBrowserNonNativeTransferRequest': return [3 /*break*/, 21];
206
- case 'walletBrowserNativeSmartDeposit': return [3 /*break*/, 26];
207
- case 'walletBrowserNonNativeSmartDeposit': return [3 /*break*/, 31];
208
- case 'walletBrowserDisconnect': return [3 /*break*/, 36];
209
- }
210
- return [3 /*break*/, 37];
211
- case 1:
212
- payload = event.data.payload;
213
- _b.label = 2;
214
- case 2:
215
- _b.trys.push([2, 4, , 5]);
216
- return [4 /*yield*/, (0, wagmiCoreConnectorsUtils_1.connectToSpecificWallet)(payload.integrationName)];
217
- case 3:
218
- result = _b.sent();
219
- if (result instanceof Error) {
220
- throw result;
221
- }
222
- sendMessageToIframe({
223
- type: 'SDKinjectedConnectionCompleted',
224
- payload: {
225
- accounts: result.accounts,
226
- chainId: result.chainId
227
- }
228
- });
229
- return [3 /*break*/, 5];
230
- case 4:
231
- error_1 = _b.sent();
232
- handleErrorAndSendMessage(error_1, 'SDKinjectedConnectionCompleted');
233
- return [3 /*break*/, 5];
234
- case 5: return [3 /*break*/, 37];
235
- case 6:
236
- payload = event.data.payload;
237
- _b.label = 7;
238
- case 7:
239
- _b.trys.push([7, 9, , 10]);
240
- return [4 /*yield*/, (0, wagmiCoreConnectorsUtils_1.signedMessage)(payload.address)];
241
- case 8:
242
- result = _b.sent();
243
- if (result instanceof Error) {
244
- throw result;
245
- }
246
- sendMessageToIframe({
247
- type: 'SDKsignRequestCompleted',
248
- payload: result
249
- });
250
- return [3 /*break*/, 10];
251
- case 9:
252
- error_2 = _b.sent();
253
- handleErrorAndSendMessage(error_2, 'SDKsignRequestCompleted');
254
- return [3 /*break*/, 10];
255
- case 10: return [3 /*break*/, 37];
256
- case 11:
257
- payload = event.data.payload;
258
- _b.label = 12;
259
- case 12:
260
- _b.trys.push([12, 14, , 15]);
261
- return [4 /*yield*/, (0, wagmiCoreConnectorsUtils_1.switchChainFromSDK)(payload.chainId)];
262
- case 13:
263
- result = _b.sent();
264
- if (result instanceof Error) {
265
- throw result;
266
- }
267
- sendMessageToIframe({
268
- type: 'SDKswitchChainCompleted',
269
- payload: result
270
- });
271
- return [3 /*break*/, 15];
272
- case 14:
273
- error_3 = _b.sent();
274
- handleErrorAndSendMessage(error_3, 'SDKswitchChainCompleted');
275
- return [3 /*break*/, 15];
276
- case 15: return [3 /*break*/, 37];
277
- case 16:
278
- payload = event.data.payload;
279
- _b.label = 17;
280
- case 17:
281
- _b.trys.push([17, 19, , 20]);
282
- return [4 /*yield*/, (0, wagmiCoreConnectorsUtils_1.sendTransactionFromSDK)(payload.toAddress, payload.amount, payload.decimalPlaces, payload.chainId, payload.account)];
283
- case 18:
284
- result = _b.sent();
285
- if (result instanceof Error) {
286
- throw result;
287
- }
288
- sendMessageToIframe({
289
- type: 'SDKnativeTransferCompleted',
290
- payload: result
291
- });
292
- return [3 /*break*/, 20];
293
- case 19:
294
- error_4 = _b.sent();
295
- handleErrorAndSendMessage(error_4, 'SDKnativeTransferCompleted');
296
- return [3 /*break*/, 20];
297
- case 20: return [3 /*break*/, 37];
298
- case 21:
299
- payload = event.data.payload;
300
- _b.label = 22;
301
- case 22:
302
- _b.trys.push([22, 24, , 25]);
303
- return [4 /*yield*/, (0, wagmiCoreConnectorsUtils_1.sendNonNativeTransactionFromSDK)(payload.address, JSON.parse(payload.abi), payload.functionName, payload.args)];
304
- case 23:
305
- result = _b.sent();
306
- if (result instanceof Error) {
307
- throw result;
308
- }
309
- sendMessageToIframe({
310
- type: 'SDKnonNativeTransferCompleted',
311
- payload: result
312
- });
313
- return [3 /*break*/, 25];
314
- case 24:
315
- error_5 = _b.sent();
316
- handleErrorAndSendMessage(error_5, 'SDKnonNativeTransferCompleted');
317
- return [3 /*break*/, 25];
318
- case 25: return [3 /*break*/, 37];
319
- case 26:
320
- payload = event.data.payload;
321
- _b.label = 27;
322
- case 27:
323
- _b.trys.push([27, 29, , 30]);
324
- return [4 /*yield*/, (0, wagmiCoreConnectorsUtils_1.sendNonNativeTransactionFromSDK)(payload.address, JSON.parse(payload.abi), payload.functionName, payload.args, payload.value)];
325
- case 28:
326
- result = _b.sent();
327
- if (result instanceof Error) {
328
- throw result;
329
- }
330
- sendMessageToIframe({
331
- type: 'SDKnativeSmartDepositCompleted',
332
- payload: {
333
- txHash: result
334
- }
335
- });
336
- return [3 /*break*/, 30];
337
- case 29:
338
- error_6 = _b.sent();
339
- handleErrorAndSendMessage(error_6, 'SDKnativeSmartDepositCompleted');
340
- return [3 /*break*/, 30];
341
- case 30: return [3 /*break*/, 37];
342
- case 31:
343
- payload = event.data.payload;
344
- _b.label = 32;
345
- case 32:
346
- _b.trys.push([32, 34, , 35]);
347
- return [4 /*yield*/, (0, wagmiCoreConnectorsUtils_1.sendNonNativeTransactionFromSDK)(payload.address, JSON.parse(payload.abi), payload.functionName, payload.args)];
348
- case 33:
349
- result = _b.sent();
350
- if (result) {
351
- sendMessageToIframe({
352
- type: 'SDKnonNativeSmartDepositCompleted',
353
- payload: {
354
- txHash: result
355
- }
356
- });
357
- }
358
- else {
359
- throw new Error('Transfer failed');
360
- }
361
- return [3 /*break*/, 35];
362
- case 34:
363
- error_7 = _b.sent();
364
- handleErrorAndSendMessage(error_7, 'SDKnonNativeSmartDepositCompleted');
365
- return [3 /*break*/, 35];
366
- case 35: return [3 /*break*/, 37];
367
- case 36:
368
- {
369
- (0, wagmiCoreConnectorsUtils_1.disconnectAllAccounts)();
370
- sendMessageToIframe({
371
- type: 'SDKdisconnectSuccess'
372
- });
373
- return [3 /*break*/, 37];
374
- }
375
- _b.label = 37;
376
- case 37: return [2 /*return*/];
377
- }
378
- });
379
- });
380
- }
381
- function eventsListener(event) {
382
- return __awaiter(this, void 0, void 0, function () {
383
- return __generator(this, function (_a) {
384
- switch (_a.label) {
385
- case 0:
386
- if (!(0, wallet_browser_event_types_1.isWalletBrowserEventTypeKey)(event.data.type)) return [3 /*break*/, 2];
387
- return [4 /*yield*/, handleWalletBrowserEvent(event)];
388
- case 1:
389
- _a.sent();
390
- return [3 /*break*/, 4];
391
- case 2: return [4 /*yield*/, handleLinkEvent(event)];
392
- case 3:
393
- _a.sent();
394
- _a.label = 4;
395
- case 4: return [2 /*return*/];
396
- }
397
- });
398
- });
399
- }
400
- function handleErrorAndSendMessage(error, messageType) {
401
- sendMessageToIframe({
402
- type: messageType,
403
- payload: {
404
- error: error
405
- }
406
- });
407
- }
408
- var createLink = function (options) {
409
- var openLink = function (linkToken) { return __awaiter(void 0, void 0, void 0, function () {
410
- var linkUrl, iframeUrlObject;
411
- var _a;
412
- return __generator(this, function (_b) {
413
- if (!linkToken) {
414
- (_a = options === null || options === void 0 ? void 0 : options.onExit) === null || _a === void 0 ? void 0 : _a.call(options, 'Invalid link token!');
415
- return [2 /*return*/];
416
- }
417
- currentOptions = options;
418
- linkUrl = window.atob(linkToken);
419
- iframeUrlObject = new URL(linkUrl);
420
- if (iframeUrlObject.origin) {
421
- possibleOrigins.add(iframeUrlObject.origin);
422
- }
423
- window.removeEventListener('message', eventsListener);
424
- (0, popup_1.addPopup)(linkUrl);
425
- window.addEventListener('message', eventsListener);
426
- return [2 /*return*/];
427
- });
428
- }); };
429
- var closeLink = function () {
430
- var _a;
431
- (0, popup_1.removePopup)();
432
- window.removeEventListener('message', eventsListener);
433
- (_a = options.onExit) === null || _a === void 0 ? void 0 : _a.call(options);
434
- (0, wagmiCoreConnectorsUtils_1.disconnectAllAccounts)();
435
- };
436
- return {
437
- openLink: openLink,
438
- closeLink: closeLink
439
- };
440
- };
441
- exports.createLink = createLink;
package/cjs/index.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createLink = void 0;
18
- __exportStar(require("./utils/types"), exports);
19
- __exportStar(require("./utils/event-types"), exports);
20
- var Link_1 = require("./Link");
21
- Object.defineProperty(exports, "createLink", { enumerable: true, get: function () { return Link_1.createLink; } });
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isLinkEventTypeKey = void 0;
4
- var LINK_EVENT_TYPE_KEYS = [
5
- 'integrationConnected',
6
- 'integrationConnectionError',
7
- 'integrationMfaRequired',
8
- 'integrationMfaEntered',
9
- 'integrationOAuthStarted',
10
- 'integrationAccountSelectionRequired',
11
- 'transferCompleted',
12
- 'integrationSelected',
13
- 'credentialsEntered',
14
- 'transferStarted',
15
- 'transferPreviewed',
16
- 'transferPreviewError',
17
- 'transferExecutionError',
18
- 'pageLoaded',
19
- 'transferAssetSelected',
20
- 'transferNetworkSelected',
21
- 'transferAmountEntered',
22
- 'transferMfaRequired',
23
- 'transferMfaEntered',
24
- 'transferKycRequired',
25
- 'done',
26
- 'close'
27
- ];
28
- function isLinkEventTypeKey(key) {
29
- return LINK_EVENT_TYPE_KEYS.includes(key);
30
- }
31
- exports.isLinkEventTypeKey = isLinkEventTypeKey;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addPopup = exports.removePopup = exports.iframeId = void 0;
4
- var style_1 = require("./style");
5
- var popupId = 'mesh-link-popup';
6
- var backdropId = 'mesh-link-popup__backdrop';
7
- var popupContentId = 'mesh-link-popup__popup-content';
8
- var stylesId = 'mesh-link-popup__styles';
9
- exports.iframeId = 'mesh-link-popup__iframe';
10
- var getPopupHtml = function (link) { return "\n<div id=\"".concat(popupId, "\">\n <div id=\"").concat(backdropId, "\"></div>\n <div id=\"").concat(popupContentId, "\">\n <iframe id=\"").concat(exports.iframeId, "\" src=\"").concat(link, "\" allow=\"clipboard-read *; clipboard-write *\" />\n </div>\n</div>\n"); };
11
- var getStyles = function (style) { return "\n<style id=\"".concat(stylesId, "\">\n body {\n position: fixed;\n left: 0;\n top: 0;\n bottom: 0;\n right: 0;\n overflow: hidden;\n }\n\n #").concat(popupId, " {\n all: unset;\n position: fixed;\n left: 0;\n top: 0;\n bottom: 0;\n right: 0;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n z-index: 10000;\n }\n\n #").concat(backdropId, " {\n position: absolute;\n left: 0;\n top: 0;\n bottom: 0;\n right: 0;\n z-index: 10000;\n background: black;\n opacity: ").concat((0, style_1.getNumber)(0.6, style === null || style === void 0 ? void 0 : style.io), ";\n }\n\n #").concat(popupContentId, " {\n position: absolute;\n height: 80%;\n max-height: 710px;\n min-height: 685px;\n margin: auto;\n z-index: 10001;\n width: 30%;\n max-width: 430px;\n min-width: 380px;\n display: flex;\n flex-direction: column;\n border-radius: ").concat((0, style_1.getNumber)(24, style === null || style === void 0 ? void 0 : style.ir), "px;\n background: white;\n flex-grow: 1;\n }\n\n #").concat(popupContentId, " iframe {\n border: none;\n width: 100%;\n flex-grow: 1;\n border-radius: ").concat((0, style_1.getNumber)(24, style === null || style === void 0 ? void 0 : style.ir), "px;\n }\n\n @media only screen and (max-width: 768px) {\n #").concat(popupContentId, " {\n height: 100vh;\n width: 100vw;\n max-width: 100%;\n min-width: 100%;\n max-height: 100%;\n min-height: 100%;\n border-radius: 0px;\n }\n\n #").concat(popupContentId, " iframe {\n border-radius: 0px;\n }\n }\n\n @media only screen and (max-height: 710px) {\n #").concat(popupContentId, " {\n max-height: 100%;\n min-height: 100%;\n }\n }\n</style>\n"); };
12
- function removePopup() {
13
- var _a, _b;
14
- var existingPopup = window.document.getElementById(popupId);
15
- (_a = existingPopup === null || existingPopup === void 0 ? void 0 : existingPopup.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(existingPopup);
16
- var existingStyles = window.document.getElementById(stylesId);
17
- (_b = existingStyles === null || existingStyles === void 0 ? void 0 : existingStyles.parentElement) === null || _b === void 0 ? void 0 : _b.removeChild(existingStyles);
18
- }
19
- exports.removePopup = removePopup;
20
- function addPopup(iframeLink) {
21
- var style = (0, style_1.getLinkStyle)(iframeLink);
22
- removePopup();
23
- var popup = getPopupHtml(iframeLink);
24
- var stylesElement = htmlToElement(getStyles(style));
25
- if (stylesElement) {
26
- window.document.head.appendChild(stylesElement);
27
- }
28
- var popupElement = htmlToElement(popup);
29
- if (popupElement) {
30
- window.document.body.appendChild(popupElement);
31
- }
32
- }
33
- exports.addPopup = addPopup;
34
- function htmlToElement(html) {
35
- var template = document.createElement('template');
36
- html = html.trim();
37
- template.innerHTML = html;
38
- return template.content.firstChild;
39
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sdkSpecs = void 0;
4
- var version_1 = require("./version");
5
- exports.sdkSpecs = {
6
- platform: 'web',
7
- version: version_1.sdkVersion
8
- };
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNumber = exports.getLinkStyle = void 0;
4
- function getLinkStyle(url) {
5
- try {
6
- var params = new URLSearchParams(new URL(url).search);
7
- var style = params.get('link_style');
8
- return style && JSON.parse(window.atob(style));
9
- }
10
- catch (e) {
11
- return undefined;
12
- }
13
- }
14
- exports.getLinkStyle = getLinkStyle;
15
- function getNumber(def, value) {
16
- return value !== undefined ? value : def;
17
- }
18
- exports.getNumber = getNumber;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sdkVersion = void 0;
4
- exports.sdkVersion = '2.1.0';
@@ -1,407 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.disconnectAllAccounts = exports.sendNonNativeTransactionFromSDK = exports.sendTransactionFromSDK = exports.switchChainFromSDK = exports.walletBalance = exports.signedMessage = exports.connectToSpecificWallet = exports.getWagmiCoreInjectedData = void 0;
49
- var core_1 = require("@wagmi/core");
50
- var connectors_1 = require("@wagmi/connectors");
51
- var viem_1 = require("viem");
52
- var resolveConfigReady;
53
- var configReady = new Promise(function (resolve) {
54
- resolveConfigReady = resolve;
55
- });
56
- var setConfig = function (config) {
57
- try {
58
- var transports = {};
59
- for (var chainId in config.transports) {
60
- var urls = config.transports[chainId];
61
- if (Array.isArray(urls)) {
62
- // If the URL is an array, create a fallback transport with multiple transports
63
- transports[chainId] = (0, core_1.fallback)(urls.map(function (url) { return (0, core_1.http)(url); }));
64
- }
65
- else {
66
- // If the URL is a string, create a single HTTP transport
67
- transports[chainId] = (0, core_1.http)(urls);
68
- }
69
- }
70
- var chainsTuple = __spreadArray([], config.chains, true);
71
- var dynamicConfig = (0, core_1.createConfig)({
72
- chains: chainsTuple,
73
- multiInjectedProviderDiscovery: true,
74
- transports: transports,
75
- connectors: [(0, connectors_1.injected)()]
76
- });
77
- resolveConfigReady(dynamicConfig);
78
- }
79
- catch (error) {
80
- console.error('Error setting configuration:', error);
81
- }
82
- };
83
- window.addEventListener('message', function (event) {
84
- if (event.data.type === 'walletBrowserConfigInitialize') {
85
- try {
86
- var parsedConfig = JSON.parse(event.data.payload);
87
- setConfig(parsedConfig);
88
- }
89
- catch (error) {
90
- console.error('Error parsing configuration:', error);
91
- }
92
- }
93
- });
94
- var configPromise = configReady;
95
- var getWagmiCoreInjectedData = function () { return __awaiter(void 0, void 0, void 0, function () {
96
- return __generator(this, function (_a) {
97
- return [2 /*return*/, withWagmiErrorHandling(function () { return __awaiter(void 0, void 0, void 0, function () {
98
- var config, connectors, mappedConnectors;
99
- return __generator(this, function (_a) {
100
- switch (_a.label) {
101
- case 0: return [4 /*yield*/, configPromise];
102
- case 1:
103
- config = _a.sent();
104
- return [4 /*yield*/, (0, core_1.getConnectors)(config)];
105
- case 2:
106
- connectors = _a.sent();
107
- mappedConnectors = connectors.map(function (_a) {
108
- var id = _a.id, name = _a.name, type = _a.type, uid = _a.uid, icon = _a.icon;
109
- return ({
110
- id: id,
111
- name: name,
112
- type: type,
113
- uid: uid,
114
- icon: icon || undefined
115
- });
116
- });
117
- return [2 /*return*/, mappedConnectors];
118
- }
119
- });
120
- }); })];
121
- });
122
- }); };
123
- exports.getWagmiCoreInjectedData = getWagmiCoreInjectedData;
124
- var connectToSpecificWallet = function (walletName) { return __awaiter(void 0, void 0, void 0, function () {
125
- return __generator(this, function (_a) {
126
- return [2 /*return*/, withWagmiErrorHandling(function () { return __awaiter(void 0, void 0, void 0, function () {
127
- var config, connectors, selectedConnector, result;
128
- return __generator(this, function (_a) {
129
- switch (_a.label) {
130
- case 0: return [4 /*yield*/, configPromise];
131
- case 1:
132
- config = _a.sent();
133
- connectors = (0, core_1.getConnectors)(config);
134
- selectedConnector = connectors.find(function (connector) {
135
- return connector.name.toLowerCase() === walletName.toLowerCase();
136
- });
137
- if (!selectedConnector) {
138
- throw new Error("No connector found for wallet: ".concat(walletName));
139
- }
140
- return [4 /*yield*/, disconnectCurrentAccount(config, selectedConnector)];
141
- case 2:
142
- _a.sent();
143
- return [4 /*yield*/, (0, core_1.connect)(config, { connector: selectedConnector })];
144
- case 3:
145
- result = _a.sent();
146
- return [2 /*return*/, {
147
- accounts: __spreadArray([], result.accounts, true),
148
- chainId: result.chainId
149
- }];
150
- }
151
- });
152
- }); })];
153
- });
154
- }); };
155
- exports.connectToSpecificWallet = connectToSpecificWallet;
156
- var signedMessage = function (address) { return __awaiter(void 0, void 0, void 0, function () {
157
- return __generator(this, function (_a) {
158
- return [2 /*return*/, withWagmiErrorHandling(function () { return __awaiter(void 0, void 0, void 0, function () {
159
- var config, signedMessage;
160
- return __generator(this, function (_a) {
161
- switch (_a.label) {
162
- case 0: return [4 /*yield*/, configPromise];
163
- case 1:
164
- config = _a.sent();
165
- return [4 /*yield*/, (0, core_1.signMessage)(config, {
166
- account: address,
167
- message: 'Sign to verify ownership of wallet'
168
- })];
169
- case 2:
170
- signedMessage = _a.sent();
171
- return [2 /*return*/, signedMessage];
172
- }
173
- });
174
- }); })];
175
- });
176
- }); };
177
- exports.signedMessage = signedMessage;
178
- var walletBalance = function (account, chainId) { return __awaiter(void 0, void 0, void 0, function () {
179
- return __generator(this, function (_a) {
180
- return [2 /*return*/, withWagmiErrorHandling(function () { return __awaiter(void 0, void 0, void 0, function () {
181
- var config, balance;
182
- return __generator(this, function (_a) {
183
- switch (_a.label) {
184
- case 0: return [4 /*yield*/, configPromise];
185
- case 1:
186
- config = _a.sent();
187
- return [4 /*yield*/, (0, core_1.getBalance)(config, {
188
- address: account,
189
- chainId: chainId
190
- })];
191
- case 2:
192
- balance = _a.sent();
193
- return [2 /*return*/, balance];
194
- }
195
- });
196
- }); })];
197
- });
198
- }); };
199
- exports.walletBalance = walletBalance;
200
- var switchChainFromSDK = function (chainId) { return __awaiter(void 0, void 0, void 0, function () {
201
- return __generator(this, function (_a) {
202
- switch (_a.label) {
203
- case 0: return [4 /*yield*/, withWagmiErrorHandling(function () { return __awaiter(void 0, void 0, void 0, function () {
204
- var config, result;
205
- return __generator(this, function (_a) {
206
- switch (_a.label) {
207
- case 0: return [4 /*yield*/, configPromise];
208
- case 1:
209
- config = _a.sent();
210
- return [4 /*yield*/, (0, core_1.switchChain)(config, { chainId: chainId })];
211
- case 2:
212
- result = _a.sent();
213
- return [2 /*return*/, result];
214
- }
215
- });
216
- }); })];
217
- case 1: return [2 /*return*/, _a.sent()];
218
- }
219
- });
220
- }); };
221
- exports.switchChainFromSDK = switchChainFromSDK;
222
- var sendTransactionFromSDK = function (toAddress, amount, decimalPlaces, chainId, account) { return __awaiter(void 0, void 0, void 0, function () {
223
- return __generator(this, function (_a) {
224
- switch (_a.label) {
225
- case 0: return [4 /*yield*/, withWagmiErrorHandling(function () { return __awaiter(void 0, void 0, void 0, function () {
226
- var config, result;
227
- return __generator(this, function (_a) {
228
- switch (_a.label) {
229
- case 0: return [4 /*yield*/, configPromise];
230
- case 1:
231
- config = _a.sent();
232
- return [4 /*yield*/, (0, core_1.sendTransaction)(config, {
233
- to: formatAddress(toAddress),
234
- value: (0, viem_1.parseUnits)(amount.toFixed(decimalPlaces) || '0', decimalPlaces),
235
- chainId: chainId,
236
- account: formatAddress(account)
237
- })];
238
- case 2:
239
- result = _a.sent();
240
- return [2 /*return*/, result];
241
- }
242
- });
243
- }); })];
244
- case 1: return [2 /*return*/, _a.sent()];
245
- }
246
- });
247
- }); };
248
- exports.sendTransactionFromSDK = sendTransactionFromSDK;
249
- var formatAddress = function (address) {
250
- return address.startsWith('0x') ? address : "0x".concat(address);
251
- };
252
- var sendNonNativeTransactionFromSDK = function (address, abi, functionName, args, // eslint-disable-line @typescript-eslint/no-explicit-any
253
- value) { return __awaiter(void 0, void 0, void 0, function () {
254
- return __generator(this, function (_a) {
255
- switch (_a.label) {
256
- case 0: return [4 /*yield*/, withWagmiErrorHandling(function () { return __awaiter(void 0, void 0, void 0, function () {
257
- var config, connector, request, result;
258
- return __generator(this, function (_a) {
259
- switch (_a.label) {
260
- case 0: return [4 /*yield*/, configPromise];
261
- case 1:
262
- config = _a.sent();
263
- return [4 /*yield*/, (0, core_1.getAccount)(config)];
264
- case 2:
265
- connector = (_a.sent()).connector;
266
- return [4 /*yield*/, (0, core_1.simulateContract)(config, {
267
- address: formatAddress(address),
268
- abi: abi,
269
- functionName: functionName,
270
- args: args,
271
- value: value,
272
- connector: connector
273
- })];
274
- case 3:
275
- request = (_a.sent()).request;
276
- return [4 /*yield*/, (0, core_1.writeContract)(config, request)];
277
- case 4:
278
- result = _a.sent();
279
- return [2 /*return*/, result];
280
- }
281
- });
282
- }); })];
283
- case 1: return [2 /*return*/, _a.sent()];
284
- }
285
- });
286
- }); };
287
- exports.sendNonNativeTransactionFromSDK = sendNonNativeTransactionFromSDK;
288
- var disconnectCurrentAccount = function (config, currentConnector) { return __awaiter(void 0, void 0, void 0, function () {
289
- return __generator(this, function (_a) {
290
- switch (_a.label) {
291
- case 0: return [4 /*yield*/, withWagmiErrorHandling(function () { return __awaiter(void 0, void 0, void 0, function () {
292
- return __generator(this, function (_a) {
293
- switch (_a.label) {
294
- case 0: return [4 /*yield*/, (0, core_1.disconnect)(config, { connector: currentConnector })];
295
- case 1:
296
- _a.sent();
297
- return [2 /*return*/];
298
- }
299
- });
300
- }); })];
301
- case 1: return [2 /*return*/, _a.sent()];
302
- }
303
- });
304
- }); };
305
- var disconnectAllAccounts = function () { return __awaiter(void 0, void 0, void 0, function () {
306
- var config;
307
- return __generator(this, function (_a) {
308
- switch (_a.label) {
309
- case 0: return [4 /*yield*/, configPromise];
310
- case 1:
311
- config = _a.sent();
312
- return [2 /*return*/, withWagmiErrorHandling(function () { return __awaiter(void 0, void 0, void 0, function () {
313
- return __generator(this, function (_a) {
314
- switch (_a.label) {
315
- case 0: return [4 /*yield*/, (0, core_1.disconnect)(config)];
316
- case 1:
317
- _a.sent();
318
- return [2 /*return*/];
319
- }
320
- });
321
- }); })];
322
- }
323
- });
324
- }); };
325
- exports.disconnectAllAccounts = disconnectAllAccounts;
326
- /**
327
- * Wrapper function for Wagmi Core functions that handles errors
328
- * @param fn - The function to wrap
329
- * @returns - The result of the function or an error
330
- */
331
- function withWagmiErrorHandling(fn) {
332
- return __awaiter(this, void 0, void 0, function () {
333
- var error_1;
334
- return __generator(this, function (_a) {
335
- switch (_a.label) {
336
- case 0:
337
- _a.trys.push([0, 2, , 3]);
338
- return [4 /*yield*/, fn()];
339
- case 1: return [2 /*return*/, _a.sent()];
340
- case 2:
341
- error_1 = _a.sent();
342
- if (error_1 instanceof core_1.BaseError) {
343
- return [2 /*return*/, handleWagmiError(error_1)];
344
- }
345
- else {
346
- throw error_1;
347
- }
348
- return [3 /*break*/, 3];
349
- case 3: return [2 /*return*/];
350
- }
351
- });
352
- });
353
- }
354
- var handleWagmiError = function (error) {
355
- if (error instanceof core_1.ChainNotConfiguredError) {
356
- return handleChainNotConfiguredError(error);
357
- }
358
- else if (error instanceof core_1.ConnectorAccountNotFoundError) {
359
- return handleConnectorAccountNotFoundError(error);
360
- }
361
- else if (error instanceof core_1.ConnectorAlreadyConnectedError) {
362
- return handleConnectorAlreadyConnectedError(error);
363
- }
364
- else if (error instanceof core_1.ConnectorNotConnectedError) {
365
- return handleConnectorNotConnectedError(error);
366
- }
367
- else if (error instanceof core_1.ConnectorNotFoundError) {
368
- return handleConnectorNotFoundError(error);
369
- }
370
- else if (error instanceof core_1.ProviderNotFoundError) {
371
- return handleProviderNotFoundError(error);
372
- }
373
- else if (error instanceof core_1.SwitchChainNotSupportedError) {
374
- return handleSwitchChainNotSupportedError(error);
375
- }
376
- else if (error instanceof core_1.BaseError) {
377
- return handleBaseError(error);
378
- }
379
- else {
380
- throw error;
381
- }
382
- };
383
- // All errors extend base error
384
- var handleBaseError = function (error) {
385
- throw new Error(error.message);
386
- };
387
- var handleChainNotConfiguredError = function (error) {
388
- throw new Error("Chain not configured: ".concat(error.message));
389
- };
390
- var handleConnectorAccountNotFoundError = function (error) {
391
- throw new Error("Connector account not found: ".concat(error.message));
392
- };
393
- var handleConnectorAlreadyConnectedError = function (error) {
394
- throw new Error("Connector already connected: ".concat(error.message));
395
- };
396
- var handleConnectorNotConnectedError = function (error) {
397
- throw new Error("Connector not connected: ".concat(error.message));
398
- };
399
- var handleConnectorNotFoundError = function (error) {
400
- throw new Error("Connector not found: ".concat(error.message));
401
- };
402
- var handleProviderNotFoundError = function (error) {
403
- throw new Error("Provider not found: ".concat(error.message));
404
- };
405
- var handleSwitchChainNotSupportedError = function (error) {
406
- throw new Error("Switch chain not supported: ".concat(error.message));
407
- };
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isWalletBrowserEventTypeKey = void 0;
4
- var WALLET_BROWSER_EVENT_TYPE_KEYS = [
5
- 'walletBrowserInjectedWalletSelected',
6
- 'walletBrowserSignRequest',
7
- 'walletBrowserChainSwitchRequest',
8
- 'walletBrowserTransferBalanceRequest',
9
- 'walletBrowserNativeTransferRequest',
10
- 'walletBrowserNonNativeTransferRequest',
11
- 'walletBrowserNativeSmartDeposit',
12
- 'walletBrowserNonNativeSmartDeposit',
13
- 'walletBrowserDisconnect'
14
- ];
15
- function isWalletBrowserEventTypeKey(key) {
16
- return WALLET_BROWSER_EVENT_TYPE_KEYS.includes(key);
17
- }
18
- exports.isWalletBrowserEventTypeKey = isWalletBrowserEventTypeKey;