forked from cerc-io/laconic-wallet
Display hdpaths for newly created accounts
This commit is contained in:
parent
1bde70b7d6
commit
dbaf43f98c
@ -27,8 +27,10 @@ const Accounts: React.FC<AccountsProps> = ({
|
||||
setIsAccountCreating(true);
|
||||
const newAccount = await addAccount(network);
|
||||
setIsAccountCreating(false);
|
||||
newAccount && updateAccounts(newAccount);
|
||||
updateIndex(selectedAccounts[selectedAccounts.length - 1].id + 1);
|
||||
if (newAccount) {
|
||||
updateAccounts(newAccount);
|
||||
updateIndex(newAccount.id);
|
||||
}
|
||||
};
|
||||
|
||||
const selectedAccounts: Account[] = (() => {
|
||||
@ -82,6 +84,12 @@ const Accounts: React.FC<AccountsProps> = ({
|
||||
<Text style={styles.highlight}>Public Key: </Text>
|
||||
{selectedAccounts[currentIndex]?.pubKey}
|
||||
</Text>
|
||||
<Text variant="bodyLarge">
|
||||
<Text style={{ fontWeight: '700' }}>HD Path: </Text>
|
||||
{selectedAccounts &&
|
||||
selectedAccounts[currentIndex] &&
|
||||
selectedAccounts[currentIndex].hdPath}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<View style={styles.signLink}>
|
||||
|
@ -30,7 +30,6 @@ const HomeScreen = () => {
|
||||
|
||||
const createWalletHandler = async () => {
|
||||
setIsWalletCreating(true);
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
const { mnemonic, ethAccounts, cosmosAccounts } = await createWallet();
|
||||
ethAccounts &&
|
||||
cosmosAccounts &&
|
||||
|
1
types.ts
1
types.ts
@ -7,6 +7,7 @@ export type Account = {
|
||||
id: number;
|
||||
pubKey: string;
|
||||
address: string;
|
||||
hdPath: string;
|
||||
};
|
||||
|
||||
export type WalletDetails = {
|
||||
|
16
utils.ts
16
utils.ts
@ -22,12 +22,8 @@ const createWallet = async (): Promise<WalletDetails> => {
|
||||
await setInternetCredentials('mnemonicServer', 'mnemonic', mnemonic);
|
||||
|
||||
const hdNode = HDNode.fromMnemonic(mnemonic);
|
||||
|
||||
const ethDerivationPath = "m/44'/60'/0'/0/0";
|
||||
const cosmosDerivationPath = "m/44'/118'/0'/0/0";
|
||||
|
||||
const ethNode = hdNode.derivePath(ethDerivationPath);
|
||||
const cosmosNode = hdNode.derivePath(cosmosDerivationPath);
|
||||
const ethNode = hdNode.derivePath("m/44'/60'/0'/0/0");
|
||||
const cosmosNode = hdNode.derivePath("m/44'/118'/0'/0/0");
|
||||
|
||||
const ethAddress = ethNode.address;
|
||||
const cosmosAddress = (await getCosmosAccounts(mnemonic, 0)).data.address;
|
||||
@ -50,12 +46,14 @@ const createWallet = async (): Promise<WalletDetails> => {
|
||||
id: 0,
|
||||
pubKey: ethNode.publicKey,
|
||||
address: ethAddress,
|
||||
hdPath: "m/44'/60'/0'/0/0",
|
||||
};
|
||||
|
||||
const cosmosAccounts = {
|
||||
id: 0,
|
||||
pubKey: cosmosNode.publicKey,
|
||||
address: cosmosAddress,
|
||||
hdPath: "m/44'/118'/0'/0/0",
|
||||
};
|
||||
|
||||
return { mnemonic, ethAccounts, cosmosAccounts };
|
||||
@ -84,10 +82,10 @@ const addAccount = async (network: string): Promise<Account | undefined> => {
|
||||
const ids = accountIds.split(',').map(Number);
|
||||
const id = ids[ids.length - 1] + 1;
|
||||
|
||||
const derivationPath =
|
||||
const hdPath =
|
||||
network === 'eth' ? `m/44'/60'/0'/0/${id}` : `m/44'/118'/0'/0/${id}`;
|
||||
|
||||
const node = hdNode.derivePath(derivationPath);
|
||||
const node = hdNode.derivePath(hdPath);
|
||||
const privKey = node.privateKey;
|
||||
const pubKey = node.publicKey;
|
||||
|
||||
@ -126,7 +124,7 @@ const addAccount = async (network: string): Promise<Account | undefined> => {
|
||||
indices,
|
||||
);
|
||||
|
||||
return { id, pubKey, address };
|
||||
return { pubKey, address, id, hdPath: hdPath };
|
||||
} catch (error) {
|
||||
console.error('Error creating account:', error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user