From 50d23185e605bfbed0fc3c27b11357e1485db0e6 Mon Sep 17 00:00:00 2001 From: Jaco Date: Mon, 14 Feb 2022 13:12:19 +0100 Subject: [PATCH] Ensure CallExpander doesn't crash (#6983) --- packages/react-components/src/CallExpander.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/react-components/src/CallExpander.tsx b/packages/react-components/src/CallExpander.tsx index 5175eff91c..ed2d3e6732 100644 --- a/packages/react-components/src/CallExpander.tsx +++ b/packages/react-components/src/CallExpander.tsx @@ -3,7 +3,7 @@ import type { Call } from '@polkadot/types/interfaces'; -import React from 'react'; +import React, { useMemo } from 'react'; import CallDisplay from './Call'; import Expander from './Expander'; @@ -16,8 +16,19 @@ interface Props { withHash?: boolean; } -function CallExpander ({ children, className = '', labelHash, value, withHash }: Props): React.ReactElement { - const { meta, method, section } = value.registry.findMetaCall(value.callIndex); +function CallExpander ({ children, className = '', labelHash, value, withHash }: Props): React.ReactElement | null { + const call = useMemo( + () => value && value.callIndex + ? value.registry.findMetaCall(value.callIndex) + : null, + [value] + ); + + if (!call) { + return null; + } + + const { meta, method, section } = call; return (