Skip to content

Commit

Permalink
fix: fix swaps button on asset overview page for multichain feature (#…
Browse files Browse the repository at this point in the history
…12650)

## **Description**

When user has "all Networks" selected; and he is on a network that does
not support swaps but clicks on a network on a chain that supports
swaps. He should be able to see the swaps button

## **Related issues**

Fixes:
#12546 (comment)

## **Manual testing steps**

1. Click on "All Networks"
2. Switch to a network where swaps is not supported (you can add Scroll
or blast from chainlist)
3. Click on a token from ethereum network
4. You should be able to see swaps button

## **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/af560641-c854-4288-b0cc-231ba450edd3



## **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
sahar-fehri authored Dec 12, 2024
1 parent 5972b5b commit 7e40e3e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/components/Views/Asset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '../../../constants/transaction';
import AppConstants from '../../../core/AppConstants';
import {
swapsLivenessMultichainSelector,
swapsLivenessSelector,
swapsTokensMultiChainObjectSelector,
swapsTokensObjectSelector,
Expand Down Expand Up @@ -476,7 +477,9 @@ class Asset extends PureComponent {
const styles = createStyles(colors);
const asset = navigation && params;
const isSwapsFeatureLive = this.props.swapsIsLive;
const isNetworkAllowed = isSwapsAllowed(chainId);
const isNetworkAllowed = isPortfolioViewEnabled()
? isSwapsAllowed(asset.chainId)
: isSwapsAllowed(chainId);

const isAssetAllowed =
asset.isETH || asset.address?.toLowerCase() in this.props.swapsTokens;
Expand Down Expand Up @@ -529,8 +532,10 @@ class Asset extends PureComponent {

Asset.contextType = ThemeContext;

const mapStateToProps = (state) => ({
swapsIsLive: swapsLivenessSelector(state),
const mapStateToProps = (state, { route }) => ({
swapsIsLive: isPortfolioViewEnabled()
? swapsLivenessMultichainSelector(state, route.params.chainId)
: swapsLivenessSelector(state),
swapsTokens: isPortfolioViewEnabled()
? swapsTokensMultiChainObjectSelector(state)
: swapsTokensObjectSelector(state),
Expand Down
5 changes: 5 additions & 0 deletions app/reducers/swaps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export const swapsLivenessSelector = createSelector(
(swapsState, chainId) => swapsState[chainId]?.isLive || false,
);

export const swapsLivenessMultichainSelector = createSelector(
[swapsStateSelector, (_state, chainId) => chainId],
(swapsState, chainId) => swapsState[chainId]?.isLive || false,
);

/**
* Returns if smart transactions are enabled in feature flags
*/
Expand Down

0 comments on commit 7e40e3e

Please sign in to comment.