From b275f376c48a813bd7273930312ced7779cb991e Mon Sep 17 00:00:00 2001 From: Adwait Gharpure <69599306+Adw8@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:40:43 +0530 Subject: [PATCH] Refactor account utils (#64) * Refactor method in account utils * Make container height auto --------- Co-authored-by: Adw8 --- src/styles/stylesheet.js | 3 ++- src/utils/accounts.ts | 37 +------------------------------------ 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/src/styles/stylesheet.js b/src/styles/stylesheet.js index 7d4fe66..d2a289d 100644 --- a/src/styles/stylesheet.js +++ b/src/styles/stylesheet.js @@ -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, diff --git a/src/utils/accounts.ts b/src/utils/accounts.ts index 382d79f..aebbf8f 100644 --- a/src/utils/accounts.ts +++ b/src/utils/accounts.ts @@ -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 => { const addAccount = async (network: string): Promise => { 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 => { - 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,