From b45a6ce8ce9fceeafe222409d7f6f64442d57a44 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 24 Mar 2022 07:00:55 +0100 Subject: [PATCH] Remove instanceof, adjust VoteThreshold rendering (#7222) * Remove instanceof, adjust VoteThreshold rendering * useMemo --- .../react-params/src/Param/VoteThreshold.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/react-params/src/Param/VoteThreshold.tsx b/packages/react-params/src/Param/VoteThreshold.tsx index 2c11a21bb2..0c363582cc 100644 --- a/packages/react-params/src/Param/VoteThreshold.tsx +++ b/packages/react-params/src/Param/VoteThreshold.tsx @@ -1,12 +1,13 @@ // Copyright 2017-2022 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { BN } from '@polkadot/util'; import type { Props } from '../types'; -import React, { useCallback } from 'react'; +import React, { useCallback, useMemo } from 'react'; import { Dropdown } from '@polkadot/react-components'; -import { bnToBn } from '@polkadot/util'; +import { bnToBn, isFunction } from '@polkadot/util'; import Bare from './Bare'; @@ -24,7 +25,7 @@ export const textMap = options.reduce((textMap, { text, value }): TextMap => { return textMap; }, {} as unknown as TextMap); -function VoteThresholdParam ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, registry, withLabel }: Props): React.ReactElement { +function VoteThresholdParam ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, withLabel }: Props): React.ReactElement { const _onChange = useCallback( (value: number) => onChange && onChange({ @@ -34,9 +35,12 @@ function VoteThresholdParam ({ className = '', defaultValue: { value }, isDisabl [onChange] ); - const defaultValue = value instanceof registry.createClass('VoteThreshold') - ? value.toNumber() - : bnToBn(value as number).toNumber(); + const defaultValue = useMemo( + () => isFunction((value as BN).toNumber) + ? (value as BN).toNumber() + : bnToBn(value as number).toNumber(), + [value] + ); return (