From 805ee9dc5cdff245a333535c83d8444ae6a3981d Mon Sep 17 00:00:00 2001 From: Brandon Kite Date: Thu, 16 Apr 2020 22:22:26 -0700 Subject: [PATCH] Support for optional usage of pallet_balance (#2578) * Allow polkadot UI to function without having pallet_balance enabled * Update packages/page-123code/src/SummaryBar.tsx Co-Authored-By: Jaco Greeff * formatting * fix spacing Co-authored-by: Jaco Greeff --- packages/page-123code/src/SummaryBar.tsx | 13 +++++++++---- packages/page-explorer/src/Summary.tsx | 16 ++++++++++------ packages/page-staking/src/Targets/Summary.tsx | 2 +- packages/react-query/src/TotalIssuance.tsx | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/page-123code/src/SummaryBar.tsx b/packages/page-123code/src/SummaryBar.tsx index e28c65006b..0ddebda0d8 100644 --- a/packages/page-123code/src/SummaryBar.tsx +++ b/packages/page-123code/src/SummaryBar.tsx @@ -17,7 +17,7 @@ function SummaryBar (): React.ReactElement { const { api, systemChain, systemName, systemVersion } = useApi(); const bestNumber = useCall(api.derive.chain.bestNumber, []); const bestNumberLag = useCall(api.derive.chain.bestNumberLag, []); - const totalInsurance = useCall(api.query.balances.totalIssuance, []); + const totalIssuance = useCall(api.query.balances?.totalIssuance, []); const validators = useCall(api.derive.staking.validators, []); return ( @@ -42,9 +42,14 @@ function SummaryBar (): React.ReactElement { )) } )} - - {formatBalance(totalInsurance)} - + {totalIssuance && ( + + {formatBalance(totalIssuance)} + + )} ); diff --git a/packages/page-explorer/src/Summary.tsx b/packages/page-explorer/src/Summary.tsx index 2cab733e8c..b9a62d827e 100644 --- a/packages/page-explorer/src/Summary.tsx +++ b/packages/page-explorer/src/Summary.tsx @@ -4,6 +4,7 @@ import BN from 'bn.js'; import React from 'react'; +import { useApi } from '@polkadot/react-hooks'; import { SummaryBox, CardSummary } from '@polkadot/react-components'; import { BestFinalized, BestNumber, BlockToTime, TimeNow, TotalIssuance } from '@polkadot/react-query'; @@ -14,6 +15,7 @@ const ONE_BLOCK = new BN(1); function Summary (): React.ReactElement<{}> { const { t } = useTranslation(); + const { api } = useApi(); return ( @@ -27,12 +29,14 @@ function Summary (): React.ReactElement<{}> { > - - - + {api.query.balances && ( + + + + )}
diff --git a/packages/page-staking/src/Targets/Summary.tsx b/packages/page-staking/src/Targets/Summary.tsx index ef4a270af2..cda7416609 100644 --- a/packages/page-staking/src/Targets/Summary.tsx +++ b/packages/page-staking/src/Targets/Summary.tsx @@ -22,7 +22,7 @@ interface Props { function Summary ({ lastReward, numNominators, numValidators, totalStaked }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const totalIssuance = useCall(api.query.balances.totalIssuance, []); + const totalIssuance = useCall(api.query.balances?.totalIssuance, []); const [percentage, setPercentage] = useState(); useEffect((): void => { diff --git a/packages/react-query/src/TotalIssuance.tsx b/packages/react-query/src/TotalIssuance.tsx index be56588165..b4e0e3ba68 100644 --- a/packages/react-query/src/TotalIssuance.tsx +++ b/packages/react-query/src/TotalIssuance.tsx @@ -15,7 +15,7 @@ interface Props extends BareProps { function TotalIssuance ({ children, className, label, style }: Props): React.ReactElement { const { api } = useApi(); - const totalIssuance = useCall(api.query.balances.totalIssuance, []); + const totalIssuance = useCall(api.query.balances?.totalIssuance, []); return (