Skip to content

feat(4469): networks with activity integration #14348

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

Open
wants to merge 6 commits 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
18 changes: 18 additions & 0 deletions app/components/Views/AccountSelector/AccountSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
useState,
} from 'react';
import { View } from 'react-native';
import { MultichainNetworkController } from '@metamask/multichain-network-controller';

// External dependencies.
import AccountSelectorList from '../../UI/AccountSelectorList';
Expand Down Expand Up @@ -63,6 +64,7 @@
const [screen, setScreen] = useState<AccountSelectorScreens>(
navigateToAddAccountActions ?? AccountSelectorScreens.AccountSelector,
);

useEffect(() => {
endTrace({ name: TraceName.AccountList });
}, []);
Expand Down Expand Up @@ -98,6 +100,22 @@
[Engine],
);

const fetchAccountsWithActivity = useCallback(async () => {
try {
const multichainNetworkController = Engine.context
.MultichainNetworkController as MultichainNetworkController;
await multichainNetworkController.getNetworksWithTransactionActivityByAccounts();

Check failure on line 107 in app/components/Views/AccountSelector/AccountSelector.tsx

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Property 'getNetworksWithTransactionActivityByAccounts' does not exist on type 'MultichainNetworkController'.
} catch (error) {
console.error('Error fetching accounts with activity', error);
}
}, [Engine]);

useEffect(() => {
if (accounts.length > 0) {
fetchAccountsWithActivity();
}
}, [fetchAccountsWithActivity, accounts]);

const renderAccountSelector = useCallback(
() => (
<Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MultichainNetworkControllerMessenger } from '@metamask/multichain-netwo
/**
* Get the MultichainNetworkControllerMessenger for the MultichainNetworkController.
*
* @param baseControllerMessenger - The base controllyer messenger.
* @param baseControllerMessenger - The base controller messenger.
* @returns The MultichainNetworkControllerMessenger.
*/
export function getMultichainNetworkControllerMessenger(
Expand All @@ -15,6 +15,7 @@ export function getMultichainNetworkControllerMessenger(
allowedActions: [
'NetworkController:setActiveNetwork',
'NetworkController:getState',
'AccountsController:listMultichainAccounts',
],
allowedEvents: ['AccountsController:selectedAccountChange'],
});
Expand Down
13 changes: 13 additions & 0 deletions app/selectors/multichainNetworkController/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,16 @@
nonEvmNetworkConfigurationsByChainId[selectedMultichainNetworkChainId]
?.ticker,
);

/**
* This selector is used to get the accounts with activity for EVM networks.
*
* @param state - The root state object.
* @returns An object where the keys are hex addresses and the values contain the namespace and an array of active chain IDs for that address.
* @returns {ActiveNetworksByAddress} Object mapping hex addresses to their network activity status.
*/
export const selectNetworksWithActivity = createSelector(
selectMultichainNetworkControllerState,
(multichainNetworkControllerState: MultichainNetworkControllerState) =>
multichainNetworkControllerState.networksWithTransactionActivity,

Check failure on line 111 in app/selectors/multichainNetworkController/index.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Property 'networksWithTransactionActivity' does not exist on type 'MultichainNetworkControllerState'.
);
1 change: 1 addition & 0 deletions app/util/logs/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ exports[`logs :: generateStateLogs generates a valid json export 1`] = `
"nativeCurrency": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
},
},
"networksWithTransactionActivity": {},
"selectedMultichainNetworkChainId": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
},
"MultichainTransactionsController": {
Expand Down
1 change: 1 addition & 0 deletions app/util/test/initial-background-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@
},
"MultichainNetworkController": {
"isEvmSelected": true,
"networksWithTransactionActivity": {},
"selectedMultichainNetworkChainId": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"multichainNetworkConfigurationsByChainId": {
"bip122:000000000019d6689c085ae165831e93": {
Expand Down
1 change: 1 addition & 0 deletions e2e/fixtures/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ class FixtureBuilder {
selectedMultichainNetworkChainId: SolScope.Mainnet,
multichainNetworkConfigurationsByChainId: {},
isEvmSelected: true,
networksWithTransactionActivity: {},
},
MultichainAssetsController: {
accountsAssets: {},
Expand Down
Loading