From 41c3c71d2653be3ffbca26dba888d468c48473e4 Mon Sep 17 00:00:00 2001 From: Alejandbel Date: Mon, 1 Dec 2025 12:44:51 +0300 Subject: [PATCH] feature: update image preload --- packages/ui/src/ton-connect-ui.ts | 40 +++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/ton-connect-ui.ts b/packages/ui/src/ton-connect-ui.ts index 7ff53240d..357a1d0cc 100644 --- a/packages/ui/src/ton-connect-ui.ts +++ b/packages/ui/src/ton-connect-ui.ts @@ -1,6 +1,7 @@ import { Account, BrowserEventDispatcher, + checkRequiredWalletFeatures, ConnectAdditionalRequest, OptionalTraceable, RequiredFeatures, @@ -43,7 +44,6 @@ import { Action, setLastSelectedWalletInfo } from 'src/app/state/modals-state'; import { ActionConfiguration, StrictActionConfiguration } from 'src/models/action-configuration'; import { ConnectedWallet, WalletInfoWithOpenMethod } from 'src/models/connected-wallet'; import { applyWalletsListConfiguration, eqWalletName } from 'src/app/utils/wallets'; -import { uniq } from 'src/app/utils/array'; import { Loadable } from 'src/models/loadable'; import { WalletsModalManager } from 'src/managers/wallets-modal-manager'; import { TransactionModalManager } from 'src/managers/transaction-modal-manager'; @@ -66,6 +66,9 @@ import { WALLET_CONNECT_WALLET_NAME } from 'src/app/env/WALLET_CONNECT'; import { IMG } from 'src/app/env/IMG'; +import { uniq } from 'src/app/utils/array'; +import { AT_WALLET_APP_NAME } from 'src/app/env/AT_WALLET_APP_NAME'; +import { logError } from 'src/app/utils/log'; export class TonConnectUI { public static getWallets(): Promise { @@ -284,7 +287,7 @@ export class TonConnectUI { this.walletsList = this.getWallets(); - this.walletsList.then(list => preloadImages(uniq(list.map(item => item.imageUrl)))); + this.preloadImages(); const rootId = this.normalizeWidgetRoot(options?.widgetRootId); @@ -1181,6 +1184,39 @@ export class TonConnectUI { } } + private preloadImages() { + this.walletsList + .then(wallets => { + const preferredName = this.preferredWalletStorage.getPreferredWalletAppName(); + const preferredWallet = preferredName + ? wallets.find(w => w.appName === preferredName) + : undefined; + + const atWallet = wallets.find(w => w.appName === AT_WALLET_APP_NAME); + + const candidateWallets = [preferredWallet, atWallet, ...wallets.slice(0, 3)].filter( + wallet => wallet !== undefined + ); + + const requiredFeatures = this.walletsRequiredFeatures; + + const walletsToPreload = candidateWallets.filter( + wallet => + !requiredFeatures || + checkRequiredWalletFeatures(wallet.features ?? [], requiredFeatures) + ); + + const imagesToPreload = uniq([ + IMG.TON, + IMG.TG, + ...walletsToPreload.map(w => w.imageUrl) + ]); + + preloadImages(imagesToPreload); + }) + .catch(logError); + } + // eslint-disable-next-line complexity private getModalsAndNotificationsConfiguration( options?: ActionConfiguration