@tonconnect/ui 2.0.1-beta.4 → 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.mjs CHANGED
@@ -7048,7 +7048,7 @@ const DropdownButtonStyled = styled(AccountButtonStyled)`
7048
7048
  justify-content: center;
7049
7049
  background-color: ${(props) => props.theme.colors.background.primary};
7050
7050
  `;
7051
- const LoaderButtonStyled = styled(Button)`
7051
+ styled(Button)`
7052
7052
  min-width: 148px;
7053
7053
  height: 40px;
7054
7054
 
@@ -7060,7 +7060,7 @@ const LoaderButtonStyled = styled(Button)`
7060
7060
  align-items: center;
7061
7061
  justify-content: center;
7062
7062
  `;
7063
- const LoaderIconStyled = styled(LoaderIcon)`
7063
+ styled(LoaderIcon)`
7064
7064
  height: 18px;
7065
7065
  width: 18px;
7066
7066
  `;
@@ -7831,7 +7831,6 @@ const AccountButton = () => {
7831
7831
  const tonConnectUI = useContext(TonConnectUiContext);
7832
7832
  const [isOpened, setIsOpened] = createSignal(false);
7833
7833
  const [account, setAccount] = createSignal(connector.account);
7834
- const [restoringProcess, setRestoringProcess] = createSignal(true);
7835
7834
  let dropDownRef;
7836
7835
  const [floating, setFloating] = createSignal();
7837
7836
  const [anchor, setAnchor] = createSignal();
@@ -7847,7 +7846,6 @@ const AccountButton = () => {
7847
7846
  }
7848
7847
  return "";
7849
7848
  };
7850
- tonConnectUI.connectionRestored.then(() => setRestoringProcess(false));
7851
7849
  const unsubscribe = connector.onStatusChange((wallet) => {
7852
7850
  if (!wallet) {
7853
7851
  setIsOpened(false);
@@ -7878,143 +7876,123 @@ const AccountButton = () => {
7878
7876
  get children() {
7879
7877
  return [createComponent(Show, {
7880
7878
  get when() {
7881
- return restoringProcess();
7879
+ return !account();
7882
7880
  },
7883
7881
  get children() {
7884
- return createComponent(LoaderButtonStyled, {
7885
- disabled: true,
7886
- "data-tc-connect-button-loading": "true",
7882
+ return createComponent(AccountButtonStyled, {
7883
+ onClick: () => tonConnectUI.openModal(),
7884
+ "data-tc-connect-button": "true",
7885
+ scale: "s",
7887
7886
  get children() {
7888
- return createComponent(LoaderIconStyled, {});
7887
+ return [createComponent(TonIcon, {
7888
+ get fill() {
7889
+ return theme.colors.connectButton.foreground;
7890
+ }
7891
+ }), createComponent(Text, {
7892
+ translationKey: "button.connectWallet",
7893
+ fontSize: "15px",
7894
+ lineHeight: "18px",
7895
+ fontWeight: "590",
7896
+ get color() {
7897
+ return theme.colors.connectButton.foreground;
7898
+ },
7899
+ children: "Connect wallet"
7900
+ })];
7889
7901
  }
7890
7902
  });
7891
7903
  }
7892
7904
  }), createComponent(Show, {
7893
7905
  get when() {
7894
- return !restoringProcess();
7906
+ return account();
7895
7907
  },
7896
7908
  get children() {
7897
- return [createComponent(Show, {
7898
- get when() {
7899
- return !account();
7900
- },
7909
+ return createComponent(DropdownContainerStyled, {
7901
7910
  get children() {
7902
- return createComponent(AccountButtonStyled, {
7903
- onClick: () => tonConnectUI.openModal(),
7904
- "data-tc-connect-button": "true",
7911
+ return [createComponent(DropdownButtonStyled, {
7912
+ onClick: () => setIsOpened((v) => !v),
7913
+ ref: setAnchor,
7914
+ "data-tc-dropdown-button": "true",
7905
7915
  scale: "s",
7906
7916
  get children() {
7907
- return [createComponent(TonIcon, {
7908
- get fill() {
7909
- return theme.colors.connectButton.foreground;
7910
- }
7911
- }), createComponent(Text, {
7912
- translationKey: "button.connectWallet",
7917
+ return [createComponent(Text, {
7913
7918
  fontSize: "15px",
7914
- lineHeight: "18px",
7915
7919
  fontWeight: "590",
7916
- get color() {
7917
- return theme.colors.connectButton.foreground;
7918
- },
7919
- children: "Connect wallet"
7920
+ lineHeight: "18px",
7921
+ get children() {
7922
+ return normalizedAddress();
7923
+ }
7924
+ }), createComponent(ArrowIcon, {
7925
+ direction: "bottom"
7920
7926
  })];
7921
7927
  }
7922
- });
7923
- }
7924
- }), createComponent(Show, {
7925
- get when() {
7926
- return account();
7927
- },
7928
- get children() {
7929
- return createComponent(DropdownContainerStyled, {
7928
+ }), createComponent(Portal, {
7930
7929
  get children() {
7931
- return [createComponent(DropdownButtonStyled, {
7932
- onClick: () => setIsOpened((v) => !v),
7933
- ref: setAnchor,
7934
- "data-tc-dropdown-button": "true",
7935
- scale: "s",
7936
- get children() {
7937
- return [createComponent(Text, {
7938
- fontSize: "15px",
7939
- fontWeight: "590",
7940
- lineHeight: "18px",
7941
- get children() {
7942
- return normalizedAddress();
7943
- }
7944
- }), createComponent(ArrowIcon, {
7945
- direction: "bottom"
7946
- })];
7947
- }
7948
- }), createComponent(Portal, {
7930
+ const _el$ = untrack(() => document.importNode(_tmpl$$3, true));
7931
+ use(setFloating, _el$);
7932
+ _el$.style.setProperty("z-index", "999");
7933
+ _el$._$owner = getOwner();
7934
+ insert(_el$, createComponent(Transition, {
7935
+ onBeforeEnter: (el) => {
7936
+ animate(el, [{
7937
+ opacity: 0,
7938
+ transform: "translateY(-8px)"
7939
+ }, {
7940
+ opacity: 1,
7941
+ transform: "translateY(0)"
7942
+ }], {
7943
+ duration: 150
7944
+ });
7945
+ },
7946
+ onExit: (el, done) => {
7947
+ const a2 = animate(el, [{
7948
+ opacity: 1,
7949
+ transform: "translateY(0)"
7950
+ }, {
7951
+ opacity: 0,
7952
+ transform: "translateY(-8px)"
7953
+ }], {
7954
+ duration: 150
7955
+ });
7956
+ a2.finished.then(done);
7957
+ },
7949
7958
  get children() {
7950
- const _el$ = untrack(() => document.importNode(_tmpl$$3, true));
7951
- use(setFloating, _el$);
7952
- _el$.style.setProperty("z-index", "999");
7953
- _el$._$owner = getOwner();
7954
- insert(_el$, createComponent(Transition, {
7955
- onBeforeEnter: (el) => {
7956
- animate(el, [{
7957
- opacity: 0,
7958
- transform: "translateY(-8px)"
7959
- }, {
7960
- opacity: 1,
7961
- transform: "translateY(0)"
7962
- }], {
7963
- duration: 150
7964
- });
7965
- },
7966
- onExit: (el, done) => {
7967
- const a2 = animate(el, [{
7968
- opacity: 1,
7969
- transform: "translateY(0)"
7970
- }, {
7971
- opacity: 0,
7972
- transform: "translateY(-8px)"
7973
- }], {
7974
- duration: 150
7975
- });
7976
- a2.finished.then(done);
7959
+ return createComponent(Show, {
7960
+ get when() {
7961
+ return isOpened();
7977
7962
  },
7978
7963
  get children() {
7979
- return createComponent(Show, {
7980
- get when() {
7981
- return isOpened();
7964
+ return createComponent(DropdownStyled, {
7965
+ get hidden() {
7966
+ return !isOpened();
7982
7967
  },
7983
- get children() {
7984
- return createComponent(DropdownStyled, {
7985
- get hidden() {
7986
- return !isOpened();
7987
- },
7988
- onClose: () => setIsOpened(false),
7989
- ref(r$) {
7990
- const _ref$ = dropDownRef;
7991
- typeof _ref$ === "function" ? _ref$(r$) : dropDownRef = r$;
7992
- }
7993
- });
7968
+ onClose: () => setIsOpened(false),
7969
+ ref(r$) {
7970
+ const _ref$ = dropDownRef;
7971
+ typeof _ref$ === "function" ? _ref$(r$) : dropDownRef = r$;
7994
7972
  }
7995
7973
  });
7996
7974
  }
7997
- }), null);
7998
- insert(_el$, createComponent(NotificationsStyled, {}), null);
7999
- createRenderEffect((_p$) => {
8000
- var _a2, _b2;
8001
- const _v$ = position.strategy, _v$2 = `${(_a2 = position.y) != null ? _a2 : 0}px`, _v$3 = `${(_b2 = position.x) != null ? _b2 : 0}px`;
8002
- _v$ !== _p$._v$ && _el$.style.setProperty("position", _p$._v$ = _v$);
8003
- _v$2 !== _p$._v$2 && _el$.style.setProperty("top", _p$._v$2 = _v$2);
8004
- _v$3 !== _p$._v$3 && _el$.style.setProperty("left", _p$._v$3 = _v$3);
8005
- return _p$;
8006
- }, {
8007
- _v$: void 0,
8008
- _v$2: void 0,
8009
- _v$3: void 0
8010
7975
  });
8011
- return _el$;
8012
7976
  }
8013
- })];
7977
+ }), null);
7978
+ insert(_el$, createComponent(NotificationsStyled, {}), null);
7979
+ createRenderEffect((_p$) => {
7980
+ var _a2, _b2;
7981
+ const _v$ = position.strategy, _v$2 = `${(_a2 = position.y) != null ? _a2 : 0}px`, _v$3 = `${(_b2 = position.x) != null ? _b2 : 0}px`;
7982
+ _v$ !== _p$._v$ && _el$.style.setProperty("position", _p$._v$ = _v$);
7983
+ _v$2 !== _p$._v$2 && _el$.style.setProperty("top", _p$._v$2 = _v$2);
7984
+ _v$3 !== _p$._v$3 && _el$.style.setProperty("left", _p$._v$3 = _v$3);
7985
+ return _p$;
7986
+ }, {
7987
+ _v$: void 0,
7988
+ _v$2: void 0,
7989
+ _v$3: void 0
7990
+ });
7991
+ return _el$;
8014
7992
  }
8015
- });
7993
+ })];
8016
7994
  }
8017
- })];
7995
+ });
8018
7996
  }
8019
7997
  })];
8020
7998
  }
@@ -10134,6 +10112,14 @@ const TextStyled = styled(Text)`
10134
10112
 
