Skip to content

Commit

Permalink
feat(refactor): remove unneeded bonded getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat committed Jan 20, 2024
1 parent 4ef3abc commit 7108e55
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 24 deletions.
2 changes: 0 additions & 2 deletions src/contexts/Bonded/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export const nominations: Nominations = {
};

export const defaultBondedContext: BondedContextInterface = {
getAccount: (address) => null,
getBondedAccount: (address) => null,
getAccountNominations: (address) => [],
isController: (address) => false,
bondedAccounts: [],
};
11 changes: 1 addition & 10 deletions src/contexts/Bonded/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,6 @@ export const BondedProvider = ({ children }: { children: ReactNode }) => {
bondedAccountsRef.current.find((a) => a.address === address)?.nominations
?.targets || [];

const getAccount = (address: MaybeAddress) =>
bondedAccountsRef.current.find((a) => a.address === address) || null;

const isController = (address: MaybeAddress) =>
bondedAccountsRef.current.filter((a) => (a?.bonded || '') === address)
?.length > 0 || false;

// Handle accounts sync on connected accounts change.
useEffectIgnoreInitial(() => {
if (isReady) {
Expand All @@ -167,11 +160,9 @@ export const BondedProvider = ({ children }: { children: ReactNode }) => {
return (
<BondedContext.Provider
value={{
getAccount,
getBondedAccount,
getAccountNominations,
isController,
bondedAccounts: bondedAccountsRef.current,
bondedAccounts,
}}
>
{children}
Expand Down
2 changes: 0 additions & 2 deletions src/contexts/Bonded/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export interface Nominations {
export type Targets = string[];

export interface BondedContextInterface {
getAccount: (address: MaybeAddress) => BondedAccount | null;
getBondedAccount: (address: MaybeAddress) => string | null;
getAccountNominations: (address: MaybeAddress) => Targets;
isController: (address: MaybeAddress) => boolean;
bondedAccounts: BondedAccount[];
}
11 changes: 1 addition & 10 deletions src/contexts/TransferOptions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { ReactNode } from 'react';
import { createContext, useContext, useState } from 'react';
import { useApi } from 'contexts/Api';
import { useBalances } from 'contexts/Balances';
import { useBonded } from 'contexts/Bonded';
import { useNetworkMetrics } from 'contexts/NetworkMetrics';
import { usePoolMemberships } from 'contexts/Pools/PoolMemberships';
import type { MaybeAddress } from 'types';
Expand All @@ -15,10 +14,7 @@ import { useNetwork } from 'contexts/Network';
import { useActiveAccounts } from 'contexts/ActiveAccounts';
import type { TransferOptions, TransferOptionsContextInterface } from './types';
import { getLocalFeeReserve, setLocalFeeReserve } from './Utils';
import {
defaultTransferOptions,
defaultTransferOptionsContext,
} from './defaults';
import { defaultTransferOptionsContext } from './defaults';
import { getUnlocking } from 'contexts/Balances/Utils';

export const TransferOptionsContext =
Expand All @@ -32,7 +28,6 @@ export const TransferOptionsProvider = ({
children: ReactNode;
}) => {
const { consts } = useApi();
const { getAccount } = useBonded();
const { activeEra } = useNetworkMetrics();
const { membership } = usePoolMemberships();
const { activeAccount } = useActiveAccounts();
Expand All @@ -52,10 +47,6 @@ export const TransferOptionsProvider = ({
// Gets balance numbers from `useBalances` state, which only takes the active accounts from
// `BalancesController`.
const getTransferOptions = (address: MaybeAddress): TransferOptions => {
if (getAccount(address) === null) {
return defaultTransferOptions;
}

const { maxLock } = getLocks(address);
const { free, frozen } = getBalance(address);
const { active, total, unlocking } = getLedger({ stash: address });
Expand Down

0 comments on commit 7108e55

Please sign in to comment.