Add accounts for all networks

This commit is contained in:
Shreerang Kale 2025-06-05 10:21:00 +05:30
parent f5b92af4f9
commit 2a07bc8b35
2 changed files with 19 additions and 7 deletions

View File

@ -135,6 +135,7 @@ const AddNetwork = () => {
);
}, CHAINID_DEBOUNCE_DELAY);
// TODO: Handle replicating existing accounts after adding new network
const submit = useCallback(
async (data: z.infer<typeof networksFormDataSchema>) => {
const newNetworkData = {

View File

@ -87,15 +87,26 @@ const createWalletFromMnemonic = async (
};
const addAccount = async (
networkData: NetworksDataState,
selectedNetwork: NetworksDataState,
): Promise<Account | undefined> => {
try {
const namespaceChainId = `${networkData.namespace}:${networkData.chainId}`;
const id = await getNextAccountId(namespaceChainId);
const hdPath = getHDPath(namespaceChainId, `0'/0/${id}`);
const accounts = await addAccountFromHDPath(hdPath, networkData);
await updateAccountCounter(namespaceChainId, id);
return accounts;
let selectedNetworkAccount
const networksData = await retrieveNetworksData();
// Add account to all networks and return account for selected network
for (const network of networksData) {
const namespaceChainId = `${network.namespace}:${network.chainId}`;
const id = await getNextAccountId(namespaceChainId);
const hdPath = getHDPath(namespaceChainId, `0'/0/${id}`);
const account = await addAccountFromHDPath(hdPath, network);
await updateAccountCounter(namespaceChainId, id);
if (network.networkId === selectedNetwork.networkId) {
selectedNetworkAccount = account;
}
}
return selectedNetworkAccount;
} catch (error) {
console.error('Error creating account:', error);
}