Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions packages/ui/src/ton-connect-ui.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Account,
BrowserEventDispatcher,
checkRequiredWalletFeatures,
ConnectAdditionalRequest,
OptionalTraceable,
RequiredFeatures,
Expand Down Expand Up @@ -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';
Expand All @@ -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<WalletInfo[]> {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down