@tonconnect/ui 2.0.1-beta.3 → 2.0.1-beta.5

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
@@ -1874,11 +1874,15 @@ function isNodeJs() {
1874
1874
  return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1875
1875
  }
1876
1876
  function getUserAgent() {
1877
- var _a2, _b2;
1877
+ var _a2, _b2, _c2;
1878
1878
  const results = new UAParser__default.default().getResult();
1879
1879
  const osName = (_a2 = results.os.name) == null ? void 0 : _a2.toLowerCase();
1880
+ const deviceModel = (_b2 = results.device.model) == null ? void 0 : _b2.toLowerCase();
1880
1881
  let os;
1881
1882
  switch (true) {
1883
+ case deviceModel === "ipad":
1884
+ os = "ipad";
1885
+ break;
1882
1886
  case osName === "ios":
1883
1887
  os = "ios";
1884
1888
  break;
@@ -1895,7 +1899,7 @@ function getUserAgent() {
1895
1899
  os = "windows";
1896
1900
  break;
1897
1901
  }
1898
- const browserName = (_b2 = results.browser.name) == null ? void 0 : _b2.toLowerCase();
1902
+ const browserName = (_c2 = results.browser.name) == null ? void 0 : _c2.toLowerCase();
1899
1903
  let browser;
1900
1904
  switch (true) {
1901
1905
  case browserName === "chrome":
@@ -2835,7 +2839,7 @@ function isDevice(device) {
2835
2839
  return width > maxWidth.mobile;
2836
2840
  default:
2837
2841
  case "mobile":
2838
- return width <= maxWidth.mobile || isOS("ios", "android");
2842
+ return width <= maxWidth.mobile || isOS("ios", "android", "ipad");
2839
2843
  }
2840
2844
  }
2841
2845
  function media(device) {
@@ -7049,7 +7053,7 @@ const DropdownButtonStyled = styled(AccountButtonStyled)`
7049
7053
  justify-content: center;
7050
7054
  background-color: ${(props) => props.theme.colors.background.primary};
7051
7055
  `;
7052
- const LoaderButtonStyled = styled(Button)`
7056
+ styled(Button)`
7053
7057
  min-width: 148px;
7054
7058
  height: 40px;
7055
7059
 
@@ -7061,7 +7065,7 @@ const LoaderButtonStyled = styled(Button)`
7061
7065
  align-items: center;
7062
7066
  justify-content: center;
7063
7067
  `;
7064
- const LoaderIconStyled = styled(LoaderIcon)`
7068
+ styled(LoaderIcon)`
7065
7069
  height: 18px;
7066
7070
  width: 18px;
7067
7071
  `;
@@ -7832,7 +7836,6 @@ const AccountButton = () => {
7832
7836
  const tonConnectUI = useContext(TonConnectUiContext);
7833
7837
  const [isOpened, setIsOpened] = createSignal(false);
7834
7838
  const [account, setAccount] = createSignal(connector.account);
7835
- const [restoringProcess, setRestoringProcess] = createSignal(true);
7836
7839
  let dropDownRef;
7837
7840
  const [floating, setFloating] = createSignal();
7838
7841
  const [anchor, setAnchor] = createSignal();
@@ -7848,7 +7851,6 @@ const AccountButton = () => {
7848
7851
  }
7849
7852
  return "";
7850
7853
  };
7851
- tonConnectUI.connectionRestored.then(() => setRestoringProcess(false));
7852
7854
  const unsubscribe = connector.onStatusChange((wallet) => {
7853
7855
  if (!wallet) {
7854
7856
  setIsOpened(false);
@@ -7879,143 +7881,123 @@ const AccountButton = () => {
7879
7881
  get children() {
7880
7882
  return [createComponent(Show, {
7881
7883
  get when() {
7882
- return restoringProcess();
7884
+ return !account();
7883
7885
  },
7884
7886
  get children() {
7885
- return createComponent(LoaderButtonStyled, {
7886
- disabled: true,
7887
- "data-tc-connect-button-loading": "true",
7887
+ return createComponent(AccountButtonStyled, {
7888
+ onClick: () => tonConnectUI.openModal(),
7889
+ "data-tc-connect-button": "true",
7890
+ scale: "s",
7888
7891
  get children() {
7889
- return createComponent(LoaderIconStyled, {});
7892
+ return [createComponent(TonIcon, {
7893
+ get fill() {
7894
+ return theme.colors.connectButton.foreground;
7895
+ }
7896
+ }), createComponent(Text, {
7897
+ translationKey: "button.connectWallet",
7898
+ fontSize: "15px",
7899
+ lineHeight: "18px",
7900
+ fontWeight: "590",
7901
+ get color() {
7902
+ return theme.colors.connectButton.foreground;
7903
+ },
7904
+ children: "Connect wallet"
7905
+ })];
7890
7906
  }
7891
7907
  });
7892
7908
  }
7893
7909
  }), createComponent(Show, {
7894
7910
  get when() {
7895
- return !restoringProcess();
7911
+ return account();
7896
7912
  },
7897
7913
  get children() {
7898
- return [createComponent(Show, {
7899
- get when() {
7900
- return !account();
7901
- },
7914
+ return createComponent(DropdownContainerStyled, {
7902
7915
  get children() {
7903
- return createComponent(AccountButtonStyled, {
7904
- onClick: () => tonConnectUI.openModal(),
7905
- "data-tc-connect-button": "true",
7916
+ return [createComponent(DropdownButtonStyled, {
7917
+ onClick: () => setIsOpened((v) => !v),
7918
+ ref: setAnchor,
7919
+ "data-tc-dropdown-button": "true",
7906
7920
  scale: "s",
7907
7921
  get children() {
7908
- return [createComponent(TonIcon, {
7909
- get fill() {
7910
- return theme.colors.connectButton.foreground;
7911
- }
7912
- }), createComponent(Text, {
7913
- translationKey: "button.connectWallet",
7922
+ return [createComponent(Text, {
7914
7923
  fontSize: "15px",
7915
- lineHeight: "18px",
7916
7924
  fontWeight: "590",
7917
- get color() {
7918
- return theme.colors.connectButton.foreground;
7919
- },
7920
- children: "Connect wallet"
7925
+ lineHeight: "18px",
7926
+ get children() {
7927
+ return normalizedAddress();
7928
+ }
7929
+ }), createComponent(ArrowIcon, {
7930
+ direction: "bottom"
7921
7931
  })];
7922
7932
  }
7923
- });
7924
- }
7925
- }), createComponent(Show, {
7926
- get when() {
7927
- return account();
7928
- },
7929
- get children() {
7930
- return createComponent(DropdownContainerStyled, {
7933
+ }), createComponent(Portal, {
7931
7934
  get children() {
7932
- return [createComponent(DropdownButtonStyled, {
7933
- onClick: () => setIsOpened((v) => !v),
7934
- ref: setAnchor,
7935
- "data-tc-dropdown-button": "true",
7936
- scale: "s",
7937
- get children() {
7938
- return [createComponent(Text, {
7939
- fontSize: "15px",
7940
- fontWeight: "590",
7941
- lineHeight: "18px",
7942
- get children() {
7943
- return normalizedAddress();
7944
- }
7945
- }), createComponent(ArrowIcon, {
7946
- direction: "bottom"
7947
- })];
7948
- }
7949
- }), createComponent(Portal, {
7935
+ const _el$ = untrack(() => document.importNode(_tmpl$$3, true));
7936
+ use(setFloating, _el$);
7937
+ _el$.style.setProperty("z-index", "999");
7938
+ _el$._$owner = getOwner();
7939
+ insert(_el$, createComponent(Transition, {
7940
+ onBeforeEnter: (el) => {
7941
+ animate(el, [{
7942
+ opacity: 0,
7943
+ transform: "translateY(-8px)"
7944
+ }, {
7945
+ opacity: 1,
7946
+ transform: "translateY(0)"
7947
+ }], {
7948
+ duration: 150
7949
+ });
7950
+ },
7951
+ onExit: (el, done) => {
7952
+ const a2 = animate(el, [{
7953
+ opacity: 1,
7954
+ transform: "translateY(0)"
7955
+ }, {
7956
+ opacity: 0,
7957
+ transform: "translateY(-8px)"
7958
+ }], {
7959
+ duration: 150
7960
+ });
7961
+ a2.finished.then(done);
7962
+ },
7950
7963
  get children() {
7951
- const _el$ = untrack(() => document.importNode(_tmpl$$3, true));
7952
- use(setFloating, _el$);
7953
- _el$.style.setProperty("z-index", "999");
7954
- _el$._$owner = getOwner();
7955
- insert(_el$, createComponent(Transition, {
7956
- onBeforeEnter: (el) => {
7957
- animate(el, [{
7958
- opacity: 0,
7959
- transform: "translateY(-8px)"
7960
- }, {
7961
- opacity: 1,
7962
- transform: "translateY(0)"
7963
- }], {
7964
- duration: 150
7965
- });
7966
- },
7967
- onExit: (el, done) => {
7968
- const a2 = animate(el, [{
7969
- opacity: 1,
7970
- transform: "translateY(0)"
7971
- }, {
7972
- opacity: 0,
7973
- transform: "translateY(-8px)"
7974
- }], {
7975
- duration: 150
7976
- });
7977
- a2.finished.then(done);
7964
+ return createComponent(Show, {
7965
+ get when() {
7966
+ return isOpened();
7978
7967
  },
7979
7968
  get children() {
7980
- return createComponent(Show, {
7981
- get when() {
7982
- return isOpened();
7969
+ return createComponent(DropdownStyled, {
7970
+ get hidden() {
7971
+ return !isOpened();
7983
7972
  },
7984
- get children() {
7985
- return createComponent(DropdownStyled, {
7986
- get hidden() {
7987
- return !isOpened();
7988
- },
7989
- onClose: () => setIsOpened(false),
7990
- ref(r$) {
7991
- const _ref$ = dropDownRef;
7992
- typeof _ref$ === "function" ? _ref$(r$) : dropDownRef = r$;
7993
- }
7994
- });
7973
+ onClose: () => setIsOpened(false),
7974
+ ref(r$) {
7975
+ const _ref$ = dropDownRef;
7976
+ typeof _ref$ === "function" ? _ref$(r$) : dropDownRef = r$;
7995
7977
  }
7996
7978
  });
7997
7979
  }
7998
- }), null);
7999
- insert(_el$, createComponent(NotificationsStyled, {}), null);
8000
- createRenderEffect((_p$) => {
8001
- var _a2, _b2;
8002
- const _v$ = position.strategy, _v$2 = `${(_a2 = position.y) != null ? _a2 : 0}px`, _v$3 = `${(_b2 = position.x) != null ? _b2 : 0}px`;
8003
- _v$ !== _p$._v$ && _el$.style.setProperty("position", _p$._v$ = _v$);
8004
- _v$2 !== _p$._v$2 && _el$.style.setProperty("top", _p$._v$2 = _v$2);
8005
- _v$3 !== _p$._v$3 && _el$.style.setProperty("left", _p$._v$3 = _v$3);
8006
- return _p$;
8007
- }, {
8008
- _v$: void 0,
8009
- _v$2: void 0,
8010
- _v$3: void 0
8011
7980
  });
8012
- return _el$;
8013
7981
  }
8014
- })];
7982
+ }), null);
7983
+ insert(_el$, createComponent(NotificationsStyled, {}), null);
7984
+ createRenderEffect((_p$) => {
7985
+ var _a2, _b2;
7986
+ const _v$ = position.strategy, _v$2 = `${(_a2 = position.y) != null ? _a2 : 0}px`, _v$3 = `${(_b2 = position.x) != null ? _b2 : 0}px`;
7987
+ _v$ !== _p$._v$ && _el$.style.setProperty("position", _p$._v$ = _v$);
7988
+ _v$2 !== _p$._v$2 && _el$.style.setProperty("top", _p$._v$2 = _v$2);
7989
+ _v$3 !== _p$._v$3 && _el$.style.setProperty("left", _p$._v$3 = _v$3);
7990
+ return _p$;
7991
+ }, {
7992
+ _v$: void 0,
7993
+ _v$2: void 0,
7994
+ _v$3: void 0
7995
+ });
7996
+ return _el$;
8015
7997
  }
8016
- });
7998
+ })];
8017
7999
  }
8018
- })];
8000
+ });
8019
8001
  }
8020
8002
  })];
8021
8003
  }
@@ -8374,6 +8356,27 @@ function redirectToTelegram(universalLink, options) {
8374
8356
  );
8375
8357
  openLinkBlank(linkWithStrategy);
8376
8358
  }
8359
+ } else if (isOS("ipad")) {
8360
+ if (options.returnStrategy === "back") {
8361
+ options.returnStrategy = "back";
8362
+ }
8363
+ const isChrome = isBrowser("chrome");
8364
+ const isFirefox = isBrowser("firefox");
8365
+ const useDeepLink = (isChrome || isFirefox) && !options.forceRedirect;
8366
+ if (useDeepLink) {
8367
+ const linkWithStrategy = addReturnStrategy(
8368
+ directLinkUrl.toString(),
8369
+ options.returnStrategy
8370
+ );
8371
+ const deepLink = convertToTGDeepLink(linkWithStrategy);
8372
+ openDeeplinkWithFallback(deepLink, () => openLinkBlank(linkWithStrategy));
8373
+ } else {
8374
+ const linkWithStrategy = addReturnStrategy(
8375
+ directLinkUrl.toString(),
8376
+ options.returnStrategy
8377
+ );
8378
+ openLinkBlank(linkWithStrategy);
8379
+ }
8377
8380
  } else if (isOS("macos", "windows", "linux")) {
8378
8381
  options.returnStrategy = "none";
8379
8382
  options.twaReturnUrl = void 0;
@@ -8511,6 +8514,17 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
8511
8514
  }
8512
8515
  setOpenMethod("universal-link");
8513
8516
  openLinkBlank(addReturnStrategy(universalLink, options.returnStrategy));
8517
+ } else if (isOS("ipad")) {
8518
+ if (options.returnStrategy === "back") {
8519
+ options.returnStrategy = "back";
8520
+ }
8521
+ if (isBrowser("chrome")) {
8522
+ setOpenMethod("universal-link");
8523
+ openLink(addReturnStrategy(universalLink, options.returnStrategy), "_self");
8524
+ } else {
8525
+ setOpenMethod("universal-link");
8526
+ openLinkBlank(addReturnStrategy(universalLink, options.returnStrategy));
8527
+ }
8514
8528
  } else if (isOS("macos", "windows", "linux")) {
8515
8529
  if (options.returnStrategy === "back") {
8516
8530
  if (isBrowser("safari")) {
@@ -10103,6 +10117,14 @@ const TextStyled = styled(Text)`
10103
10117
 
10104
10118
  color: ${(props) => props.theme.colors.text.secondary};
10105
10119
  `;
10120
+ const LoaderButtonStyled = styled(Button)`
10121
+ min-width: 112px;
10122
+ margin-top: 32px;
10123
+ `;
10124
+ const LoaderIconStyled = styled(LoaderIcon)`
10125
+ height: 16px;
10126
+ width: 16px;
10127
+ `;
10106
10128
  const ButtonStyled = styled(Button)`
10107
10129
  margin-top: 32px;
10108
10130
  `;
@@ -10110,6 +10132,11 @@ const ActionModal = (props) => {
10110
10132
  const dataAttrs = useDataAttributes(props);
10111
10133
  const tonConnectUI = useContext(TonConnectUiContext);
10112
10134
  const [firstClick, setFirstClick] = createSignal(true);
10135
+ const [sent, setSent] = createSignal(false);
10136
+ createEffect(() => {
10137
+ const currentAction = action();
10138
+ setSent(!!currentAction && "sent" in currentAction && currentAction.sent);
10139
+ });
10113
10140
  let universalLink;
10114
10141
  if ((tonConnectUI == null ? void 0 : tonConnectUI.wallet) && "universalLink" in tonConnectUI.wallet && (tonConnectUI.wallet.openMethod === "universal-link" || sdk.isTelegramUrl(tonConnectUI.wallet.universalLink) && isInTMA())) {
10115
10142
  universalLink = tonConnectUI.wallet.universalLink;
@@ -10155,33 +10182,53 @@ const ActionModal = (props) => {
10155
10182
  }
10156
10183
  }), createComponent(Show, {
10157
10184
  get when() {
10158
- return props.showButton !== "open-wallet";
10185
+ return !sent();
10159
10186
  },
10160
10187
  get children() {
10161
- return createComponent(ButtonStyled, {
10162
- onClick: () => props.onClose(),
10188
+ return createComponent(LoaderButtonStyled, {
10189
+ disabled: true,
10190
+ "data-tc-connect-button-loading": "true",
10163
10191
  get children() {
10164
- return createComponent(Translation, {
10165
- translationKey: "common.close",
10166
- children: "Close"
10167
- });
10192
+ return createComponent(LoaderIconStyled, {});
10168
10193
  }
10169
10194
  });
10170
10195
  }
10171
10196
  }), createComponent(Show, {
10172
10197
  get when() {
10173
- return props.showButton === "open-wallet" && universalLink;
10198
+ return sent();
10174
10199
  },
10175
10200
  get children() {
10176
- return createComponent(ButtonStyled, {
10177
- onClick: onOpenWallet,
10201
+ return [createComponent(Show, {
10202
+ get when() {
10203
+ return props.showButton !== "open-wallet";
10204
+ },
10178
10205
  get children() {
10179
- return createComponent(Translation, {
10180
- translationKey: "common.openWallet",
10181
- children: "Open wallet"
10206
+ return createComponent(ButtonStyled, {
10207
+ onClick: () => props.onClose(),
10208
+ get children() {
10209
+ return createComponent(Translation, {
10210
+ translationKey: "common.close",
10211
+ children: "Close"
10212
+ });
10213
+ }
10182
10214
  });
10183
10215
  }
10184
- });
10216
+ }), createComponent(Show, {
10217
+ get when() {
10218
+ return props.showButton === "open-wallet" && universalLink;
10219
+ },
10220
+ get children() {
10221
+ return createComponent(ButtonStyled, {
10222
+ onClick: onOpenWallet,
10223
+ get children() {
10224
+ return createComponent(Translation, {
10225
+ translationKey: "common.openWallet",
10226
+ children: "Open wallet"
10227
+ });
10228
+ }
10229
+ });
10230
+ }
10231
+ })];
10185
10232
  }
10186
10233
  })];
10187
10234
  }
@@ -10813,9 +10860,19 @@ class TonConnectUI {
10813
10860
  widgetController.setAction({
10814
10861
  name: "confirm-transaction",
10815
10862
  showNotification: notifications2.includes("before"),
10816
- openModal: modals.includes("before")
10863
+ openModal: modals.includes("before"),
10864
+ sent: false
10817
10865
  });
10818
10866
  const onRequestSent = () => {
10867
+ if (abortController.signal.aborted) {
10868
+ return;
10869
+ }
10870
+ widgetController.setAction({
10871
+ name: "confirm-transaction",
10872
+ showNotification: notifications2.includes("before"),
10873
+ openModal: modals.includes("before"),
10874
+ sent: true
10875
+ });
10819
10876
  const userOSIsIos = getUserAgent().os === "ios";
10820
10877
  const shouldSkipRedirectToWallet = skipRedirectToWallet === "ios" && userOSIsIos || skipRedirectToWallet === "always";
10821
10878
  if (this.walletInfo && "universalLink" in this.walletInfo && this.walletInfo.openMethod === "universal-link" && !shouldSkipRedirectToWallet) {
@@ -10844,7 +10901,7 @@ class TonConnectUI {
10844
10901
  const result = yield this.waitForSendTransaction(
10845
10902
  {
10846
10903
  transaction: tx,
10847
- abortSignal: abortController.signal
10904
+ signal: abortController.signal
10848
10905
  },
10849
10906
  onRequestSent
10850
10907
  );
@@ -10904,15 +10961,15 @@ class TonConnectUI {
10904
10961
  });
10905
10962
  return yield this.waitForWalletConnection({
10906
10963
  ignoreErrors: true,
10907
- abortSignal: abortController.signal
10964
+ signal: abortController.signal
10908
10965
  });
10909
10966
  });
10910
10967
  }
10911
10968
  waitForWalletConnection(options) {
10912
10969
  return __async(this, null, function* () {
10913
10970
  return new Promise((resolve, reject) => {
10914
- const { ignoreErrors = false, abortSignal = null } = options;
10915
- if (abortSignal && abortSignal.aborted) {
10971
+ const { ignoreErrors = false, signal = null } = options;
10972
+ if (signal && signal.aborted) {
10916
10973
  return reject(new TonConnectUIError("Wallet was not connected"));
10917
10974
  }
10918
10975
  const onStatusChangeHandler = (wallet) => __async(this, null, function* () {
@@ -10938,11 +10995,15 @@ class TonConnectUI {
10938
10995
  (wallet) => onStatusChangeHandler(wallet),
10939
10996
  (reason) => onErrorsHandler(reason)
10940
10997
  );
10941
- if (abortSignal) {
10942
- abortSignal.addEventListener("abort", () => {
10943
- unsubscribe();
10944
- reject(new TonConnectUIError("Wallet was not connected"));
10945
- });
10998
+ if (signal) {
10999
+ signal.addEventListener(
11000
+ "abort",
11001
+ () => {
11002
+ unsubscribe();
11003
+ reject(new TonConnectUIError("Wallet was not connected"));
11004
+ },
11005
+ { once: true }
11006
+ );
10946
11007
  }
10947
11008
  });
10948
11009
  });
@@ -10950,8 +11011,8 @@ class TonConnectUI {
10950
11011
  waitForSendTransaction(options, onRequestSent) {
10951
11012
  return __async(this, null, function* () {
10952
11013
  return new Promise((resolve, reject) => {
10953
- const { transaction, abortSignal } = options;
10954
- if (abortSignal.aborted) {
11014
+ const { transaction, signal } = options;
11015
+ if (signal.aborted) {
10955
11016
  return reject(new TonConnectUIError("Transaction was not sent"));
10956
11017
  }
10957
11018
  const onTransactionHandler = (transaction2) => __async(this, null, function* () {
@@ -10960,10 +11021,14 @@ class TonConnectUI {
10960
11021
  const onErrorsHandler = (reason) => {
10961
11022
  reject(reason);
10962
11023
  };
10963
- this.connector.sendTransaction(transaction, onRequestSent).then((result) => onTransactionHandler(result)).catch((reason) => onErrorsHandler(reason));
10964
- abortSignal.addEventListener("abort", () => {
10965
- reject(new TonConnectUIError("Transaction was not sent"));
10966
- });
11024
+ this.connector.sendTransaction(transaction, { onRequestSent, signal }).then((result) => onTransactionHandler(result)).catch((reason) => onErrorsHandler(reason));
11025
+ signal.addEventListener(
11026
+ "abort",
11027
+ () => {
11028
+ reject(new TonConnectUIError("Transaction was not sent"));
11029
+ },
11030
+ { once: true }
11031
+ );
10967
11032
  });
10968
11033
  });
10969
11034
  }