Skip to content

Commit fb48175

Browse files
authored
feat: MultichainBalanceController (#12599)
## **Description** Builds off of the work done in [this PR](MetaMask/core#4965). - This PR adds the ability to see your non EVM token balance and the fiat token rates (Solana and Bitcoin accounts) - This is achieved by using the RatesController and the MultichainBalanceController - This PR also extract the balance logic from the PortfolioBalance PR into the useMultichainBalances hook - creates the selectors for multichain non evm This PR DOES NOT... 1. show the correct native token balance in the account picker. This will be done in a [following PR](MetaMask/accounts-planning#697) that builds off of this work. 2. enable token details for these non evm assets. (for now it will simply show no data) ## **Related issues** Fixes: MetaMask/accounts-planning#696 ## **Manual testing steps** 1. checkout this branch 3. open .js.env 4. set export METAMASK_BUILD_TYPE="flask" // flask 5. source .js.env 6. yarn setup 7. yarn start:ios 8. create/import a wallet 9. open the account menu actions 10. you should see that you can add a BTC and BTC Testnet account 11. click Add a new Bitcoin account (Beta) 12. a popup with a suggested name should appear click confirm 13. the newly selected account should be your Bitcoin account and the network picker should show the Bitcoin logo the network should not be clickable 14. Optionally, create a testnet account and fund it with this faucet: https://bitcoinfaucet.uo1.net/ 15. If you have a balance, you should see the fiat balance rendered on the wallet 16. if not you have a balance, then you should see a 0 fiat balance. 17. If you change your selected currency (settings/general) and then return to the main wallet view, the balance should update based on the new fiat currency. 18. The token list should also list your account balance in both fiat and and the native token balance. 19. the token displayed should be the BTC logo and not have any network badge above it (like the eth account does) 20. now add a bitcoin TestNet account. 21. the portfolio balance should show the native token balance not the fiat balance. 22. repeat the above steps but this time add a new Solana account. If your Solana account has a balance, it should be rendered on the home page in fiat. If not you should see a 0 balance. 23. we do not currently support Solana testnet accounts. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** https://github.com/user-attachments/assets/12d4bfeb-608f-4744-9c0a-459163eb0dba <img src="https://github.com/user-attachments/assets/f8428b91-fb45-433d-921e-3824845a71ef" height="400" height="600"/> ## **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.
1 parent 6f342b8 commit fb48175

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3293
-420
lines changed

app/component-library/components-temp/Price/AggregatedPercentage/AggregatedPercentage.stories.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React from 'react';
22
import { Provider } from 'react-redux';
3-
import AggregatedPercentage, {
4-
AggregatedPercentageProps,
5-
} from './AggregatedPercentage';
3+
import AggregatedPercentage from './AggregatedPercentage';
64
import { createStore } from 'redux';
75
import initialBackgroundState from '../../../../util/test/initial-background-state.json';
8-
6+
import { AggregatedPercentageProps } from './AggregatedPercentage.types';
97
const mockInitialState = {
108
wizard: {
119
step: 1,

app/component-library/components-temp/Price/AggregatedPercentage/AggregatedPercentage.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ import {
1515
FORMATTED_PERCENTAGE_TEST_ID,
1616
} from './AggregatedPercentage.constants';
1717
import { DECIMALS_TO_SHOW } from '../../../../components/UI/Tokens/constants';
18-
19-
export interface AggregatedPercentageProps {
20-
ethFiat: number;
21-
tokenFiat: number;
22-
tokenFiat1dAgo: number;
23-
ethFiat1dAgo: number;
24-
}
18+
import { AggregatedPercentageProps } from './AggregatedPercentage.types';
2519

2620
const isValidAmount = (amount: number | null | undefined): boolean =>
2721
amount !== null && amount !== undefined && !Number.isNaN(amount);
@@ -32,13 +26,7 @@ const AggregatedPercentage = ({
3226
tokenFiat1dAgo,
3327
ethFiat1dAgo,
3428
privacyMode = false,
35-
}: {
36-
ethFiat: number;
37-
tokenFiat: number;
38-
tokenFiat1dAgo: number;
39-
ethFiat1dAgo: number;
40-
privacyMode?: boolean;
41-
}) => {
29+
}: AggregatedPercentageProps) => {
4230
const { styles } = useStyles(styleSheet, {});
4331

4432
const currentCurrency = useSelector(selectCurrentCurrency);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface AggregatedPercentageProps {
2+
ethFiat: number;
3+
tokenFiat: number;
4+
tokenFiat1dAgo: number;
5+
ethFiat1dAgo: number;
6+
privacyMode?: boolean;
7+
}

app/component-library/components-temp/Price/AggregatedPercentage/AggregatedPercentageCrossChains.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ import {
1717
TokensWithBalances,
1818
} from '../../../../components/hooks/useGetFormattedTokensPerChain';
1919
import { getFormattedAmountChange, getPercentageTextColor } from './utils';
20-
21-
export interface AggregatedPercentageProps {
22-
ethFiat: number;
23-
tokenFiat: number;
24-
tokenFiat1dAgo: number;
25-
ethFiat1dAgo: number;
26-
}
20+
import { AggregatedPercentageCrossChainsProps } from './AggregatedPercentageCrossChains.types';
2721

2822
export const getCalculatedTokenAmount1dAgo = (
2923
tokenFiatBalance: number,
@@ -40,16 +34,7 @@ const AggregatedPercentageCrossChains = ({
4034
privacyMode = false,
4135
totalFiatCrossChains,
4236
tokenFiatBalancesCrossChains,
43-
}: {
44-
privacyMode?: boolean;
45-
totalFiatCrossChains: number;
46-
tokenFiatBalancesCrossChains: {
47-
chainId: string;
48-
nativeFiatValue: number;
49-
tokenFiatBalances: number[];
50-
tokensWithBalances: TokensWithBalances[];
51-
}[];
52-
}) => {
37+
}: AggregatedPercentageCrossChainsProps) => {
5338
const crossChainMarketData: MarketDataMapping = useSelector(
5439
selectTokenMarketData,
5540
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { TokensWithBalances } from '../../../../components/hooks/useGetFormattedTokensPerChain';
2+
3+
export interface AggregatedPercentageCrossChainsProps {
4+
privacyMode?: boolean;
5+
totalFiatCrossChains: number;
6+
tokenFiatBalancesCrossChains: {
7+
chainId: string;
8+
nativeFiatValue: number;
9+
tokenFiatBalances: number[];
10+
tokensWithBalances: TokensWithBalances[];
11+
}[];
12+
}

0 commit comments

Comments
 (0)