Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
perf: import lodash only as modules (#2426)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzmp authored Sep 23, 2021
1 parent ffe11f9 commit 322c45b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"error",
{
"paths": [
{
"name": "lodash",
"message": "Please import lodash modules directly (lodash/module)."
},
{
"name": "styled-components",
"message": "Please import from styled-components/macro."
Expand Down
21 changes: 12 additions & 9 deletions src/hooks/useFeeTierDistribution.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { skipToken } from '@reduxjs/toolkit/query/react'
import { Currency, Token } from '@uniswap/sdk-core'
import { FeeAmount } from '@uniswap/v3-sdk'
import { reduce } from 'lodash'
import ms from 'ms.macro'
import { useMemo } from 'react'
import ReactGA from 'react-ga'
Expand Down Expand Up @@ -118,7 +117,7 @@ function usePoolTVL(token0: Token | undefined, token1: Token | undefined) {
const all = asToken0.concat(asToken1)

// sum tvl for token0 and token1 by fee tier
const tvlByFeeTer = all.reduce<{ [feeAmount: number]: [number | undefined, number | undefined] }>(
const tvlByFeeTier = all.reduce<{ [feeAmount: number]: [number | undefined, number | undefined] }>(
(acc, value) => {
acc[value.feeTier][0] = (acc[value.feeTier][0] ?? 0) + Number(value.totalValueLockedToken0)
acc[value.feeTier][1] = (acc[value.feeTier][1] ?? 0) + Number(value.totalValueLockedToken1)
Expand All @@ -132,8 +131,7 @@ function usePoolTVL(token0: Token | undefined, token1: Token | undefined) {
)

// sum total tvl for token0 and token1
const [sumToken0Tvl, sumToken1Tvl] = reduce(
tvlByFeeTer,
const [sumToken0Tvl, sumToken1Tvl] = Object.values(tvlByFeeTier).reduce(
(acc: [number, number], value) => {
acc[0] += value[0] ?? 0
acc[1] += value[1] ?? 0
Expand All @@ -152,17 +150,22 @@ function usePoolTVL(token0: Token | undefined, token1: Token | undefined) {
isUninitialized,
isError,
distributions: {
[FeeAmount.LOW]: mean(tvlByFeeTer[FeeAmount.LOW][0], sumToken0Tvl, tvlByFeeTer[FeeAmount.LOW][1], sumToken1Tvl),
[FeeAmount.LOW]: mean(
tvlByFeeTier[FeeAmount.LOW][0],
sumToken0Tvl,
tvlByFeeTier[FeeAmount.LOW][1],
sumToken1Tvl
),
[FeeAmount.MEDIUM]: mean(
tvlByFeeTer[FeeAmount.MEDIUM][0],
tvlByFeeTier[FeeAmount.MEDIUM][0],
sumToken0Tvl,
tvlByFeeTer[FeeAmount.MEDIUM][1],
tvlByFeeTier[FeeAmount.MEDIUM][1],
sumToken1Tvl
),
[FeeAmount.HIGH]: mean(
tvlByFeeTer[FeeAmount.HIGH][0],
tvlByFeeTier[FeeAmount.HIGH][0],
sumToken0Tvl,
tvlByFeeTer[FeeAmount.HIGH][1],
tvlByFeeTier[FeeAmount.HIGH][1],
sumToken1Tvl
),
},
Expand Down

0 comments on commit 322c45b

Please sign in to comment.