test-ahaan-v2-4 1.0.20 → 1.0.22

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/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var __async = (__this, __arguments, generator) => {
20
30
  return new Promise((resolve, reject) => {
@@ -49,7 +59,7 @@ __export(src_exports, {
49
59
  useTriaTransaction: () => useTriaTransaction
50
60
  });
51
61
  module.exports = __toCommonJS(src_exports);
52
- var import_react7 = require("react");
62
+ var import_react6 = require("react");
53
63
 
54
64
  // src/NavContext.tsx
55
65
  var import_react = require("react");
@@ -164,26 +174,10 @@ var WalletCloseButton_default = WalletCloseButton;
164
174
 
165
175
  // src/index.tsx
166
176
  var import_connect = require("@tria-sdk/connect");
167
-
168
- // src/hooks/usePageVisibilty.tsx
169
- var import_react2 = require("react");
170
- var usePageVisibility = () => {
171
- const [isVisible, setIsVisible] = (0, import_react2.useState)(!document.hidden);
172
- (0, import_react2.useEffect)(() => {
173
- const handleVisibilityChange = () => {
174
- setIsVisible(!document.hidden);
175
- };
176
- document.addEventListener("visibilitychange", handleVisibilityChange);
177
- return () => {
178
- document.removeEventListener("visibilitychange", handleVisibilityChange);
179
- };
180
- }, []);
181
- return isVisible;
182
- };
183
- var usePageVisibilty_default = usePageVisibility;
177
+ var import_react_draggable = __toESM(require("react-draggable"));
184
178
 
185
179
  // src/hooks/useContractWrite.tsx
186
- var import_react3 = require("react");
180
+ var import_react2 = require("react");
187
181
 
188
182
  // src/utils/shared.ts
189
183
  var createEncodedData = (data) => {
@@ -218,9 +212,9 @@ var createIframe = (iframeUrl, hookName) => {
218
212
  // src/hooks/useContractWrite.tsx
219
213
  var authUrl = "https://auth.tria.so";
220
214
  var useContractWrite = (calldata) => {
221
- const [data, setData] = (0, import_react3.useState)("");
222
- const [isLoading, setIsLoading] = (0, import_react3.useState)(false);
223
- const [isError, setIsError] = (0, import_react3.useState)(false);
215
+ const [data, setData] = (0, import_react2.useState)("");
216
+ const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
217
+ const [isError, setIsError] = (0, import_react2.useState)(false);
224
218
  const write = () => {
225
219
  setIsLoading(true);
226
220
  const iframeEncodedData = createEncodedData(calldata);
@@ -229,7 +223,7 @@ var useContractWrite = (calldata) => {
229
223
  setIsLoading(false);
230
224
  return signIframeUrl;
231
225
  };
232
- (0, import_react3.useEffect)(() => {
226
+ (0, import_react2.useEffect)(() => {
233
227
  const detect = (event) => {
234
228
  var _a;
235
229
  console.log("event---------------->", event);
@@ -256,12 +250,12 @@ var useContractWrite = (calldata) => {
256
250
  };
257
251
 
258
252
  // src/hooks/useSendTransaction.tsx
259
- var import_react4 = require("react");
253
+ var import_react3 = require("react");
260
254
  var authUrl2 = "https://auth.tria.so";
261
255
  var useSendTransaction = (calldata) => {
262
- const [data, setData] = (0, import_react4.useState)("");
263
- const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
264
- const [isError, setIsError] = (0, import_react4.useState)(false);
256
+ const [data, setData] = (0, import_react3.useState)("");
257
+ const [isLoading, setIsLoading] = (0, import_react3.useState)(false);
258
+ const [isError, setIsError] = (0, import_react3.useState)(false);
265
259
  const sendTransaction = () => {
266
260
  setIsLoading(true);
267
261
  const iframeEncodedData = createEncodedData(calldata);
@@ -270,7 +264,7 @@ var useSendTransaction = (calldata) => {
270
264
  setIsLoading(false);
271
265
  return signIframeUrl;
272
266
  };
273
- (0, import_react4.useEffect)(() => {
267
+ (0, import_react3.useEffect)(() => {
274
268
  const detect = (event) => {
275
269
  var _a;
276
270
  if (event.origin !== authUrl2)
@@ -296,12 +290,12 @@ var useSendTransaction = (calldata) => {
296
290
  };
297
291
 
298
292
  // src/hooks/useSignMessage.tsx
299
- var import_react5 = require("react");
293
+ var import_react4 = require("react");
300
294
  var authUrl3 = "https://auth.tria.so";
301
295
  var useSignMessage = (calldata) => {
302
- const [data, setData] = (0, import_react5.useState)("");
303
- const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
304
- const [isError, setIsError] = (0, import_react5.useState)(false);
296
+ const [data, setData] = (0, import_react4.useState)("");
297
+ const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
298
+ const [isError, setIsError] = (0, import_react4.useState)(false);
305
299
  const signMessage = () => {
306
300
  setIsLoading(true);
307
301
  const iframeEncodedData = createEncodedData(calldata);
@@ -310,7 +304,7 @@ var useSignMessage = (calldata) => {
310
304
  setIsLoading(false);
311
305
  return signIframeUrl;
312
306
  };
313
- (0, import_react5.useEffect)(() => {
307
+ (0, import_react4.useEffect)(() => {
314
308
  const detect = (event) => {
315
309
  var _a;
316
310
  if (event.origin !== authUrl3)
@@ -337,13 +331,13 @@ var useSignMessage = (calldata) => {
337
331
  };
338
332
 
339
333
  // src/hooks/useContractRead.tsx
340
- var import_react6 = require("react");
334
+ var import_react5 = require("react");
341
335
  var import_ethers = require("ethers");
342
336
  var import_web = require("@tria-sdk/web");
343
337
  var useContractRead = (params) => {
344
- const [data, setData] = (0, import_react6.useState)("");
345
- const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
346
- const [isError, setIsError] = (0, import_react6.useState)(false);
338
+ const [data, setData] = (0, import_react5.useState)("");
339
+ const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
340
+ const [isError, setIsError] = (0, import_react5.useState)(false);
347
341
  const read = () => __async(void 0, null, function* () {
348
342
  try {
349
343
  setIsLoading(true);
@@ -423,61 +417,105 @@ var useTriaTransaction = () => {
423
417
  callContract
424
418
  };
425
419
  };
426
- var TriaConnectProvider = () => {
427
- const [renderAuthIframe, setRenderAuthIframe] = (0, import_react7.useState)(false);
428
- (0, import_react7.useEffect)(() => {
420
+ var TriaConnectProvider = ({ triaStaging = false }) => {
421
+ const [renderAuthIframe, setRenderAuthIframe] = (0, import_react6.useState)(false);
422
+ const [authIframeSrc, setAuthIframeSrc] = (0, import_react6.useState)("");
423
+ (0, import_react6.useEffect)(() => {
429
424
  const getQueryParam = (param) => {
430
425
  return new URLSearchParams(window.location.search).get(param);
431
426
  };
432
427
  const isVerified = getQueryParam("verified") === "true";
433
428
  setRenderAuthIframe(isVerified);
429
+ {
430
+ triaStaging ? setAuthIframeSrc("https://auth-tria.vercel.app/verified") : setAuthIframeSrc("https://auth.tria.so/verified");
431
+ }
434
432
  }, []);
435
433
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: renderAuthIframe && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
436
434
  "iframe",
437
435
  {
438
- src: "https://auth.tria.so/verified",
436
+ src: authIframeSrc,
439
437
  title: "Auth Verification",
440
438
  style: { display: "none" }
441
439
  }
442
440
  ) });
443
441
  };
444
442
  var initialChains = ["POLYGON", "ARBITRUM", "FUSE", "AVALANCHE", "BINANCE", "ETH", "FANTOM", "OPTIMISM"];
445
- var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7", supportedChains = initialChains, defaultChain = "POLYGON" }) => {
446
- const [view, setView] = (0, import_react7.useState)("Home");
447
- const [triaName, setTriaName] = (0, import_react7.useState)();
448
- const [userAddress, setUserAddress] = (0, import_react7.useState)(null);
449
- const [email, setEmail] = (0, import_react7.useState)("");
450
- const [showWallet, setShowWallet] = (0, import_react7.useState)(false);
451
- const [isDarkMode, setIsDarkMode] = (0, import_react7.useState)(true);
452
- const [showOnboarding, setShowOnboarding] = (0, import_react7.useState)(false);
453
- const [appDomain, setAppDomain] = (0, import_react7.useState)();
454
- const [iframeURL, setIframeURL] = (0, import_react7.useState)();
455
- const WALLET_BASE_URL = "https://jade-gingersnap-930e55.netlify.app/";
456
- const [accessToken, setAccessToken] = (0, import_react7.useState)();
457
- const darkMode = true;
458
- const [authIFrameUrl, setAuthIFrameUrl] = (0, import_react7.useState)("");
443
+ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7", supportedChains = initialChains, defaultChain = "POLYGON", darkMode = true, triaStaging = false, buttonPosition = { x: 100, y: 100 } }) => {
444
+ const [view, setView] = (0, import_react6.useState)("Home");
445
+ const [triaName, setTriaName] = (0, import_react6.useState)();
446
+ const [userAddress, setUserAddress] = (0, import_react6.useState)(null);
447
+ const [email, setEmail] = (0, import_react6.useState)("");
448
+ const [showWallet, setShowWallet] = (0, import_react6.useState)(false);
449
+ const [isDarkMode, setIsDarkMode] = (0, import_react6.useState)(true);
450
+ const [showOnboarding, setShowOnboarding] = (0, import_react6.useState)(false);
451
+ const [appDomain, setAppDomain] = (0, import_react6.useState)();
452
+ const [iframeURL, setIframeURL] = (0, import_react6.useState)();
453
+ const [accessToken, setAccessToken] = (0, import_react6.useState)();
454
+ const [authIFrameUrl, setAuthIFrameUrl] = (0, import_react6.useState)("");
459
455
  const { account } = (0, import_connect.useAccount)();
460
- const [stackui, setStackUi] = (0, import_react7.useState)(false);
461
- const [wasOpen, setWasOpen] = (0, import_react7.useState)(false);
462
- const [walletVisible, setWalletVisible] = (0, import_react7.useState)(false);
463
- const isTabVisible = usePageVisibilty_default();
464
- const [isAnimating, setIsAnimating] = (0, import_react7.useState)(false);
465
- (0, import_react7.useEffect)(() => {
466
- if (!isTabVisible && showWallet) {
467
- setShowWallet(false);
468
- setWasOpen(true);
469
- } else if (wasOpen) {
470
- setShowWallet(true);
456
+ const [stackui, setStackUi] = (0, import_react6.useState)(false);
457
+ const [wasOpen, setWasOpen] = (0, import_react6.useState)(false);
458
+ const [coords, setCoords] = (0, import_react6.useState)({ x: 0, y: 0 });
459
+ const [walletVisible, setWalletVisible] = (0, import_react6.useState)(false);
460
+ const [posX, setPosX] = (0, import_react6.useState)();
461
+ const [posY, setPosY] = (0, import_react6.useState)();
462
+ const [buttonPosX, setButtonPosX] = (0, import_react6.useState)(window.innerWidth - ((buttonPosition == null ? void 0 : buttonPosition.x) || 100));
463
+ const [buttonPosY, setButtonPosY] = (0, import_react6.useState)(window.innerHeight - ((buttonPosition == null ? void 0 : buttonPosition.y) || 100));
464
+ const [currentTime, setCurrentTime] = (0, import_react6.useState)();
465
+ (0, import_react6.useEffect)(() => {
466
+ const handleWindowMouseMove = (e) => {
467
+ setCoords({
468
+ x: e.clientX,
469
+ y: e.clientY
470
+ });
471
+ };
472
+ window.addEventListener("mousemove", handleWindowMouseMove);
473
+ return () => {
474
+ window.removeEventListener(
475
+ "mousemove",
476
+ handleWindowMouseMove
477
+ );
478
+ };
479
+ }, []);
480
+ (0, import_react6.useEffect)(() => {
481
+ console.log(buttonPosX, buttonPosY);
482
+ }, [buttonPosX, buttonPosY]);
483
+ const handleStartDragging = () => {
484
+ var now = /* @__PURE__ */ new Date();
485
+ setCurrentTime(now.getTime());
486
+ };
487
+ const handleStopDragging = () => {
488
+ var now = /* @__PURE__ */ new Date();
489
+ console.log(coords);
490
+ console.log(window.innerWidth);
491
+ console.log(window.innerHeight);
492
+ setButtonPosX(coords.x);
493
+ setButtonPosY(coords.y);
494
+ if (window.innerWidth - coords.x < 312 && window.innerHeight - coords.y < 586) {
495
+ setPosX(window.innerWidth - 312);
496
+ setPosY(window.innerHeight - 586);
497
+ } else if (window.innerWidth - coords.x < 312) {
498
+ setPosX(window.innerWidth - 312);
499
+ setPosY(coords.y);
500
+ } else if (window.innerHeight - coords.y < 586) {
501
+ setPosX(coords.x);
502
+ setPosY(window.innerHeight - 586);
503
+ } else {
504
+ setPosX(coords.x);
505
+ setPosY(coords.y);
506
+ }
507
+ if (currentTime && now.getTime() - currentTime < 200) {
508
+ handleWalletButtonClick();
471
509
  }
472
- }, [isTabVisible]);
473
- (0, import_react7.useEffect)(() => {
510
+ };
511
+ (0, import_react6.useEffect)(() => {
474
512
  if (!account && triaName) {
475
513
  console.log("Account is null, reloading the page");
476
514
  localStorage.setItem("hasReloaded", "true");
477
515
  window.location.reload();
478
516
  }
479
517
  }, [account, triaName]);
480
- (0, import_react7.useEffect)(() => {
518
+ (0, import_react6.useEffect)(() => {
481
519
  setInterval(() => {
482
520
  var _a, _b, _c;
483
521
  if (localStorage.getItem("tria.wallet.store") !== null) {
@@ -493,23 +531,26 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
493
531
  }
494
532
  }, 500);
495
533
  }, []);
496
- (0, import_react7.useEffect)(() => {
534
+ (0, import_react6.useEffect)(() => {
497
535
  setInterval(() => {
498
536
  setShowOnboarding(true);
499
537
  }, 1e3);
500
538
  }, []);
501
- (0, import_react7.useEffect)(() => {
539
+ (0, import_react6.useEffect)(() => {
502
540
  const item = localStorage.getItem("access_token");
503
541
  setAccessToken(item || "");
504
542
  setAppDomain(window.parent.origin);
505
543
  }, [triaName]);
506
544
  const fromDapp = true;
507
- (0, import_react7.useEffect)(() => {
545
+ (0, import_react6.useEffect)(() => {
508
546
  const encodedParams = btoa(JSON.stringify({ triaName, userAddress, appDomain, darkMode, logo, accessToken, primaryColor, fromDapp, dappName, defaultChain, supportedChains }));
509
547
  console.log(encodedParams, userAddress, triaName, accessToken, logo, appDomain, darkMode, primaryColor, fromDapp, dappName, defaultChain, supportedChains);
510
- setIframeURL(`https://tria-wallet-git-walllet-responsive-lego-triahq.vercel.app/${encodedParams}`);
548
+ {
549
+ triaStaging ? setIframeURL(`https://staging-tria-wallet.vercel.app/${encodedParams}`) : setIframeURL(`https://wallet.tria.so/${encodedParams}`);
550
+ }
551
+ ;
511
552
  }, [triaName, userAddress]);
512
- (0, import_react7.useEffect)(() => {
553
+ (0, import_react6.useEffect)(() => {
513
554
  console.log("WALLET URL ---->", iframeURL);
514
555
  }, [iframeURL]);
515
556
  const nav_context_object = {
@@ -526,18 +567,21 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
526
567
  email,
527
568
  setEmail
528
569
  };
529
- (0, import_react7.useEffect)(() => {
570
+ (0, import_react6.useEffect)(() => {
530
571
  console.log("log from sdk ----->", dappName, logo);
531
572
  if (dappName && (dappName == null ? void 0 : dappName.length) > 0 && logo && (logo == null ? void 0 : logo.length) > 0) {
532
- setAuthIFrameUrl(`https://auth.tria.so/?dappName=${dappName}&dappLogo=${logo}&stackui=${uiType}&dappDomain=${dappDomain}`);
573
+ {
574
+ triaStaging ? setAuthIFrameUrl(`https://auth-tria.vercel.app/?dappName=${dappName}&dappLogo=${logo}&stackui=${uiType}&dappDomain=${dappDomain}`) : setAuthIFrameUrl(`https://auth.tria.so/?dappName=${dappName}&dappLogo=${logo}&stackui=${uiType}&dappDomain=${dappDomain}`);
575
+ }
576
+ ;
533
577
  }
534
578
  }, [dappName, logo]);
535
- (0, import_react7.useEffect)(() => {
579
+ (0, import_react6.useEffect)(() => {
536
580
  if (uiType === "yes") {
537
581
  setStackUi(true);
538
582
  }
539
583
  }, [uiType]);
540
- (0, import_react7.useEffect)(() => {
584
+ (0, import_react6.useEffect)(() => {
541
585
  const handleClickOutside = (event) => {
542
586
  const iframeElement = document.getElementById("triaWallet");
543
587
  if (iframeElement && !iframeElement.contains(event.target)) {
@@ -549,17 +593,12 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
549
593
  document.removeEventListener("mousedown", handleClickOutside);
550
594
  };
551
595
  }, []);
552
- (0, import_react7.useEffect)(() => {
596
+ (0, import_react6.useEffect)(() => {
553
597
  if (primaryColor) {
554
598
  document.documentElement.style.setProperty("--primary-color", primaryColor);
555
599
  }
556
600
  }, [primaryColor]);
557
601
  const handleWalletButtonClick = () => {
558
- setIsAnimating(true);
559
- setWalletVisible(true);
560
- setTimeout(() => {
561
- setIsAnimating(false);
562
- }, 400);
563
602
  if (showWallet) {
564
603
  setWalletVisible(true);
565
604
  } else {
@@ -567,7 +606,7 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
567
606
  setWalletVisible(true);
568
607
  }
569
608
  };
570
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(NavContext_default.Provider, { value: nav_context_object, children: [
609
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { position: "fixed", zIndex: 9999, height: "100vw", width: "100vh" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(NavContext_default.Provider, { value: nav_context_object, children: [
571
610
  !triaName && showOnboarding && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: {
572
611
  borderRadius: "20px",
573
612
  overflow: "hidden",
@@ -585,16 +624,9 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
585
624
  justifyItems: "space-between",
586
625
  backgroundColor: "transparent",
587
626
  position: "fixed",
588
- zIndex: 9999,
589
- bottom: isAnimating ? "4px" : "4px",
590
- // Start from button position
591
- right: isAnimating ? "60px" : "2px",
592
- opacity: isAnimating ? 0 : 1,
593
- // Start with 0 opacity and animate to 1
594
- transformOrigin: "bottom right",
595
- transform: isAnimating ? "scale(0.5)" : "scale(1)",
596
- // Start smaller and animate to full size
597
- transition: "all 1s ease"
627
+ top: posY,
628
+ left: posX,
629
+ zIndex: 9999
598
630
  },
599
631
  children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
600
632
  "div",
@@ -654,21 +686,35 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
654
686
  }
655
687
  ),
656
688
  triaName && !walletVisible && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
657
- "div",
689
+ import_react_draggable.default,
658
690
  {
659
- style: {
660
- position: "fixed",
661
- maxWidth: "80px",
662
- width: "auto",
663
- bottom: "4px",
664
- right: "60px",
665
- cursor: "pointer",
666
- marginTop: "25px",
667
- height: "150px",
668
- zIndex: 9999
669
- },
670
- onClick: handleWalletButtonClick,
671
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TriaWalletButton, { bgColor: primaryColor || "#A855F7", stackui })
691
+ defaultPosition: { x: buttonPosX, y: buttonPosY },
692
+ onStart: handleStartDragging,
693
+ onStop: handleStopDragging,
694
+ bounds: { top: 0, left: 0 },
695
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
696
+ "div",
697
+ {
698
+ style: {
699
+ // display: 'flex',
700
+ // position: 'fixed',
701
+ // cursor:'move',
702
+ // flexDirection: 'row',
703
+ // justifyContent: 'center',
704
+ // alignItems: 'center',
705
+ // height: '60px',
706
+ // width: '60px',
707
+ // borderRadius: '100%',
708
+ // background: '#FFFFFF',
709
+ // boxShadow: isPressed ? '0 0 10px 0 rgba(0,0,0,0.2)' : '0 0 20px 0 rgba(0,0,0,0.25)',
710
+ // transform: isPressed ? 'scale(0.80)' : 'scale(1)',
711
+ // transition: 'all 0.1s ease',
712
+ cursor: "pointer",
713
+ zIndex: "9999"
714
+ },
715
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TriaWalletButton, { bgColor: primaryColor || "#A855F7", stackui })
716
+ }
717
+ )
672
718
  }
673
719
  )
674
720
  ] }) });