Optional balances & timestamp (#5188)
This commit is contained in:
parent
482d0b1aeb
commit
cf6c682333
@ -93,7 +93,7 @@ function Account ({ account: { address, meta }, className = '', delegation, filt
|
||||
const api = useApi();
|
||||
const { getLedger } = useLedger();
|
||||
const bestNumber = useBestNumber();
|
||||
const balancesAll = useCall<DeriveBalancesAll>(api.api.derive.balances.all, [address]);
|
||||
const balancesAll = useCall<DeriveBalancesAll>(api.api.derive.balances?.all, [address]);
|
||||
const democracyLocks = useCall<DeriveDemocracyLock[]>(api.api.derive.democracy?.locks, [address]);
|
||||
const recoveryInfo = useCall<RecoveryConfig | null>(api.api.query.recovery?.recoverable, [address], transformRecovery);
|
||||
const multiInfos = useMultisigApprovals(address);
|
||||
|
||||
@ -22,7 +22,7 @@ interface Props {
|
||||
function ValidateAmount ({ amount, delegatingAccount, onError }: Props): React.ReactElement<Props> | null {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const delegatingAccountBalance = useCall<DeriveBalancesAll>(api.derive.balances.all, [delegatingAccount]);
|
||||
const delegatingAccountBalance = useCall<DeriveBalancesAll>(api.derive.balances?.all, [delegatingAccount]);
|
||||
const [{ error, warning }, setResult] = useState<AmountValidateState>({ error: null, warning: null });
|
||||
|
||||
useEffect((): void => {
|
||||
|
||||
@ -51,7 +51,7 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send
|
||||
const [recipientId, setRecipientId] = useState<string | null>(null);
|
||||
const [senderId, setSenderId] = useState<string | null>(null);
|
||||
const [[, recipientPhish], setPhishing] = useState<[string | null, string | null]>([null, null]);
|
||||
const balances = useCall<DeriveBalancesAll>(api.derive.balances.all, [propSenderId || senderId]);
|
||||
const balances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [propSenderId || senderId]);
|
||||
const accountInfo = useCall<AccountInfoWithProviders | AccountInfoWithRefCount>(api.query.system.account, [propSenderId || senderId]);
|
||||
|
||||
useEffect((): void => {
|
||||
|
||||
@ -34,7 +34,7 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite
|
||||
const { theme } = useContext<ThemeDef>(ThemeContext);
|
||||
const api = useApi();
|
||||
const info = useCall<DeriveAccountInfo>(api.api.derive.accounts.info, [address]);
|
||||
const balancesAll = useCall<DeriveBalancesAll>(api.api.derive.balances.all, [address]);
|
||||
const balancesAll = useCall<DeriveBalancesAll>(api.api.derive.balances?.all, [address]);
|
||||
const [tags, setTags] = useState<string[]>([]);
|
||||
const [accName, setAccName] = useState('');
|
||||
const [current, setCurrent] = useState<KeyringAddress | null>(null);
|
||||
|
||||
@ -9,5 +9,5 @@ import { useApi, useCall } from '@polkadot/react-hooks';
|
||||
export function useBalance (accountId: string | null): Balance | undefined {
|
||||
const { api } = useApi();
|
||||
|
||||
return useCall<DeriveBalancesAll>(api.derive.balances.all, [accountId])?.availableBalance;
|
||||
return useCall<DeriveBalancesAll>(api.derive.balances?.all, [accountId])?.availableBalance;
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ function Referendum ({ className = '', value: { allAye, allNay, image, imageHash
|
||||
const { api } = useApi();
|
||||
const { allAccounts } = useAccounts();
|
||||
const bestNumber = useBestNumber();
|
||||
const totalIssuance = useCall<Balance>(api.query.balances.totalIssuance);
|
||||
const totalIssuance = useCall<Balance>(api.query.balances?.totalIssuance);
|
||||
const { changeAye, changeNay } = useChangeCalc(status.threshold, votedAye, votedNay, votedTotal);
|
||||
const threshold = useMemo(
|
||||
() => status.threshold.type.toString().replace('majority', ' majority '),
|
||||
|
||||
@ -5,7 +5,7 @@ import type { HeaderExtended } from '@polkadot/api-derive/types';
|
||||
import type { KeyedEvent } from '@polkadot/react-query/types';
|
||||
import type { EventRecord, SignedBlock } from '@polkadot/types/interfaces';
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { AddressSmall, Columar, LinkExternal, Table } from '@polkadot/react-components';
|
||||
@ -24,6 +24,8 @@ interface Props {
|
||||
value?: string | null;
|
||||
}
|
||||
|
||||
const EMPTY_HEADER = [['...', 'start', 6]];
|
||||
|
||||
function transformResult ([events, getBlock, getHeader]: [EventRecord[], SignedBlock, HeaderExtended?]): [KeyedEvent[], SignedBlock, HeaderExtended?] {
|
||||
return [
|
||||
events.map((record, index) => ({
|
||||
@ -58,6 +60,20 @@ function BlockByHash ({ className = '', error, value }: Props): React.ReactEleme
|
||||
});
|
||||
}, [api, mountedRef, value]);
|
||||
|
||||
const header = useMemo(
|
||||
() => getHeader
|
||||
? [
|
||||
[formatNumber(getHeader.number.unwrap()), 'start', 1],
|
||||
[t('hash'), 'start'],
|
||||
[t('parent'), 'start'],
|
||||
[t('extrinsics'), 'start'],
|
||||
[t('state'), 'start'],
|
||||
[undefined, 'media--1200']
|
||||
]
|
||||
: EMPTY_HEADER,
|
||||
[getHeader, t]
|
||||
);
|
||||
|
||||
const blockNumber = getHeader?.number.unwrap();
|
||||
const parentHash = getHeader?.parentHash.toHex();
|
||||
const hasParent = !getHeader?.parentHash.isEmpty;
|
||||
@ -65,23 +81,12 @@ function BlockByHash ({ className = '', error, value }: Props): React.ReactEleme
|
||||
return (
|
||||
<div className={className}>
|
||||
<Table
|
||||
header={
|
||||
getHeader
|
||||
? [
|
||||
[formatNumber(blockNumber), 'start', 1],
|
||||
[t('hash'), 'start'],
|
||||
[t('parent'), 'start'],
|
||||
[t('extrinsics'), 'start'],
|
||||
[t('state'), 'start'],
|
||||
[undefined, 'media--1200']
|
||||
]
|
||||
: [['...', 'start', 6]]
|
||||
}
|
||||
header={header}
|
||||
isFixed
|
||||
>
|
||||
{myError
|
||||
? <tr><td colSpan={6}>{t('Unable to retrieve the specified block details. {{error}}', { replace: { error: myError.message } })}</td></tr>
|
||||
: getBlock && !getBlock.isEmpty && getHeader && !getHeader.isEmpty && (
|
||||
: getBlock && getHeader && !getBlock.isEmpty && !getHeader.isEmpty && (
|
||||
<tr>
|
||||
<td className='address'>
|
||||
{getHeader.author && (
|
||||
|
||||
@ -16,7 +16,7 @@ interface Props {
|
||||
|
||||
function BalanceDisplay ({ className = '', label, params }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances.all, [params]);
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [params]);
|
||||
|
||||
return (
|
||||
<InputBalance
|
||||
|
||||
@ -23,7 +23,7 @@ function Summary ({ auctionInfo, className, lastWinners }: Props): React.ReactEl
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const bestNumber = useBestNumber();
|
||||
const totalIssuance = useCall<Balance>(api.query.balances.totalIssuance);
|
||||
const totalIssuance = useCall<Balance>(api.query.balances?.totalIssuance);
|
||||
|
||||
return (
|
||||
<SummaryBox className={className}>
|
||||
|
||||
@ -37,7 +37,7 @@ function PollApp ({ basePath, className }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const bestNumber = useBestNumber();
|
||||
const [totalIssuance, totals] = useCallMulti<MultiResult>([
|
||||
api.query.balances.totalIssuance,
|
||||
api.query.balances?.totalIssuance,
|
||||
api.query.poll.totals
|
||||
], optMulti);
|
||||
const [accountId, setAccountId] = useState<string | null>(null);
|
||||
|
||||
@ -42,7 +42,7 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea
|
||||
const { api } = useApi();
|
||||
const [amountError, setAmountError] = useState<AmountValidateState | null>(null);
|
||||
const [maxAdditional, setMaxAdditional] = useState<BN | undefined>();
|
||||
const stashBalance = useCall<DeriveBalancesAll>(api.derive.balances.all, [stashId]);
|
||||
const stashBalance = useCall<DeriveBalancesAll>(api.derive.balances?.all, [stashId]);
|
||||
const currentAmount = useMemo(
|
||||
() => stakingInfo && stakingInfo.stakingLedger?.active.unwrap(),
|
||||
[stakingInfo]
|
||||
|
||||
@ -42,7 +42,7 @@ function formatExistential (value: BN): string {
|
||||
function ValidateAmount ({ currentAmount, isNominating, minNomination, onError, stashId, value }: Props): React.ReactElement<Props> | null {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const stashBalance = useCall<DeriveBalancesAll>(api.derive.balances.all, [stashId]);
|
||||
const stashBalance = useCall<DeriveBalancesAll>(api.derive.balances?.all, [stashId]);
|
||||
const [{ error, warning }, setResult] = useState<AmountValidateState>({ error: null, warning: null });
|
||||
|
||||
useEffect((): void => {
|
||||
|
||||
@ -43,7 +43,7 @@ function ValidateController ({ accountId, controllerId, defaultController, onErr
|
||||
const { api } = useApi();
|
||||
const bondedId = useCall<string | null>(controllerId ? api.query.staking.bonded : null, [controllerId], transformBonded);
|
||||
const stashId = useCall<string | null>(controllerId ? api.query.staking.ledger : null, [controllerId], transformStash);
|
||||
const allBalances = useCall<DeriveBalancesAll>(controllerId ? api.derive.balances.all : null, [controllerId]);
|
||||
const allBalances = useCall<DeriveBalancesAll>(controllerId ? api.derive.balances?.all : null, [controllerId]);
|
||||
const [{ error, isFatal }, setError] = useState<ErrorState>({ error: null, isFatal: false });
|
||||
|
||||
useEffect((): void => {
|
||||
|
||||
@ -25,7 +25,7 @@ function SetRewardDestination ({ controllerId, defaultDestination, onClose, stas
|
||||
const { api } = useApi();
|
||||
const [destination, setDestination] = useState<DestinationType>(() => ((defaultDestination?.isAccount ? 'Account' : defaultDestination?.toString()) || 'Staked') as 'Staked');
|
||||
const [destAccount, setDestAccount] = useState<string | null>(() => defaultDestination?.isAccount ? defaultDestination.asAccount.toString() : null);
|
||||
const destBalance = useCall<DeriveBalancesAll>(api.derive.balances.all, [destAccount]);
|
||||
const destBalance = useCall<DeriveBalancesAll>(api.derive.balances?.all, [destAccount]);
|
||||
|
||||
const options = useMemo(
|
||||
() => createDestCurr(t),
|
||||
|
||||
@ -60,7 +60,7 @@ const transformSpan = {
|
||||
|
||||
function useStashCalls (api: ApiPromise, stashId: string) {
|
||||
const params = useMemo(() => [stashId], [stashId]);
|
||||
const balancesAll = useCall<DeriveBalancesAll>(api.derive.balances.all, params);
|
||||
const balancesAll = useCall<DeriveBalancesAll>(api.derive.balances?.all, params);
|
||||
const spanCount = useCall<number>(api.query.staking.slashingSpans, params, transformSpan);
|
||||
const stakingAccount = useCall<DeriveStakingAccount>(api.derive.staking.account, params);
|
||||
|
||||
|
||||
@ -45,8 +45,8 @@ function Bond ({ className = '', isNominating, minNomination, onChange }: Props)
|
||||
const [destAccount, setDestAccount] = useState<string | null>(null);
|
||||
const [stashId, setStashId] = useState<string | null>(null);
|
||||
const [startBalance, setStartBalance] = useState<BN | null>(null);
|
||||
const stashBalance = useCall<DeriveBalancesAll>(api.derive.balances.all, [stashId]);
|
||||
const destBalance = useCall<DeriveBalancesAll>(api.derive.balances.all, [destAccount]);
|
||||
const stashBalance = useCall<DeriveBalancesAll>(api.derive.balances?.all, [stashId]);
|
||||
const destBalance = useCall<DeriveBalancesAll>(api.derive.balances?.all, [destAccount]);
|
||||
const bondedBlocks = useUnbondDuration();
|
||||
|
||||
const options = useMemo(
|
||||
|
||||
@ -236,7 +236,7 @@ export default function useSortedTargets (favorites: string[], withLedger: boole
|
||||
const { api } = useApi();
|
||||
const { allAccounts } = useAccounts();
|
||||
const historyDepth = useCall<BN>(api.query.staking.historyDepth);
|
||||
const totalIssuance = useCall<BN>(api.query.balances.totalIssuance);
|
||||
const totalIssuance = useCall<BN>(api.query.balances?.totalIssuance);
|
||||
const electedInfo = useCall<DeriveStakingElected>(api.derive.staking.electedInfo, [{ ...DEFAULT_FLAGS_ELECTED, withLedger }]);
|
||||
const waitingInfo = useCall<DeriveStakingWaiting>(api.derive.staking.waitingInfo, [{ ...DEFAULT_FLAGS_WAITING, withLedger }]);
|
||||
const lastEraInfo = useCall<LastEra>(api.derive.session.info, undefined, transformEra);
|
||||
|
||||
@ -102,7 +102,7 @@ function expandKey (api: ApiPromise, key: QueryableStorageEntry<'promise'>): Key
|
||||
function Modules ({ onAdd }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const [{ defaultValues, isIterable, key, params }, setKey] = useState<KeyState>({ defaultValues: undefined, isIterable: false, key: api.query.timestamp.now, params: [] });
|
||||
const [{ defaultValues, isIterable, key, params }, setKey] = useState<KeyState>({ defaultValues: undefined, isIterable: false, key: api.query.timestamp?.now || api.query.system.events, params: [] });
|
||||
const [{ isValid, values }, setValues] = useState<ValState>({ isValid: true, values: [] });
|
||||
|
||||
const _onAdd = useCallback(
|
||||
@ -138,7 +138,7 @@ function Modules ({ onAdd }: Props): React.ReactElement<Props> {
|
||||
<section className='storage--actionrow'>
|
||||
<div className='storage--actionrow-value'>
|
||||
<InputStorage
|
||||
defaultValue={api.query.timestamp.now}
|
||||
defaultValue={api.query.timestamp?.now || api.query.system.events}
|
||||
help={meta?.documentation.join(' ')}
|
||||
label={t<string>('selected state query')}
|
||||
onChange={_onChangeKey}
|
||||
|
||||
@ -44,7 +44,7 @@ function getValues (selectedId: string | null | undefined, isCouncil: boolean |
|
||||
function VoteValue ({ accountId, autoFocus, isCouncil, onChange }: Props): React.ReactElement<Props> | null {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances.all, [accountId]);
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [accountId]);
|
||||
const [{ maxValue, selectedId, value }, setValue] = useState<ValueState>({ maxValue: BN_ZERO, value: BN_ZERO });
|
||||
|
||||
useEffect((): void => {
|
||||
|
||||
@ -37,7 +37,7 @@ export function calcInflation (api: ApiPromise, totalStaked: BN, totalIssuance:
|
||||
|
||||
export function useInflation (totalStaked?: BN): Inflation {
|
||||
const { api } = useApi();
|
||||
const totalIssuance = useCall<BN>(api.query.balances.totalIssuance);
|
||||
const totalIssuance = useCall<BN>(api.query.balances?.totalIssuance);
|
||||
const [state, setState] = useState<Inflation>(EMPTY);
|
||||
|
||||
useEffect((): void => {
|
||||
|
||||
@ -27,7 +27,7 @@ export function useTreasury (): Result {
|
||||
: BN_ZERO
|
||||
});
|
||||
|
||||
const treasuryBalance = useCall<DeriveBalancesAccount>(api.derive.balances.account, [TREASURY_ACCOUNT]);
|
||||
const treasuryBalance = useCall<DeriveBalancesAccount>(api.derive.balances?.account, [TREASURY_ACCOUNT]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!api.consts.treasury) {
|
||||
|
||||
@ -19,7 +19,7 @@ interface Props {
|
||||
|
||||
function AvailableDisplay ({ children, className = '', label, params }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances.all, [params]);
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [params]);
|
||||
|
||||
return (
|
||||
<FormatBalance
|
||||
|
||||
@ -19,7 +19,7 @@ interface Props {
|
||||
|
||||
function BalanceDisplay ({ children, className = '', label, params }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances.all, [params]);
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [params]);
|
||||
|
||||
return (
|
||||
<FormatBalance
|
||||
|
||||
@ -19,7 +19,7 @@ interface Props {
|
||||
|
||||
function BalanceFree ({ children, className = '', label, params }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances.all, [params]);
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [params]);
|
||||
|
||||
return (
|
||||
<FormatBalance
|
||||
|
||||
@ -20,7 +20,7 @@ interface Props {
|
||||
|
||||
function BalanceVoting ({ children, className = '', isCouncil, label, params }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances.all, [params]);
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [params]);
|
||||
|
||||
return (
|
||||
<FormatBalance
|
||||
|
||||
@ -19,7 +19,7 @@ interface Props {
|
||||
|
||||
function Nonce ({ children, className = '', label, params }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances.all, [params]);
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [params]);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
|
||||
@ -17,15 +17,19 @@ interface Props {
|
||||
value?: Moment;
|
||||
}
|
||||
|
||||
function TimeNow ({ children, className = '', label, value }: Props): React.ReactElement<Props> {
|
||||
function TimeNow ({ children, className = '', label, value }: Props): React.ReactElement<Props> | null {
|
||||
const { api } = useApi();
|
||||
const timestamp = useCall<Moment>(!value && api.query.timestamp.now);
|
||||
const timestamp = useCall<Moment>(!value && api.query.timestamp?.now);
|
||||
const [now, setNow] = useState<BN | undefined>();
|
||||
|
||||
useEffect((): void => {
|
||||
setNow(value || timestamp);
|
||||
}, [timestamp, value]);
|
||||
|
||||
if (!now) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
{label || ''}
|
||||
|
||||
@ -28,7 +28,7 @@ function PaymentInfo ({ accountId, className = '', extrinsic }: Props): React.Re
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const [dispatchInfo, setDispatchInfo] = useState<RuntimeDispatchInfo | null>(null);
|
||||
const balances = useCall<DeriveBalancesAll>(api.derive.balances.all, [accountId]);
|
||||
const balances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [accountId]);
|
||||
const mountedRef = useIsMountedRef();
|
||||
|
||||
useEffect((): void => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user