@tonconnect/ui-react 0.0.10 → 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 +68 -18
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +68 -18
- 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
|
);
|
|
@@ -11960,13 +11992,15 @@ var __objRest = (source, exclude) => {
|
|
|
11960
11992
|
}
|
|
11961
11993
|
connectWallet() {
|
|
11962
11994
|
return __async(this, null, function* () {
|
|
11995
|
+
var _a;
|
|
11963
11996
|
const walletsList = yield this.getWallets();
|
|
11964
11997
|
const embeddedWallet = walletsList.find(
|
|
11965
11998
|
(wallet) => "embedded" in wallet && wallet.embedded
|
|
11966
11999
|
);
|
|
11967
12000
|
if (embeddedWallet) {
|
|
12001
|
+
const additionalRequest = yield (_a = appState.getConnectParameters) == null ? void 0 : _a.call(appState);
|
|
11968
12002
|
setLastSelectedWalletInfo(embeddedWallet);
|
|
11969
|
-
this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey });
|
|
12003
|
+
this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey }, additionalRequest);
|
|
11970
12004
|
} else {
|
|
11971
12005
|
widgetController.openWalletsModal();
|
|
11972
12006
|
}
|
|
@@ -12098,6 +12132,12 @@ var __objRest = (source, exclude) => {
|
|
|
12098
12132
|
};
|
|
12099
12133
|
}
|
|
12100
12134
|
}
|
|
12135
|
+
function isClientSide() {
|
|
12136
|
+
return typeof window !== "undefined";
|
|
12137
|
+
}
|
|
12138
|
+
function isServerSide() {
|
|
12139
|
+
return !isClientSide();
|
|
12140
|
+
}
|
|
12101
12141
|
const TonConnectUIContext = require$$0$2.createContext(null);
|
|
12102
12142
|
let tonConnectUI = null;
|
|
12103
12143
|
const TonConnectUIProvider = (_a) => {
|
|
@@ -12106,7 +12146,7 @@ var __objRest = (source, exclude) => {
|
|
|
12106
12146
|
} = _b, options = __objRest(_b, [
|
|
12107
12147
|
"children"
|
|
12108
12148
|
]);
|
|
12109
|
-
if (!tonConnectUI) {
|
|
12149
|
+
if (isClientSide() && !tonConnectUI) {
|
|
12110
12150
|
tonConnectUI = new TonConnectUI(options);
|
|
12111
12151
|
}
|
|
12112
12152
|
return /* @__PURE__ */ jsx(TonConnectUIContext.Provider, { value: tonConnectUI, children: children2 });
|
|
@@ -12133,6 +12173,10 @@ var __objRest = (source, exclude) => {
|
|
|
12133
12173
|
return true;
|
|
12134
12174
|
}
|
|
12135
12175
|
function useTonConnectUI() {
|
|
12176
|
+
if (isServerSide()) {
|
|
12177
|
+
return [null, () => {
|
|
12178
|
+
}];
|
|
12179
|
+
}
|
|
12136
12180
|
const tonConnectUI2 = require$$0$2.useContext(TonConnectUIContext);
|
|
12137
12181
|
checkProvider(tonConnectUI2);
|
|
12138
12182
|
const setOptions = (options) => void (tonConnectUI2.uiOptions = options);
|
|
@@ -12148,6 +12192,9 @@ var __objRest = (source, exclude) => {
|
|
|
12148
12192
|
};
|
|
12149
12193
|
const TonConnectButton$1 = require$$0$2.memo(TonConnectButton);
|
|
12150
12194
|
function useTonWallet() {
|
|
12195
|
+
if (isServerSide()) {
|
|
12196
|
+
return null;
|
|
12197
|
+
}
|
|
12151
12198
|
const [tonConnectUI2] = useTonConnectUI();
|
|
12152
12199
|
const [wallet, setWallet] = require$$0$2.useState(
|
|
12153
12200
|
() => tonConnectUI2.wallet && __spreadValues2(__spreadValues2({}, tonConnectUI2.wallet), tonConnectUI2.walletInfo)
|
|
@@ -15024,6 +15071,9 @@ var __objRest = (source, exclude) => {
|
|
|
15024
15071
|
}
|
|
15025
15072
|
}
|
|
15026
15073
|
function useIsConnectionRestored() {
|
|
15074
|
+
if (isServerSide()) {
|
|
15075
|
+
return false;
|
|
15076
|
+
}
|
|
15027
15077
|
const [restored, setRestored] = require$$0$2.useState(false);
|
|
15028
15078
|
const [tonConnectUI2] = useTonConnectUI();
|
|
15029
15079
|
tonConnectUI2.connectionRestored.then(() => setRestored(true));
|