Skip to content

Commit

Permalink
hotfix followup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Oct 13, 2023
1 parent 499b33f commit a3848eb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
63 changes: 42 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 @@ -101,15 +115,21 @@ const createUlTree = ({ name, args, decimals, unit, api, typeName }: CreateTreeP
if (!args) return
if (!name) return

// console.log('args', args)
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)
console.log('typename, key, val', _typeName, key, value)

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 @@ -124,8 +144,9 @@ const createUlTree = ({ name, args, decimals, unit, api, typeName }: CreateTreeP
)
}

typeof value === 'object' && console.log('calling with typename, args', _typeName, value)
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

0 comments on commit a3848eb

Please sign in to comment.