Skip to content

Commit

Permalink
fixes & tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbulat committed Dec 22, 2024
1 parent 672714a commit fc185eb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 68 deletions.
24 changes: 0 additions & 24 deletions packages/app/src/api/query/blockNumber.ts

This file was deleted.

25 changes: 0 additions & 25 deletions packages/app/src/hooks/useFetchBlockNumber/index.tsx

This file was deleted.

15 changes: 10 additions & 5 deletions packages/app/src/pages/Overview/Payouts/ActiveGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { useActiveAccounts } from 'contexts/ActiveAccounts'
import { useApi } from 'contexts/Api'
import { useNetwork } from 'contexts/Network'
import { getUnixTime } from 'date-fns'
import { PayoutBar } from 'library/Graphs/PayoutBar'
import { PayoutLine } from 'library/Graphs/PayoutLine'
import {
Expand All @@ -24,14 +25,12 @@ interface Props {
inPool: boolean
lineMarginTop: string
setLastReward: (reward: RewardResult | undefined) => void
poolRewardsFrom: number
}
export const ActiveGraphInner = ({
nominating,
inPool,
lineMarginTop,
setLastReward,
poolRewardsFrom,
}: Props) => {
const { activeEra } = useApi()
const { network } = useNetwork()
Expand All @@ -42,10 +41,16 @@ export const ActiveGraphInner = ({
who: activeAccount || '',
fromEra: Math.max(activeEra.index.minus(1).toNumber(), 0),
})

const days = 19
const fromDate = new Date()
fromDate.setDate(fromDate.getDate() - days)
fromDate.setHours(0, 0, 0, 0)

const { data: poolRewardsData } = usePoolRewards({
chain: network,
who: activeAccount || '',
from: poolRewardsFrom,
from: getUnixTime(fromDate),
})

const nominatorRewards = nominatorRewardData?.allRewards ?? []
Expand All @@ -70,15 +75,15 @@ export const ActiveGraphInner = ({
return (
<>
<PayoutBar
days={19}
days={days}
height="150px"
data={{ payouts, unclaimedPayouts, poolClaims }}
nominating={nominating}
inPool={inPool}
/>
<div style={{ marginTop: lineMarginTop }}>
<PayoutLine
days={19}
days={days}
average={10}
height="65px"
data={{ payouts, unclaimedPayouts, poolClaims }}
Expand Down
6 changes: 1 addition & 5 deletions packages/app/src/pages/Overview/Payouts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useActivePool } from 'contexts/Pools/ActivePool'
import { useStaking } from 'contexts/Staking'
import { useUi } from 'contexts/UI'
import { formatDistance, fromUnixTime, getUnixTime } from 'date-fns'
import { useFetchBlockNumber } from 'hooks/useFetchBlockNumber'
import { useSyncing } from 'hooks/useSyncing'
import { CardHeaderWrapper } from 'library/Card/Wrappers'
import { formatSize } from 'library/Graphs/Utils'
Expand All @@ -28,7 +27,6 @@ import { InactiveGraph } from './InactiveGraph'
export const Payouts = () => {
const { i18n, t } = useTranslation('pages')
const {
network,
networkData: {
units,
brand: { token: Token },
Expand All @@ -39,7 +37,6 @@ export const Payouts = () => {
const { containerRefs } = useUi()
const { inPool } = useActivePool()
const { pluginEnabled } = usePlugins()
const blockNumber = useFetchBlockNumber(network)

const staking = !inSetup() || inPool
const notStaking = !syncing && !staking
Expand Down Expand Up @@ -116,13 +113,12 @@ export const Payouts = () => {
transition: 'opacity 0.5s',
}}
>
{staking && pluginEnabled('staking_api') && blockNumber > 0 ? (
{staking && pluginEnabled('staking_api') ? (
<ActiveGraph
nominating={!inSetup()}
inPool={inPool()}
lineMarginTop="3rem"
setLastReward={setLastReward}
poolRewardsFrom={blockNumber}
/>
) : (
<InactiveGraph setLastReward={setLastReward} />
Expand Down
10 changes: 7 additions & 3 deletions packages/app/src/pages/Payouts/ActiveGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MaxPayoutDays } from 'consts'
import { useActiveAccounts } from 'contexts/ActiveAccounts'
import { useApi } from 'contexts/Api'
import { useNetwork } from 'contexts/Network'
import { getUnixTime } from 'date-fns'
import { PayoutBar } from 'library/Graphs/PayoutBar'
import { PayoutLine } from 'library/Graphs/PayoutLine'
import { removeNonZeroAmountAndSort } from 'library/Graphs/Utils'
Expand All @@ -22,14 +23,12 @@ interface Props {
nominating: boolean
inPool: boolean
setPayoutLists: (payouts: AnyApi[]) => void
poolRewardsFrom: number
}

export const ActiveGraphInner = ({
nominating,
inPool,
setPayoutLists,
poolRewardsFrom,
}: Props) => {
const { activeEra } = useApi()
const { network } = useNetwork()
Expand All @@ -40,10 +39,15 @@ export const ActiveGraphInner = ({
who: activeAccount || '',
fromEra: Math.max(activeEra.index.minus(1).toNumber(), 0),
})

const fromDate = new Date()
fromDate.setDate(fromDate.getDate() - MaxPayoutDays)
fromDate.setHours(0, 0, 0, 0)

const { data: poolRewardsData } = usePoolRewards({
chain: network,
who: activeAccount || '',
from: poolRewardsFrom,
from: getUnixTime(fromDate),
})

const allRewards = nominatorRewardsData?.allRewards ?? []
Expand Down
7 changes: 1 addition & 6 deletions packages/app/src/pages/Payouts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import { useSize } from '@w3ux/hooks'
import type { PageProps } from 'common-types'
import { useHelp } from 'contexts/Help'
import { useNetwork } from 'contexts/Network'
import { usePlugins } from 'contexts/Plugins'
import { useActivePool } from 'contexts/Pools/ActivePool'
import { useStaking } from 'contexts/Staking'
import { useUi } from 'contexts/UI'
import { useFetchBlockNumber } from 'hooks/useFetchBlockNumber'
import { useSyncing } from 'hooks/useSyncing'
import { CardHeaderWrapper, CardWrapper } from 'library/Card/Wrappers'
import {
Expand Down Expand Up @@ -37,10 +35,8 @@ export const Payouts = ({ page: { key } }: PageProps) => {
const { inSetup } = useStaking()
const { syncing } = useSyncing()
const { containerRefs } = useUi()
const { network } = useNetwork()
const { inPool } = useActivePool()
const { pluginEnabled } = usePlugins()
const blockNumber = useFetchBlockNumber(network)

const nominating = !inSetup()
const staking = nominating || inPool
Expand Down Expand Up @@ -122,12 +118,11 @@ export const Payouts = ({ page: { key } }: PageProps) => {
transition: 'opacity 0.5s',
}}
>
{staking && pluginEnabled('staking_api') && blockNumber > 0 ? (
{staking && pluginEnabled('staking_api') ? (
<ActiveGraph
nominating={nominating}
inPool={inPool()}
setPayoutLists={setPayoutLists}
poolRewardsFrom={blockNumber}
/>
) : (
<InactiveGraph />
Expand Down

0 comments on commit fc185eb

Please sign in to comment.