Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): add featured wallet spot after ecosystem wallets #292

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/ui/src/app/env/ECOSYSTEM_WALLETS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ECOSYSTEM_WALLETS = ['telegram-wallet', 'tonkeeper', 'mytonwallet'];
32 changes: 20 additions & 12 deletions packages/ui/src/app/utils/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { WalletInfo, TonConnect } from '@tonconnect/sdk';
import { UIWallet } from 'src/models/ui-wallet';
import { WalletsListConfiguration } from 'src/models';
import { mergeConcat } from 'src/app/utils/array';
import { ECOSYSTEM_WALLETS } from 'src/app/env/ECOSYSTEM_WALLETS';

export function uiWalletToWalletInfo(uiWallet: UIWallet): WalletInfo {
if ('jsBridgeKey' in uiWallet) {
Expand All @@ -20,7 +21,7 @@ export function applyWalletsListConfiguration(
configuration?: WalletsListConfiguration
): WalletInfo[] {
if (!configuration) {
return walletsList;
return arrangeWallets(walletsList);
}

if (configuration.includeWallets?.length) {
Expand All @@ -31,21 +32,28 @@ export function applyWalletsListConfiguration(
);
}

if (configuration.customOrder?.length) {
const uniqueOrderedNames = [...new Set(configuration.customOrder)];
return arrangeWallets(walletsList, configuration.featuredWallet);
}

const customOrderedWallets = uniqueOrderedNames
.map(orderedName => walletsList.find(wallet => wallet.appName === orderedName))
.filter((wallet): wallet is WalletInfo => wallet !== undefined);
function arrangeWallets(walletsList: WalletInfo[], featuredWallet?: string): WalletInfo[] {
const ecosystemWallets = walletsList.filter(wallet =>
ECOSYSTEM_WALLETS.includes(wallet.appName)
);

const remainingWallets = walletsList.filter(
wallet => !uniqueOrderedNames.includes(wallet.appName)
);
const featuredWalletInfo =
featuredWallet && !ECOSYSTEM_WALLETS.includes(featuredWallet)
? walletsList.find(wallet => wallet.appName === featuredWallet)
: undefined;

walletsList = [...customOrderedWallets, ...remainingWallets];
}
const remainingWallets = walletsList.filter(
wallet => !ECOSYSTEM_WALLETS.includes(wallet.appName) && wallet.appName !== featuredWallet
);

return walletsList;
return [
...ecosystemWallets,
...(featuredWalletInfo ? [featuredWalletInfo] : []),
...remainingWallets
];
}

export function supportsDesktop(walletInfo: WalletInfo): boolean {
Expand Down
7 changes: 4 additions & 3 deletions packages/ui/src/models/wallets-list-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export type WalletsListConfiguration = {
includeWallets?: UIWallet[];

/**
* List of wallet IDs to be displayed first in the specified order.
* Other wallets will be shown below in their original order.
* Specifies a wallet to be featured in a special spot right after ecosystem wallets.
* Should use `app_name` from the official TON wallets list:
* https://raw.githubusercontent.com/ton-blockchain/wallets-list/main/wallets-v2.json
*/
customOrder?: string[];
featuredWallet?: string;
};