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

feat: use eth_sendTransactionBatch for swaps requiring allowance bump #122

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

meeh0w
Copy link
Member

@meeh0w meeh0w commented Jan 10, 2025

Description

Notes for reviewers

  • The best way to review would be going through commits:
    • The first commit updates the backend to be able to handle batch approval requests (ApprovalController.requestBatchApproval method).
    • The second commit updates useFeeCustomizer() hook so that it's able to update the fee settings on the entire transaction batch. + some small updates to UI components.
    • Third commit extracts shared utilities from the SwapProvider - things like params validation, response validation, building transactions.
    • Fourth commit implements oneClickSwap() method in the SwapProvider (using those previously extracted shared utils), hides it behind a feature flag and makes it so it's only called when the feature flag is enabled.
    • And the later commits implement the TxBatchApprovalScreen and related components.

Testing

  • Perform swaps as you used to.
  • Make sure to sell ERC-20 tokens, as those are the only ones that can require the allowance to be set first.
    • Make sure you test scenarios where you don't have the allowance set yet and those where you already DO have the allowance set (you can set the allowance by using the production build and abandoning the swap flow after the first approval).
  • Verify that the feature flag works as intended.
  • Verify that you get the old behavior with hardware wallets

Screenshots:

Screen.Recording.2025-01-17.at.12.39.15.mov

Checklist for the author

  • I've covered new/modified business logic with Jest test cases.
  • I've tested the changes myself before sending it to code review and QA.

src/background/services/actions/models.ts Outdated Show resolved Hide resolved
Comment on lines +470 to +473
// Only wallets that provide us signed transactions without additional approvals
// can be used to sign transaction batches (so for example hardware wallets or accounts
// that connect through WalletConnect protocol would not work, since users have to approve
// each transaction one by one anyways.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add a follow up story and make the other other wallets capable of something similar.
i.e: After the user presses approve all, the transactions would display one after the other on the hw wallet without UI interaction. The Ledger dialog could display, "Approve transaction 1/2 ... (and thisplay the details)"

Copy link
Member Author

Choose a reason for hiding this comment

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

action: Action | MultiTxAction,
): action is MultiTxAction =>
action &&
'signingRequests' in action &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use some sort of type or enum for this instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added ActionType enum

displayData: DisplayData;
};

export type MultiTxAction = Omit<Action, 'signingData' | 'displayData'> & {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are regular transactions a batch of one? Do we need to keep two separate types? Should we just use the one that is capable of handling more and on the UI we just display the single vs batch UI based on the number of transactions needed to be approved?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to doing that as a follow-up PR, as it would involve revamping the current (single) Action model on each handler we have, which would blow up this branch tremendously.

To be completely honest, I would like to revisit the Action model as a whole and require it to always be typed (for internal request handlers too) -- especially the data we use on the UI side.

Comment on lines +17 to +23
display: 'flex',
width: 320,
flex: '0 0 auto',
backgroundColor: 'grey.850',
ml: isFirst ? 3.5 : 0,
mr: isLast ? 3.5 : 0,
position: 'relative',
Copy link
Contributor

Choose a reason for hiding this comment

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

I know designs are like this so no action just a note. We are getting sooo far off from the component library.

export const isBatchApprovalParams = (
params: ApprovalParams | BatchApprovalParams,
): params is BatchApprovalParams => {
return 'signingRequests' in params;
Copy link
Contributor

Choose a reason for hiding this comment

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

same here regarding using an enum or type instead.

Comment on lines +603 to +610
const isOneClickSwapSupported =
walletDetails?.type === SecretType.Mnemonic ||
walletDetails?.type === SecretType.Seedless ||
walletDetails?.type === SecretType.PrivateKey;

if (isOneClickSwapEnabled && isOneClickSwapSupported) {
return oneClickSwap(params);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add tests for the new on-click swap path as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

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