Skip to content

Commit 183e682

Browse files
committed
feat: Select all network by default when we connect with TronWalletAdapter
1 parent d0ab867 commit 183e682

File tree

2 files changed

+89
-6
lines changed

2 files changed

+89
-6
lines changed

ui/pages/multichain-accounts/multichain-accounts-connect-page/multichain-accounts-connect-page.test.tsx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
MultichainAccountsConnectPage,
2828
MultichainConnectPageProps,
2929
} from './multichain-accounts-connect-page';
30+
import { MultichainNetworks } from '../../../../shared/constants/multichain/networks';
3031

3132
const mockGetAllNetworkConfigurationsByCaipChainId =
3233
getAllNetworkConfigurationsByCaipChainId as jest.MockedFunction<
@@ -873,6 +874,82 @@ describe('MultichainConnectPage', () => {
873874
);
874875
});
875876

877+
it('returns all default networks for Tron Wallet Adapter requests', () => {
878+
const TRON_CAIP_CHAIN_ID = MultichainNetworks.TRON;
879+
880+
mockGetCaip25CaveatValueFromPermissions.mockReturnValue({
881+
requiredScopes: {},
882+
optionalScopes: {
883+
[TRON_CAIP_CHAIN_ID]: {
884+
accounts: [],
885+
},
886+
},
887+
sessionProperties: {
888+
[KnownSessionProperties.TronAccountChangedNotifications]: true,
889+
},
890+
isMultichainOrigin: true,
891+
});
892+
893+
mockGetAllScopesFromCaip25CaveatValue.mockReturnValue([
894+
TRON_CAIP_CHAIN_ID,
895+
]);
896+
897+
mockGetAllNetworkConfigurationsByCaipChainId.mockReturnValue({
898+
'eip155:1': {
899+
chainId: 'eip155:1',
900+
name: 'Ethereum Mainnet',
901+
nativeCurrency: 'ETH',
902+
} as unknown as EvmAndMultichainNetworkConfigurationsWithCaipChainId,
903+
[TRON_CAIP_CHAIN_ID]: {
904+
chainId: TRON_CAIP_CHAIN_ID,
905+
name: 'Tron Mainnet',
906+
nativeCurrency: 'TRX',
907+
} as unknown as EvmAndMultichainNetworkConfigurationsWithCaipChainId,
908+
});
909+
910+
render({
911+
props: {
912+
request: {
913+
permissions: {
914+
'endowment:caip25': {
915+
caveats: [
916+
{
917+
type: 'restrictNetworkSwitching',
918+
value: {
919+
requiredScopes: {},
920+
optionalScopes: {
921+
[TRON_CAIP_CHAIN_ID]: {
922+
accounts: [],
923+
},
924+
},
925+
sessionProperties: {
926+
[KnownSessionProperties.TronAccountChangedNotifications]: true, // Tron Wallet Adapter indicator
927+
},
928+
isMultichainOrigin: true,
929+
},
930+
},
931+
],
932+
},
933+
},
934+
metadata: {
935+
id: '1',
936+
origin: mockTargetSubjectMetadata.origin,
937+
},
938+
},
939+
},
940+
});
941+
942+
// For Tron Wallet Adapter requests, should return all default networks (EVM + Tron)
943+
// even though only Tron was explicitly requested
944+
const { calls } = mockUseAccountGroupsForPermissions.mock;
945+
expect(calls.length).toBeGreaterThan(0);
946+
const actualChainIds = calls[0]?.[2] as string[] | undefined;
947+
expect(actualChainIds).toBeDefined();
948+
// Should include both EVM and Tron networks by default
949+
expect(actualChainIds).toContain('eip155:1');
950+
expect(actualChainIds).toContain(TRON_CAIP_CHAIN_ID);
951+
});
952+
876953
it('returns all default networks when EIP-1193 request with no specific chain IDs requested', () => {
877954
mockGetCaip25CaveatValueFromPermissions.mockReturnValue({
878955
requiredScopes: {},

ui/pages/multichain-accounts/multichain-accounts-connect-page/multichain-accounts-connect-page.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import { AccountGroupWithInternalAccounts } from '../../../selectors/multichain-
9090
import { getMultichainNetwork } from '../../../selectors/multichain';
9191
import { TrustSignalDisplayState } from '../../../hooks/useTrustSignals';
9292
import { useOriginTrustSignals } from '../../../hooks/useOriginTrustSignals';
93+
import { MultichainNetworks } from '../../../../shared/constants/multichain/networks';
9394

9495
export type MultichainAccountsConnectPageRequest = {
9596
permissions?: PermissionsRequest;
@@ -164,16 +165,20 @@ export const MultichainAccountsConnectPage: React.FC<
164165
requestedCaip25CaveatValue,
165166
);
166167

167-
const SOLANA_MAINNET_CAIP_CHAIN_ID =
168-
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
169-
170168
const isSolanaWalletStandardRequest =
171169
requestedScopes.length === 1 &&
172-
requestedScopes[0] === SOLANA_MAINNET_CAIP_CHAIN_ID &&
170+
requestedScopes[0] === MultichainNetworks.SOLANA &&
173171
requestedCaip25CaveatValue.sessionProperties[
174172
KnownSessionProperties.SolanaAccountChangedNotifications
175173
];
176174

175+
const isTronWalletAdapterRequest =
176+
requestedScopes.length === 1 &&
177+
requestedScopes[0] === MultichainNetworks.TRON &&
178+
requestedCaip25CaveatValue.sessionProperties[
179+
KnownSessionProperties.TronAccountChangedNotifications
180+
];
181+
177182
const requestedCaip25CaveatValueWithExistingPermissions = useMemo(
178183
() =>
179184
existingCaip25CaveatValue
@@ -267,10 +272,11 @@ export const MultichainAccountsConnectPage: React.FC<
267272
)
268273
: nonTestNetworkConfigurations.map(({ caipChainId }) => caipChainId);
269274

270-
// If the request is an EIP-1193 request (with no specific chains requested) or a Solana wallet standard request , return the default selected network list
275+
// If the request is an EIP-1193 request (with no specific chains requested), a Solana wallet standard or a tronWallet library request , return the default selected network list
271276
if (
272277
(requestedCaipChainIds.length === 0 && isEip1193Request) ||
273-
isSolanaWalletStandardRequest
278+
isSolanaWalletStandardRequest ||
279+
isTronWalletAdapterRequest
274280
) {
275281
return defaultSelectedNetworkList;
276282
}

0 commit comments

Comments
 (0)