@tonconnect/ui-react 0.0.11 → 0.0.12
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/README.md +2 -2
- package/lib/index.js +65 -17
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +65 -17
- package/lib/index.umd.js.map +1 -1
- package/lib/utils/web.d.ts +2 -0
- package/package.json +2 -2
package/lib/index.umd.js
CHANGED
|
@@ -4056,10 +4056,12 @@ var __objRest = (source, exclude) => {
|
|
|
4056
4056
|
this.storage = storage;
|
|
4057
4057
|
this.walletConnectionSource = walletConnectionSource;
|
|
4058
4058
|
this.type = "http";
|
|
4059
|
+
this.standardUniversalLink = "https://connect.ton.org";
|
|
4059
4060
|
this.pendingRequests = /* @__PURE__ */ new Map();
|
|
4060
4061
|
this.nextRequestId = 0;
|
|
4061
4062
|
this.session = null;
|
|
4062
4063
|
this.bridge = null;
|
|
4064
|
+
this.pendingBridges = [];
|
|
4063
4065
|
this.listeners = [];
|
|
4064
4066
|
this.connectionStorage = new BridgeConnectionStorage(storage);
|
|
4065
4067
|
}
|
|
@@ -4071,21 +4073,32 @@ var __objRest = (source, exclude) => {
|
|
|
4071
4073
|
});
|
|
4072
4074
|
}
|
|
4073
4075
|
connect(message) {
|
|
4074
|
-
|
|
4075
|
-
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4076
|
+
this.closeBridges();
|
|
4076
4077
|
const sessionCrypto = new SessionCrypto();
|
|
4078
|
+
let walletConnectionSource = {
|
|
4079
|
+
universalLink: this.standardUniversalLink,
|
|
4080
|
+
bridgeUrl: ""
|
|
4081
|
+
};
|
|
4082
|
+
if (Array.isArray(this.walletConnectionSource)) {
|
|
4083
|
+
this.pendingBridges = this.walletConnectionSource.map((source) => new BridgeGateway(this.storage, source, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this)));
|
|
4084
|
+
this.pendingBridges.forEach((bridge) => bridge.registerSession());
|
|
4085
|
+
} else {
|
|
4086
|
+
walletConnectionSource = this.walletConnectionSource;
|
|
4087
|
+
this.bridge = new BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
|
|
4088
|
+
this.bridge.registerSession();
|
|
4089
|
+
}
|
|
4077
4090
|
this.session = {
|
|
4078
4091
|
sessionCrypto,
|
|
4079
|
-
walletConnectionSource
|
|
4092
|
+
walletConnectionSource
|
|
4080
4093
|
};
|
|
4081
|
-
this.
|
|
4082
|
-
this.bridge.registerSession();
|
|
4083
|
-
return this.generateUniversalLink(message);
|
|
4094
|
+
return this.generateUniversalLink(walletConnectionSource.universalLink, message);
|
|
4084
4095
|
}
|
|
4085
4096
|
restoreConnection() {
|
|
4086
|
-
var _a;
|
|
4087
4097
|
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4088
|
-
(
|
|
4098
|
+
if (Array.isArray(this.walletConnectionSource)) {
|
|
4099
|
+
throw new TonConnectError$1("Internal error. Connection source is array while WalletConnectionSourceHTTP was expected.");
|
|
4100
|
+
}
|
|
4101
|
+
this.closeBridges();
|
|
4089
4102
|
const storedConnection = yield this.connectionStorage.getHttpConnection();
|
|
4090
4103
|
if (!storedConnection) {
|
|
4091
4104
|
return;
|
|
@@ -4109,15 +4122,13 @@ var __objRest = (source, exclude) => {
|
|
|
4109
4122
|
});
|
|
4110
4123
|
}
|
|
4111
4124
|
closeConnection() {
|
|
4112
|
-
|
|
4113
|
-
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4125
|
+
this.closeBridges();
|
|
4114
4126
|
this.listeners = [];
|
|
4115
4127
|
this.session = null;
|
|
4116
4128
|
this.bridge = null;
|
|
4117
4129
|
}
|
|
4118
4130
|
disconnect() {
|
|
4119
|
-
|
|
4120
|
-
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4131
|
+
this.closeBridges();
|
|
4121
4132
|
this.listeners = [];
|
|
4122
4133
|
return this.removeBridgeAndSession();
|
|
4123
4134
|
}
|
|
@@ -4125,6 +4136,18 @@ var __objRest = (source, exclude) => {
|
|
|
4125
4136
|
this.listeners.push(callback);
|
|
4126
4137
|
return () => this.listeners = this.listeners.filter((listener) => listener !== callback);
|
|
4127
4138
|
}
|
|
4139
|
+
pendingGatewaysListener(gateway, bridgeIncomingMessage) {
|
|
4140
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4141
|
+
if (!this.pendingBridges.includes(gateway)) {
|
|
4142
|
+
gateway.close();
|
|
4143
|
+
return;
|
|
4144
|
+
}
|
|
4145
|
+
this.closeBridges();
|
|
4146
|
+
this.session.walletConnectionSource.bridgeUrl = gateway.bridgeUrl;
|
|
4147
|
+
this.bridge = gateway;
|
|
4148
|
+
return this.gatewayListener(bridgeIncomingMessage);
|
|
4149
|
+
});
|
|
4150
|
+
}
|
|
4128
4151
|
gatewayListener(bridgeIncomingMessage) {
|
|
4129
4152
|
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4130
4153
|
const walletMessage = JSON.parse(this.session.sessionCrypto.decrypt(Base64$1.decode(bridgeIncomingMessage.message).toUint8Array(), hexToByteArray(bridgeIncomingMessage.from)));
|
|
@@ -4171,13 +4194,19 @@ var __objRest = (source, exclude) => {
|
|
|
4171
4194
|
yield this.connectionStorage.removeConnection();
|
|
4172
4195
|
});
|
|
4173
4196
|
}
|
|
4174
|
-
generateUniversalLink(message) {
|
|
4175
|
-
const url = new URL(
|
|
4197
|
+
generateUniversalLink(universalLink, message) {
|
|
4198
|
+
const url = new URL(universalLink);
|
|
4176
4199
|
url.searchParams.append("v", PROTOCOL_VERSION.toString());
|
|
4177
4200
|
url.searchParams.append("id", this.session.sessionCrypto.sessionId);
|
|
4178
4201
|
url.searchParams.append("r", JSON.stringify(message));
|
|
4179
4202
|
return url.toString();
|
|
4180
4203
|
}
|
|
4204
|
+
closeBridges(except) {
|
|
4205
|
+
var _a;
|
|
4206
|
+
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4207
|
+
this.pendingBridges.filter((item) => item !== except).forEach((bridge) => bridge.close());
|
|
4208
|
+
this.pendingBridges = [];
|
|
4209
|
+
}
|
|
4181
4210
|
}
|
|
4182
4211
|
function getWindow$1() {
|
|
4183
4212
|
if (typeof window === "undefined") {
|
|
@@ -4661,7 +4690,7 @@ var __objRest = (source, exclude) => {
|
|
|
4661
4690
|
}
|
|
4662
4691
|
createProvider(wallet) {
|
|
4663
4692
|
let provider;
|
|
4664
|
-
if (isWalletConnectionSourceJS(wallet)) {
|
|
4693
|
+
if (!Array.isArray(wallet) && isWalletConnectionSourceJS(wallet)) {
|
|
4665
4694
|
provider = new InjectedProvider(this.dappSettings.storage, wallet.jsBridgeKey);
|
|
4666
4695
|
} else {
|
|
4667
4696
|
provider = new BridgeProvider(this.dappSettings.storage, wallet);
|
|
@@ -5856,6 +5885,9 @@ var __objRest = (source, exclude) => {
|
|
|
5856
5885
|
};
|
|
5857
5886
|
}
|
|
5858
5887
|
function template$1(html, check, isSVG) {
|
|
5888
|
+
if (typeof window === "undefined") {
|
|
5889
|
+
return null;
|
|
5890
|
+
}
|
|
5859
5891
|
const t2 = document.createElement("template");
|
|
5860
5892
|
t2.innerHTML = html;
|
|
5861
5893
|
let node = t2.content.firstChild;
|
|
@@ -11835,7 +11867,7 @@ var __objRest = (source, exclude) => {
|
|
|
11835
11867
|
constructor() {
|
|
11836
11868
|
__publicField(this, "localStorage");
|
|
11837
11869
|
__publicField(this, "storageKey", "ton-connect-ui_wallet-info");
|
|
11838
|
-
if (
|
|
11870
|
+
if (typeof localStorage === "undefined") {
|
|
11839
11871
|
throw new TonConnectUIError(
|
|
11840
11872
|
"window.localStorage is undefined. localStorage is required for TonConnectUI"
|
|
11841
11873
|
);
|
|
@@ -12100,6 +12132,12 @@ var __objRest = (source, exclude) => {
|
|
|
12100
12132
|
};
|
|
12101
12133
|
}
|
|
12102
12134
|
}
|
|
12135
|
+
function isClientSide() {
|
|
12136
|
+
return typeof window !== "undefined";
|
|
12137
|
+
}
|
|
12138
|
+
function isServerSide() {
|
|
12139
|
+
return !isClientSide();
|
|
12140
|
+
}
|
|
12103
12141
|
const TonConnectUIContext = require$$0$2.createContext(null);
|
|
12104
12142
|
let tonConnectUI = null;
|
|
12105
12143
|
const TonConnectUIProvider = (_a) => {
|
|
@@ -12108,7 +12146,7 @@ var __objRest = (source, exclude) => {
|
|
|
12108
12146
|
} = _b, options = __objRest(_b, [
|
|
12109
12147
|
"children"
|
|
12110
12148
|
]);
|
|
12111
|
-
if (!tonConnectUI) {
|
|
12149
|
+
if (isClientSide() && !tonConnectUI) {
|
|
12112
12150
|
tonConnectUI = new TonConnectUI(options);
|
|
12113
12151
|
}
|
|
12114
12152
|
return /* @__PURE__ */ jsx(TonConnectUIContext.Provider, { value: tonConnectUI, children: children2 });
|
|
@@ -12135,6 +12173,10 @@ var __objRest = (source, exclude) => {
|
|
|
12135
12173
|
return true;
|
|
12136
12174
|
}
|
|
12137
12175
|
function useTonConnectUI() {
|
|
12176
|
+
if (isServerSide()) {
|
|
12177
|
+
return [null, () => {
|
|
12178
|
+
}];
|
|
12179
|
+
}
|
|
12138
12180
|
const tonConnectUI2 = require$$0$2.useContext(TonConnectUIContext);
|
|
12139
12181
|
checkProvider(tonConnectUI2);
|
|
12140
12182
|
const setOptions = (options) => void (tonConnectUI2.uiOptions = options);
|
|
@@ -12150,6 +12192,9 @@ var __objRest = (source, exclude) => {
|
|
|
12150
12192
|
};
|
|
12151
12193
|
const TonConnectButton$1 = require$$0$2.memo(TonConnectButton);
|
|
12152
12194
|
function useTonWallet() {
|
|
12195
|
+
if (isServerSide()) {
|
|
12196
|
+
return null;
|
|
12197
|
+
}
|
|
12153
12198
|
const [tonConnectUI2] = useTonConnectUI();
|
|
12154
12199
|
const [wallet, setWallet] = require$$0$2.useState(
|
|
12155
12200
|
() => tonConnectUI2.wallet && __spreadValues2(__spreadValues2({}, tonConnectUI2.wallet), tonConnectUI2.walletInfo)
|
|
@@ -15026,6 +15071,9 @@ var __objRest = (source, exclude) => {
|
|
|
15026
15071
|
}
|
|
15027
15072
|
}
|
|
15028
15073
|
function useIsConnectionRestored() {
|
|
15074
|
+
if (isServerSide()) {
|
|
15075
|
+
return false;
|
|
15076
|
+
}
|
|
15029
15077
|
const [restored, setRestored] = require$$0$2.useState(false);
|
|
15030
15078
|
const [tonConnectUI2] = useTonConnectUI();
|
|
15031
15079
|
tonConnectUI2.connectionRestored.then(() => setRestored(true));
|