@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/README.md
CHANGED
|
@@ -153,9 +153,9 @@ You can use it to detect when connection restoring process if finished.
|
|
|
153
153
|
import { useIsConnectionRestored } from '@tonconnect/ui-react';
|
|
154
154
|
|
|
155
155
|
export const EntrypointPage = () => {
|
|
156
|
-
const
|
|
156
|
+
const connectionRestored = useIsConnectionRestored();
|
|
157
157
|
|
|
158
|
-
if (
|
|
158
|
+
if (!connectionRestored) {
|
|
159
159
|
return <Loader>Please wait...</Loader>;
|
|
160
160
|
}
|
|
161
161
|
|
|
@@ -42,7 +42,7 @@ export interface TonConnectUIProviderPropsBase {
|
|
|
42
42
|
*/
|
|
43
43
|
walletsList?: WalletsListConfiguration;
|
|
44
44
|
/**
|
|
45
|
-
* Configuration for action-period (e.g. sendTransaction) UI elements: modals and notifications.
|
|
45
|
+
* Configuration for action-period (e.g. sendTransaction) UI elements: modals and notifications and wallet behaviour (return strategy).
|
|
46
46
|
*/
|
|
47
47
|
actionsConfiguration?: ActionConfiguration;
|
|
48
48
|
/**
|
package/lib/index.js
CHANGED
|
@@ -4053,10 +4053,12 @@ class BridgeProvider {
|
|
|
4053
4053
|
this.storage = storage;
|
|
4054
4054
|
this.walletConnectionSource = walletConnectionSource;
|
|
4055
4055
|
this.type = "http";
|
|
4056
|
+
this.standardUniversalLink = "https://connect.ton.org";
|
|
4056
4057
|
this.pendingRequests = /* @__PURE__ */ new Map();
|
|
4057
4058
|
this.nextRequestId = 0;
|
|
4058
4059
|
this.session = null;
|
|
4059
4060
|
this.bridge = null;
|
|
4061
|
+
this.pendingBridges = [];
|
|
4060
4062
|
this.listeners = [];
|
|
4061
4063
|
this.connectionStorage = new BridgeConnectionStorage(storage);
|
|
4062
4064
|
}
|
|
@@ -4068,21 +4070,32 @@ class BridgeProvider {
|
|
|
4068
4070
|
});
|
|
4069
4071
|
}
|
|
4070
4072
|
connect(message) {
|
|
4071
|
-
|
|
4072
|
-
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4073
|
+
this.closeBridges();
|
|
4073
4074
|
const sessionCrypto = new SessionCrypto();
|
|
4075
|
+
let walletConnectionSource = {
|
|
4076
|
+
universalLink: this.standardUniversalLink,
|
|
4077
|
+
bridgeUrl: ""
|
|
4078
|
+
};
|
|
4079
|
+
if (Array.isArray(this.walletConnectionSource)) {
|
|
4080
|
+
this.pendingBridges = this.walletConnectionSource.map((source) => new BridgeGateway(this.storage, source, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this)));
|
|
4081
|
+
this.pendingBridges.forEach((bridge) => bridge.registerSession());
|
|
4082
|
+
} else {
|
|
4083
|
+
walletConnectionSource = this.walletConnectionSource;
|
|
4084
|
+
this.bridge = new BridgeGateway(this.storage, this.walletConnectionSource.bridgeUrl, sessionCrypto.sessionId, this.gatewayListener.bind(this), this.gatewayErrorsListener.bind(this));
|
|
4085
|
+
this.bridge.registerSession();
|
|
4086
|
+
}
|
|
4074
4087
|
this.session = {
|
|
4075
4088
|
sessionCrypto,
|
|
4076
|
-
walletConnectionSource
|
|
4089
|
+
walletConnectionSource
|
|
4077
4090
|
};
|
|
4078
|
-
this.
|
|
4079
|
-
this.bridge.registerSession();
|
|
4080
|
-
return this.generateUniversalLink(message);
|
|
4091
|
+
return this.generateUniversalLink(walletConnectionSource.universalLink, message);
|
|
4081
4092
|
}
|
|
4082
4093
|
restoreConnection() {
|
|
4083
|
-
var _a;
|
|
4084
4094
|
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4085
|
-
(
|
|
4095
|
+
if (Array.isArray(this.walletConnectionSource)) {
|
|
4096
|
+
throw new TonConnectError$1("Internal error. Connection source is array while WalletConnectionSourceHTTP was expected.");
|
|
4097
|
+
}
|
|
4098
|
+
this.closeBridges();
|
|
4086
4099
|
const storedConnection = yield this.connectionStorage.getHttpConnection();
|
|
4087
4100
|
if (!storedConnection) {
|
|
4088
4101
|
return;
|
|
@@ -4106,15 +4119,13 @@ class BridgeProvider {
|
|
|
4106
4119
|
});
|
|
4107
4120
|
}
|
|
4108
4121
|
closeConnection() {
|
|
4109
|
-
|
|
4110
|
-
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4122
|
+
this.closeBridges();
|
|
4111
4123
|
this.listeners = [];
|
|
4112
4124
|
this.session = null;
|
|
4113
4125
|
this.bridge = null;
|
|
4114
4126
|
}
|
|
4115
4127
|
disconnect() {
|
|
4116
|
-
|
|
4117
|
-
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4128
|
+
this.closeBridges();
|
|
4118
4129
|
this.listeners = [];
|
|
4119
4130
|
return this.removeBridgeAndSession();
|
|
4120
4131
|
}
|
|
@@ -4122,6 +4133,18 @@ class BridgeProvider {
|
|
|
4122
4133
|
this.listeners.push(callback);
|
|
4123
4134
|
return () => this.listeners = this.listeners.filter((listener) => listener !== callback);
|
|
4124
4135
|
}
|
|
4136
|
+
pendingGatewaysListener(gateway, bridgeIncomingMessage) {
|
|
4137
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4138
|
+
if (!this.pendingBridges.includes(gateway)) {
|
|
4139
|
+
gateway.close();
|
|
4140
|
+
return;
|
|
4141
|
+
}
|
|
4142
|
+
this.closeBridges();
|
|
4143
|
+
this.session.walletConnectionSource.bridgeUrl = gateway.bridgeUrl;
|
|
4144
|
+
this.bridge = gateway;
|
|
4145
|
+
return this.gatewayListener(bridgeIncomingMessage);
|
|
4146
|
+
});
|
|
4147
|
+
}
|
|
4125
4148
|
gatewayListener(bridgeIncomingMessage) {
|
|
4126
4149
|
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4127
4150
|
const walletMessage = JSON.parse(this.session.sessionCrypto.decrypt(Base64$1.decode(bridgeIncomingMessage.message).toUint8Array(), hexToByteArray(bridgeIncomingMessage.from)));
|
|
@@ -4168,13 +4191,19 @@ class BridgeProvider {
|
|
|
4168
4191
|
yield this.connectionStorage.removeConnection();
|
|
4169
4192
|
});
|
|
4170
4193
|
}
|
|
4171
|
-
generateUniversalLink(message) {
|
|
4172
|
-
const url = new URL(
|
|
4194
|
+
generateUniversalLink(universalLink, message) {
|
|
4195
|
+
const url = new URL(universalLink);
|
|
4173
4196
|
url.searchParams.append("v", PROTOCOL_VERSION.toString());
|
|
4174
4197
|
url.searchParams.append("id", this.session.sessionCrypto.sessionId);
|
|
4175
4198
|
url.searchParams.append("r", JSON.stringify(message));
|
|
4176
4199
|
return url.toString();
|
|
4177
4200
|
}
|
|
4201
|
+
closeBridges(except) {
|
|
4202
|
+
var _a;
|
|
4203
|
+
(_a = this.bridge) === null || _a === void 0 ? void 0 : _a.close();
|
|
4204
|
+
this.pendingBridges.filter((item) => item !== except).forEach((bridge) => bridge.close());
|
|
4205
|
+
this.pendingBridges = [];
|
|
4206
|
+
}
|
|
4178
4207
|
}
|
|
4179
4208
|
function getWindow$1() {
|
|
4180
4209
|
if (typeof window === "undefined") {
|
|
@@ -4658,7 +4687,7 @@ class TonConnect {
|
|
|
4658
4687
|
}
|
|
4659
4688
|
createProvider(wallet) {
|
|
4660
4689
|
let provider;
|
|
4661
|
-
if (isWalletConnectionSourceJS(wallet)) {
|
|
4690
|
+
if (!Array.isArray(wallet) && isWalletConnectionSourceJS(wallet)) {
|
|
4662
4691
|
provider = new InjectedProvider(this.dappSettings.storage, wallet.jsBridgeKey);
|
|
4663
4692
|
} else {
|
|
4664
4693
|
provider = new BridgeProvider(this.dappSettings.storage, wallet);
|
|
@@ -5853,6 +5882,9 @@ function render(code, element, init, options = {}) {
|
|
|
5853
5882
|
};
|
|
5854
5883
|
}
|
|
5855
5884
|
function template$1(html, check, isSVG) {
|
|
5885
|
+
if (typeof window === "undefined") {
|
|
5886
|
+
return null;
|
|
5887
|
+
}
|
|
5856
5888
|
const t2 = document.createElement("template");
|
|
5857
5889
|
t2.innerHTML = html;
|
|
5858
5890
|
let node = t2.content.firstChild;
|
|
@@ -11135,6 +11167,20 @@ function subscribeToThemeChange(callback) {
|
|
|
11135
11167
|
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", handler);
|
|
11136
11168
|
return () => window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", handler);
|
|
11137
11169
|
}
|
|
11170
|
+
function addQueryParameter(url, key, value) {
|
|
11171
|
+
const parsed = new URL(url);
|
|
11172
|
+
parsed.searchParams.append(key, value);
|
|
11173
|
+
return parsed.toString();
|
|
11174
|
+
}
|
|
11175
|
+
function addReturnStrategy(url, returnStrategy) {
|
|
11176
|
+
return addQueryParameter(url, "ret", returnStrategy);
|
|
11177
|
+
}
|
|
11178
|
+
const [appState, setAppState] = createStore({
|
|
11179
|
+
buttonRootId: null,
|
|
11180
|
+
language: "en",
|
|
11181
|
+
returnStrategy: "back",
|
|
11182
|
+
walletsList: {}
|
|
11183
|
+
});
|
|
11138
11184
|
const QrCodeModal = (props) => {
|
|
11139
11185
|
const connector = useContext(ConnectorContext);
|
|
11140
11186
|
const universalLink = connector.connect({
|
|
@@ -11185,7 +11231,7 @@ const QrCodeModal = (props) => {
|
|
|
11185
11231
|
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
11186
11232
|
openMethod: "universal-link"
|
|
11187
11233
|
}));
|
|
11188
|
-
openLink(universalLink);
|
|
11234
|
+
openLink(addReturnStrategy(universalLink, appState.returnStrategy));
|
|
11189
11235
|
},
|
|
11190
11236
|
get children() {
|
|
11191
11237
|
return createComponent(Translation, {
|
|
@@ -11425,11 +11471,6 @@ const LoaderContainerStyled = styled.div`
|
|
|
11425
11471
|
align-items: center;
|
|
11426
11472
|
}
|
|
11427
11473
|
`;
|
|
11428
|
-
const [appState, setAppState] = createStore({
|
|
11429
|
-
buttonRootId: null,
|
|
11430
|
-
language: "en",
|
|
11431
|
-
walletsList: {}
|
|
11432
|
-
});
|
|
11433
11474
|
function uiWalletToWalletInfo(uiWallet) {
|
|
11434
11475
|
if ("jsBridgeKey" in uiWallet) {
|
|
11435
11476
|
return __spreadProps(__spreadValues({}, uiWallet), {
|
|
@@ -11533,14 +11574,14 @@ const WalletsModal = () => {
|
|
|
11533
11574
|
setSelectedWalletInfo(walletInfo);
|
|
11534
11575
|
return;
|
|
11535
11576
|
}
|
|
11536
|
-
|
|
11577
|
+
openLinkBlank(walletInfo.aboutUrl);
|
|
11537
11578
|
};
|
|
11538
11579
|
const onSelectIfMobile = (walletInfo) => {
|
|
11539
11580
|
const universalLink = connector.connect({
|
|
11540
11581
|
universalLink: walletInfo.universalLink,
|
|
11541
11582
|
bridgeUrl: walletInfo.bridgeUrl
|
|
11542
11583
|
}, additionalRequest());
|
|
11543
|
-
openLink(universalLink);
|
|
11584
|
+
openLink(addReturnStrategy(universalLink, appState.returnStrategy));
|
|
11544
11585
|
};
|
|
11545
11586
|
const onSelectIfInjected = (walletInfo) => {
|
|
11546
11587
|
connector.connect({
|
|
@@ -11832,7 +11873,7 @@ class WalletInfoStorage {
|
|
|
11832
11873
|
constructor() {
|
|
11833
11874
|
__publicField(this, "localStorage");
|
|
11834
11875
|
__publicField(this, "storageKey", "ton-connect-ui_wallet-info");
|
|
11835
|
-
if (
|
|
11876
|
+
if (typeof localStorage === "undefined") {
|
|
11836
11877
|
throw new TonConnectUIError(
|
|
11837
11878
|
"window.localStorage is undefined. localStorage is required for TonConnectUI"
|
|
11838
11879
|
);
|
|
@@ -11930,8 +11971,11 @@ class TonConnectUI {
|
|
|
11930
11971
|
setBorderRadius(options.uiPreferences.borderRadius);
|
|
11931
11972
|
}
|
|
11932
11973
|
setAppState((state) => {
|
|
11974
|
+
var _a2;
|
|
11933
11975
|
const merged = mergeOptions(
|
|
11934
|
-
__spreadValues(__spreadValues({}, options.language && { language: options.language }), !!options.
|
|
11976
|
+
__spreadValues(__spreadValues(__spreadValues({}, options.language && { language: options.language }), !!((_a2 = options.actionsConfiguration) == null ? void 0 : _a2.returnStrategy) && {
|
|
11977
|
+
returnStrategy: options.actionsConfiguration.returnStrategy
|
|
11978
|
+
}), !!options.walletsList && { walletsList: options.walletsList }),
|
|
11935
11979
|
unwrap(state)
|
|
11936
11980
|
);
|
|
11937
11981
|
if (options.buttonRootId !== void 0) {
|
|
@@ -11991,10 +12035,10 @@ class TonConnectUI {
|
|
|
11991
12035
|
if (!this.connected || !this.walletInfo) {
|
|
11992
12036
|
throw new TonConnectUIError("Connect wallet to send a transaction.");
|
|
11993
12037
|
}
|
|
12038
|
+
const { notifications: notifications2, modals, returnStrategy } = this.getModalsAndNotificationsConfiguration(options);
|
|
11994
12039
|
if ("universalLink" in this.walletInfo && this.walletInfo.openMethod === "universal-link") {
|
|
11995
|
-
openLink(this.walletInfo.universalLink);
|
|
12040
|
+
openLink(addReturnStrategy(this.walletInfo.universalLink, returnStrategy));
|
|
11996
12041
|
}
|
|
11997
|
-
const { notifications: notifications2, modals } = this.getModalsAndNotificationsConfiguration(options);
|
|
11998
12042
|
widgetController.setAction({
|
|
11999
12043
|
name: "confirm-transaction",
|
|
12000
12044
|
showNotification: notifications2.includes("before"),
|
|
@@ -12093,10 +12137,17 @@ class TonConnectUI {
|
|
|
12093
12137
|
}
|
|
12094
12138
|
return {
|
|
12095
12139
|
notifications: notifications2,
|
|
12096
|
-
modals
|
|
12140
|
+
modals,
|
|
12141
|
+
returnStrategy: (options == null ? void 0 : options.returnStrategy) || "back"
|
|
12097
12142
|
};
|
|
12098
12143
|
}
|
|
12099
12144
|
}
|
|
12145
|
+
function isClientSide() {
|
|
12146
|
+
return typeof window !== "undefined";
|
|
12147
|
+
}
|
|
12148
|
+
function isServerSide() {
|
|
12149
|
+
return !isClientSide();
|
|
12150
|
+
}
|
|
12100
12151
|
const TonConnectUIContext = createContext$1(null);
|
|
12101
12152
|
let tonConnectUI = null;
|
|
12102
12153
|
const TonConnectUIProvider = (_a) => {
|
|
@@ -12105,7 +12156,7 @@ const TonConnectUIProvider = (_a) => {
|
|
|
12105
12156
|
} = _b, options = __objRest(_b, [
|
|
12106
12157
|
"children"
|
|
12107
12158
|
]);
|
|
12108
|
-
if (!tonConnectUI) {
|
|
12159
|
+
if (isClientSide() && !tonConnectUI) {
|
|
12109
12160
|
tonConnectUI = new TonConnectUI(options);
|
|
12110
12161
|
}
|
|
12111
12162
|
return /* @__PURE__ */ jsx(TonConnectUIContext.Provider, { value: tonConnectUI, children: children2 });
|
|
@@ -12132,6 +12183,10 @@ function checkProvider(provider) {
|
|
|
12132
12183
|
return true;
|
|
12133
12184
|
}
|
|
12134
12185
|
function useTonConnectUI() {
|
|
12186
|
+
if (isServerSide()) {
|
|
12187
|
+
return [null, () => {
|
|
12188
|
+
}];
|
|
12189
|
+
}
|
|
12135
12190
|
const tonConnectUI2 = useContext$1(TonConnectUIContext);
|
|
12136
12191
|
checkProvider(tonConnectUI2);
|
|
12137
12192
|
const setOptions = (options) => void (tonConnectUI2.uiOptions = options);
|
|
@@ -12147,6 +12202,9 @@ const TonConnectButton = ({ className: className2, style: style2 }) => {
|
|
|
12147
12202
|
};
|
|
12148
12203
|
const TonConnectButton$1 = memo(TonConnectButton);
|
|
12149
12204
|
function useTonWallet() {
|
|
12205
|
+
if (isServerSide()) {
|
|
12206
|
+
return null;
|
|
12207
|
+
}
|
|
12150
12208
|
const [tonConnectUI2] = useTonConnectUI();
|
|
12151
12209
|
const [wallet, setWallet] = useState(
|
|
12152
12210
|
() => tonConnectUI2.wallet && __spreadValues2(__spreadValues2({}, tonConnectUI2.wallet), tonConnectUI2.walletInfo)
|
|
@@ -15023,6 +15081,9 @@ function useTonAddress(userFriendly = true) {
|
|
|
15023
15081
|
}
|
|
15024
15082
|
}
|
|
15025
15083
|
function useIsConnectionRestored() {
|
|
15084
|
+
if (isServerSide()) {
|
|
15085
|
+
return false;
|
|
15086
|
+
}
|
|
15026
15087
|
const [restored, setRestored] = useState(false);
|
|
15027
15088
|
const [tonConnectUI2] = useTonConnectUI();
|
|
15028
15089
|
tonConnectUI2.connectionRestored.then(() => setRestored(true));
|