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:
Adwait Gharpure 2024-03-22 15:40:43 +05:30 committed by GitHub
parent 0fa793bead
commit b275f376c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 37 deletions

View File

@ -117,9 +117,10 @@ const styles = StyleSheet.create({
borderWidth: 1,
borderRadius: 5,
marginTop: 50,
height: 50,
height: 'auto',
alignItems: 'center',
justifyContent: 'center',
padding: 10,
},
requestDirectMessage: {
borderWidth: 1,

View File

@ -19,7 +19,6 @@ import { stringToPath } from '@cosmjs/crypto';
import { Account, WalletDetails } from '../types';
import {
getHDPath,
getMnemonic,
getPathKey,
resetKeyServers,
updateGlobalCounter,
@ -85,27 +84,9 @@ const createWallet = async (): Promise<WalletDetails> => {
const addAccount = async (network: string): Promise<Account | undefined> => {
try {
const mnemonic = await getMnemonic();
const hdNode = HDNode.fromMnemonic(mnemonic);
const id = await getNextAccountId(network);
const hdPath = getHDPath(network, `0'/0/${id}`);
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 };
return addAccountFromHDPath(hdPath);
} catch (error) {
console.error('Error creating account:', error);
}
@ -322,22 +303,6 @@ const getCosmosAccounts = async (
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 {
createWallet,
addAccount,