@tonconnect/ui 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 +40 -0
- package/dist/tonconnect-ui.min.js +11 -6
- package/dist/tonconnect-ui.min.js.map +1 -1
- package/lib/index.d.ts +13 -5
- package/lib/index.js +59 -19
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +59 -19
- package/lib/index.umd.js.map +1 -1
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletInfoBase, WalletInfoInjected, WalletInfoRemote, ITonConnect, WalletInfo, Account, Wallet, TonConnectError, SendTransactionRequest, SendTransactionResponse } from '@tonconnect/sdk';
|
|
1
|
+
import { WalletInfoBase, WalletInfoInjected, WalletInfoRemote, ITonConnect, ConnectAdditionalRequest, WalletInfo, Account, Wallet, TonConnectError, SendTransactionRequest, SendTransactionResponse } from '@tonconnect/sdk';
|
|
2
2
|
import { Property } from 'csstype';
|
|
3
3
|
|
|
4
4
|
declare type Locales = 'en' | 'ru';
|
|
@@ -149,10 +149,6 @@ interface TonConnectUiOptions {
|
|
|
149
149
|
* Configuration for action-period (e.g. sendTransaction) UI elements: modals and notifications.
|
|
150
150
|
*/
|
|
151
151
|
actionsConfiguration?: ActionConfiguration;
|
|
152
|
-
/**
|
|
153
|
-
* @deprecated Don't use it
|
|
154
|
-
*/
|
|
155
|
-
walletsListSource?: string;
|
|
156
152
|
}
|
|
157
153
|
|
|
158
154
|
declare type TonConnectUiCreateOptions = TonConnectUiOptionsWithConnector | TonConnectUiOptionsWithManifest;
|
|
@@ -180,6 +176,18 @@ interface TonConnectUiCreateOptionsBase extends TonConnectUiOptions {
|
|
|
180
176
|
* @default `div#tc-widget-root`.
|
|
181
177
|
*/
|
|
182
178
|
widgetRootId?: string;
|
|
179
|
+
/**
|
|
180
|
+
* Use it to customize ConnectRequest and add `tonProof` payload.
|
|
181
|
+
* The function will be called after wallets modal opens, and wallets selection will be blocked until it's resolved.
|
|
182
|
+
* If you have to make a http-request to your backend, it is better to do it after app initialization (if possible) and return (probably completed) promise to reduce loading time for the user.
|
|
183
|
+
*/
|
|
184
|
+
getConnectParameters?: () => Promise<ConnectAdditionalRequest>;
|
|
185
|
+
/**
|
|
186
|
+
* Redefine wallets list source URL. Must be a link to a json file with [following structure]{@link https://github.com/ton-connect/wallets-list}
|
|
187
|
+
* @default https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json
|
|
188
|
+
* @
|
|
189
|
+
*/
|
|
190
|
+
walletsListSource?: string;
|
|
183
191
|
}
|
|
184
192
|
|
|
185
193
|
declare class TonConnectUI {
|
package/lib/index.js
CHANGED
|
@@ -3767,11 +3767,16 @@ class TonConnect {
|
|
|
3767
3767
|
TonConnect.walletsList = new WalletsListManager();
|
|
3768
3768
|
TonConnect.isWalletInjected = (walletJSKey) => InjectedProvider.isWalletInjected(walletJSKey);
|
|
3769
3769
|
TonConnect.isInsideWalletBrowser = (walletJSKey) => InjectedProvider.isInsideWalletBrowser(walletJSKey);
|
|
3770
|
-
|
|
3770
|
+
const bounceableTag = 17;
|
|
3771
|
+
const testOnlyTag = 128;
|
|
3772
|
+
function toUserFriendlyAddress(hexAddress, testOnly = false) {
|
|
3771
3773
|
const { wc, hex } = parseHexAddress(hexAddress);
|
|
3772
|
-
|
|
3774
|
+
let tag = bounceableTag;
|
|
3775
|
+
if (testOnly) {
|
|
3776
|
+
tag |= testOnlyTag;
|
|
3777
|
+
}
|
|
3773
3778
|
const addr = new Int8Array(34);
|
|
3774
|
-
addr[0] =
|
|
3779
|
+
addr[0] = tag;
|
|
3775
3780
|
addr[1] = wc;
|
|
3776
3781
|
addr.set(hex, 2);
|
|
3777
3782
|
const addressWithChecksum = new Uint8Array(36);
|
|
@@ -7085,7 +7090,7 @@ const AccountButtonDropdown = (props) => {
|
|
|
7085
7090
|
const connector = useContext(ConnectorContext);
|
|
7086
7091
|
const [isCopiedShown, setIsCopiedShown] = createSignal(false);
|
|
7087
7092
|
const onCopy = () => __async(void 0, null, function* () {
|
|
7088
|
-
const userFriendlyAddress = toUserFriendlyAddress(tonConnectUi.account.address);
|
|
7093
|
+
const userFriendlyAddress = toUserFriendlyAddress(tonConnectUi.account.address, tonConnectUi.account.chain === CHAIN.TESTNET);
|
|
7089
7094
|
yield copyToClipboard(userFriendlyAddress);
|
|
7090
7095
|
setIsCopiedShown(true);
|
|
7091
7096
|
setTimeout(() => setIsCopiedShown(false), 1e3);
|
|
@@ -8160,7 +8165,7 @@ const AccountButton = () => {
|
|
|
8160
8165
|
const connector = useContext(ConnectorContext);
|
|
8161
8166
|
const tonConnectUI = useContext(TonConnectUiContext);
|
|
8162
8167
|
const [isOpened, setIsOpened] = createSignal(false);
|
|
8163
|
-
const [
|
|
8168
|
+
const [account, setAccount] = createSignal(null);
|
|
8164
8169
|
let dropDownRef;
|
|
8165
8170
|
const [floating, setFloating] = createSignal();
|
|
8166
8171
|
const [anchor, setAnchor] = createSignal();
|
|
@@ -8169,8 +8174,9 @@ const AccountButton = () => {
|
|
|
8169
8174
|
placement: "bottom-end"
|
|
8170
8175
|
});
|
|
8171
8176
|
const normalizedAddress = () => {
|
|
8172
|
-
|
|
8173
|
-
|
|
8177
|
+
const acc = account();
|
|
8178
|
+
if (acc) {
|
|
8179
|
+
const userFriendlyAddress = toUserFriendlyAddress(acc.address, acc.chain === CHAIN.TESTNET);
|
|
8174
8180
|
return userFriendlyAddress.slice(0, 4) + "..." + userFriendlyAddress.slice(-4);
|
|
8175
8181
|
}
|
|
8176
8182
|
return "";
|
|
@@ -8178,13 +8184,13 @@ const AccountButton = () => {
|
|
|
8178
8184
|
const unsubscribe = connector.onStatusChange((wallet) => {
|
|
8179
8185
|
if (!wallet) {
|
|
8180
8186
|
setIsOpened(false);
|
|
8181
|
-
|
|
8187
|
+
setAccount(null);
|
|
8182
8188
|
return;
|
|
8183
8189
|
}
|
|
8184
|
-
|
|
8190
|
+
setAccount(wallet.account);
|
|
8185
8191
|
});
|
|
8186
8192
|
const onClick = (e2) => {
|
|
8187
|
-
if (!
|
|
8193
|
+
if (!account() || !isOpened()) {
|
|
8188
8194
|
return;
|
|
8189
8195
|
}
|
|
8190
8196
|
const clickToButton = anchor().contains(e2.target);
|
|
@@ -8202,7 +8208,7 @@ const AccountButton = () => {
|
|
|
8202
8208
|
});
|
|
8203
8209
|
return [createComponent(Show, {
|
|
8204
8210
|
get when() {
|
|
8205
|
-
return !
|
|
8211
|
+
return !account();
|
|
8206
8212
|
},
|
|
8207
8213
|
get children() {
|
|
8208
8214
|
return createComponent(AccountButtonStyled, {
|
|
@@ -8228,7 +8234,7 @@ const AccountButton = () => {
|
|
|
8228
8234
|
}
|
|
8229
8235
|
}), createComponent(Show, {
|
|
8230
8236
|
get when() {
|
|
8231
|
-
return
|
|
8237
|
+
return account();
|
|
8232
8238
|
},
|
|
8233
8239
|
get children() {
|
|
8234
8240
|
return createComponent(DropdownContainerStyled, {
|
|
@@ -8332,6 +8338,11 @@ const QrCodeStyled = styled.div`
|
|
|
8332
8338
|
display: flex;
|
|
8333
8339
|
align-items: center;
|
|
8334
8340
|
justify-content: center;
|
|
8341
|
+
|
|
8342
|
+
> svg {
|
|
8343
|
+
height: 276px;
|
|
8344
|
+
width: 276px;
|
|
8345
|
+
}
|
|
8335
8346
|
}
|
|
8336
8347
|
|
|
8337
8348
|
rect {
|
|
@@ -10105,7 +10116,7 @@ const QrCodeModal = (props) => {
|
|
|
10105
10116
|
const universalLink = connector.connect({
|
|
10106
10117
|
universalLink: props.wallet.universalLink,
|
|
10107
10118
|
bridgeUrl: props.wallet.bridgeUrl
|
|
10108
|
-
});
|
|
10119
|
+
}, props.additionalRequest);
|
|
10109
10120
|
return createComponent(QrCodeModalStyled, {
|
|
10110
10121
|
get id() {
|
|
10111
10122
|
return props.id;
|
|
@@ -10168,7 +10179,7 @@ const QrCodeModal = (props) => {
|
|
|
10168
10179
|
return createComponent(ActionButtonStyled, {
|
|
10169
10180
|
onClick: () => connector.connect({
|
|
10170
10181
|
jsBridgeKey: props.wallet.jsBridgeKey
|
|
10171
|
-
}),
|
|
10182
|
+
}, props.additionalRequest),
|
|
10172
10183
|
get children() {
|
|
10173
10184
|
return createComponent(Translation, {
|
|
10174
10185
|
translationKey: "walletModal.qrCodeModal.openExtension",
|
|
@@ -10438,6 +10449,22 @@ const WalletsModal = () => {
|
|
|
10438
10449
|
const connector = useContext(ConnectorContext);
|
|
10439
10450
|
const tonConnectUI = useContext(TonConnectUiContext);
|
|
10440
10451
|
const [fetchedWalletsList] = createResource(() => tonConnectUI.getWallets());
|
|
10452
|
+
const [fetchedAdditionalRequest, {
|
|
10453
|
+
refetch
|
|
10454
|
+
}] = createResource((_, {
|
|
10455
|
+
refetching
|
|
10456
|
+
}) => {
|
|
10457
|
+
var _a;
|
|
10458
|
+
if (refetching) {
|
|
10459
|
+
return (_a = appState.getConnectParameters) == null ? void 0 : _a.call(appState);
|
|
10460
|
+
}
|
|
10461
|
+
return void 0;
|
|
10462
|
+
});
|
|
10463
|
+
createEffect(on(walletsModalOpen, () => {
|
|
10464
|
+
if (walletsModalOpen() && fetchedAdditionalRequest.state !== "refreshing") {
|
|
10465
|
+
refetch();
|
|
10466
|
+
}
|
|
10467
|
+
}));
|
|
10441
10468
|
const [selectedWalletInfo, setSelectedWalletInfo] = createSignal(null);
|
|
10442
10469
|
const walletsList = createMemo(() => {
|
|
10443
10470
|
if (fetchedWalletsList.state !== "ready") {
|
|
@@ -10445,6 +10472,13 @@ const WalletsModal = () => {
|
|
|
10445
10472
|
}
|
|
10446
10473
|
return applyWalletsListConfiguration(fetchedWalletsList(), appState.walletsList);
|
|
10447
10474
|
});
|
|
10475
|
+
const additionalRequestLoading = () => fetchedAdditionalRequest.state !== "ready" && fetchedAdditionalRequest.state !== "errored";
|
|
10476
|
+
const additionalRequest = createMemo(() => {
|
|
10477
|
+
if (fetchedAdditionalRequest.state !== "ready") {
|
|
10478
|
+
return void 0;
|
|
10479
|
+
}
|
|
10480
|
+
return fetchedAdditionalRequest();
|
|
10481
|
+
});
|
|
10448
10482
|
const onClose = () => {
|
|
10449
10483
|
setWalletsModalOpen(false);
|
|
10450
10484
|
setSelectedWalletInfo(null);
|
|
@@ -10467,13 +10501,13 @@ const WalletsModal = () => {
|
|
|
10467
10501
|
const universalLink = connector.connect({
|
|
10468
10502
|
universalLink: walletInfo.universalLink,
|
|
10469
10503
|
bridgeUrl: walletInfo.bridgeUrl
|
|
10470
|
-
});
|
|
10504
|
+
}, additionalRequest());
|
|
10471
10505
|
openLink(universalLink);
|
|
10472
10506
|
};
|
|
10473
10507
|
const onSelectIfInjected = (walletInfo) => {
|
|
10474
10508
|
connector.connect({
|
|
10475
10509
|
jsBridgeKey: walletInfo.jsBridgeKey
|
|
10476
|
-
});
|
|
10510
|
+
}, additionalRequest());
|
|
10477
10511
|
};
|
|
10478
10512
|
const unsubscribe = connector.onStatusChange((wallet) => {
|
|
10479
10513
|
if (wallet) {
|
|
@@ -10490,7 +10524,7 @@ const WalletsModal = () => {
|
|
|
10490
10524
|
get children() {
|
|
10491
10525
|
return [createComponent(Show, {
|
|
10492
10526
|
get when() {
|
|
10493
|
-
return !walletsList();
|
|
10527
|
+
return !walletsList() || additionalRequestLoading();
|
|
10494
10528
|
},
|
|
10495
10529
|
get children() {
|
|
10496
10530
|
return [createComponent(H1Styled$1, {
|
|
@@ -10504,7 +10538,7 @@ const WalletsModal = () => {
|
|
|
10504
10538
|
}
|
|
10505
10539
|
}), createComponent(Show, {
|
|
10506
10540
|
get when() {
|
|
10507
|
-
return walletsList();
|
|
10541
|
+
return createMemo(() => !!walletsList())() && !additionalRequestLoading();
|
|
10508
10542
|
},
|
|
10509
10543
|
get children() {
|
|
10510
10544
|
return [createComponent(Show, {
|
|
@@ -10528,6 +10562,9 @@ const WalletsModal = () => {
|
|
|
10528
10562
|
keyed: false,
|
|
10529
10563
|
get children() {
|
|
10530
10564
|
return createComponent(QrCodeModal, {
|
|
10565
|
+
get additionalRequest() {
|
|
10566
|
+
return additionalRequest();
|
|
10567
|
+
},
|
|
10531
10568
|
get wallet() {
|
|
10532
10569
|
return selectedWalletInfo();
|
|
10533
10570
|
},
|
|
@@ -10808,7 +10845,10 @@ class TonConnectUI {
|
|
|
10808
10845
|
});
|
|
10809
10846
|
}
|
|
10810
10847
|
this.uiOptions = mergeOptions(options, { uiPreferences: { theme: "SYSTEM" } });
|
|
10811
|
-
setAppState({
|
|
10848
|
+
setAppState({
|
|
10849
|
+
connector: this.connector,
|
|
10850
|
+
getConnectParameters: options == null ? void 0 : options.getConnectParameters
|
|
10851
|
+
});
|
|
10812
10852
|
widgetController.renderApp(rootId, this);
|
|
10813
10853
|
}
|
|
10814
10854
|
static getWallets() {
|