@tonconnect/ui 2.0.0 → 2.0.1-beta.0
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 +34 -0
- package/dist/tonconnect-ui.min.js +190 -190
- package/dist/tonconnect-ui.min.js.map +1 -1
- package/lib/index.cjs +261 -9
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +64 -0
- package/lib/index.mjs +261 -9
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -1956,6 +1956,20 @@ const [walletsModalState, setWalletsModalState] = createSignal({
|
|
|
1956
1956
|
closeReason: null
|
|
1957
1957
|
});
|
|
1958
1958
|
const getWalletsModalIsOpened = createMemo(() => walletsModalState().status === "opened");
|
|
1959
|
+
const [singleWalletModalState, setSingleWalletModalState] = createSignal({
|
|
1960
|
+
status: "closed",
|
|
1961
|
+
closeReason: null
|
|
1962
|
+
});
|
|
1963
|
+
const getSingleWalletModalIsOpened = createMemo(
|
|
1964
|
+
() => singleWalletModalState().status === "opened"
|
|
1965
|
+
);
|
|
1966
|
+
const getSingleWalletModalWalletInfo = createMemo(() => {
|
|
1967
|
+
const state = singleWalletModalState();
|
|
1968
|
+
if (state.status === "opened") {
|
|
1969
|
+
return state.walletInfo;
|
|
1970
|
+
}
|
|
1971
|
+
return null;
|
|
1972
|
+
});
|
|
1959
1973
|
let lastSelectedWalletInfoStorage = typeof window !== "undefined" ? new LastSelectedWalletInfoStorage() : void 0;
|
|
1960
1974
|
const [lastSelectedWalletInfo, _setLastSelectedWalletInfo] = createSignal((lastSelectedWalletInfoStorage == null ? void 0 : lastSelectedWalletInfoStorage.getLastSelectedWalletInfo()) || null);
|
|
1961
1975
|
const setLastSelectedWalletInfo = (walletInfo) => {
|
|
@@ -8429,9 +8443,16 @@ const DesktopConnectionModal = (props) => {
|
|
|
8429
8443
|
return createComponent(DesktopConnectionModalStyled, {
|
|
8430
8444
|
"data-tc-wallets-modal-connection-desktop": "true",
|
|
8431
8445
|
get children() {
|
|
8432
|
-
return [createComponent(
|
|
8433
|
-
|
|
8434
|
-
|
|
8446
|
+
return [createComponent(Show, {
|
|
8447
|
+
get when() {
|
|
8448
|
+
return !props.backDisabled;
|
|
8449
|
+
},
|
|
8450
|
+
get children() {
|
|
8451
|
+
return createComponent(StyledIconButton$2, {
|
|
8452
|
+
icon: "arrow",
|
|
8453
|
+
onClick: () => props.onBackClick()
|
|
8454
|
+
});
|
|
8455
|
+
}
|
|
8435
8456
|
}), createComponent(H1Styled$6, {
|
|
8436
8457
|
get children() {
|
|
8437
8458
|
return props.wallet.name;
|
|
@@ -8969,7 +8990,22 @@ const MobileConnectionModal = (props) => {
|
|
|
8969
8990
|
universalLink: props.wallet.universalLink,
|
|
8970
8991
|
bridgeUrl: props.wallet.bridgeUrl
|
|
8971
8992
|
}, props.additionalRequest));
|
|
8993
|
+
const onClickTelegram = () => {
|
|
8994
|
+
const alwaysForceRedirect = true;
|
|
8995
|
+
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
8996
|
+
openMethod: "universal-link"
|
|
8997
|
+
}));
|
|
8998
|
+
redirectToTelegram(universalLink(), {
|
|
8999
|
+
returnStrategy: appState.returnStrategy,
|
|
9000
|
+
twaReturnUrl: appState.twaReturnUrl,
|
|
9001
|
+
forceRedirect: alwaysForceRedirect
|
|
9002
|
+
});
|
|
9003
|
+
};
|
|
8972
9004
|
const onRetry = () => {
|
|
9005
|
+
const currentUniversalLink = universalLink();
|
|
9006
|
+
if (sdk.isTelegramUrl(currentUniversalLink)) {
|
|
9007
|
+
return onClickTelegram();
|
|
9008
|
+
}
|
|
8973
9009
|
setConnectionErrored(false);
|
|
8974
9010
|
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
8975
9011
|
openMethod: "universal-link"
|
|
@@ -9001,9 +9037,16 @@ const MobileConnectionModal = (props) => {
|
|
|
9001
9037
|
return createComponent(MobileConnectionModalStyled, {
|
|
9002
9038
|
"data-tc-wallets-modal-connection-mobile": "true",
|
|
9003
9039
|
get children() {
|
|
9004
|
-
return [createComponent(
|
|
9005
|
-
|
|
9006
|
-
|
|
9040
|
+
return [createComponent(Show, {
|
|
9041
|
+
get when() {
|
|
9042
|
+
return !props.backDisabled || showQR();
|
|
9043
|
+
},
|
|
9044
|
+
get children() {
|
|
9045
|
+
return createComponent(StyledIconButton, {
|
|
9046
|
+
icon: "arrow",
|
|
9047
|
+
onClick: onBack
|
|
9048
|
+
});
|
|
9049
|
+
}
|
|
9007
9050
|
}), createComponent(Show, {
|
|
9008
9051
|
get when() {
|
|
9009
9052
|
return showQR();
|
|
@@ -10013,6 +10056,109 @@ const ActionsModal = () => {
|
|
|
10013
10056
|
}
|
|
10014
10057
|
});
|
|
10015
10058
|
};
|
|
10059
|
+
const SingleWalletModal = () => {
|
|
10060
|
+
const {
|
|
10061
|
+
locale
|
|
10062
|
+
} = useI18n()[1];
|
|
10063
|
+
createEffect(() => locale(appState.language));
|
|
10064
|
+
createEffect(() => {
|
|
10065
|
+
if (getSingleWalletModalIsOpened()) {
|
|
10066
|
+
updateIsMobile();
|
|
10067
|
+
}
|
|
10068
|
+
});
|
|
10069
|
+
const connector = useContext(ConnectorContext);
|
|
10070
|
+
const [infoTab, setInfoTab] = createSignal(false);
|
|
10071
|
+
const additionalRequestLoading = () => {
|
|
10072
|
+
var _a2;
|
|
10073
|
+
return ((_a2 = appState.connectRequestParameters) == null ? void 0 : _a2.state) === "loading";
|
|
10074
|
+
};
|
|
10075
|
+
const additionalRequest = createMemo(() => {
|
|
10076
|
+
var _a2;
|
|
10077
|
+
if (additionalRequestLoading()) {
|
|
10078
|
+
return void 0;
|
|
10079
|
+
}
|
|
10080
|
+
return (_a2 = appState.connectRequestParameters) == null ? void 0 : _a2.value;
|
|
10081
|
+
});
|
|
10082
|
+
const onClose = (closeReason) => {
|
|
10083
|
+
setSingleWalletModalState({
|
|
10084
|
+
status: "closed",
|
|
10085
|
+
closeReason
|
|
10086
|
+
});
|
|
10087
|
+
setInfoTab(false);
|
|
10088
|
+
};
|
|
10089
|
+
const unsubscribe = connector.onStatusChange((wallet) => {
|
|
10090
|
+
if (wallet) {
|
|
10091
|
+
onClose("wallet-selected");
|
|
10092
|
+
}
|
|
10093
|
+
});
|
|
10094
|
+
onCleanup(unsubscribe);
|
|
10095
|
+
return createComponent(StyledModal, {
|
|
10096
|
+
get opened() {
|
|
10097
|
+
return getSingleWalletModalIsOpened();
|
|
10098
|
+
},
|
|
10099
|
+
get enableAndroidBackHandler() {
|
|
10100
|
+
return appState.enableAndroidBackHandler;
|
|
10101
|
+
},
|
|
10102
|
+
onClose: () => onClose("action-cancelled"),
|
|
10103
|
+
onClickQuestion: () => setInfoTab((v) => !v),
|
|
10104
|
+
"data-tc-wallets-modal-container": "true",
|
|
10105
|
+
get children() {
|
|
10106
|
+
return [createComponent(Show, {
|
|
10107
|
+
get when() {
|
|
10108
|
+
return infoTab();
|
|
10109
|
+
},
|
|
10110
|
+
get children() {
|
|
10111
|
+
return createComponent(InfoModal, {
|
|
10112
|
+
onBackClick: () => setInfoTab(false)
|
|
10113
|
+
});
|
|
10114
|
+
}
|
|
10115
|
+
}), createComponent(Show, {
|
|
10116
|
+
get when() {
|
|
10117
|
+
return !infoTab();
|
|
10118
|
+
},
|
|
10119
|
+
get children() {
|
|
10120
|
+
return [createComponent(Show, {
|
|
10121
|
+
get when() {
|
|
10122
|
+
return additionalRequestLoading();
|
|
10123
|
+
},
|
|
10124
|
+
get children() {
|
|
10125
|
+
return [createComponent(H1Styled$8, {
|
|
10126
|
+
translationKey: "walletModal.loading",
|
|
10127
|
+
children: "Wallets list is loading"
|
|
10128
|
+
}), createComponent(LoaderContainerStyled, {
|
|
10129
|
+
get children() {
|
|
10130
|
+
return createComponent(LoaderIcon, {
|
|
10131
|
+
size: "m"
|
|
10132
|
+
});
|
|
10133
|
+
}
|
|
10134
|
+
})];
|
|
10135
|
+
}
|
|
10136
|
+
}), createComponent(Show, {
|
|
10137
|
+
get when() {
|
|
10138
|
+
return !additionalRequestLoading();
|
|
10139
|
+
},
|
|
10140
|
+
get children() {
|
|
10141
|
+
return createComponent(Dynamic, {
|
|
10142
|
+
get component() {
|
|
10143
|
+
return isMobile() ? MobileConnectionModal : DesktopConnectionModal;
|
|
10144
|
+
},
|
|
10145
|
+
get wallet() {
|
|
10146
|
+
return getSingleWalletModalWalletInfo();
|
|
10147
|
+
},
|
|
10148
|
+
get additionalRequest() {
|
|
10149
|
+
return additionalRequest();
|
|
10150
|
+
},
|
|
10151
|
+
onBackClick: () => {
|
|
10152
|
+
},
|
|
10153
|
+
backDisabled: true
|
|
10154
|
+
});
|
|
10155
|
+
}
|
|
10156
|
+
})];
|
|
10157
|
+
}
|
|
10158
|
+
})];
|
|
10159
|
+
}
|
|
10160
|
+
});
|
|
10161
|
+
};
|
|
10016
10162
|
const App = (props) => {
|
|
10017
10163
|
const translations = createI18nContext(i18nDictionary, appState.language);
|
|
10018
10164
|
defineStylesRoot();
|
|
@@ -10050,7 +10196,7 @@ const App = (props) => {
|
|
|
10050
10196
|
}), createComponent(Dynamic, {
|
|
10051
10197
|
component: globalStylesTag,
|
|
10052
10198
|
get children() {
|
|
10053
|
-
return [createComponent(WalletsModal, {}), createComponent(ActionsModal, {})];
|
|
10199
|
+
return [createComponent(WalletsModal, {}), createComponent(SingleWalletModal, {}), createComponent(ActionsModal, {})];
|
|
10054
10200
|
}
|
|
10055
10201
|
})];
|
|
10056
10202
|
}
|
|
@@ -10071,6 +10217,17 @@ const widgetController = {
|
|
|
10071
10217
|
status: "closed",
|
|
10072
10218
|
closeReason: reason
|
|
10073
10219
|
})),
|
|
10220
|
+
openSingleWalletModal: (walletInfo) => {
|
|
10221
|
+
void setTimeout(() => setSingleWalletModalState({
|
|
10222
|
+
status: "opened",
|
|
10223
|
+
closeReason: null,
|
|
10224
|
+
walletInfo
|
|
10225
|
+
}));
|
|
10226
|
+
},
|
|
10227
|
+
closeSingleWalletModal: (reason) => void setTimeout(() => setSingleWalletModalState({
|
|
10228
|
+
status: "closed",
|
|
10229
|
+
closeReason: reason
|
|
10230
|
+
})),
|
|
10074
10231
|
setAction: (action2) => void setTimeout(() => setAction(action2)),
|
|
10075
10232
|
clearAction: () => void setTimeout(() => setAction(null)),
|
|
10076
10233
|
getSelectedWalletInfo: () => lastSelectedWalletInfo(),
|
|
@@ -10100,7 +10257,7 @@ class WalletsModalManager {
|
|
|
10100
10257
|
if (embeddedWallet) {
|
|
10101
10258
|
return this.connectEmbeddedWallet(embeddedWallet);
|
|
10102
10259
|
} else {
|
|
10103
|
-
return this.
|
|
10260
|
+
return this.openWalletsModal();
|
|
10104
10261
|
}
|
|
10105
10262
|
});
|
|
10106
10263
|
}
|
|
@@ -10125,7 +10282,7 @@ class WalletsModalManager {
|
|
|
10125
10282
|
connect(additionalRequest == null ? void 0 : additionalRequest.value);
|
|
10126
10283
|
}
|
|
10127
10284
|
}
|
|
10128
|
-
|
|
10285
|
+
openWalletsModal() {
|
|
10129
10286
|
return __async(this, null, function* () {
|
|
10130
10287
|
if (isInTMA()) {
|
|
10131
10288
|
sendExpand();
|
|
@@ -10160,6 +10317,80 @@ class TransactionModalManager {
|
|
|
10160
10317
|
};
|
|
10161
10318
|
}
|
|
10162
10319
|
}
|
|
10320
|
+
class SingleWalletModalManager {
|
|
10321
|
+
constructor(options) {
|
|
10322
|
+
__publicField(this, "connector");
|
|
10323
|
+
__publicField(this, "setConnectRequestParametersCallback");
|
|
10324
|
+
__publicField(this, "consumers", []);
|
|
10325
|
+
__publicField(this, "state", singleWalletModalState());
|
|
10326
|
+
this.connector = options.connector;
|
|
10327
|
+
this.setConnectRequestParametersCallback = options.setConnectRequestParametersCallback;
|
|
10328
|
+
createEffect(() => {
|
|
10329
|
+
const state = singleWalletModalState();
|
|
10330
|
+
this.state = state;
|
|
10331
|
+
this.consumers.forEach((consumer) => consumer(state));
|
|
10332
|
+
});
|
|
10333
|
+
}
|
|
10334
|
+
open(wallet) {
|
|
10335
|
+
return __async(this, null, function* () {
|
|
10336
|
+
const fetchedWalletsList = yield this.connector.getWallets();
|
|
10337
|
+
const walletsList = applyWalletsListConfiguration(
|
|
10338
|
+
fetchedWalletsList,
|
|
10339
|
+
appState.walletsListConfiguration
|
|
10340
|
+
);
|
|
10341
|
+
const embeddedWallet = walletsList.find(sdk.isWalletInfoCurrentlyEmbedded);
|
|
10342
|
+
const isEmbeddedWalletExist = !!embeddedWallet;
|
|
10343
|
+
if (isEmbeddedWalletExist) {
|
|
10344
|
+
return this.connectEmbeddedWallet(embeddedWallet);
|
|
10345
|
+
}
|
|
10346
|
+
const externalWallets = walletsList.filter(sdk.isWalletInfoRemote);
|
|
10347
|
+
const externalWallet = externalWallets.find((walletInfo) => eqWalletName(walletInfo, wallet));
|
|
10348
|
+
const isExternalWalletExist = !!externalWallet;
|
|
10349
|
+
if (isExternalWalletExist) {
|
|
10350
|
+
return this.openSingleWalletModal(externalWallet);
|
|
10351
|
+
}
|
|
10352
|
+
throw new TonConnectUIError(`Trying to open modal window with unknown wallet "${wallet}".`);
|
|
10353
|
+
});
|
|
10354
|
+
}
|
|
10355
|
+
close() {
|
|
10356
|
+
widgetController.closeSingleWalletModal("action-cancelled");
|
|
10357
|
+
}
|
|
10358
|
+
onStateChange(onChange) {
|
|
10359
|
+
this.consumers.push(onChange);
|
|
10360
|
+
return () => {
|
|
10361
|
+
this.consumers = this.consumers.filter((consumer) => consumer !== onChange);
|
|
10362
|
+
};
|
|
10363
|
+
}
|
|
10364
|
+
connectEmbeddedWallet(embeddedWallet) {
|
|
10365
|
+
const connect = (parameters) => {
|
|
10366
|
+
setLastSelectedWalletInfo(embeddedWallet);
|
|
10367
|
+
this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey }, parameters);
|
|
10368
|
+
};
|
|
10369
|
+
const additionalRequest = appState.connectRequestParameters;
|
|
10370
|
+
if ((additionalRequest == null ? void 0 : additionalRequest.state) === "loading") {
|
|
10371
|
+
this.setConnectRequestParametersCallback(connect);
|
|
10372
|
+
} else {
|
|
10373
|
+
connect(additionalRequest == null ? void 0 : additionalRequest.value);
|
|
10374
|
+
}
|
|
10375
|
+
}
|
|
10376
|
+
openSingleWalletModal(wallet) {
|
|
10377
|
+
return __async(this, null, function* () {
|
|
10378
|
+
if (isInTMA()) {
|
|
10379
|
+
sendExpand();
|
|
10380
|
+
}
|
|
10381
|
+
widgetController.openSingleWalletModal(wallet);
|
|
10382
|
+
return new Promise((resolve) => {
|
|
10383
|
+
const unsubscribe = this.onStateChange((state) => {
|
|
10384
|
+
const { status } = state;
|
|
10385
|
+
if (status === "opened") {
|
|
10386
|
+
unsubscribe();
|
|
10387
|
+
resolve();
|
|
10388
|
+
}
|
|
10389
|
+
});
|
|
10390
|
+
});
|
|
10391
|
+
});
|
|
10392
|
+
}
|
|
10393
|
+
}
|
|
10163
10394
|
class TonConnectUI {
|
|
10164
10395
|
constructor(options) {
|
|
10165
10396
|
__publicField(this, "walletInfoStorage", new WalletInfoStorage());
|
|
@@ -10171,6 +10402,7 @@ class TonConnectUI {
|
|
|
10171
10402
|
__publicField(this, "connectRequestParametersCallback");
|
|
10172
10403
|
__publicField(this, "connector");
|
|
10173
10404
|
__publicField(this, "modal");
|
|
10405
|
+
__publicField(this, "singleWalletModal");
|
|
10174
10406
|
__publicField(this, "transactionModal");
|
|
10175
10407
|
__publicField(this, "connectionRestored", Promise.resolve(false));
|
|
10176
10408
|
if (options && "connector" in options && options.connector) {
|
|
@@ -10188,6 +10420,12 @@ class TonConnectUI {
|
|
|
10188
10420
|
this.connectRequestParametersCallback = callback;
|
|
10189
10421
|
}
|
|
10190
10422
|
});
|
|
10423
|
+
this.singleWalletModal = new SingleWalletModalManager({
|
|
10424
|
+
connector: this.connector,
|
|
10425
|
+
setConnectRequestParametersCallback: (callback) => {
|
|
10426
|
+
this.connectRequestParametersCallback = callback;
|
|
10427
|
+
}
|
|
10428
|
+
});
|
|
10191
10429
|
this.transactionModal = new TransactionModalManager({
|
|
10192
10430
|
connector: this.connector
|
|
10193
10431
|
});
|
|
@@ -10306,6 +10544,20 @@ class TonConnectUI {
|
|
|
10306
10544
|
get modalState() {
|
|
10307
10545
|
return this.modal.state;
|
|
10308
10546
|
}
|
|
10547
|
+
openSingleWalletModal(wallet) {
|
|
10548
|
+
return __async(this, null, function* () {
|
|
10549
|
+
return this.singleWalletModal.open(wallet);
|
|
10550
|
+
});
|
|
10551
|
+
}
|
|
10552
|
+
closeSingleWalletModal() {
|
|
10553
|
+
this.singleWalletModal.close();
|
|
10554
|
+
}
|
|
10555
|
+
onSingleWalletModalStateChange(onChange) {
|
|
10556
|
+
return this.singleWalletModal.onStateChange(onChange);
|
|
10557
|
+
}
|
|
10558
|
+
get singleWalletModalState() {
|
|
10559
|
+
return this.singleWalletModal.state;
|
|
10560
|
+
}
|
|
10309
10561
|
connectWallet() {
|
|
10310
10562
|
return __async(this, null, function* () {
|
|
10311
10563
|
const walletsList = yield this.getWallets();
|