@tonconnect/ui 2.2.0-beta.0 → 2.3.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs CHANGED
@@ -18,6 +18,18 @@ var __spreadValues = (a2, b) => {
18
18
  return a2;
19
19
  };
20
20
  var __spreadProps = (a2, b) => __defProps(a2, __getOwnPropDescs(b));
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
21
33
  var __publicField = (obj, key, value) => {
22
34
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
23
35
  return value;
@@ -1825,8 +1837,10 @@ function fixMobileSafariActiveTransition() {
1825
1837
  }
1826
1838
  }
1827
1839
  function defineStylesRoot() {
1828
- customElements.define(globalStylesTag, class TcRootElement extends HTMLElement {
1829
- });
1840
+ if (!customElements.get("tc-root")) {
1841
+ customElements.define(globalStylesTag, class TcRootElement extends HTMLElement {
1842
+ });
1843
+ }
1830
1844
  }
1831
1845
  function createMacrotask(callback) {
1832
1846
  return __async(this, null, function* () {
@@ -3034,6 +3048,7 @@ function useDataAttributes(props) {
3034
3048
  const Button = (props) => {
3035
3049
  const dataAttrs = useDataAttributes(props);
3036
3050
  return createComponent(ButtonStyled$1, mergeProps({
3051
+ type: "button",
3037
3052
  get appearance() {
3038
3053
  return props.appearance || "primary";
3039
3054
  },
@@ -4915,16 +4930,16 @@ var qrcode$1 = { exports: {} };
4915
4930
  };
4916
4931
  return _this;
4917
4932
  }();
4918
- function qrPolynomial(num, shift) {
4933
+ function qrPolynomial(num, shift2) {
4919
4934
  if (typeof num.length == "undefined") {
4920
- throw num.length + "/" + shift;
4935
+ throw num.length + "/" + shift2;
4921
4936
  }
4922
4937
  var _num = function() {
4923
4938
  var offset = 0;
4924
4939
  while (offset < num.length && num[offset] == 0) {
4925
4940
  offset += 1;
4926
4941
  }
4927
- var _num2 = new Array(num.length - offset + shift);
4942
+ var _num2 = new Array(num.length - offset + shift2);
4928
4943
  for (var i2 = 0; i2 < num.length - offset; i2 += 1) {
4929
4944
  _num2[i2] = num[i2 + offset];
4930
4945
  }
@@ -7465,6 +7480,22 @@ const computePosition$1 = (reference, floating, config) => __async(exports, null
7465
7480
  middlewareData
7466
7481
  };
7467
7482
  });
7483
+ function expandPaddingObject(padding) {
7484
+ return __spreadValues({
7485
+ top: 0,
7486
+ right: 0,
7487
+ bottom: 0,
7488
+ left: 0
7489
+ }, padding);
7490
+ }
7491
+ function getSideObjectFromPadding(padding) {
7492
+ return typeof padding !== "number" ? expandPaddingObject(padding) : {
7493
+ top: padding,
7494
+ right: padding,
7495
+ bottom: padding,
7496
+ left: padding
7497
+ };
7498
+ }
7468
7499
  function rectToClientRect(rect) {
7469
7500
  return __spreadProps(__spreadValues({}, rect), {
7470
7501
  top: rect.y,
@@ -7473,6 +7504,270 @@ function rectToClientRect(rect) {
7473
7504
  bottom: rect.y + rect.height
7474
7505
  });
7475
7506
  }
7507
+ function detectOverflow(middlewareArguments, options) {
7508
+ return __async(this, null, function* () {
7509
+ var _await$platform$isEle;
7510
+ if (options === void 0) {
7511
+ options = {};
7512
+ }
7513
+ const {
7514
+ x,
7515
+ y,
7516
+ platform: platform2,
7517
+ rects,
7518
+ elements,
7519
+ strategy
7520
+ } = middlewareArguments;
7521
+ const {
7522
+ boundary = "clippingAncestors",
7523
+ rootBoundary = "viewport",
7524
+ elementContext = "floating",
7525
+ altBoundary = false,
7526
+ padding = 0
7527
+ } = options;
7528
+ const paddingObject = getSideObjectFromPadding(padding);
7529
+ const altContext = elementContext === "floating" ? "reference" : "floating";
7530
+ const element = elements[altBoundary ? altContext : elementContext];
7531
+ const clippingClientRect = rectToClientRect(yield platform2.getClippingRect({
7532
+ element: ((_await$platform$isEle = yield platform2.isElement == null ? void 0 : platform2.isElement(element)) != null ? _await$platform$isEle : true) ? element : element.contextElement || (yield platform2.getDocumentElement == null ? void 0 : platform2.getDocumentElement(elements.floating)),
7533
+ boundary,
7534
+ rootBoundary,
7535
+ strategy
7536
+ }));
7537
+ const rect = elementContext === "floating" ? __spreadProps(__spreadValues({}, rects.floating), {
7538
+ x,
7539
+ y
7540
+ }) : rects.reference;
7541
+ const offsetParent = yield platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating);
7542
+ const offsetScale = (yield platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? (yield platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
7543
+ x: 1,
7544
+ y: 1
7545
+ } : {
7546
+ x: 1,
7547
+ y: 1
7548
+ };
7549
+ const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? yield platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
7550
+ rect,
7551
+ offsetParent,
7552
+ strategy
7553
+ }) : rect);
7554
+ return {
7555
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
7556
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
7557
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
7558
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
7559
+ };
7560
+ });
7561
+ }
7562
+ const min$1 = Math.min;
7563
+ const max$1 = Math.max;
7564
+ function within(min$1$1, value, max$1$1) {
7565
+ return max$1(min$1$1, min$1(value, max$1$1));
7566
+ }
7567
+ const hash$1 = {
7568
+ left: "right",
7569
+ right: "left",
7570
+ bottom: "top",
7571
+ top: "bottom"
7572
+ };
7573
+ function getOppositePlacement(placement) {
7574
+ return placement.replace(/left|right|bottom|top/g, (matched) => hash$1[matched]);
7575
+ }
7576
+ function getAlignmentSides(placement, rects, rtl) {
7577
+ if (rtl === void 0) {
7578
+ rtl = false;
7579
+ }
7580
+ const alignment = getAlignment(placement);
7581
+ const mainAxis = getMainAxisFromPlacement(placement);
7582
+ const length = getLengthFromAxis(mainAxis);
7583
+ let mainAlignmentSide = mainAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
7584
+ if (rects.reference[length] > rects.floating[length]) {
7585
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
7586
+ }
7587
+ return {
7588
+ main: mainAlignmentSide,
7589
+ cross: getOppositePlacement(mainAlignmentSide)
7590
+ };
7591
+ }
7592
+ const hash = {
7593
+ start: "end",
7594
+ end: "start"
7595
+ };
7596
+ function getOppositeAlignmentPlacement(placement) {
7597
+ return placement.replace(/start|end/g, (matched) => hash[matched]);
7598
+ }
7599
+ function getExpandedPlacements(placement) {
7600
+ const oppositePlacement = getOppositePlacement(placement);
7601
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
7602
+ }
7603
+ const flip = function(options) {
7604
+ if (options === void 0) {
7605
+ options = {};
7606
+ }
7607
+ return {
7608
+ name: "flip",
7609
+ options,
7610
+ fn(middlewareArguments) {
7611
+ return __async(this, null, function* () {
7612
+ var _middlewareData$flip;
7613
+ const {
7614
+ placement,
7615
+ middlewareData,
7616
+ rects,
7617
+ initialPlacement,
7618
+ platform: platform2,
7619
+ elements
7620
+ } = middlewareArguments;
7621
+ const _a3 = options, {
7622
+ mainAxis: checkMainAxis = true,
7623
+ crossAxis: checkCrossAxis = true,
7624
+ fallbackPlacements: specifiedFallbackPlacements,
7625
+ fallbackStrategy = "bestFit",
7626
+ flipAlignment = true
7627
+ } = _a3, detectOverflowOptions = __objRest(_a3, [
7628
+ "mainAxis",
7629
+ "crossAxis",
7630
+ "fallbackPlacements",
7631
+ "fallbackStrategy",
7632
+ "flipAlignment"
7633
+ ]);
7634
+ const side = getSide(placement);
7635
+ const isBasePlacement = side === initialPlacement;
7636
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
7637
+ const placements = [initialPlacement, ...fallbackPlacements];
7638
+ const overflow = yield detectOverflow(middlewareArguments, detectOverflowOptions);
7639
+ const overflows = [];
7640
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
7641
+ if (checkMainAxis) {
7642
+ overflows.push(overflow[side]);
7643
+ }
7644
+ if (checkCrossAxis) {
7645
+ const {
7646
+ main,
7647
+ cross
7648
+ } = getAlignmentSides(placement, rects, yield platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
7649
+ overflows.push(overflow[main], overflow[cross]);
7650
+ }
7651
+ overflowsData = [...overflowsData, {
7652
+ placement,
7653
+ overflows
7654
+ }];
7655
+ if (!overflows.every((side2) => side2 <= 0)) {
7656
+ var _middlewareData$flip$, _middlewareData$flip2;
7657
+ const nextIndex = ((_middlewareData$flip$ = (_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) != null ? _middlewareData$flip$ : 0) + 1;
7658
+ const nextPlacement = placements[nextIndex];
7659
+ if (nextPlacement) {
7660
+ return {
7661
+ data: {
7662
+ index: nextIndex,
7663
+ overflows: overflowsData
7664
+ },
7665
+ reset: {
7666
+ placement: nextPlacement
7667
+ }
7668
+ };
7669
+ }
7670
+ let resetPlacement = "bottom";
7671
+ switch (fallbackStrategy) {
7672
+ case "bestFit": {
7673
+ var _overflowsData$map$so;
7674
+ const placement2 = (_overflowsData$map$so = overflowsData.map((d) => [d, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a2, b) => a2[1] - b[1])[0]) == null ? void 0 : _overflowsData$map$so[0].placement;
7675
+ if (placement2) {
7676
+ resetPlacement = placement2;
7677
+ }
7678
+ break;
7679
+ }
7680
+ case "initialPlacement":
7681
+ resetPlacement = initialPlacement;
7682
+ break;
7683
+ }
7684
+ if (placement !== resetPlacement) {
7685
+ return {
7686
+ reset: {
7687
+ placement: resetPlacement
7688
+ }
7689
+ };
7690
+ }
7691
+ }
7692
+ return {};
7693
+ });
7694
+ }
7695
+ };
7696
+ };
7697
+ function getCrossAxis(axis) {
7698
+ return axis === "x" ? "y" : "x";
7699
+ }
7700
+ const shift = function(options) {
7701
+ if (options === void 0) {
7702
+ options = {};
7703
+ }
7704
+ return {
7705
+ name: "shift",
7706
+ options,
7707
+ fn(middlewareArguments) {
7708
+ return __async(this, null, function* () {
7709
+ const {
7710
+ x,
7711
+ y,
7712
+ placement
7713
+ } = middlewareArguments;
7714
+ const _a3 = options, {
7715
+ mainAxis: checkMainAxis = true,
7716
+ crossAxis: checkCrossAxis = false,
7717
+ limiter = {
7718
+ fn: (_ref) => {
7719
+ let {
7720
+ x: x2,
7721
+ y: y2
7722
+ } = _ref;
7723
+ return {
7724
+ x: x2,
7725
+ y: y2
7726
+ };
7727
+ }
7728
+ }
7729
+ } = _a3, detectOverflowOptions = __objRest(_a3, [
7730
+ "mainAxis",
7731
+ "crossAxis",
7732
+ "limiter"
7733
+ ]);
7734
+ const coords = {
7735
+ x,
7736
+ y
7737
+ };
7738
+ const overflow = yield detectOverflow(middlewareArguments, detectOverflowOptions);
7739
+ const mainAxis = getMainAxisFromPlacement(getSide(placement));
7740
+ const crossAxis = getCrossAxis(mainAxis);
7741
+ let mainAxisCoord = coords[mainAxis];
7742
+ let crossAxisCoord = coords[crossAxis];
7743
+ if (checkMainAxis) {
7744
+ const minSide = mainAxis === "y" ? "top" : "left";
7745
+ const maxSide = mainAxis === "y" ? "bottom" : "right";
7746
+ const min2 = mainAxisCoord + overflow[minSide];
7747
+ const max2 = mainAxisCoord - overflow[maxSide];
7748
+ mainAxisCoord = within(min2, mainAxisCoord, max2);
7749
+ }
7750
+ if (checkCrossAxis) {
7751
+ const minSide = crossAxis === "y" ? "top" : "left";
7752
+ const maxSide = crossAxis === "y" ? "bottom" : "right";
7753
+ const min2 = crossAxisCoord + overflow[minSide];
7754
+ const max2 = crossAxisCoord - overflow[maxSide];
7755
+ crossAxisCoord = within(min2, crossAxisCoord, max2);
7756
+ }
7757
+ const limitedCoords = limiter.fn(__spreadProps(__spreadValues({}, middlewareArguments), {
7758
+ [mainAxis]: mainAxisCoord,
7759
+ [crossAxis]: crossAxisCoord
7760
+ }));
7761
+ return __spreadProps(__spreadValues({}, limitedCoords), {
7762
+ data: {
7763
+ x: limitedCoords.x - x,
7764
+ y: limitedCoords.y - y
7765
+ }
7766
+ });
7767
+ });
7768
+ }
7769
+ };
7770
+ };
7476
7771
  function getWindow(node) {
7477
7772
  var _node$ownerDocument;
7478
7773
  return ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
@@ -8055,7 +8350,8 @@ const AccountButton = () => {
8055
8350
  const [anchor, setAnchor] = createSignal();
8056
8351
  const position = P(anchor, floating, {
8057
8352
  whileElementsMounted: autoUpdate,
8058
- placement: "bottom-end"
8353
+ placement: "bottom-end",
8354
+ middleware: [flip(), shift()]
8059
8355
  });
8060
8356
  const normalizedAddress = () => {
8061
8357
  const acc = account();
@@ -11370,9 +11666,13 @@ const ActionModal = (props) => {
11370
11666
  const tonConnectUI = useContext(TonConnectUiContext);
11371
11667
  const [firstClick, setFirstClick] = createSignal(true);
11372
11668
  const [sent, setSent] = createSignal(false);
11669
+ const [signed, setSigned] = createSignal(false);
11670
+ const [canceled, setCanceled] = createSignal(false);
11373
11671
  createEffect(() => {
11374
11672
  const currentAction = action();
11375
- setSent(!!currentAction && "sent" in currentAction && currentAction.sent);
11673
+ setSent(!!currentAction && ("sent" in currentAction && currentAction.sent || currentAction.name === "transaction-sent"));
11674
+ setSigned(!!currentAction && ("signed" in currentAction && currentAction.signed || currentAction.name === "data-signed"));
11675
+ setCanceled(!!currentAction && (currentAction.name === "transaction-canceled" || currentAction.name === "sign-data-canceled"));
11376
11676
  });
11377
11677
  let universalLink;
11378
11678
  if ((tonConnectUI == null ? void 0 : tonConnectUI.wallet) && "universalLink" in tonConnectUI.wallet && (tonConnectUI.wallet.openMethod === "universal-link" || sdk.isTelegramUrl(tonConnectUI.wallet.universalLink) && isInTMA())) {
@@ -11419,7 +11719,7 @@ const ActionModal = (props) => {
11419
11719
  }
11420
11720
  }), createComponent(Show, {
11421
11721
  get when() {
11422
- return !sent() && (props.showButton === "open-wallet" && universalLink || props.showButton !== "open-wallet");
11722
+ return !sent() && !signed() && !canceled() && (props.showButton === "open-wallet" && universalLink || props.showButton !== "open-wallet");
11423
11723
  },
11424
11724
  get children() {
11425
11725
  return createComponent(LoaderButtonStyled, {
@@ -11432,7 +11732,7 @@ const ActionModal = (props) => {
11432
11732
  }
11433
11733
  }), createComponent(Show, {
11434
11734
  get when() {
11435
- return sent();
11735
+ return sent() || signed();
11436
11736
  },
11437
11737
  get children() {
11438
11738
  return [createComponent(Show, {
@@ -11515,6 +11815,7 @@ const TransactionSentModal = (props) => {
11515
11815
  size: "m"
11516
11816
  });
11517
11817
  },
11818
+ showButton: "open-wallet",
11518
11819
  onClose: () => props.onClose(),
11519
11820
  "data-tc-transaction-sent-modal": "true"
11520
11821
  });
@@ -12152,7 +12453,7 @@ class TonConnectUITracker {
12152
12453
  }
12153
12454
  }
12154
12455
  }
12155
- const tonConnectUiVersion = "2.2.0-beta.0";
12456
+ const tonConnectUiVersion = "2.3.0-beta.0";
12156
12457
  class TonConnectUI {
12157
12458
  constructor(options) {
12158
12459
  __publicField(this, "walletInfoStorage", new WalletInfoStorage());
@@ -12388,6 +12689,7 @@ class TonConnectUI {
12388
12689
  });
12389
12690
  const abortController = new AbortController();
12390
12691
  const onRequestSent = () => {
12692
+ var _a2;
12391
12693
  if (abortController.signal.aborted) {
12392
12694
  return;
12393
12695
  }
@@ -12401,6 +12703,20 @@ class TonConnectUI {
12401
12703
  returnStrategy,
12402
12704
  twaReturnUrl
12403
12705
  });
12706
+ let firstClick = true;
12707
+ const redirectToWallet2 = () => {
12708
+ if (abortController.signal.aborted) {
12709
+ return;
12710
+ }
12711
+ const forceRedirect = !firstClick;
12712
+ firstClick = false;
12713
+ this.redirectAfterRequestSent({
12714
+ returnStrategy,
12715
+ twaReturnUrl,
12716
+ forceRedirect
12717
+ });
12718
+ };
12719
+ (_a2 = options == null ? void 0 : options.onRequestSent) == null ? void 0 : _a2.call(options, redirectToWallet2);
12404
12720
  };
12405
12721
  const unsubscribe = this.onTransactionModalStateChange((action2) => {
12406
12722
  if (action2 == null ? void 0 : action2.openModal) {
@@ -12448,7 +12764,7 @@ class TonConnectUI {
12448
12764
  }
12449
12765
  });
12450
12766
  }
12451
- signData(data) {
12767
+ signData(data, options) {
12452
12768
  return __async(this, null, function* () {
12453
12769
  this.tracker.trackDataSentForSignature(this.wallet, data);
12454
12770
  if (!this.connected) {
@@ -12467,6 +12783,7 @@ class TonConnectUI {
12467
12783
  });
12468
12784
  const abortController = new AbortController();
12469
12785
  const onRequestSent = () => {
12786
+ var _a2;
12470
12787
  if (abortController.signal.aborted) {
12471
12788
  return;
12472
12789
  }
@@ -12480,6 +12797,20 @@ class TonConnectUI {
12480
12797
  returnStrategy,
12481
12798
  twaReturnUrl
12482
12799
  });
12800
+ let firstClick = true;
12801
+ const redirectToWallet2 = () => {
12802
+ if (abortController.signal.aborted) {
12803
+ return;
12804
+ }
12805
+ const forceRedirect = !firstClick;
12806
+ firstClick = false;
12807
+ this.redirectAfterRequestSent({
12808
+ returnStrategy,
12809
+ twaReturnUrl,
12810
+ forceRedirect
12811
+ });
12812
+ };
12813
+ (_a2 = options == null ? void 0 : options.onRequestSent) == null ? void 0 : _a2.call(options, redirectToWallet2);
12483
12814
  };
12484
12815
  const unsubscribe = this.onTransactionModalStateChange((action2) => {
12485
12816
  if (action2 == null ? void 0 : action2.openModal) {
@@ -12529,14 +12860,15 @@ class TonConnectUI {
12529
12860
  }
12530
12861
  redirectAfterRequestSent({
12531
12862
  returnStrategy,
12532
- twaReturnUrl
12863
+ twaReturnUrl,
12864
+ forceRedirect
12533
12865
  }) {
12534
12866
  if (this.walletInfo && "universalLink" in this.walletInfo && (this.walletInfo.openMethod === "universal-link" || this.walletInfo.openMethod === "custom-deeplink")) {
12535
12867
  if (sdk.isTelegramUrl(this.walletInfo.universalLink)) {
12536
12868
  redirectToTelegram(this.walletInfo.universalLink, {
12537
12869
  returnStrategy,
12538
12870
  twaReturnUrl: twaReturnUrl || appState.twaReturnUrl,
12539
- forceRedirect: false
12871
+ forceRedirect: forceRedirect || false
12540
12872
  });
12541
12873
  } else {
12542
12874
  redirectToWallet(
@@ -12544,7 +12876,7 @@ class TonConnectUI {
12544
12876
  this.walletInfo.deepLink,
12545
12877
  {
12546
12878
  returnStrategy,
12547
- forceRedirect: false
12879
+ forceRedirect: forceRedirect || false
12548
12880
  },
12549
12881
  () => {
12550
12882
  }