@tonconnect/ui 2.3.0-beta.2 → 2.3.0-beta.3
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/tonconnect-ui.min.js +239 -240
- package/dist/tonconnect-ui.min.js.map +1 -1
- package/lib/index.cjs +114 -47
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +5 -0
- package/lib/index.mjs +115 -48
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -1754,6 +1754,9 @@ function disableScroll() {
|
|
|
1754
1754
|
document.body.classList.add(disableScrollClass);
|
|
1755
1755
|
}
|
|
1756
1756
|
function enableScroll() {
|
|
1757
|
+
if (!document.body.classList.contains(disableScrollClass)) {
|
|
1758
|
+
return;
|
|
1759
|
+
}
|
|
1757
1760
|
document.body.classList.remove(disableScrollClass);
|
|
1758
1761
|
document.documentElement.scrollTo({ top: -parseFloat(getComputedStyle(document.body).top) });
|
|
1759
1762
|
document.body.style.top = "auto";
|
|
@@ -5680,7 +5683,6 @@ const WalletItemStyled = styled.button`
|
|
|
5680
5683
|
border: none;
|
|
5681
5684
|
background-color: unset;
|
|
5682
5685
|
padding: 8px 4px;
|
|
5683
|
-
width: 100%;
|
|
5684
5686
|
min-width: 78px;
|
|
5685
5687
|
display: flex;
|
|
5686
5688
|
flex-direction: column;
|
|
@@ -8943,16 +8945,19 @@ function redirectToTelegram(universalLink, options) {
|
|
|
8943
8945
|
}
|
|
8944
8946
|
if (isInTelegramBrowser()) {
|
|
8945
8947
|
options.returnStrategy = "back";
|
|
8946
|
-
const
|
|
8947
|
-
|
|
8948
|
+
const linkWithStrategy = addReturnStrategy(
|
|
8949
|
+
directLinkUrl.toString(),
|
|
8950
|
+
options.returnStrategy
|
|
8951
|
+
);
|
|
8952
|
+
openLinkBlank(linkWithStrategy);
|
|
8948
8953
|
} else if (isInTMA()) {
|
|
8949
8954
|
if (isTmaPlatform("ios", "android", "macos", "tdesktop", "web")) {
|
|
8950
8955
|
options.returnStrategy = "back";
|
|
8951
|
-
const
|
|
8956
|
+
const linkWithStrategy = addReturnStrategy(
|
|
8952
8957
|
directLinkUrl.toString(),
|
|
8953
8958
|
options.returnStrategy
|
|
8954
8959
|
);
|
|
8955
|
-
sendOpenTelegramLink(
|
|
8960
|
+
sendOpenTelegramLink(linkWithStrategy);
|
|
8956
8961
|
} else if (isTmaPlatform("weba")) {
|
|
8957
8962
|
sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8958
8963
|
} else {
|
|
@@ -9065,8 +9070,8 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
|
|
|
9065
9070
|
openLink(addReturnStrategy(universalLink, options.returnStrategy), "_self");
|
|
9066
9071
|
} else {
|
|
9067
9072
|
setOpenMethod("universal-link");
|
|
9068
|
-
const
|
|
9069
|
-
openLinkBlank(
|
|
9073
|
+
const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
|
|
9074
|
+
openLinkBlank(linkWithStrategy);
|
|
9070
9075
|
}
|
|
9071
9076
|
} else if (isInTMA()) {
|
|
9072
9077
|
if (isTmaPlatform("ios", "android")) {
|
|
@@ -9074,26 +9079,26 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
|
|
|
9074
9079
|
options.returnStrategy = "tg://resolve";
|
|
9075
9080
|
}
|
|
9076
9081
|
setOpenMethod("universal-link");
|
|
9077
|
-
const
|
|
9078
|
-
sendOpenTelegramLink(
|
|
9082
|
+
const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
|
|
9083
|
+
sendOpenTelegramLink(linkWithStrategy, () => {
|
|
9079
9084
|
setOpenMethod("universal-link");
|
|
9080
|
-
openLinkBlank(
|
|
9085
|
+
openLinkBlank(linkWithStrategy);
|
|
9081
9086
|
});
|
|
9082
9087
|
} else if (isTmaPlatform("macos", "tdesktop")) {
|
|
9083
9088
|
if (options.returnStrategy === "back") {
|
|
9084
9089
|
options.returnStrategy = "tg://resolve";
|
|
9085
9090
|
}
|
|
9086
|
-
const
|
|
9091
|
+
const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
|
|
9087
9092
|
const useDeepLink = !!deepLink && !options.forceRedirect;
|
|
9088
9093
|
if (useDeepLink) {
|
|
9089
9094
|
setOpenMethod("custom-deeplink");
|
|
9090
|
-
openDeeplinkWithFallback(toDeeplink(
|
|
9095
|
+
openDeeplinkWithFallback(toDeeplink(linkWithStrategy, deepLink), () => {
|
|
9091
9096
|
setOpenMethod("universal-link");
|
|
9092
|
-
openLinkBlank(
|
|
9097
|
+
openLinkBlank(linkWithStrategy);
|
|
9093
9098
|
});
|
|
9094
9099
|
} else {
|
|
9095
9100
|
setOpenMethod("universal-link");
|
|
9096
|
-
openLinkBlank(
|
|
9101
|
+
openLinkBlank(linkWithStrategy);
|
|
9097
9102
|
}
|
|
9098
9103
|
} else if (isTmaPlatform("weba")) {
|
|
9099
9104
|
if (options.returnStrategy === "back") {
|
|
@@ -9109,17 +9114,17 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
|
|
|
9109
9114
|
options.returnStrategy = location.href;
|
|
9110
9115
|
}
|
|
9111
9116
|
}
|
|
9112
|
-
const
|
|
9117
|
+
const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
|
|
9113
9118
|
const useDeepLink = !!deepLink && !options.forceRedirect;
|
|
9114
9119
|
if (useDeepLink) {
|
|
9115
9120
|
setOpenMethod("custom-deeplink");
|
|
9116
|
-
openDeeplinkWithFallback(toDeeplink(
|
|
9121
|
+
openDeeplinkWithFallback(toDeeplink(linkWithStrategy, deepLink), () => {
|
|
9117
9122
|
setOpenMethod("universal-link");
|
|
9118
|
-
openLinkBlank(
|
|
9123
|
+
openLinkBlank(linkWithStrategy);
|
|
9119
9124
|
});
|
|
9120
9125
|
} else {
|
|
9121
9126
|
setOpenMethod("universal-link");
|
|
9122
|
-
openLinkBlank(
|
|
9127
|
+
openLinkBlank(linkWithStrategy);
|
|
9123
9128
|
}
|
|
9124
9129
|
} else if (isTmaPlatform("web")) {
|
|
9125
9130
|
if (options.returnStrategy === "back") {
|
|
@@ -9135,22 +9140,22 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
|
|
|
9135
9140
|
options.returnStrategy = location.href;
|
|
9136
9141
|
}
|
|
9137
9142
|
}
|
|
9138
|
-
const
|
|
9143
|
+
const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
|
|
9139
9144
|
const useDeepLink = !!deepLink && !options.forceRedirect;
|
|
9140
9145
|
if (useDeepLink) {
|
|
9141
9146
|
setOpenMethod("custom-deeplink");
|
|
9142
|
-
openDeeplinkWithFallback(toDeeplink(
|
|
9147
|
+
openDeeplinkWithFallback(toDeeplink(linkWithStrategy, deepLink), () => {
|
|
9143
9148
|
setOpenMethod("universal-link");
|
|
9144
|
-
openLinkBlank(
|
|
9149
|
+
openLinkBlank(linkWithStrategy);
|
|
9145
9150
|
});
|
|
9146
9151
|
} else {
|
|
9147
9152
|
setOpenMethod("universal-link");
|
|
9148
|
-
openLinkBlank(
|
|
9153
|
+
openLinkBlank(linkWithStrategy);
|
|
9149
9154
|
}
|
|
9150
9155
|
} else {
|
|
9151
9156
|
setOpenMethod("universal-link");
|
|
9152
|
-
const
|
|
9153
|
-
openLinkBlank(
|
|
9157
|
+
const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
|
|
9158
|
+
openLinkBlank(linkWithStrategy);
|
|
9154
9159
|
}
|
|
9155
9160
|
} else {
|
|
9156
9161
|
if (isOS("ios")) {
|
|
@@ -9223,17 +9228,17 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
|
|
|
9223
9228
|
options.returnStrategy = "none";
|
|
9224
9229
|
}
|
|
9225
9230
|
}
|
|
9226
|
-
const
|
|
9231
|
+
const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
|
|
9227
9232
|
const useDeepLink = !!deepLink && !options.forceRedirect;
|
|
9228
9233
|
if (useDeepLink) {
|
|
9229
9234
|
setOpenMethod("custom-deeplink");
|
|
9230
|
-
openDeeplinkWithFallback(toDeeplink(
|
|
9235
|
+
openDeeplinkWithFallback(toDeeplink(linkWithStrategy, deepLink), () => {
|
|
9231
9236
|
setOpenMethod("universal-link");
|
|
9232
|
-
openLinkBlank(
|
|
9237
|
+
openLinkBlank(linkWithStrategy);
|
|
9233
9238
|
});
|
|
9234
9239
|
} else {
|
|
9235
9240
|
setOpenMethod("universal-link");
|
|
9236
|
-
openLinkBlank(
|
|
9241
|
+
openLinkBlank(linkWithStrategy);
|
|
9237
9242
|
}
|
|
9238
9243
|
} else {
|
|
9239
9244
|
setOpenMethod("universal-link");
|
|
@@ -9241,6 +9246,14 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
|
|
|
9241
9246
|
}
|
|
9242
9247
|
}
|
|
9243
9248
|
}
|
|
9249
|
+
function addSessionIdToUniversalLink(universalLink, sessionId) {
|
|
9250
|
+
if (!sessionId) {
|
|
9251
|
+
return universalLink;
|
|
9252
|
+
}
|
|
9253
|
+
const url = new URL(universalLink);
|
|
9254
|
+
url.searchParams.set("id", sessionId);
|
|
9255
|
+
return url.toString();
|
|
9256
|
+
}
|
|
9244
9257
|
function addQueryParameter(url, key, value) {
|
|
9245
9258
|
const parsed = new URL(url);
|
|
9246
9259
|
parsed.searchParams.append(key, value);
|
|
@@ -9258,7 +9271,8 @@ function convertToTGDeepLink(directLink) {
|
|
|
9258
9271
|
const parsed = new URL(directLink);
|
|
9259
9272
|
const [, domain, appname] = parsed.pathname.split("/");
|
|
9260
9273
|
const startapp = parsed.searchParams.get("startapp");
|
|
9261
|
-
|
|
9274
|
+
const id = parsed.searchParams.get("id");
|
|
9275
|
+
return `tg://resolve?domain=${domain}&appname=${appname}&startapp=${startapp}&id=${id}`;
|
|
9262
9276
|
}
|
|
9263
9277
|
const DesktopConnectionModal = (props) => {
|
|
9264
9278
|
const [mode, setMode] = createSignal("mobile");
|
|
@@ -11308,6 +11322,7 @@ const WalletsModal = () => {
|
|
|
11308
11322
|
createEffect(() => {
|
|
11309
11323
|
if (getWalletsModalIsOpened()) {
|
|
11310
11324
|
updateIsMobile();
|
|
11325
|
+
refetchWallets();
|
|
11311
11326
|
} else {
|
|
11312
11327
|
setSelectedWalletInfo(null);
|
|
11313
11328
|
setSelectedTab("universal");
|
|
@@ -11316,7 +11331,11 @@ const WalletsModal = () => {
|
|
|
11316
11331
|
});
|
|
11317
11332
|
const connector = useContext(ConnectorContext);
|
|
11318
11333
|
const tonConnectUI = useContext(TonConnectUiContext);
|
|
11319
|
-
const [fetchedWalletsList
|
|
11334
|
+
const [fetchedWalletsList, {
|
|
11335
|
+
refetch: refetchWallets
|
|
11336
|
+
}] = createResource(() => {
|
|
11337
|
+
return tonConnectUI.getWallets();
|
|
11338
|
+
});
|
|
11320
11339
|
const [selectedWalletInfo, setSelectedWalletInfo] = createSignal(null);
|
|
11321
11340
|
const [selectedWalletError, setSelectedWalletError] = createSignal(null);
|
|
11322
11341
|
const [selectedTab, setSelectedTab] = createSignal("universal");
|
|
@@ -11599,14 +11618,15 @@ const ActionModal = (props) => {
|
|
|
11599
11618
|
const returnStrategy = "returnStrategy" in currentAction ? currentAction.returnStrategy : appState.returnStrategy;
|
|
11600
11619
|
const forceRedirect = !firstClick();
|
|
11601
11620
|
setFirstClick(false);
|
|
11621
|
+
const linkWithSessionId = addSessionIdToUniversalLink(universalLink, currentAction.sessionId);
|
|
11602
11622
|
if (sdk.isTelegramUrl(universalLink)) {
|
|
11603
|
-
redirectToTelegram(
|
|
11623
|
+
redirectToTelegram(linkWithSessionId, {
|
|
11604
11624
|
returnStrategy,
|
|
11605
11625
|
twaReturnUrl: "twaReturnUrl" in currentAction ? currentAction.twaReturnUrl : appState.twaReturnUrl,
|
|
11606
11626
|
forceRedirect
|
|
11607
11627
|
});
|
|
11608
11628
|
} else {
|
|
11609
|
-
redirectToWallet(
|
|
11629
|
+
redirectToWallet(linkWithSessionId, deepLink, {
|
|
11610
11630
|
returnStrategy,
|
|
11611
11631
|
forceRedirect
|
|
11612
11632
|
}, () => {
|
|
@@ -12469,7 +12489,7 @@ class TonConnectUITracker {
|
|
|
12469
12489
|
}
|
|
12470
12490
|
}
|
|
12471
12491
|
}
|
|
12472
|
-
const tonConnectUiVersion = "2.3.0-beta.
|
|
12492
|
+
const tonConnectUiVersion = "2.3.0-beta.3";
|
|
12473
12493
|
class TonConnectUI {
|
|
12474
12494
|
// TODO: `actionsConfiguration.twaReturnUrl` is used only in `connectWallet` method, but it's not used in `sendTransaction` method, NEED TO FIX IT
|
|
12475
12495
|
constructor(options) {
|
|
@@ -12756,11 +12776,13 @@ class TonConnectUI {
|
|
|
12756
12776
|
sendExpand();
|
|
12757
12777
|
}
|
|
12758
12778
|
const { notifications: notifications2, modals, returnStrategy, twaReturnUrl } = this.getModalsAndNotificationsConfiguration(options);
|
|
12779
|
+
const sessionId = yield this.getSessionId();
|
|
12759
12780
|
widgetController.setAction({
|
|
12760
12781
|
name: "confirm-transaction",
|
|
12761
12782
|
showNotification: notifications2.includes("before"),
|
|
12762
12783
|
openModal: modals.includes("before"),
|
|
12763
|
-
sent: false
|
|
12784
|
+
sent: false,
|
|
12785
|
+
sessionId: sessionId || void 0
|
|
12764
12786
|
});
|
|
12765
12787
|
const abortController = new AbortController();
|
|
12766
12788
|
const onRequestSent = () => {
|
|
@@ -12772,25 +12794,28 @@ class TonConnectUI {
|
|
|
12772
12794
|
name: "confirm-transaction",
|
|
12773
12795
|
showNotification: notifications2.includes("before"),
|
|
12774
12796
|
openModal: modals.includes("before"),
|
|
12775
|
-
sent: true
|
|
12797
|
+
sent: true,
|
|
12798
|
+
sessionId: sessionId || void 0
|
|
12776
12799
|
});
|
|
12777
12800
|
this.redirectAfterRequestSent({
|
|
12778
12801
|
returnStrategy,
|
|
12779
|
-
twaReturnUrl
|
|
12802
|
+
twaReturnUrl,
|
|
12803
|
+
sessionId: sessionId || void 0
|
|
12780
12804
|
});
|
|
12781
12805
|
let firstClick = true;
|
|
12782
|
-
const redirectToWallet2 = () => {
|
|
12806
|
+
const redirectToWallet2 = () => __async(this, null, function* () {
|
|
12783
12807
|
if (abortController.signal.aborted) {
|
|
12784
12808
|
return;
|
|
12785
12809
|
}
|
|
12786
12810
|
const forceRedirect = !firstClick;
|
|
12787
12811
|
firstClick = false;
|
|
12788
|
-
this.redirectAfterRequestSent({
|
|
12812
|
+
yield this.redirectAfterRequestSent({
|
|
12789
12813
|
returnStrategy,
|
|
12790
12814
|
twaReturnUrl,
|
|
12791
|
-
forceRedirect
|
|
12815
|
+
forceRedirect,
|
|
12816
|
+
sessionId: sessionId || void 0
|
|
12792
12817
|
});
|
|
12793
|
-
};
|
|
12818
|
+
});
|
|
12794
12819
|
(_a2 = options == null ? void 0 : options.onRequestSent) == null ? void 0 : _a2.call(options, redirectToWallet2);
|
|
12795
12820
|
};
|
|
12796
12821
|
const unsubscribe = this.onTransactionModalStateChange((action2) => {
|
|
@@ -12854,11 +12879,13 @@ class TonConnectUI {
|
|
|
12854
12879
|
sendExpand();
|
|
12855
12880
|
}
|
|
12856
12881
|
const { notifications: notifications2, modals, returnStrategy, twaReturnUrl } = this.getModalsAndNotificationsConfiguration();
|
|
12882
|
+
const sessionId = yield this.getSessionId();
|
|
12857
12883
|
widgetController.setAction({
|
|
12858
12884
|
name: "confirm-sign-data",
|
|
12859
12885
|
showNotification: notifications2.includes("before"),
|
|
12860
12886
|
openModal: modals.includes("before"),
|
|
12861
|
-
signed: false
|
|
12887
|
+
signed: false,
|
|
12888
|
+
sessionId: sessionId || void 0
|
|
12862
12889
|
});
|
|
12863
12890
|
const abortController = new AbortController();
|
|
12864
12891
|
const onRequestSent = () => {
|
|
@@ -12870,11 +12897,13 @@ class TonConnectUI {
|
|
|
12870
12897
|
name: "confirm-sign-data",
|
|
12871
12898
|
showNotification: notifications2.includes("before"),
|
|
12872
12899
|
openModal: modals.includes("before"),
|
|
12873
|
-
signed: true
|
|
12900
|
+
signed: true,
|
|
12901
|
+
sessionId: sessionId || void 0
|
|
12874
12902
|
});
|
|
12875
12903
|
this.redirectAfterRequestSent({
|
|
12876
12904
|
returnStrategy,
|
|
12877
|
-
twaReturnUrl
|
|
12905
|
+
twaReturnUrl,
|
|
12906
|
+
sessionId: sessionId || void 0
|
|
12878
12907
|
});
|
|
12879
12908
|
let firstClick = true;
|
|
12880
12909
|
const redirectToWallet2 = () => {
|
|
@@ -12886,7 +12915,8 @@ class TonConnectUI {
|
|
|
12886
12915
|
this.redirectAfterRequestSent({
|
|
12887
12916
|
returnStrategy,
|
|
12888
12917
|
twaReturnUrl,
|
|
12889
|
-
forceRedirect
|
|
12918
|
+
forceRedirect,
|
|
12919
|
+
sessionId: sessionId || void 0
|
|
12890
12920
|
});
|
|
12891
12921
|
};
|
|
12892
12922
|
(_a2 = options == null ? void 0 : options.onRequestSent) == null ? void 0 : _a2.call(options, redirectToWallet2);
|
|
@@ -12937,21 +12967,58 @@ class TonConnectUI {
|
|
|
12937
12967
|
}
|
|
12938
12968
|
});
|
|
12939
12969
|
}
|
|
12970
|
+
/**
|
|
12971
|
+
* Gets the current session ID if available.
|
|
12972
|
+
* @returns session ID string or null if not available.
|
|
12973
|
+
*/
|
|
12974
|
+
getSessionId() {
|
|
12975
|
+
return __async(this, null, function* () {
|
|
12976
|
+
var _a2, _b2;
|
|
12977
|
+
if (!this.connected) {
|
|
12978
|
+
return null;
|
|
12979
|
+
}
|
|
12980
|
+
try {
|
|
12981
|
+
const storage = (_a2 = this.connector.dappSettings) == null ? void 0 : _a2.storage;
|
|
12982
|
+
if (storage) {
|
|
12983
|
+
const stored = yield storage.getItem("ton-connect-storage_bridge-connection");
|
|
12984
|
+
if (stored) {
|
|
12985
|
+
const connection = JSON.parse(stored);
|
|
12986
|
+
if (connection.type === "http" && connection.sessionCrypto) {
|
|
12987
|
+
const sessionCrypto = new sdk.SessionCrypto(connection.sessionCrypto);
|
|
12988
|
+
const sessionId = sessionCrypto.sessionId;
|
|
12989
|
+
return sessionId;
|
|
12990
|
+
} else if (connection.type === "http" && ((_b2 = connection.session) == null ? void 0 : _b2.sessionKeyPair)) {
|
|
12991
|
+
const sessionCrypto = new sdk.SessionCrypto(connection.session.sessionKeyPair);
|
|
12992
|
+
const sessionId = sessionCrypto.sessionId;
|
|
12993
|
+
return sessionId;
|
|
12994
|
+
}
|
|
12995
|
+
}
|
|
12996
|
+
}
|
|
12997
|
+
} catch (e2) {
|
|
12998
|
+
}
|
|
12999
|
+
return null;
|
|
13000
|
+
});
|
|
13001
|
+
}
|
|
12940
13002
|
redirectAfterRequestSent({
|
|
12941
13003
|
returnStrategy,
|
|
12942
13004
|
twaReturnUrl,
|
|
12943
|
-
forceRedirect
|
|
13005
|
+
forceRedirect,
|
|
13006
|
+
sessionId
|
|
12944
13007
|
}) {
|
|
12945
13008
|
if (this.walletInfo && "universalLink" in this.walletInfo && (this.walletInfo.openMethod === "universal-link" || this.walletInfo.openMethod === "custom-deeplink")) {
|
|
13009
|
+
const linkWithSessionId = addSessionIdToUniversalLink(
|
|
13010
|
+
this.walletInfo.universalLink,
|
|
13011
|
+
sessionId
|
|
13012
|
+
);
|
|
12946
13013
|
if (sdk.isTelegramUrl(this.walletInfo.universalLink)) {
|
|
12947
|
-
redirectToTelegram(
|
|
13014
|
+
redirectToTelegram(linkWithSessionId, {
|
|
12948
13015
|
returnStrategy,
|
|
12949
13016
|
twaReturnUrl: twaReturnUrl || appState.twaReturnUrl,
|
|
12950
13017
|
forceRedirect: forceRedirect || false
|
|
12951
13018
|
});
|
|
12952
13019
|
} else {
|
|
12953
13020
|
redirectToWallet(
|
|
12954
|
-
|
|
13021
|
+
linkWithSessionId,
|
|
12955
13022
|
this.walletInfo.deepLink,
|
|
12956
13023
|
{
|
|
12957
13024
|
returnStrategy,
|