Skip to content

Commit

Permalink
feat(refactor): Pool rewards to controller, pool types to types pac…
Browse files Browse the repository at this point in the history
…kage (#2344)
  • Loading branch information
rossbulat authored Dec 1, 2024
1 parent 8037312 commit 437ffe4
Show file tree
Hide file tree
Showing 175 changed files with 516 additions and 667 deletions.
1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"rxjs": "^7.8.1",
"styled-components": "^6.1.13",
"styles": "workspace:*",
"types": "workspace:*",
"ui-buttons": "workspace:*",
"ui-structure": "workspace:*",
"usehooks-ts": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import type { ChainId } from 'common-types';
import { Apis } from 'controllers/Apis';
import type { PolkadotClient } from 'polkadot-api';
import type { ChainId } from 'types';

export class Base {
#client: PolkadotClient;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/entries/bondedPoolsEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { Base } from 'api/base';
import BigNumber from 'bignumber.js';
import type { AnyApi, ChainId } from 'types';
import type { AnyApi, ChainId } from 'common-types';
import { perbillToPercent } from 'utils';

export class BondedPoolsEntries extends Base {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/entries/erasStakersPagedEntries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ErasStakersPagedEntries extends Base {
constructor(network: ChainId) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/entries/validatorsEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ValidatorsEntries extends Base {
constructor(network: ChainId) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import type { ChainId } from 'common-types';
import { NetworkList, SystemChainList } from 'config/networks';
import { getLightClientMetadata } from 'config/util';
import { Subscriptions } from 'controllers/Subscriptions';
Expand All @@ -10,7 +11,6 @@ import { getSmProvider } from 'polkadot-api/sm-provider';
import { startFromWorker } from 'polkadot-api/smoldot/from-worker';
import SmWorker from 'polkadot-api/smoldot/worker?worker';
import { getWsProvider } from 'polkadot-api/ws-provider/web';
import type { ChainId } from 'types';
import type {
ApiChainType,
APIEventDetail,
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/query/claimedRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ClaimedRewards extends Base {
#era: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/query/era.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { Base } from 'api/base';
import BigNumber from 'bignumber.js';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class Era extends Base {
constructor(network: ChainId) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/query/erasRewardPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ErasRewardPoints extends Base {
#era: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/query/erasStakersOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ErasStakersOverview extends Base {
constructor(network: ChainId) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/query/erasValidatorReward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ErasValidatorReward extends Base {
#era: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/query/networkMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { Base } from 'api/base';
import BigNumber from 'bignumber.js';
import type { ChainId } from 'common-types';
import type { APIActiveEra } from 'contexts/Api/types';
import type { ChainId } from 'types';
import { perbillToPercent, stringToBn } from 'utils';

export class NetworkMeta extends Base {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/query/paraSessionAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ParaSessionAccounts extends Base {
#session: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/query/proxiesQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ProxiesQuery extends Base {
#address: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/query/sessionValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class SessionValidators extends Base {
constructor(network: ChainId) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/query/validatorPrefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ValidatorPrefs extends Base {
#era: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/queryMulti/bondedMulti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class BondedMulti extends Base {
#addresses: [string][];
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/queryMulti/erasRewardPointsMulti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ErasRewardPointsMulti extends Base {
#eras: [number][];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ErasValidatorRewardMulti extends Base {
#eras: [number][];
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/queryMulti/identityOfMulti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class IdentityOfMulti extends Base {
#addresses: [string][];
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/queryMulti/nominatorsMulti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class NominatorsMulti extends Base {
#addresses: [string][];
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/queryMulti/poolMetadataMulti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class PoolMetadataMulti extends Base {
#ids: [number][];
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/queryMulti/superOfMulti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class SuperOfMulti extends Base {
#addresses: [string][];
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/queryMulti/validatorsMulti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class ValidatorsMulti extends Base {
#addresses: [string][];
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/runtimeApi/poolPendingRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class PoolPendingRewards extends Base {
#who: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/runtimeApi/poolPointsToBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { ChainId } from 'types';
import type { ChainId } from 'common-types';

export class PoolPointsToBalance extends Base {
#poolId: number;
Expand Down
9 changes: 3 additions & 6 deletions packages/app/src/api/subscribe/accountBalances/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// SPDX-License-Identifier: GPL-3.0-only

import BigNumber from 'bignumber.js';
import type {
Balances as IBalances,
Ledger,
Nominations,
} from 'contexts/Balances/types';
import type { AnyApi, NetworkId } from 'common-types';
import type { Balances as IBalances, Ledger } from 'contexts/Balances/types';
import type { PoolMembership } from 'contexts/Pools/types';
import type { PayeeConfig } from 'contexts/Setup/types';
import { Apis } from 'controllers/Apis';
Expand All @@ -16,7 +13,7 @@ import type { Unsubscribable } from 'controllers/Subscriptions/types';
import type { UnsafeApi } from 'polkadot-api';
import type { Subscription } from 'rxjs';
import { combineLatest } from 'rxjs';
import type { AnyApi, NetworkId } from 'types';
import type { Nominations } from 'types';
import { stringToBn } from 'utils';

export class AccountBalances implements Unsubscribable {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/subscribe/accountProxies/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import type { AnyApi, NetworkId } from 'common-types';
import { Apis } from 'controllers/Apis';
import type { Unsubscribable } from 'controllers/Subscriptions/types';
import type { Subscription } from 'rxjs';
import type { AnyApi, NetworkId } from 'types';

export class AccountProxies implements Unsubscribable {
// The associated network for this instance.
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/subscribe/activeEra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// SPDX-License-Identifier: GPL-3.0-only

import BigNumber from 'bignumber.js';
import type { NetworkId } from 'common-types';
import { defaultActiveEra } from 'contexts/Api/defaults';
import type { APIActiveEra } from 'contexts/Api/types';
import { Apis } from 'controllers/Apis';
import { Subscriptions } from 'controllers/Subscriptions';
import type { Unsubscribable } from 'controllers/Subscriptions/types';
import type { Subscription } from 'rxjs';
import type { NetworkId } from 'types';
import { StakingMetrics } from '../stakingMetrics';

export class ActiveEra implements Unsubscribable {
Expand Down
11 changes: 7 additions & 4 deletions packages/app/src/api/subscribe/activePoolAccount/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import type { Nominations } from 'contexts/Balances/types';
import { PoolPendingRewards } from 'api/runtimeApi/poolPendingRewards';
import type { AnyApi, ChainId, SystemChainId } from 'common-types';
import { defaultPoolNominations } from 'contexts/Pools/ActivePool/defaults';
import type { ActivePool, PoolRoles } from 'contexts/Pools/ActivePool/types';
import type { ActivePoolItem } from 'controllers/ActivePools/types';
import { Apis } from 'controllers/Apis';
import { Identities } from 'controllers/Identities';
import type { Unsubscribable } from 'controllers/Subscriptions/types';
import { combineLatest, type Subscription } from 'rxjs';
import type { AnyApi, ChainId, SystemChainId } from 'types';
import type { ActivePool, ActivePoolItem, Nominations, PoolRoles } from 'types';

export class ActivePoolAccount implements Unsubscribable {
// The associated network for this instance.
Expand Down Expand Up @@ -124,6 +123,9 @@ export class ActivePoolAccount implements Unsubscribable {
totalRewardsClaimed: rewardPool.total_rewards_claimed.toString(),
};

const pendingRewards =
(await new PoolPendingRewards(this.#network, this.address).fetch()) || 0n;

// Only persist the active pool to class state (and therefore dispatch an event) if both the
// bonded pool and reward pool are returned.
if (bondedPool && rewardPool) {
Expand All @@ -133,6 +135,7 @@ export class ActivePoolAccount implements Unsubscribable {
bondedPool: bondedPoolFormatted,
rewardPool: rewardPoolFormatted,
rewardAccountBalance,
pendingRewards,
};

this.activePool = newPool;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/subscribe/blockNumber/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Base } from 'api/base';
import type { NetworkId } from 'common-types';
import type { Unsubscribable } from 'controllers/Subscriptions/types';
import type { Subscription } from 'rxjs';
import type { NetworkId } from 'types';

export class BlockNumber extends Base implements Unsubscribable {
// The current block number.
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/subscribe/bonded/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import type { NetworkId } from 'common-types';
import type { BondedAccount } from 'contexts/Bonded/types';
import { Apis } from 'controllers/Apis';
import type { Unsubscribable } from 'controllers/Subscriptions/types';
import type { Subscription } from 'rxjs';
import type { NetworkId } from 'types';

export class Bonded implements Unsubscribable {
// The associated network for this instance.
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/subscribe/fastUnstakeConfig/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import type { NetworkId } from 'common-types';
import { Apis } from 'controllers/Apis';
import type { Unsubscribable } from 'controllers/Subscriptions/types';
import type { Subscription } from 'rxjs';
import { combineLatest } from 'rxjs';
import type { NetworkId } from 'types';
import type { FastUnstakeConfigResult } from './types';

export class FastUnstakeConfig implements Unsubscribable {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/subscribe/fastUnstakeQueue/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import type { NetworkId } from 'common-types';
import { Apis } from 'controllers/Apis';
import type { Unsubscribable } from 'controllers/Subscriptions/types';
import type { Subscription } from 'rxjs';
import type { NetworkId } from 'types';

export class FastUnstakeQueue implements Unsubscribable {
// The associated network for this instance.
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/api/subscribe/networkMetrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// SPDX-License-Identifier: GPL-3.0-only

import BigNumber from 'bignumber.js';
import type { NetworkId } from 'common-types';
import { Apis } from 'controllers/Apis';
import type { Unsubscribable } from 'controllers/Subscriptions/types';
import type { Subscription } from 'rxjs';
import { combineLatest } from 'rxjs';
import type { NetworkId } from 'types';

export class NetworkMetrics implements Unsubscribable {
// The associated network for this instance.
Expand Down
Loading

0 comments on commit 437ffe4

Please sign in to comment.