ghost-portal/packages/react-components/src/CallExpander.tsx
Jaco 04058c67dd
Support PalletSchedulerScheduledV3 (#6985)
* Support PalletSchedulerScheduledV3

* Adjust
2022-02-14 14:59:54 +02:00

51 lines
1.1 KiB
TypeScript

// Copyright 2017-2022 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Call } from '@polkadot/types/interfaces';
import React, { useMemo } from 'react';
import CallDisplay from './Call';
import Expander from './Expander';
interface Props {
children?: React.ReactNode;
className?: string;
labelHash?: React.ReactNode;
value?: Call | null;
withHash?: boolean;
}
function CallExpander ({ children, className = '', labelHash, value, withHash }: Props): React.ReactElement<Props> | null {
const call = useMemo(
() => value && value.callIndex
? value.registry.findMetaCall(value.callIndex)
: null,
[value]
);
if (!call) {
return null;
}
const { meta, method, section } = call;
return (
<div className={`ui--CallExpander ${className}`}>
<Expander
summaryHead={<div>{section}.{method}</div>}
summaryMeta={meta}
>
<CallDisplay
labelHash={labelHash}
value={value}
withHash={withHash}
/>
{children}
</Expander>
</div>
);
}
export default React.memo(CallExpander);