Skip to content

Commit 604bdfe

Browse files
committed
feat: Select all network by default when we connect with TronWalletAdapter
1 parent a259c6c commit 604bdfe

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
@@ -26,6 +26,7 @@ import {
2626
MultichainAccountsConnectPage,
2727
MultichainConnectPageProps,
2828
} from './multichain-accounts-connect-page';
29+
import { MultichainNetworks } from '../../../../shared/constants/multichain/networks';
2930

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

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