@tonconnect/ui 0.0.13 → 0.0.15
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 +2 -2
- package/dist/tonconnect-ui.min.js.map +1 -1
- package/lib/index.js +52 -17
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +52 -17
- package/lib/index.umd.js.map +1 -1
- package/package.json +2 -2
package/lib/index.umd.js
CHANGED
|
@@ -3080,10 +3080,12 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3080
3080
|
this.storage = storage;
|
|
3081
3081
|
this.walletConnectionSource = walletConnectionSource;
|
|
3082
3082
|
this.type = "http";
|
|
3083
|
+
this.standardUniversalLink = "https://connect.ton.org";
|
|
3083
3084
|
this.pendingRequests = /* @__PURE__ */ new Map();
|
|
3084
3085
|
this.nextRequestId = 0;
|
|
3085
3086
|
this.session = null;
|
|
3086
3087
|
this.bridge = null;
|
|
3088
|
+
this.pendingBridges = [];
|
|
3087
3089
|
this.listeners = [];
|
|
3088
3090
|
this.connectionStorage = new BridgeConnectionStorage(storage);
|
|
3089
3091
|
}
|
|
@@ -3095,21 +3097,32 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3095
3097
|
});
|
|
3096
3098
|
}
|
|
3097
3099
|
connect(message) {
|
|
3098
|
-
|
|
3099
|
-
(_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
|
|
3100
|
+
this.closeBridges();
|
|
3100
3101
|
const sessionCrypto = new SessionCrypto();
|
|
3102
|
+
let walletConnectionSource = {
|
|
3103
|
+
universalLink: this.standardUniversalLink,
|
|
3104
|
+
bridgeUrl: ""
|
|
3105
|
+
};
|
|
3106
|
+
if (Array.isArray(this.walletConnectionSource)) {
|
|
3107
|
+
this.pendingBridges = this.walletConnectionSource.map((source) => new BridgeGateway(this.storage, source, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this)));
|
|
3108
|
+
this.pendingBridges.forEach((bridge) => bridge.registerSession());
|
|
3109
|
+
} else {
|
|
3110
|
+
walletConnectionSource = this.walletConnectionSource;
|
|
3111
|
+
this.bridge = new BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
|
|
3112
|
+
this.bridge.registerSession();
|
|
3113
|
+
}
|
|
3101
3114
|
this.session = {
|
|
3102
3115
|
sessionCrypto,
|
|
3103
|
-
walletConnectionSource
|
|
3116
|
+
walletConnectionSource
|
|
3104
3117
|
};
|
|
3105
|
-
this.
|
|
3106
|
-
this.bridge.registerSession();
|
|
3107
|
-
return this.generateUniversalLink(message);
|
|
3118
|
+
return this.generateUniversalLink(walletConnectionSource.universalLink, message);
|
|
3108
3119
|
}
|
|
3109
3120
|
restoreConnection() {
|
|
3110
|
-
var _a2;
|
|
3111
3121
|
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3112
|
-
(
|
|
3122
|
+
if (Array.isArray(this.walletConnectionSource)) {
|
|
3123
|
+
throw new TonConnectError("Internal error. Connection source is array while WalletConnectionSourceHTTP was expected.");
|
|
3124
|
+
}
|
|
3125
|
+
this.closeBridges();
|
|
3113
3126
|
const storedConnection = yield this.connectionStorage.getHttpConnection();
|
|
3114
3127
|
if (!storedConnection) {
|
|
3115
3128
|
return;
|
|
@@ -3133,15 +3146,13 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3133
3146
|
});
|
|
3134
3147
|
}
|
|
3135
3148
|
closeConnection() {
|
|
3136
|
-
|
|
3137
|
-
(_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
|
|
3149
|
+
this.closeBridges();
|
|
3138
3150
|
this.listeners = [];
|
|
3139
3151
|
this.session = null;
|
|
3140
3152
|
this.bridge = null;
|
|
3141
3153
|
}
|
|
3142
3154
|
disconnect() {
|
|
3143
|
-
|
|
3144
|
-
(_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
|
|
3155
|
+
this.closeBridges();
|
|
3145
3156
|
this.listeners = [];
|
|
3146
3157
|
return this.removeBridgeAndSession();
|
|
3147
3158
|
}
|
|
@@ -3149,6 +3160,18 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3149
3160
|
this.listeners.push(callback);
|
|
3150
3161
|
return () => this.listeners = this.listeners.filter((listener) => listener !== callback);
|
|
3151
3162
|
}
|
|
3163
|
+
pendingGatewaysListener(gateway, bridgeIncomingMessage) {
|
|
3164
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3165
|
+
if (!this.pendingBridges.includes(gateway)) {
|
|
3166
|
+
gateway.close();
|
|
3167
|
+
return;
|
|
3168
|
+
}
|
|
3169
|
+
this.closeBridges();
|
|
3170
|
+
this.session.walletConnectionSource.bridgeUrl = gateway.bridgeUrl;
|
|
3171
|
+
this.bridge = gateway;
|
|
3172
|
+
return this.gatewayListener(bridgeIncomingMessage);
|
|
3173
|
+
});
|
|
3174
|
+
}
|
|
3152
3175
|
gatewayListener(bridgeIncomingMessage) {
|
|
3153
3176
|
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3154
3177
|
const walletMessage = JSON.parse(this.session.sessionCrypto.decrypt(Base64.decode(bridgeIncomingMessage.message).toUint8Array(), hexToByteArray(bridgeIncomingMessage.from)));
|
|
@@ -3195,13 +3218,19 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3195
3218
|
yield this.connectionStorage.removeConnection();
|
|
3196
3219
|
});
|
|
3197
3220
|
}
|
|
3198
|
-
generateUniversalLink(message) {
|
|
3199
|
-
const url = new URL(
|
|
3221
|
+
generateUniversalLink(universalLink, message) {
|
|
3222
|
+
const url = new URL(universalLink);
|
|
3200
3223
|
url.searchParams.append("v", PROTOCOL_VERSION.toString());
|
|
3201
3224
|
url.searchParams.append("id", this.session.sessionCrypto.sessionId);
|
|
3202
3225
|
url.searchParams.append("r", JSON.stringify(message));
|
|
3203
3226
|
return url.toString();
|
|
3204
3227
|
}
|
|
3228
|
+
closeBridges(except) {
|
|
3229
|
+
var _a2;
|
|
3230
|
+
(_a2 = this.bridge) === null || _a2 === void 0 ? void 0 : _a2.close();
|
|
3231
|
+
this.pendingBridges.filter((item) => item !== except).forEach((bridge) => bridge.close());
|
|
3232
|
+
this.pendingBridges = [];
|
|
3233
|
+
}
|
|
3205
3234
|
}
|
|
3206
3235
|
function getWindow$1() {
|
|
3207
3236
|
if (typeof window === "undefined") {
|
|
@@ -3685,7 +3714,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3685
3714
|
}
|
|
3686
3715
|
createProvider(wallet) {
|
|
3687
3716
|
let provider;
|
|
3688
|
-
if (isWalletConnectionSourceJS(wallet)) {
|
|
3717
|
+
if (!Array.isArray(wallet) && isWalletConnectionSourceJS(wallet)) {
|
|
3689
3718
|
provider = new InjectedProvider(this.dappSettings.storage, wallet.jsBridgeKey);
|
|
3690
3719
|
} else {
|
|
3691
3720
|
provider = new BridgeProvider(this.dappSettings.storage, wallet);
|
|
@@ -4880,6 +4909,10 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4880
4909
|
};
|
|
4881
4910
|
}
|
|
4882
4911
|
function template$1(html, check, isSVG) {
|
|
4912
|
+
if (typeof window === 'undefined') {
|
|
4913
|
+
return null;
|
|
4914
|
+
}
|
|
4915
|
+
|
|
4883
4916
|
const t2 = document.createElement("template");
|
|
4884
4917
|
t2.innerHTML = html;
|
|
4885
4918
|
let node = t2.content.firstChild;
|
|
@@ -10859,7 +10892,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
10859
10892
|
constructor() {
|
|
10860
10893
|
__publicField(this, "localStorage");
|
|
10861
10894
|
__publicField(this, "storageKey", "ton-connect-ui_wallet-info");
|
|
10862
|
-
if (
|
|
10895
|
+
if (typeof localStorage === "undefined") {
|
|
10863
10896
|
throw new TonConnectUIError(
|
|
10864
10897
|
"window.localStorage is undefined. localStorage is required for TonConnectUI"
|
|
10865
10898
|
);
|
|
@@ -10984,13 +11017,15 @@ var __async = (__this, __arguments, generator) => {
|
|
|
10984
11017
|
}
|
|
10985
11018
|
connectWallet() {
|
|
10986
11019
|
return __async(this, null, function* () {
|
|
11020
|
+
var _a2;
|
|
10987
11021
|
const walletsList = yield this.getWallets();
|
|
10988
11022
|
const embeddedWallet = walletsList.find(
|
|
10989
11023
|
(wallet) => "embedded" in wallet && wallet.embedded
|
|
10990
11024
|
);
|
|
10991
11025
|
if (embeddedWallet) {
|
|
11026
|
+
const additionalRequest = yield (_a2 = appState.getConnectParameters) == null ? void 0 : _a2.call(appState);
|
|
10992
11027
|
setLastSelectedWalletInfo(embeddedWallet);
|
|
10993
|
-
this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey });
|
|
11028
|
+
this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey }, additionalRequest);
|
|
10994
11029
|
} else {
|
|
10995
11030
|
widgetController.openWalletsModal();
|
|
10996
11031
|
}
|