Skip to content

Commit

Permalink
feat: Add gas included swaps (#13430)
Browse files Browse the repository at this point in the history
## **Description**
Users who don't have enough ETH to pay for gas fees while swapping will
be able to swap now if the gas fee can be taken from one of the tokens
they are swapping. Smart transactions must be enabled for this.

## **Related issues**

Fixes:

## **Manual testing steps**
Test case 1:
1. Make sure you are on Ethereum mainnet and have Smart Transactions on
in Advanced Settings
2. Have e.g. 0 ETH and 100 USDC
3. Fill in the swap form with 10 USDC -> ETH
6. You will see gas included swaps UI

Test case 2:
1. Make sure you are on Ethereum mainnet and have Smart Transactions on
in Advanced Settings
4. In Swaps you can now click on `Use max` for ETH
5. Get quotes
6. You will see gas included swaps UI

## **Screenshots/Recordings**

User doesn't have enough ETH for gas fees (gas included swaps):

![image](https://github.com/user-attachments/assets/a16ccf1d-bebd-4dad-8668-639c2f912aa5)

User has enough ETH for gas fees:

![image](https://github.com/user-attachments/assets/d0bfa7e4-ffa1-4899-a0ba-725dcaee7833)


### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
dan437 authored Feb 13, 2025
1 parent ed21162 commit 665035f
Show file tree
Hide file tree
Showing 14 changed files with 791 additions and 212 deletions.
6 changes: 4 additions & 2 deletions app/components/Nav/Main/RootRPCMethodsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ const RootRPCMethodsUI = (props) => {
quote_vs_executionRatio: quoteVsExecutionRatio,
token_to_amount_received: tokenToAmountReceived.toString(),
is_smart_transaction: props.shouldUseSmartTransaction,
gas_included: analyticsParams.isGasIncludedTrade,
...smartTransactionMetricsProperties,
available_quotes: analyticsParams.available_quotes,
best_quote_source: analyticsParams.best_quote_source,
Expand Down Expand Up @@ -335,7 +336,7 @@ const RootRPCMethodsUI = (props) => {
transactionId: transactionMeta.id,
deviceId,
// eslint-disable-next-line no-empty-function
onConfirmationComplete: () => { },
onConfirmationComplete: () => {},
type: 'signTransaction',
}),
);
Expand Down Expand Up @@ -405,7 +406,8 @@ const RootRPCMethodsUI = (props) => {
data &&
data !== '0x' &&
to &&
(await getMethodData(data, networkClientId)).name === TOKEN_METHOD_TRANSFER
(await getMethodData(data, networkClientId)).name ===
TOKEN_METHOD_TRANSFER
) {
let asset = props.tokens.find(({ address }) =>
toLowerCaseEquals(address, to),
Expand Down
Loading

0 comments on commit 665035f

Please sign in to comment.