Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2edfb4b4cf | ||
|
|
fe3d2411a2 |
@@ -85,7 +85,7 @@ const Accounts = () => {
|
||||
|
||||
const addAccountHandler = async () => {
|
||||
setIsAccountCreating(true);
|
||||
const newAccount = await addAccount(selectedNetwork!);
|
||||
const newAccount = await addAccount(selectedNetwork!.chainId);
|
||||
setIsAccountCreating(false);
|
||||
if (newAccount) {
|
||||
updateAccounts(newAccount);
|
||||
|
||||
@@ -16,7 +16,7 @@ const useAddAccountEmbed = () => {
|
||||
const { getAccountsData } = useAccountsData();
|
||||
|
||||
const addAccountHandler = useCallback(async (network: NetworksDataState) => {
|
||||
const newAccount = await addAccount(network);
|
||||
const newAccount = await addAccount(network.chainId);
|
||||
if (newAccount) {
|
||||
setAccounts(prev => [...prev, newAccount]);
|
||||
setCurrentIndex(newAccount.index);
|
||||
|
||||
@@ -13,7 +13,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||
|
||||
import { StackParamsList } from "../types";
|
||||
import { SelectNetworkType } from "../components/SelectNetworkType";
|
||||
import { storeNetworkData } from "../utils/accounts";
|
||||
import { addAccountsForNetwork, getNextAccountId, storeNetworkData } from "../utils/accounts";
|
||||
import { useNetworks } from "../context/NetworksContext";
|
||||
import {
|
||||
COSMOS,
|
||||
@@ -181,6 +181,15 @@ const AddNetwork = () => {
|
||||
const retrievedNetworksData = await storeNetworkData(newNetworkData);
|
||||
setNetworksData(retrievedNetworksData);
|
||||
|
||||
// Get number of accounts in first network
|
||||
const nextAccountId = await getNextAccountId(
|
||||
`${retrievedNetworksData[0].namespace}:${retrievedNetworksData[0].chainId}`,
|
||||
);
|
||||
|
||||
const selectedNetwork = retrievedNetworksData.find(
|
||||
(network) => network.chainId === newNetworkData.chainId,
|
||||
);
|
||||
|
||||
await Promise.all([
|
||||
setInternetCredentials(
|
||||
`accounts/${newNetworkData.namespace}:${newNetworkData.chainId}/0`,
|
||||
@@ -199,6 +208,8 @@ const AddNetwork = () => {
|
||||
),
|
||||
]);
|
||||
|
||||
await addAccountsForNetwork(selectedNetwork!, nextAccountId - 1);
|
||||
|
||||
navigation.navigate("Home");
|
||||
},
|
||||
[navigation, namespace, setNetworksData],
|
||||
|
||||
@@ -277,7 +277,26 @@ export const SignTxEmbed = () => {
|
||||
return
|
||||
}
|
||||
|
||||
return JSONbig.stringify(transactionDetails.txBody, null, 2)
|
||||
let txBody = transactionDetails.txBody;
|
||||
|
||||
// If it's a MsgCreateValidator, format pubkey in present in the message
|
||||
if (txBody.value.messages[0].typeUrl === "/cosmos.staking.v1beta1.MsgCreateValidator") {
|
||||
txBody = {
|
||||
...txBody,
|
||||
value: {
|
||||
...txBody.value,
|
||||
messages: txBody.value.messages.map((msg) => ({
|
||||
...msg,
|
||||
value: {
|
||||
...msg.value,
|
||||
pubkey: decodeOptionalPubkey(msg.value.pubkey),
|
||||
},
|
||||
})),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return JSONbig.stringify(txBody, null, 2)
|
||||
},
|
||||
[transactionDetails]
|
||||
);
|
||||
|
||||
+37
-7
@@ -87,15 +87,44 @@ const createWalletFromMnemonic = async (
|
||||
};
|
||||
|
||||
const addAccount = async (
|
||||
networkData: NetworksDataState,
|
||||
chainId: string,
|
||||
): 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.chainId === chainId) {
|
||||
selectedNetworkAccount = account;
|
||||
}
|
||||
}
|
||||
|
||||
return selectedNetworkAccount;
|
||||
} catch (error) {
|
||||
console.error('Error creating account:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const addAccountsForNetwork = async (
|
||||
network: NetworksDataState,
|
||||
numberOfAccounts: number,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const namespaceChainId = `${network.namespace}:${network.chainId}`;
|
||||
|
||||
for (let i = 0; i < numberOfAccounts; i++) {
|
||||
const id = await getNextAccountId(namespaceChainId);
|
||||
const hdPath = getHDPath(namespaceChainId, `0'/0/${id}`);
|
||||
await addAccountFromHDPath(hdPath, network);
|
||||
await updateAccountCounter(namespaceChainId, id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error creating account:', error);
|
||||
}
|
||||
@@ -343,6 +372,7 @@ export {
|
||||
createWallet,
|
||||
addAccount,
|
||||
addAccountFromHDPath,
|
||||
addAccountsForNetwork,
|
||||
storeNetworkData,
|
||||
retrieveNetworksData,
|
||||
retrieveAccounts,
|
||||
|
||||
Reference in New Issue
Block a user