-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## **Description** This is the first of a series of PRs that aim to address two things: 1. Simplify/fix some technical debt accrued during `PortfolioView` sprints 2. Prepare AssetList for chain agnostic tokens (removal of EVM specific conventions) This PR aims to simplify `asset-list` and `token-list` components. The next PR will simplify `token-cell` and `token-list-item` - Refactor `consolidateTokenBalances` into a redux selector `getTokenBalancesEvm`. Eventually (soon) this will be wrapped in a more generic selector, that will understand how to select/calculate balances for tokens on different chains. - Add a `app/assets/hooks` directory to help clean up and extract business logic away from the body of `asset-list` and `token-list` components and improve readability - Adds two utility files: `calculateTokenBalance` and `calculateTokenFiatAmount` (these are called from the selector file) - Adds a `app/assets/types.ts` file to consolidate all the types related to assets. [](https://codespaces.new/MetaMask/metamask-extension/pull/29886?quickstart=1) ## **Related issues** ## **Manual testing steps** This PR should not break anything. It also should not introduce anything. ## **Screenshots/Recordings** ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/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
Showing
21 changed files
with
532 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
ui/components/app/assets/asset-list/asset-list-funding-modals/asset-list-funding-modals.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { ReceiveModal } from '../../../../multichain'; | ||
import { FundingMethodModal } from '../../../../multichain/funding-method-modal/funding-method-modal'; | ||
import { useI18nContext } from '../../../../../hooks/useI18nContext'; | ||
import { getSelectedAccount } from '../../../../../selectors'; | ||
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask) | ||
import { | ||
getMultichainIsBitcoin, | ||
getMultichainSelectedAccountCachedBalanceIsZero, | ||
} from '../../../../../selectors/multichain'; | ||
import { getIsNativeTokenBuyable } from '../../../../../ducks/ramps'; | ||
import { RampsCard } from '../../../../multichain/ramps-card'; | ||
import { RAMPS_CARD_VARIANT_TYPES } from '../../../../multichain/ramps-card/ramps-card'; | ||
///: END:ONLY_INCLUDE_IF | ||
|
||
const AssetListFundingModals = () => { | ||
const t = useI18nContext(); | ||
const selectedAccount = useSelector(getSelectedAccount); | ||
|
||
const [showFundingMethodModal, setShowFundingMethodModal] = useState(false); | ||
const [showReceiveModal, setShowReceiveModal] = useState(false); | ||
|
||
const onClickReceive = () => { | ||
setShowFundingMethodModal(false); | ||
setShowReceiveModal(true); | ||
}; | ||
|
||
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask) | ||
const balanceIsZero = useSelector( | ||
getMultichainSelectedAccountCachedBalanceIsZero, | ||
); | ||
const isBuyableChain = useSelector(getIsNativeTokenBuyable); | ||
const shouldShowBuy = isBuyableChain && balanceIsZero; | ||
const isBtc = useSelector(getMultichainIsBitcoin); | ||
///: END:ONLY_INCLUDE_IF | ||
|
||
return ( | ||
<> | ||
{ | ||
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask) | ||
shouldShowBuy ? ( | ||
<RampsCard | ||
variant={ | ||
isBtc | ||
? RAMPS_CARD_VARIANT_TYPES.BTC | ||
: RAMPS_CARD_VARIANT_TYPES.TOKEN | ||
} | ||
handleOnClick={ | ||
isBtc ? undefined : () => setShowFundingMethodModal(true) | ||
} | ||
/> | ||
) : null | ||
///: END:ONLY_INCLUDE_IF | ||
} | ||
{showReceiveModal && selectedAccount?.address && ( | ||
<ReceiveModal | ||
address={selectedAccount.address} | ||
onClose={() => setShowReceiveModal(false)} | ||
/> | ||
)} | ||
{showFundingMethodModal && ( | ||
<FundingMethodModal | ||
isOpen={showFundingMethodModal} | ||
onClose={() => setShowFundingMethodModal(false)} | ||
title={t('fundingMethod')} | ||
onClickReceive={onClickReceive} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default AssetListFundingModals; |
1 change: 1 addition & 0 deletions
1
ui/components/app/assets/asset-list/asset-list-funding-modals/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './asset-list-funding-modals'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.