test-ahaan-v2-4 1.0.15 → 1.0.16

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,60 +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
- (0, import_react7.useEffect)(() => {
465
- if (!isTabVisible && showWallet) {
466
- setShowWallet(false);
467
- setWasOpen(true);
468
- } else if (wasOpen) {
469
- 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);
470
506
  }
471
- }, [isTabVisible]);
472
- (0, import_react7.useEffect)(() => {
507
+ if (currentTime && now.getTime() - currentTime < 200) {
508
+ handleWalletButtonClick();
509
+ }
510
+ };
511
+ (0, import_react6.useEffect)(() => {
473
512
  if (!account && triaName) {
474
513
  console.log("Account is null, reloading the page");
475
514
  localStorage.setItem("hasReloaded", "true");
476
515
  window.location.reload();
477
516
  }
478
517
  }, [account, triaName]);
479
- (0, import_react7.useEffect)(() => {
518
+ (0, import_react6.useEffect)(() => {
480
519
  setInterval(() => {
481
520
  var _a, _b, _c;
482
521
  if (localStorage.getItem("tria.wallet.store") !== null) {
@@ -492,23 +531,26 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
492
531
  }
493
532
  }, 500);
494
533
  }, []);
495
- (0, import_react7.useEffect)(() => {
534
+ (0, import_react6.useEffect)(() => {
496
535
  setInterval(() => {
497
536
  setShowOnboarding(true);
498
537
  }, 1e3);
499
538
  }, []);
500
- (0, import_react7.useEffect)(() => {
539
+ (0, import_react6.useEffect)(() => {
501
540
  const item = localStorage.getItem("access_token");
502
541
  setAccessToken(item || "");
503
542
  setAppDomain(window.parent.origin);
504
543
  }, [triaName]);
505
544
  const fromDapp = true;
506
- (0, import_react7.useEffect)(() => {
545
+ (0, import_react6.useEffect)(() => {
507
546
  const encodedParams = btoa(JSON.stringify({ triaName, userAddress, appDomain, darkMode, logo, accessToken, primaryColor, fromDapp, dappName, defaultChain, supportedChains }));
508
547
  console.log(encodedParams, userAddress, triaName, accessToken, logo, appDomain, darkMode, primaryColor, fromDapp, dappName, defaultChain, supportedChains);
509
- 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
+ ;
510
552
  }, [triaName, userAddress]);
511
- (0, import_react7.useEffect)(() => {
553
+ (0, import_react6.useEffect)(() => {
512
554
  console.log("WALLET URL ---->", iframeURL);
513
555
  }, [iframeURL]);
514
556
  const nav_context_object = {
@@ -525,18 +567,21 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
525
567
  email,
526
568
  setEmail
527
569
  };
528
- (0, import_react7.useEffect)(() => {
570
+ (0, import_react6.useEffect)(() => {
529
571
  console.log("log from sdk ----->", dappName, logo);
530
572
  if (dappName && (dappName == null ? void 0 : dappName.length) > 0 && logo && (logo == null ? void 0 : logo.length) > 0) {
531
- 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
+ ;
532
577
  }
533
578
  }, [dappName, logo]);
534
- (0, import_react7.useEffect)(() => {
579
+ (0, import_react6.useEffect)(() => {
535
580
  if (uiType === "yes") {
536
581
  setStackUi(true);
537
582
  }
538
583
  }, [uiType]);
539
- (0, import_react7.useEffect)(() => {
584
+ (0, import_react6.useEffect)(() => {
540
585
  const handleClickOutside = (event) => {
541
586
  const iframeElement = document.getElementById("triaWallet");
542
587
  if (iframeElement && !iframeElement.contains(event.target)) {
@@ -548,7 +593,7 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
548
593
  document.removeEventListener("mousedown", handleClickOutside);
549
594
  };
550
595
  }, []);
551
- (0, import_react7.useEffect)(() => {
596
+ (0, import_react6.useEffect)(() => {
552
597
  if (primaryColor) {
553
598
  document.documentElement.style.setProperty("--primary-color", primaryColor);
554
599
  }
@@ -561,7 +606,7 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
561
606
  setWalletVisible(true);
562
607
  }
563
608
  };
564
- 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", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(NavContext_default.Provider, { value: nav_context_object, children: [
565
610
  !triaName && showOnboarding && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: {
566
611
  borderRadius: "20px",
567
612
  overflow: "hidden",
@@ -574,7 +619,15 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
574
619
  "div",
575
620
  {
576
621
  id: "triaWallet",
577
- style: { display: walletVisible ? "block" : "none", justifyItems: "space-between", backgroundColor: "transparent", position: "fixed", bottom: "4px", right: "2px", zIndex: 9999 },
622
+ style: {
623
+ display: walletVisible ? "block" : "none",
624
+ justifyItems: "space-between",
625
+ backgroundColor: "transparent",
626
+ position: "fixed",
627
+ top: posY,
628
+ left: posX,
629
+ zIndex: 9999
630
+ },
578
631
  children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
579
632
  "div",
580
633
  {
@@ -607,10 +660,8 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
607
660
  "div",
608
661
  {
609
662
  style: {
610
- height: "60vh",
611
- width: "32vh",
612
- minHeight: "586px",
613
- minWidth: "312px",
663
+ height: "586px",
664
+ width: "312px",
614
665
  borderRadius: "20px",
615
666
  overflow: "hidden",
616
667
  backgroundColor: "#101010"
@@ -635,21 +686,34 @@ var Application = ({ dappName, dappDomain, uiType, logo, primaryColor = "#A855F7
635
686
  }
636
687
  ),
637
688
  triaName && !walletVisible && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
638
- "div",
689
+ import_react_draggable.default,
639
690
  {
640
- style: {
641
- position: "fixed",
642
- maxWidth: "80px",
643
- width: "auto",
644
- bottom: "4px",
645
- right: "60px",
646
- cursor: "pointer",
647
- marginTop: "25px",
648
- height: "150px",
649
- zIndex: 9999
650
- },
651
- onClick: handleWalletButtonClick,
652
- 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
+ // cursor:'move',
701
+ flexDirection: "row",
702
+ justifyContent: "center",
703
+ alignItems: "center",
704
+ height: "60px",
705
+ width: "60px",
706
+ borderRadius: "100%",
707
+ background: "#FFFFFF",
708
+ // boxShadow: isPressed ? '0 0 10px 0 rgba(0,0,0,0.2)' : '0 0 20px 0 rgba(0,0,0,0.25)',
709
+ // transform: isPressed ? 'scale(0.80)' : 'scale(1)',
710
+ transition: "all 0.1s ease",
711
+ cursor: "pointer",
712
+ zIndex: "9999"
713
+ },
714
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TriaWalletButton, { bgColor: primaryColor || "#A855F7", stackui })
715
+ }
716
+ )
653
717
  }
654
718
  )
655
719
  ] }) });