Skip to content

Commit

Permalink
feat: cross chain swap STX (#28460)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

This PR improves support for Smart Transactions (STX). It will not show
the STX status page if the tx is a Bridge tx. Instead users will be
immediately sent to the Activity list. If the user opens the Bridge tx
detaills, they should be able to see the proper info.

The main change is that in `BridgeStatusController` the `txHistory` is
now keyed by `txMeta.id` rather than `txMeta.hash`. This is because for
an STX we might not have the hash immediately, but we still want to look
things up.

We also add a way to call `addTransaction` from the UI side. Previously
we used `addTransactionAndWaitForPublish`. However for STX, this will
cause the app to wait until a `txHash` is available before returning a
`txMeta`, which means we can't even use the `txMeta.id` to key a
`BridgeHistoryItem`. If we use `addTransaction` this will allow us to
receive a `txMeta` object back immediately and use `txMeta.id`.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28460?quickstart=1)

## **Related issues**

Depends on MetaMask/core#4918

## **Manual testing steps**

1. Add `BRIDGE_USE_DEV_APIS=1` to `.metamaskrc`
1. Go to Settings > Advanced, make sure Smart Transactions is on
2. Switch network to Ethereum
3. Go to Bridge
4. Selection source network, source token, dest network, dest token
5. Request a quote
6. Execute a bridge
7. Go to Activity
8. Click on the Bridge tx

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

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

### **After**

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


https://github.com/user-attachments/assets/364b93ec-3b54-4ce6-acd5-5001236c128c



## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.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-extension/blob/develop/.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
infiniteflower authored Dec 5, 2024
1 parent 47c89ec commit 58f727f
Show file tree
Hide file tree
Showing 32 changed files with 925 additions and 585 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.yalc
yalc.lock

npm-debug.log
yarn-error.log
node_modules
Expand Down
2 changes: 1 addition & 1 deletion app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

exports[`BridgeStatusController constructor rehydrates the tx history state 1`] = `
{
"0xsrcTxHash1": {
"bridgeTxMetaId1": {
"account": "0xaccount1",
"estimatedProcessingTimeInSeconds": 15,
"initialDestAssetBalance": undefined,
"pricingData": undefined,
"pricingData": {
"amountSent": "1.234",
},
"quote": {
"bridgeId": "lifi",
"bridges": [
Expand Down Expand Up @@ -102,17 +104,20 @@ exports[`BridgeStatusController constructor rehydrates the tx history state 1`]
"status": "PENDING",
},
"targetContractAddress": "0x23981fC34e69eeDFE2BD9a0a9fCb0719Fe09DbFC",
"txMetaId": "bridgeTxMetaId1",
},
}
`;

exports[`BridgeStatusController startPollingForBridgeTxStatus sets the inital tx history state 1`] = `
{
"0xsrcTxHash1": {
"bridgeTxMetaId1": {
"account": "0xaccount1",
"estimatedProcessingTimeInSeconds": 15,
"initialDestAssetBalance": undefined,
"pricingData": undefined,
"pricingData": {
"amountSent": "1.234",
},
"quote": {
"bridgeId": "lifi",
"bridges": [
Expand Down Expand Up @@ -208,6 +213,7 @@ exports[`BridgeStatusController startPollingForBridgeTxStatus sets the inital tx
"status": "PENDING",
},
"targetContractAddress": "0x23981fC34e69eeDFE2BD9a0a9fCb0719Fe09DbFC",
"txMetaId": "bridgeTxMetaId1",
},
}
`;
Loading

0 comments on commit 58f727f

Please sign in to comment.