Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Nominator Rewards from Staking API, discontinue Subscan nominator rewards #2365

Merged
merged 33 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
204c961
separate payout state
rossbulat Dec 11, 2024
89f3fc1
refactor rewards to new structure
rossbulat Dec 12, 2024
5672b8f
mv `Payouts` to folder
rossbulat Dec 12, 2024
972e129
use `nominating` and `inPool` props
rossbulat Dec 12, 2024
723d07c
payouts list use staking api
rossbulat Dec 12, 2024
25e8adc
tidy up plugin management
rossbulat Dec 12, 2024
b95af22
mv Subcan methods to graph utils
rossbulat Dec 12, 2024
188f1a6
set lastReward
rossbulat Dec 12, 2024
418922d
remove plugin label
rossbulat Dec 12, 2024
beb47a2
fetch unclaimed rewards from staking api
rossbulat Dec 12, 2024
59d971c
deprecate removeEraPayout
rossbulat Dec 12, 2024
6513c24
stop exposing payoutsSynced
rossbulat Dec 12, 2024
5332be3
remove legacy reward calculations
rossbulat Dec 12, 2024
0fc09e4
fix
rossbulat Dec 12, 2024
3233d16
use full amount
rossbulat Dec 14, 2024
004f6f5
fetch payouts
rossbulat Dec 14, 2024
c379788
tidy up router
rossbulat Dec 14, 2024
6210879
StakingApi polish
rossbulat Dec 14, 2024
f17dfa0
active account never null
rossbulat Dec 14, 2024
34150bb
use defaults
rossbulat Dec 14, 2024
8592b64
improve staking apii exports
rossbulat Dec 14, 2024
32414ee
remove deprecated subscan boilerplate
rossbulat Dec 14, 2024
0bc2713
polish hook
rossbulat Dec 14, 2024
1be14ec
polish useSubscanData
rossbulat Dec 14, 2024
6e5c8e1
polish PayoutBar
rossbulat Dec 14, 2024
3d4fd9d
polish PayoutlLine
rossbulat Dec 14, 2024
c090799
polish
rossbulat Dec 14, 2024
0f34dd6
lint
rossbulat Dec 14, 2024
5a17853
add Props
rossbulat Dec 14, 2024
633ee27
polish
rossbulat Dec 14, 2024
c8e31e9
polish
rossbulat Dec 14, 2024
bb1ff3b
prevent dip on unfinished era
rossbulat Dec 15, 2024
84bc8f9
disable payouts on staking api disabled
rossbulat Dec 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 15 additions & 31 deletions packages/app/src/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { extractUrlValue } from '@w3ux/utils'
import { PagesConfig } from 'config/pages'
import { useActiveAccounts } from 'contexts/ActiveAccounts'
import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'
import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'
import { useNetwork } from 'contexts/Network'
import { usePlugins } from 'contexts/Plugins'
import { useStaking } from 'contexts/Staking'
import { useUi } from 'contexts/UI'
import { Notifications } from 'controllers/Notifications'
import { useAccountFromUrl } from 'hooks/useAccountFromUrl'
import { ErrorFallbackApp, ErrorFallbackRoutes } from 'library/ErrorBoundary'
import { Headers } from 'library/Headers'
import { Help } from 'library/Help'
Expand All @@ -23,62 +22,47 @@ import { Tooltip } from 'library/Tooltip'
import { Overlays } from 'overlay'
import { useEffect, useRef } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import { useTranslation } from 'react-i18next'
import {
HashRouter,
Navigate,
Route,
Routes,
useLocation,
} from 'react-router-dom'
import { StakingApi } from 'StakingApi'
import { Body, Main } from 'ui-structure'

const RouterInner = () => {
const { t } = useTranslation()
const { network } = useNetwork()
const { inSetup } = useStaking()
const { pathname } = useLocation()
const { setContainerRefs } = useUi()
const { accounts } = useImportedAccounts()
const { accountsInitialised } = useOtherAccounts()
const { activeAccount, setActiveAccount } = useActiveAccounts()
const { pluginEnabled } = usePlugins()
const { activeAccount } = useActiveAccounts()

// References to outer container.
// References to outer container
const mainInterfaceRef = useRef<HTMLDivElement>(null)

// Scroll to top of the window on every page change or network change.
// Scroll to top of the window on every page change or network change
useEffect(() => {
window.scrollTo(0, 0)
}, [pathname, network])

// Set container references to UI context and make available throughout app.
// Set container references to UI context and make available throughout app
useEffect(() => {
setContainerRefs({
mainInterface: mainInterfaceRef,
})
}, [])

// Open default account modal if url var present and accounts initialised.
useEffect(() => {
if (accountsInitialised) {
const aUrl = extractUrlValue('a')
if (aUrl) {
const account = accounts.find((a) => a.address === aUrl)
if (account && aUrl !== activeAccount) {
setActiveAccount(account.address || null)

Notifications.emit({
title: t('accountConnected', { ns: 'library' }),
subtitle: `${t('connectedTo', { ns: 'library' })} ${
account.name || aUrl
}.`,
})
}
}
}
}, [accountsInitialised])
// Support active account from url
useAccountFromUrl()

return (
<ErrorBoundary FallbackComponent={ErrorFallbackApp}>
{pluginEnabled('staking_api') && !inSetup() && activeAccount && (
<StakingApi activeAccount={activeAccount} />
)}
<NotificationPrompts />
<Body>
<Help />
Expand Down
38 changes: 38 additions & 0 deletions packages/app/src/StakingApi.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { useApi } from 'contexts/Api'
import { useNetwork } from 'contexts/Network'
import { usePayouts } from 'contexts/Payouts'
import { ApolloProvider, client, useUnclaimedRewards } from 'plugin-staking-api'
import { useEffect } from 'react'

interface Props {
activeAccount: string
}

const Inner = ({ activeAccount }: Props) => {
const { activeEra } = useApi()
const { network } = useNetwork()
const { setUnclaimedRewards } = usePayouts()

const { data, loading, error } = useUnclaimedRewards({
chain: network,
who: activeAccount,
fromEra: Math.max(activeEra.index.minus(1).toNumber(), 0),
})

useEffect(() => {
if (!loading && !error && data?.unclaimedRewards) {
setUnclaimedRewards(data?.unclaimedRewards)
}
}, [data?.unclaimedRewards.total])

return null
}

export const StakingApi = (props: Props) => (
<ApolloProvider client={client}>
<Inner {...props} />
</ApolloProvider>
)
99 changes: 0 additions & 99 deletions packages/app/src/contexts/Payouts/Utils.ts

This file was deleted.

10 changes: 6 additions & 4 deletions packages/app/src/contexts/Payouts/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import type { PayoutsContextInterface } from './types'

export const MaxSupportedPayoutEras = 7
export const defaultUnclaimedRewards = {
total: '0',
entries: [],
}

export const defaultPayoutsContext: PayoutsContextInterface = {
payoutsSynced: 'unsynced',
unclaimedPayouts: null,
removeEraPayout: (era, validator) => {},
unclaimedRewards: defaultUnclaimedRewards,
setUnclaimedRewards: (unclaimedRewards) => {},
}
Loading
Loading