Skip to content

Commit

Permalink
Merge pull request #442 from HausDAO/fix/decoded-actions-array
Browse files Browse the repository at this point in the history
Fix decoding actions with array params
  • Loading branch information
dekanbro authored Nov 9, 2023
2 parents 63368ff + 0ce1e5d commit 4d83cce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 12 additions & 4 deletions libs/moloch-v3-macro-ui/src/utils/proposalDetailsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ const getValueFromMintOrTransferAction = (
return 'decoding error';
}

const value = Array.isArray(actionData.params[1].value)
? (actionData.params[1].value[0] as bigint)
: (actionData.params[1].value as bigint);
const value = actionData.params[1].type.endsWith('[]')
? actionData.params[1].value
.toString()
.split(',')
.map((v) => BigInt(v))
: [BigInt(actionData.params[1].value.toString())];

return formatValueTo({
value: toWholeUnits(value.toString(), decimals),
value: toWholeUnits(
value
.reduce((val: bigint, accValue: bigint) => accValue + val, BigInt(0))
.toString(),
decimals
),
decimals: 2,
format: 'numberShort',
});
Expand Down
6 changes: 5 additions & 1 deletion libs/tx-builder/src/utils/deepDecoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ const decodeMethod = (options: {
const inputsWithValues = (inputs as any[]).map((input, index) => ({
name: input.name,
type: input.type,
value: result.args?.[index]?.toString() || '0x',
value: Array.isArray(result.args?.[index])
? (result.args?.[index] as Array<any>).length

Check warning on line 161 in libs/tx-builder/src/utils/deepDecoding.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
? (result.args?.[index] as Array<any>).toString()

Check warning on line 162 in libs/tx-builder/src/utils/deepDecoding.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
: '[]'
: result.args?.[index]?.toString() || '0x',
}));

return {
Expand Down

0 comments on commit 4d83cce

Please sign in to comment.