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

Refactor: Move all components to separate files #379

Merged
merged 36 commits into from
Jan 21, 2025
Merged

Refactor: Move all components to separate files #379

merged 36 commits into from
Jan 21, 2025

Conversation

Montoya
Copy link
Contributor

@Montoya Montoya commented Dec 17, 2024

This refactors everything as independent modules with shared global context. We also attempted to

  • make these modules as self-contained as possible.
  • move constants and functions into separate files.
  • use shared constants and objects for sharing state.
  • add events and listeners where appropriate for handling state changes.

This refactor does not:

  • Change the connect / disconnect / provider logic very much
  • Rewrite with React

But it's progress

Montoya and others added 13 commits December 16, 2024 23:35
* chore: refactor signature types to different components

* fix: injection order of components
And committing a naming crime, but we will allow it
This introduces a new parameters on `globalContext` called `_connected` with a getter and setter. When set to a new value, the setter dispatches a custom event `globalConnectionChange`. Each module with a button that needs to be enabled when MetaMask is connected thus has an event listener for that event. Now, those buttons are enabled via the listener.

This gets us part way to relying on listeners for all state changes.
Also fix a few small errors from previous commits
* chore: Split transactions into separate components

* chore: add index.js to export all modules

* chore: add index.js to export all modules
Unfortunately most of the connection logic is still in index.js and is hard to untangle
@Montoya Montoya marked this pull request as ready for review December 20, 2024 04:58
@Montoya Montoya changed the title WIP: Refactor: Move all components to separate files Refactor: Move all components to separate files Dec 20, 2024
export function signTypedDataV3Component(parentContainer) {
parentContainer.insertAdjacentHTML(
'beforeend',
`<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12 d-flex align-items-stretch">
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great! Would it make sense to keep a separate HTML file for each component so that it has syntax highlighting, and import the markup here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. There are other ways to do it too, like importing a JSX parser so you can use JSX fragments instead of strings.

Copy link
Contributor Author

@Montoya Montoya Dec 20, 2024

Choose a reason for hiding this comment

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

(Or just use a plugin, or just bite the bullet and port to React :) )

@pnarayanaswamy
Copy link
Contributor

pnarayanaswamy commented Jan 6, 2025

Ran all e2e on chrome and firefox successfully with a patch version from local: MetaMask/metamask-extension#29433

pnarayanaswamy
pnarayanaswamy previously approved these changes Jan 6, 2025
Copy link
Contributor

@seaona seaona left a comment

Choose a reason for hiding this comment

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

hi there! Nice work 🔥
I'm in the middle of the testing, will update this comment with my findings.

So far, I found that whenever I am using the Wallet Connect functionalty several buttons remain disabled (deploy contracts, signatures..) see video with the comparision of current prod and this test dapp version below:

wallet-connect-btn-disabled.mp4

[Update] The rest seems to work fine on my end!

</p>
</div>
</div>
</div>`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice new section! Suggestion: could we add a Verify section too, so we are sure the wallet works correctly with those signature values?
No need to be in this PR, but would be nice to have this, at some point

@Montoya
Copy link
Contributor Author

Montoya commented Jan 17, 2025

hi there! Nice work 🔥 I'm in the middle of the testing, will update this comment with my findings.

So far, I found that whenever I am using the Wallet Connect functionalty several buttons remain disabled (deploy contracts, signatures..) see video with the comparision of current prod and this test dapp version below:

wallet-connect-btn-disabled.mp4
[Update] The rest seems to work fine on my end!

Hmmm @pnarayanaswamy we will have to figure out where this might have gone wrong... maybe just missed some elements in the events?

@Montoya
Copy link
Contributor Author

Montoya commented Jan 20, 2025

hi there! Nice work 🔥 I'm in the middle of the testing, will update this comment with my findings.

So far, I found that whenever I am using the Wallet Connect functionalty several buttons remain disabled (deploy contracts, signatures..) see video with the comparision of current prod and this test dapp version below:

wallet-connect-btn-disabled.mp4
[Update] The rest seems to work fine on my end!

Please try again, just merged a fix by @pnarayanaswamy

Copy link
Contributor

@seaona seaona left a comment

Choose a reason for hiding this comment

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

thanks, I see the issue fixed now!!

wc-dapp.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this functionality seems to be incorrectly placed under transactions

Copy link
Contributor

@seaona seaona Jan 21, 2025

Choose a reason for hiding this comment

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

nit: this file could be consolidated with the network data we already have here

https://github.com/MetaMask/test-dapp/blob/main/src/onchain-sample-contracts.js#L2

Comment on lines +72 to +87
Malicious Permit
</button>
<button
class="btn btn-primary btn-lg btn-block mb-3"
id="maliciousTradeOrder"
disabled
>
Malicious Trade Order
</button>
<button
class="btn btn-primary btn-lg btn-block mb-3"
id="maliciousSeaport"
disabled
>
Malicious Seaport
</button>
Copy link
Contributor

@seaona seaona Jan 21, 2025

Choose a reason for hiding this comment

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

nit: this section is placed under ppom/transactions but those are actually signatures

  • Malicious Permit
  • Malicious Trade Order
  • Malicious Seaport

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is how the test-dapp was originally organized. We could rename transactions.js to something else.

Copy link
Contributor

Choose a reason for hiding this comment

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

the following content is related to transactions, but it's placed under signatures folder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the way the cards are grouped is based on the name of the section. It's not ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One solution could be to move this card to the transactions section, but I did not want to make any IA changes

Copy link
Contributor

Choose a reason for hiding this comment

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

mm yeah so I think something could be improved there, as at the moment the current folder naming doesn't completely match the classification 🤔

mm if I imagine if I want to add a new section, let's say Solana tx's and signatures, where will they go?
I think the natural way might be to create a solana folder, and inside, to have a signature component and then a tx component.

So I think we might want to follow the same approach here. We could have a folder for Malformed Interactions and inside we can distinguish between signatures and tx. Same goes for Blockaid and so on.

-- Malformed Interactions
|
|--- Signatures
|--- Transactions

-- Malicious Interactions
|
|--- Signatures
|--- Transactions

-- Solana
|
|--- Signatures
|--- Transactions

What do you think?

Captura desde 2025-01-22 09-33-54

Captura desde 2025-01-22 09-34-11

@seaona
Copy link
Contributor

seaona commented Jan 21, 2025

The functionality seems to be preserved so I've approved the PR, but recently added a couple of nits regarding the re-org, non-blocking but might be worth taking a look now or in a future PR

@Montoya Montoya merged commit dac0701 into main Jan 21, 2025
7 checks passed
@Montoya Montoya deleted the modular branch January 21, 2025 14:21
@Montoya
Copy link
Contributor Author

Montoya commented Jan 21, 2025

@seaona I think overall the IA nits should be for the developers who made these cards. I don't want to mess with how the cards are grouped and sorted, my intention was to keep the IA the same.

Montoya added a commit that referenced this pull request Jan 21, 2025
This is the release candidate PR for `v9.0.0`

### Added
- Add SignTypedData primaryType variants: Blur - Order, PermitBatch, PermitSingle, Seaport - BulkOrder ([#376](#376))

### Changed
- Move all components to separate files, use shared global state and events for updating cards based on connect / disconnect / deploy contract ([#379](#379))
@Montoya Montoya mentioned this pull request Jan 21, 2025
Montoya added a commit that referenced this pull request Jan 21, 2025
* Release Candidate v9.0.0

This is the release candidate PR for `v9.0.0`

### Added
- Add SignTypedData primaryType variants: Blur - Order, PermitBatch, PermitSingle, Seaport - BulkOrder ([#376](#376))

### Changed
- Move all components to separate files, use shared global state and events for updating cards based on connect / disconnect / deploy contract ([#379](#379))

* Put Unreleased lines back in CHANGELOG
@MetaMask MetaMask deleted a comment Jan 21, 2025
@seaona
Copy link
Contributor

seaona commented Jan 22, 2025

hi there 👋 thanks for the reply!! I made a couple of the cards mentioned above so I'm happy to add the changes if they make sense to you!

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.

4 participants