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

fix(website): interact render of objects #1659

Merged
merged 3 commits into from
Jan 30, 2025
Merged

fix(website): interact render of objects #1659

merged 3 commits into from
Jan 30, 2025

Conversation

mjlescano
Copy link
Member

@mjlescano mjlescano commented Jan 28, 2025

This PR refactors the Abi Input renderer from the TransactionDisplay component into a separate component, which then it is reutilised for rendering interact outputs. Effectively fixing some rendering bugs for rendering arrays and objects which were already solved on the TX view.

It also fixes the rendering of non-values for objects and arrays, generating an template result with zeroed values (working the same way as Solidity).

return '0';
default:
return '(no result)';
function _isArrayAbiParameter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to wrap Array.isArray? perhaps we can use it directly in the condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or is it for TS to devive the value to AbiParameter[]?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a TS thing, when used it fixes the types on the following lines

return arrayTooltip === _encodeArg(type, val) ? '' : arrayTooltip;
}

if (type.startsWith('bytes') && val.startsWith('0x')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is hard to read. Couldn't we use the return early strategy? It should eliminate the complexity.

if (type assertion) {
  doSomething...
  return
}

if (type assertion2) {
   doSomething...
   return
}

Copy link
Contributor

@nicosampler nicosampler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work Mati 💯 .

perhaps we can go one step further and convert packages/website/src/components/AbiParameterPreview into a folder with the following structure:

utils > with all the internal functions. Then we can add UT in this folder for each function.
index.ts > that exports AbiParameterPreview.tsx

@mjlescano mjlescano merged commit 3c68cda into dev Jan 30, 2025
7 of 8 checks passed
@mjlescano mjlescano deleted the fix-object-render branch January 30, 2025 12:31
@nicosampler
Copy link
Contributor

moving this chat here, from Mati to future references:

http://localhost:3000/packages/foil/latest/8453-eth-gas/interact/foil/FoilYin/0x20ba5e24ad8a5b9502d4882607f0c8526a1f3205#selector-0x7a0ed627
http://localhost:3000/packages/synthetix-governance/latest/2192-spartan/interact/synthetix-governance/GovernanceProxy/0x2082d5A6f6F17F5e421FD6508b867D794472A42a#selector-0x60988e09
http://localhost:3000/packages/synthetix-governance/latest/2192-spartan/interact/synthetix-governance/GovernanceProxy/0x2082d5A6f6F17F5e421FD6508b867D794472A42a#selector-0xb119c5bd

And also, a TransactionDisplay one, which also had to do some modifications:
http://localhost:3000/deploy/txn/1729/0x1Fe50318e5E3165742eDC9c4a15d997bDB935Eb9/185/0x12ec2f5968b96e0aeb6ca7a6bd5501fe37ef5afafdf3964ef511941e4b4e9d44?address=0x1Fe50318e5E3165742eDC9c4a15d997bDB935Eb9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants