Optional call

This commit is contained in:
Jaco Greeff 2020-03-09 21:42:25 +01:00
parent 50ec50ebef
commit 45265f7cd3
3 changed files with 4 additions and 4 deletions

View File

@ -99,8 +99,8 @@ function Account ({ allStashes, className, isOwnStash, isVisible, next, onUpdate
const { allAccounts } = useAccounts();
const validateInfo = useCall<ValidatorInfo>(api.query.staking.validators, [stashId]);
const balancesAll = useCall<DerivedBalancesAll>(api.derive.balances.all as any, [stashId]);
const stakingAccount = isVisible ? useCall<DerivedStakingAccount>(api.derive.staking.account as any, [stashId]) : undefined;
const stakingRewardsAll = isVisible ? useCall<DeriveStakerReward[]>(api.derive.staking.stakerRewards as any, [stashId]) : undefined;
const stakingAccount = useCall<DerivedStakingAccount>(isVisible && api.derive.staking.account as any, [stashId]);
const stakingRewardsAll = useCall<DeriveStakerReward[]>(isVisible && api.derive.staking.stakerRewards as any, [stashId]);
const [[stakingRewards, payoutEras], setStakingRewards] = useState<[DeriveStakerReward[], EraIndex[]]>([[], []]);
const [{ controllerId, destination, hexSessionIdQueue, hexSessionIdNext, isLoading, isOwnController, isStashNominating, isStashValidating, nominees, sessionIds, validatorPrefs }, setStakeState] = useState<StakeState>({ controllerId: null, destination: 0, hexSessionIdNext: null, hexSessionIdQueue: null, isLoading: true, isOwnController: false, isStashNominating: false, isStashValidating: false, sessionIds: [] });
const [activeNoms, setActiveNoms] = useState<string[]>([]);

View File

@ -102,7 +102,7 @@ export default function Address ({ address, className, filterName, hasQueries, h
const { t } = useTranslation();
const { api } = useApi();
const info = useCall<DeriveAccountInfo>(api.derive.accounts.info as any, [address]);
const stakingInfo = isMain ? useCall<DerivedStakingQuery>(api.derive.staking.query as any, [address]) : undefined;
const stakingInfo = useCall<DerivedStakingQuery>(isMain && api.derive.staking.query as any, [address]);
const [{ commission, nominators, stakeOwn, stakeOther }, setStakingState] = useState<StakingState>({ nominators: [] });
const [isExpanded, setIsExpanded] = useState(false);
const [isVisible, setIsVisible] = useState(true);

View File

@ -98,7 +98,7 @@ function subscribe <T> (mounted: MountedRef, tracker: TrackerRef, fn: TrackFn |
// - returns a promise with an unsubscribe function
// - has a callback to set the value
// FIXME The typings here need some serious TLC
export default function useCall <T> (fn: TrackFn | undefined | null, params: CallParams = [], options: CallOptions<T> = {}): T | undefined {
export default function useCall <T> (fn: TrackFn | undefined | null | false, params: CallParams = [], options: CallOptions<T> = {}): T | undefined {
const mounted = useIsMountedRef();
const tracker = useRef<Tracker>({ isActive: false, count: 0, serialized: null, subscriber: null });
const [value, setValue] = useState<T | undefined>(options.defaultValue);