10135
10113
  color: ${(props) => props.theme.colors.text.secondary};
10136
10114
  `;
10115
+ const LoaderButtonStyled = styled(Button)`
10116
+ min-width: 112px;
10117
+ margin-top: 32px;
10118
+ `;
10119
+ const LoaderIconStyled = styled(LoaderIcon)`
10120
+ height: 16px;
10121
+ width: 16px;
10122
+ `;
10137
10123
  const ButtonStyled = styled(Button)`
10138
10124
  margin-top: 32px;
10139
10125
  `;
@@ -10141,6 +10127,11 @@ const ActionModal = (props) => {
10141
10127
  const dataAttrs = useDataAttributes(props);
10142
10128
  const tonConnectUI = useContext(TonConnectUiContext);
10143
10129
  const [firstClick, setFirstClick] = createSignal(true);
10130
+ const [sent, setSent] = createSignal(false);
10131
+ createEffect(() => {
10132
+ const currentAction = action();
10133
+ setSent(!!currentAction && "sent" in currentAction && currentAction.sent);
10134
+ });
10144
10135
  let universalLink;
10145
10136
  if ((tonConnectUI == null ? void 0 : tonConnectUI.wallet) && "universalLink" in tonConnectUI.wallet && (tonConnectUI.wallet.openMethod === "universal-link" || isTelegramUrl(tonConnectUI.wallet.universalLink) && isInTMA())) {
10146
10137
  universalLink = tonConnectUI.wallet.universalLink;
@@ -10186,33 +10177,53 @@ const ActionModal = (props) => {
10186
10177
  }
10187
10178
  }), createComponent(Show, {
10188
10179
  get when() {
10189
- return props.showButton !== "open-wallet";
10180
+ return !sent();
10190
10181
  },
10191
10182
  get children() {
10192
- return createComponent(ButtonStyled, {
10193
- onClick: () => props.onClose(),
10183
+ return createComponent(LoaderButtonStyled, {
10184
+ disabled: true,
10185
+ "data-tc-connect-button-loading": "true",
10194
10186
  get children() {
10195
- return createComponent(Translation, {
10196
- translationKey: "common.close",
10197
- children: "Close"
10198
- });
10187
+ return createComponent(LoaderIconStyled, {});
10199
10188
  }
10200
10189
  });
10201
10190
  }
10202
10191
  }), createComponent(Show, {
10203
10192
  get when() {
10204
- return props.showButton === "open-wallet" && universalLink;
10193
+ return sent();
10205
10194
  },
10206
10195
  get children() {
10207
- return createComponent(ButtonStyled, {
10208
- onClick: onOpenWallet,
10196
+ return [createComponent(Show, {
10197
+ get when() {
10198
+ return props.showButton !== "open-wallet";
10199
+ },
10209
10200
  get children() {
10210
- return createComponent(Translation, {
10211
- translationKey: "common.openWallet",
10212
- children: "Open wallet"
10201
+ return createComponent(ButtonStyled, {
10202
+ onClick: () => props.onClose(),
10203
+ get children() {
10204
+ return createComponent(Translation, {
10205
+ translationKey: "common.close",
10206
+ children: "Close"
10207
+ });
10208
+ }
10213
10209
  });
10214
10210
  }
10215
- });
10211
+ }), createComponent(Show, {
10212
+ get when() {
10213
+ return props.showButton === "open-wallet" && universalLink;
10214
+ },
10215
+ get children() {
10216
+ return createComponent(ButtonStyled, {
10217
+ onClick: onOpenWallet,
10218
+ get children() {
10219
+ return createComponent(Translation, {
10220
+ translationKey: "common.openWallet",
10221
+ children: "Open wallet"
10222
+ });
10223
+ }
10224
+ });
10225
+ }
10226
+ })];
10216
10227
  }
10217
10228
  })];
10218
10229
  }
@@ -10844,9 +10855,19 @@ class TonConnectUI {
10844
10855
  widgetController.setAction({
10845
10856
  name: "confirm-transaction",
10846
10857
  showNotification: notifications2.includes("before"),
10847
- openModal: modals.includes("before")
10858
+ openModal: modals.includes("before"),
10859
+ sent: false
10848
10860
  });
10849
10861
  const onRequestSent = () => {
10862
+ if (abortController.signal.aborted) {
10863
+ return;
10864
+ }
10865
+ widgetController.setAction({
10866
+ name: "confirm-transaction",
10867
+ showNotification: notifications2.includes("before"),
10868
+ openModal: modals.includes("before"),
10869
+ sent: true
10870
+ });
10850
10871
  const userOSIsIos = getUserAgent().os === "ios";
10851
10872
  const shouldSkipRedirectToWallet = skipRedirectToWallet === "ios" && userOSIsIos || skipRedirectToWallet === "always";
10852
10873
  if (this.walletInfo && "universalLink" in this.walletInfo && this.walletInfo.openMethod === "universal-link" && !shouldSkipRedirectToWallet) {
@@ -10875,7 +10896,7 @@ class TonConnectUI {
10875
10896
  const result = yield this.waitForSendTransaction(
10876
10897
  {
10877
10898
  transaction: tx,
10878
- abortSignal: abortController.signal
10899
+ signal: abortController.signal
10879
10900
  },
10880
10901
  onRequestSent
10881
10902
  );
@@ -10935,15 +10956,15 @@ class TonConnectUI {
10935
10956
  });
10936
10957
  return yield this.waitForWalletConnection({
10937
10958
  ignoreErrors: true,
10938
- abortSignal: abortController.signal
10959
+ signal: abortController.signal
10939
10960
  });
10940
10961
  });
10941
10962
  }
10942
10963
  waitForWalletConnection(options) {
10943
10964
  return __async(this, null, function* () {
10944
10965
  return new Promise((resolve, reject) => {
10945
- const { ignoreErrors = false, abortSignal = null } = options;
10946
- if (abortSignal && abortSignal.aborted) {
10966
+ const { ignoreErrors = false, signal = null } = options;
10967
+ if (signal && signal.aborted) {
10947
10968
  return reject(new TonConnectUIError("Wallet was not connected"));
10948
10969
  }
10949
10970
  const onStatusChangeHandler = (wallet) => __async(this, null, function* () {
@@ -10969,11 +10990,15 @@ class TonConnectUI {
10969
10990
  (wallet) => onStatusChangeHandler(wallet),
10970
10991
  (reason) => onErrorsHandler(reason)
10971
10992
  );
10972
- if (abortSignal) {
10973
- abortSignal.addEventListener("abort", () => {
10974
- unsubscribe();
10975
- reject(new TonConnectUIError("Wallet was not connected"));
10976
- });
10993
+ if (signal) {
10994
+ signal.addEventListener(
10995
+ "abort",
10996
+ () => {
10997
+ unsubscribe();
10998
+ reject(new TonConnectUIError("Wallet was not connected"));
10999
+ },
11000
+ { once: true }
11001
+ );
10977
11002
  }
10978
11003
  });
10979
11004
  });
@@ -10981,8 +11006,8 @@ class TonConnectUI {
10981
11006
  waitForSendTransaction(options, onRequestSent) {
10982
11007
  return __async(this, null, function* () {
10983
11008
  return new Promise((resolve, reject) => {
10984
- const { transaction, abortSignal } = options;
10985
- if (abortSignal.aborted) {
11009
+ const { transaction, signal } = options;
11010
+ if (signal.aborted) {
10986
11011
  return reject(new TonConnectUIError("Transaction was not sent"));
10987
11012
  }
10988
11013
  const onTransactionHandler = (transaction2) => __async(this, null, function* () {
@@ -10991,10 +11016,14 @@ class TonConnectUI {
10991
11016
  const onErrorsHandler = (reason) => {
10992
11017
  reject(reason);
10993
11018
  };
10994
- this.connector.sendTransaction(transaction, onRequestSent).then((result) => onTransactionHandler(result)).catch((reason) => onErrorsHandler(reason));
10995
- abortSignal.addEventListener("abort", () => {
10996
- reject(new TonConnectUIError("Transaction was not sent"));
10997
- });
11019
+ this.connector.sendTransaction(transaction, { onRequestSent, signal }).then((result) => onTransactionHandler(result)).catch((reason) => onErrorsHandler(reason));
11020
+ signal.addEventListener(
11021
+ "abort",
11022
+ () => {
11023
+ reject(new TonConnectUIError("Transaction was not sent"));
11024
+ },
11025
+ { once: true }
11026
+ );
10998
11027
  });
10999
11028
  });
11000
11029
  }