forked from cerc-io/laconic-wallet
Refactor account utils (#64)
* Refactor method in account utils * Make container height auto --------- Co-authored-by: Adw8 <adwait@deepstacksoft.com>
This commit is contained in:
parent
0fa793bead
commit
b275f376c4
@ -117,9 +117,10 @@ const styles = StyleSheet.create({
|
|||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
borderRadius: 5,
|
borderRadius: 5,
|
||||||
marginTop: 50,
|
marginTop: 50,
|
||||||
height: 50,
|
height: 'auto',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
|
padding: 10,
|
||||||
},
|
},
|
||||||
requestDirectMessage: {
|
requestDirectMessage: {
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
|
@ -19,7 +19,6 @@ import { stringToPath } from '@cosmjs/crypto';
|
|||||||
import { Account, WalletDetails } from '../types';
|
import { Account, WalletDetails } from '../types';
|
||||||
import {
|
import {
|
||||||
getHDPath,
|
getHDPath,
|
||||||
getMnemonic,
|
|
||||||
getPathKey,
|
getPathKey,
|
||||||
resetKeyServers,
|
resetKeyServers,
|
||||||
updateGlobalCounter,
|
updateGlobalCounter,
|
||||||
@ -85,27 +84,9 @@ const createWallet = async (): Promise<WalletDetails> => {
|
|||||||
|
|
||||||
const addAccount = async (network: string): Promise<Account | undefined> => {
|
const addAccount = async (network: string): Promise<Account | undefined> => {
|
||||||
try {
|
try {
|
||||||
const mnemonic = await getMnemonic();
|
|
||||||
const hdNode = HDNode.fromMnemonic(mnemonic);
|
|
||||||
const id = await getNextAccountId(network);
|
const id = await getNextAccountId(network);
|
||||||
const hdPath = getHDPath(network, `0'/0/${id}`);
|
const hdPath = getHDPath(network, `0'/0/${id}`);
|
||||||
|
return addAccountFromHDPath(hdPath);
|
||||||
const node = hdNode.derivePath(hdPath);
|
|
||||||
const pubKey = node.publicKey;
|
|
||||||
const address = await getAddress(network, mnemonic, `0'/0/${id}`);
|
|
||||||
|
|
||||||
await updateAccountIndices(network, id);
|
|
||||||
const { counterId } = await updateGlobalCounter(network);
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
setInternetCredentials(
|
|
||||||
`${network}:keyServer:${counterId}`,
|
|
||||||
`${network}:pathKey:${counterId}`,
|
|
||||||
`0'/0/${id},${node.privateKey},${node.publicKey},${address}`,
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return { counterId, pubKey, address, hdPath };
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating account:', error);
|
console.error('Error creating account:', error);
|
||||||
}
|
}
|
||||||
@ -322,22 +303,6 @@ const getCosmosAccounts = async (
|
|||||||
return { cosmosWallet, data };
|
return { cosmosWallet, data };
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAddress = async (
|
|
||||||
network: string,
|
|
||||||
mnemonic: string,
|
|
||||||
path: string,
|
|
||||||
): Promise<string> => {
|
|
||||||
switch (network) {
|
|
||||||
case 'eth':
|
|
||||||
return HDNode.fromMnemonic(mnemonic).derivePath(`m/44'/60'/${path}`)
|
|
||||||
.address;
|
|
||||||
case 'cosmos':
|
|
||||||
return (await getCosmosAccounts(mnemonic, `${path}`)).data.address;
|
|
||||||
default:
|
|
||||||
throw new Error('Invalid wallet type');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
createWallet,
|
createWallet,
|
||||||
addAccount,
|
addAccount,
|
||||||
|
Loading…
Reference in New Issue
Block a user