From 54555ac7e878caf1d3e26a65a9c01f42f575a3bd Mon Sep 17 00:00:00 2001 From: BenoistP <75934369+BenoistP@users.noreply.github.com> Date: Fri, 27 Dec 2024 14:02:53 +0100 Subject: [PATCH] prettier --- src/hooks/useREG.ts | 7 ++- src/hooks/useREGVotingPower.ts | 2 +- src/hooks/useRWA.ts | 5 +- src/repositories/RpcProvider.ts | 8 ++- src/store/features/wallets/walletsSelector.ts | 32 +++++----- src/utils/blockchain/erc20Infos.ts | 62 ++++++++++++------- 6 files changed, 71 insertions(+), 45 deletions(-) diff --git a/src/hooks/useREG.ts b/src/hooks/useREG.ts index 114bafa..78ae35d 100644 --- a/src/hooks/useREG.ts +++ b/src/hooks/useREG.ts @@ -12,7 +12,10 @@ import { selectUserAddressList, selectUserIncludesEth, } from 'src/store/features/settings/settingsSelector' -import { REGRealtoken, updateBalanceValues } from 'src/store/features/wallets/walletsSelector' +import { + REGRealtoken, + updateBalanceValues, +} from 'src/store/features/wallets/walletsSelector' import { APIRealTokenProductType } from 'src/types/APIRealToken' import { Currency } from 'src/types/Currencies' import { ERC20ABI } from 'src/utils/blockchain/abi/ERC20ABI' @@ -163,7 +166,7 @@ const getREG = async ( value, totalInvestment, unitPriceCost: tokenPrice, - balance: balances.balance + balance: balances.balance, } } diff --git a/src/hooks/useREGVotingPower.ts b/src/hooks/useREGVotingPower.ts index e3c9c68..ef8580f 100644 --- a/src/hooks/useREGVotingPower.ts +++ b/src/hooks/useREGVotingPower.ts @@ -55,7 +55,7 @@ const getRegVotingPower = async ( value, totalInvestment, unitPriceCost: tokenPrice, - balance: balances.balance + balance: balances.balance, } } diff --git a/src/hooks/useRWA.ts b/src/hooks/useRWA.ts index 9e3d7b6..839be89 100644 --- a/src/hooks/useRWA.ts +++ b/src/hooks/useRWA.ts @@ -11,7 +11,10 @@ import { import { selectUserAddressList, // selectUserIncludesEth, } from 'src/store/features/settings/settingsSelector' -import { RWARealtoken, updateBalanceValues } from 'src/store/features/wallets/walletsSelector' +import { + RWARealtoken, + updateBalanceValues, +} from 'src/store/features/wallets/walletsSelector' import { APIRealTokenProductType } from 'src/types/APIRealToken' import { Currency } from 'src/types/Currencies' import { ERC20ABI } from 'src/utils/blockchain/abi/ERC20ABI' diff --git a/src/repositories/RpcProvider.ts b/src/repositories/RpcProvider.ts index 6de3732..6ce9193 100644 --- a/src/repositories/RpcProvider.ts +++ b/src/repositories/RpcProvider.ts @@ -245,6 +245,10 @@ export async function getTransactionReceipt( * @param provider (Ethers) RPC provider * @returns Chain ID as number | undefined */ -export const getChainId = (provider: JsonRpcProvider | undefined): number | undefined => { - return (provider?._network?.chainId ? (Number(provider?._network?.chainId)) : undefined) +export const getChainId = ( + provider: JsonRpcProvider | undefined, +): number | undefined => { + return provider?._network?.chainId + ? Number(provider?._network?.chainId) + : undefined } diff --git a/src/store/features/wallets/walletsSelector.ts b/src/store/features/wallets/walletsSelector.ts index 69a1e67..7d2c319 100644 --- a/src/store/features/wallets/walletsSelector.ts +++ b/src/store/features/wallets/walletsSelector.ts @@ -25,18 +25,16 @@ import { CHAIN_NAME_ETHEREUM, CHAIN_NAME_GNOSIS_XDAI, } from '../../../utils/blockchain/consts/otherTokens' - import { selectRealtokens } from '../realtokens/realtokensSelector' import { selectUserRentCalculation } from '../settings/settingsSelector' -export type BalanceByWalletType = - Record< - WalletType, - { - amount: number - value: number - } - > +export type BalanceByWalletType = Record< + WalletType, + { + amount: number + value: number + } +> export interface UserRealtoken extends RealToken { id: string @@ -69,14 +67,18 @@ export interface OtherRealtoken { /** * Updates all balance values with token price - * @param balance - * @param tokenPrice + * @param balance + * @param tokenPrice */ -export const updateBalanceValues = (balance: BalanceByWalletType, tokenPrice:number) => { +export const updateBalanceValues = ( + balance: BalanceByWalletType, + tokenPrice: number, +) => { // Loop on each record Object.keys(balance).forEach((key) => { - balance[key as WalletType].value = balance[key as WalletType].amount * tokenPrice; - }); + balance[key as WalletType].value = + balance[key as WalletType].amount * tokenPrice + }) } // eslint-disable-next-line @typescript-eslint/no-empty-interface @@ -278,4 +280,4 @@ export const getWalletChainName = (chainId: number) => { case CHAIN_ID_GNOSIS_XDAI: return CHAIN_NAME_GNOSIS_XDAI } -} \ No newline at end of file +} diff --git a/src/utils/blockchain/erc20Infos.ts b/src/utils/blockchain/erc20Infos.ts index 84e3a13..5590306 100644 --- a/src/utils/blockchain/erc20Infos.ts +++ b/src/utils/blockchain/erc20Infos.ts @@ -1,15 +1,15 @@ import { Contract, JsonRpcProvider } from 'ethers' +import { getChainId } from 'src/repositories/RpcProvider' +import { BalanceByWalletType } from 'src/store/features/wallets/walletsSelector' +import { getWalletChainName } from 'src/store/features/wallets/walletsSelector' import { getErc20AbiBalanceOfOnly } from 'src/utils/blockchain/ERC20' import { batchCallOneContractOneFunctionMultipleParams } from './contract' -import { BalanceByWalletType } from 'src/store/features/wallets/walletsSelector' -import { getWalletChainName } from 'src/store/features/wallets/walletsSelector' -import { getChainId } from 'src/repositories/RpcProvider' export interface Balances { - totalAmount: number, - balance: BalanceByWalletType, + totalAmount: number + balance: BalanceByWalletType } const getAddressesBalances = async ( @@ -17,27 +17,27 @@ const getAddressesBalances = async ( addressList: string[], providers: JsonRpcProvider[], consoleWarnOnError = false, -):Promise => { +): Promise => { const balances: Balances = { totalAmount: 0, balance: { gnosis: { amount: 0, - value : 0, + value: 0, }, ethereum: { amount: 0, - value : 0, + value: 0, }, rmm: { amount: 0, - value : 0, + value: 0, }, levinSwap: { amount: 0, - value : 0, - } - } + value: 0, + }, + }, } try { if (!contractAddress) { @@ -71,23 +71,37 @@ const getAddressesBalances = async ( }) const balancesArray = await Promise.all(balancesPromises.flat()) // warn but don't stop - balancesArray?.length !== providers.length && consoleWarnOnError && console.warn(`Invalid balances array length (${balancesArray?.length}) (inconsistent with providers length (${providers.length}))`) + balancesArray?.length !== providers.length && + consoleWarnOnError && + console.warn( + `Invalid balances array length (${balancesArray?.length}) (inconsistent with providers length (${providers.length}))`, + ) providers.forEach((provider: JsonRpcProvider, providerIdx) => { const chainId = getChainId(provider) const wt = chainId ? getWalletChainName(chainId) : null if (wt) { - balances.balance[wt].value = 0; + balances.balance[wt].value = 0 // warn but don't stop - balancesArray[providerIdx]?.length !== addressList.length && consoleWarnOnError && console.warn('Invalid balances array (inconsistent addressList length)'); - (balancesArray[providerIdx] as unknown as bigint[])?.forEach((addressBalanceBI: bigint, addressIdx) => { - try { - const addressBalance = Number(addressBalanceBI) - balances.balance[wt].amount += addressBalance - } catch (error) { - // warn but don't stop - consoleWarnOnError && console.warn(`Invalid balance conversion for address ${addressList[addressIdx]} on chain ${chainId}`, error) - } - }) + balancesArray[providerIdx]?.length !== addressList.length && + consoleWarnOnError && + console.warn( + 'Invalid balances array (inconsistent addressList length)', + ) + ;(balancesArray[providerIdx] as unknown as bigint[])?.forEach( + (addressBalanceBI: bigint, addressIdx) => { + try { + const addressBalance = Number(addressBalanceBI) + balances.balance[wt].amount += addressBalance + } catch (error) { + // warn but don't stop + consoleWarnOnError && + console.warn( + `Invalid balance conversion for address ${addressList[addressIdx]} on chain ${chainId}`, + error, + ) + } + }, + ) balances.totalAmount += balances.balance[wt].amount } })