@tonconnect/ui-react 0.0.11 → 0.0.13
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/components/TonConnectUIProvider.d.ts +1 -1
- package/lib/index.js +90 -29
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +90 -29
- 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;
|
|
@@ -11138,6 +11170,20 @@ var __objRest = (source, exclude) => {
|
|
|
11138
11170
|
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", handler);
|
|
11139
11171
|
return () => window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", handler);
|
|
11140
11172
|
}
|
|
11173
|
+
function addQueryParameter(url, key, value) {
|
|
11174
|
+
const parsed = new URL(url);
|
|
11175
|
+
parsed.searchParams.append(key, value);
|
|
11176
|
+
return parsed.toString();
|
|
11177
|
+
}
|
|
11178
|
+
function addReturnStrategy(url, returnStrategy) {
|
|
11179
|
+
return addQueryParameter(url, "ret", returnStrategy);
|
|
11180
|
+
}
|
|
11181
|
+
const [appState, setAppState] = createStore({
|
|
11182
|
+
buttonRootId: null,
|
|
11183
|
+
language: "en",
|
|
11184
|
+
returnStrategy: "back",
|
|
11185
|
+
walletsList: {}
|
|
11186
|
+
});
|
|
11141
11187
|
const QrCodeModal = (props) => {
|
|
11142
11188
|
const connector = useContext(ConnectorContext);
|
|
11143
11189
|
const universalLink = connector.connect({
|
|
@@ -11188,7 +11234,7 @@ var __objRest = (source, exclude) => {
|
|
|
11188
11234
|
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
11189
11235
|
openMethod: "universal-link"
|
|
11190
11236
|
}));
|
|
11191
|
-
openLink(universalLink);
|
|
11237
|
+
openLink(addReturnStrategy(universalLink, appState.returnStrategy));
|
|
11192
11238
|
},
|
|
11193
11239
|
get children() {
|
|
11194
11240
|
return createComponent(Translation, {
|
|
@@ -11428,11 +11474,6 @@ var __objRest = (source, exclude) => {
|
|
|
11428
11474
|
align-items: center;
|
|
11429
11475
|
}
|
|
11430
11476
|
`;
|
|
11431
|
-
const [appState, setAppState] = createStore({
|
|
11432
|
-
buttonRootId: null,
|
|
11433
|
-
language: "en",
|
|
11434
|
-
walletsList: {}
|
|
11435
|
-
});
|
|
11436
11477
|
function uiWalletToWalletInfo(uiWallet) {
|
|
11437
11478
|
if ("jsBridgeKey" in uiWallet) {
|
|
11438
11479
|
return __spreadProps(__spreadValues({}, uiWallet), {
|
|
@@ -11536,14 +11577,14 @@ var __objRest = (source, exclude) => {
|
|
|
11536
11577
|
setSelectedWalletInfo(walletInfo);
|
|
11537
11578
|
return;
|
|
11538
11579
|
}
|
|
11539
|
-
|
|
11580
|
+
openLinkBlank(walletInfo.aboutUrl);
|
|
11540
11581
|
};
|
|
11541
11582
|
const onSelectIfMobile = (walletInfo) => {
|
|
11542
11583
|
const universalLink = connector.connect({
|
|
11543
11584
|
universalLink: walletInfo.universalLink,
|
|
11544
11585
|
bridgeUrl: walletInfo.bridgeUrl
|
|
11545
11586
|
}, additionalRequest());
|
|
11546
|
-
openLink(universalLink);
|
|
11587
|
+
openLink(addReturnStrategy(universalLink, appState.returnStrategy));
|
|
11547
11588
|
};
|
|
11548
11589
|
const onSelectIfInjected = (walletInfo) => {
|
|
11549
11590
|
connector.connect({
|
|
@@ -11835,7 +11876,7 @@ var __objRest = (source, exclude) => {
|
|
|
11835
11876
|
constructor() {
|
|
11836
11877
|
__publicField(this, "localStorage");
|
|
11837
11878
|
__publicField(this, "storageKey", "ton-connect-ui_wallet-info");
|
|
11838
|
-
if (
|
|
11879
|
+
if (typeof localStorage === "undefined") {
|
|
11839
11880
|
throw new TonConnectUIError(
|
|
11840
11881
|
"window.localStorage is undefined. localStorage is required for TonConnectUI"
|
|
11841
11882
|
);
|
|
@@ -11933,8 +11974,11 @@ var __objRest = (source, exclude) => {
|
|
|
11933
11974
|
setBorderRadius(options.uiPreferences.borderRadius);
|
|
11934
11975
|
}
|
|
11935
11976
|
setAppState((state) => {
|
|
11977
|
+
var _a2;
|
|
11936
11978
|
const merged = mergeOptions(
|
|
11937
|
-
__spreadValues(__spreadValues({}, options.language && { language: options.language }), !!options.
|
|
11979
|
+
__spreadValues(__spreadValues(__spreadValues({}, options.language && { language: options.language }), !!((_a2 = options.actionsConfiguration) == null ? void 0 : _a2.returnStrategy) && {
|
|
11980
|
+
returnStrategy: options.actionsConfiguration.returnStrategy
|
|
11981
|
+
}), !!options.walletsList && { walletsList: options.walletsList }),
|
|
11938
11982
|
unwrap(state)
|
|
11939
11983
|
);
|
|
11940
11984
|
if (options.buttonRootId !== void 0) {
|
|
@@ -11994,10 +12038,10 @@ var __objRest = (source, exclude) => {
|
|
|
11994
12038
|
if (!this.connected || !this.walletInfo) {
|
|
11995
12039
|
throw new TonConnectUIError("Connect wallet to send a transaction.");
|
|
11996
12040
|
}
|
|
12041
|
+
const { notifications: notifications2, modals, returnStrategy } = this.getModalsAndNotificationsConfiguration(options);
|
|
11997
12042
|
if ("universalLink" in this.walletInfo && this.walletInfo.openMethod === "universal-link") {
|
|
11998
|
-
openLink(this.walletInfo.universalLink);
|
|
12043
|
+
openLink(addReturnStrategy(this.walletInfo.universalLink, returnStrategy));
|
|
11999
12044
|
}
|
|
12000
|
-
const { notifications: notifications2, modals } = this.getModalsAndNotificationsConfiguration(options);
|
|
12001
12045
|
widgetController.setAction({
|
|
12002
12046
|
name: "confirm-transaction",
|
|
12003
12047
|
showNotification: notifications2.includes("before"),
|
|
@@ -12096,10 +12140,17 @@ var __objRest = (source, exclude) => {
|
|
|
12096
12140
|
}
|
|
12097
12141
|
return {
|
|
12098
12142
|
notifications: notifications2,
|
|
12099
|
-
modals
|
|
12143
|
+
modals,
|
|
12144
|
+
returnStrategy: (options == null ? void 0 : options.returnStrategy) || "back"
|
|
12100
12145
|
};
|
|
12101
12146
|
}
|
|
12102
12147
|
}
|
|
12148
|
+
function isClientSide() {
|
|
12149
|
+
return typeof window !== "undefined";
|
|
12150
|
+
}
|
|
12151
|
+
function isServerSide() {
|
|
12152
|
+
return !isClientSide();
|
|
12153
|
+
}
|
|
12103
12154
|
const TonConnectUIContext = require$$0$2.createContext(null);
|
|
12104
12155
|
let tonConnectUI = null;
|
|
12105
12156
|
const TonConnectUIProvider = (_a) => {
|
|
@@ -12108,7 +12159,7 @@ var __objRest = (source, exclude) => {
|
|
|
12108
12159
|
} = _b, options = __objRest(_b, [
|
|
12109
12160
|
"children"
|
|
12110
12161
|
]);
|
|
12111
|
-
if (!tonConnectUI) {
|
|
12162
|
+
if (isClientSide() && !tonConnectUI) {
|
|
12112
12163
|
tonConnectUI = new TonConnectUI(options);
|
|
12113
12164
|
}
|
|
12114
12165
|
return /* @__PURE__ */ jsx(TonConnectUIContext.Provider, { value: tonConnectUI, children: children2 });
|
|
@@ -12135,6 +12186,10 @@ var __objRest = (source, exclude) => {
|
|
|
12135
12186
|
return true;
|
|
12136
12187
|
}
|
|
12137
12188
|
function useTonConnectUI() {
|
|
12189
|
+
if (isServerSide()) {
|
|
12190
|
+
return [null, () => {
|
|
12191
|
+
}];
|
|
12192
|
+
}
|
|
12138
12193
|
const tonConnectUI2 = require$$0$2.useContext(TonConnectUIContext);
|
|
12139
12194
|
checkProvider(tonConnectUI2);
|
|
12140
12195
|
const setOptions = (options) => void (tonConnectUI2.uiOptions = options);
|
|
@@ -12150,6 +12205,9 @@ var __objRest = (source, exclude) => {
|
|
|
12150
12205
|
};
|
|
12151
12206
|
const TonConnectButton$1 = require$$0$2.memo(TonConnectButton);
|
|
12152
12207
|
function useTonWallet() {
|
|
12208
|
+
if (isServerSide()) {
|
|
12209
|
+
return null;
|
|
12210
|
+
}
|
|
12153
12211
|
const [tonConnectUI2] = useTonConnectUI();
|
|
12154
12212
|
const [wallet, setWallet] = require$$0$2.useState(
|
|
12155
12213
|
() => tonConnectUI2.wallet && __spreadValues2(__spreadValues2({}, tonConnectUI2.wallet), tonConnectUI2.walletInfo)
|
|
@@ -15026,6 +15084,9 @@ var __objRest = (source, exclude) => {
|
|
|
15026
15084
|
}
|
|
15027
15085
|
}
|
|
15028
15086
|
function useIsConnectionRestored() {
|
|
15087
|
+
if (isServerSide()) {
|
|
15088
|
+
return false;
|
|
15089
|
+
}
|
|
15029
15090
|
const [restored, setRestored] = require$$0$2.useState(false);
|
|
15030
15091
|
const [tonConnectUI2] = useTonConnectUI();
|
|
15031
15092
|
tonConnectUI2.connectionRestored.then(() => setRestored(true));
|