Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle RuntimeCall the same way as Vec<RuntimeCall> #401

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 39 additions & 21 deletions packages/ui/src/components/CallInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ interface CreateTreeParams {
typeName?: string
}

const handleCallDisplay = ({
call,
decimals,
unit,
api,
key
}: {
call: any
decimals: number
unit: string
key: string
api: ApiPromise
}) => {
const name = `${call.section}.${call.method}`
return (
<>
<li key={key}>{name}</li>
{createUlTree({
name: `${call.section}.${call.method}`,
args: call.args,
decimals,
unit,
api
})}
</>
)
}

const handleBatchDisplay = ({
value,
decimals,
Expand All @@ -46,21 +74,9 @@ const handleBatchDisplay = ({
key: string
api: ApiPromise
}) =>
value.map((call: any, index: number) => {
const name = `${call.section}.${call.method}`
return (
<>
<li key={`${key}-${index}`}>{name}</li>
{createUlTree({
name: `${call.section}.${call.method}`,
args: call.args,
decimals,
unit,
api
})}
</>
)
})
value.map((call: any, index: number) =>
handleCallDisplay({ call, decimals, unit, api, key: `${key}-${index}` })
)

const handleBalanceDisplay = ({
value,
Expand All @@ -86,10 +102,8 @@ const handleBalanceDisplay = ({
)
}

const getTypeName = (index: number, name: string, value: any, api: ApiPromise) => {
const [palletFromName, methodFromName] = name.split('.')
const pallet = value?.section || palletFromName
const method = value?.method || methodFromName
const getTypeName = (index: number, name: string, api: ApiPromise) => {
const [pallet, method] = name.split('.')
const metaArgs = !!pallet && !!method && api.tx[pallet][method].meta.args

return (
Expand All @@ -104,12 +118,16 @@ const createUlTree = ({ name, args, decimals, unit, api, typeName }: CreateTreeP
return (
<ul className="params">
{Object.entries(args).map(([key, value], index) => {
const _typeName = typeName || getTypeName(index, name, value, api)
const _typeName = typeName || getTypeName(index, name, api)

if (_typeName === 'Vec<RuntimeCall>') {
return handleBatchDisplay({ value, decimals, unit, api, key: `${key}-batch` })
}

if (_typeName === 'RuntimeCall') {
return handleCallDisplay({ call: value, decimals, unit, api, key: `${key}` })
}

// generically show nice value for Balance type
if (isTypeBalance(_typeName)) {
return handleBalanceDisplay({ value, decimals, unit, key })
Expand All @@ -125,7 +143,7 @@ const createUlTree = ({ name, args, decimals, unit, api, typeName }: CreateTreeP
}

return (
<li key={key}>
<li key={`${key}-root-${index}`}>
{key}:{' '}
{typeof value === 'object'
? createUlTree({
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/EasySetup/FromCallData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const FromCallData = ({ className, onSetExtrinsic, isProxySelected, onSetErrorMe
<TextFieldStyled
label={`Call data`}
onChange={onCallDataChange}
value={pastedCallData}
value={pastedCallData || ''}
helperText={callDataError}
error={!!callDataError}
fullWidth
Expand Down
Loading