Skip to content

Commit

Permalink
Merge branch 'main' into tbaut-clickonConnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut authored Oct 13, 2023
2 parents a4774f8 + 44f7a8c commit 5359143
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
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

0 comments on commit 5359143

Please sign in to comment.