From 01c67245fe67ffc634aaef64359f598a695f5214 Mon Sep 17 00:00:00 2001 From: salimtb Date: Tue, 27 Feb 2024 12:02:28 +0100 Subject: [PATCH 1/7] fix: fix hex to BN conversion (#8734) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** conversion from hex to BN doesn't work for very large numbers, because the convertHexToDecimal function uses parseInt to convert from hex to decimal, but for numbers greater than 54 digits this may send an incorrect result. the fix was to use `toHexBN` function ## **Related issues** Fixes: #8703 ## **Manual testing steps** 1. Click on any token where you hold a large amount 2.Go to the received/sen activity ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [x] I've linked related issues - [x] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [x] I’ve included tests if applicable - [ ] 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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [x] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [x] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **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. --- app/components/UI/TransactionElement/utils.js | 5 +- .../UI/TransactionElement/utils.test.js | 57 ++++++++++++++++++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/app/components/UI/TransactionElement/utils.js b/app/components/UI/TransactionElement/utils.js index 3e36ad8f714..c09cff46d73 100644 --- a/app/components/UI/TransactionElement/utils.js +++ b/app/components/UI/TransactionElement/utils.js @@ -10,7 +10,6 @@ import { balanceToFiatNumber, weiToFiatNumber, addCurrencySymbol, - toBN, BNToHex, limitToMaximumDecimalPlaces, } from '../../../util/number'; @@ -34,7 +33,6 @@ import { isSwapsNativeAsset } from '../Swaps/utils'; import { toLowerCaseEquals } from '../../../util/general'; import Engine from '../../../core/Engine'; import { isEIP1559Transaction } from '@metamask/transaction-controller'; -import { convertHexToDecimal } from '@metamask/controller-utils'; const { getSwapsContractAddress } = swapsUtils; @@ -282,8 +280,7 @@ export function decodeIncomingTransfer(args) { selectedAddress, } = args; - const decimalAmount = convertHexToDecimal(value); - const amount = toBN(decimalAmount); + const amount = hexToBN(value); const token = { symbol, decimals, address: contractAddress }; const renderTokenAmount = token diff --git a/app/components/UI/TransactionElement/utils.test.js b/app/components/UI/TransactionElement/utils.test.js index c0eab53f9d1..480582eb7d7 100644 --- a/app/components/UI/TransactionElement/utils.test.js +++ b/app/components/UI/TransactionElement/utils.test.js @@ -7,7 +7,7 @@ describe('decodeIncomingTransfer', () => { transaction: { to: '0x77648f1407986479fb1fa5cc3597084b5dbdb057', from: '0x1440ec793ae50fa046b95bfeca5af475b6003f9e', - value: '0x52daf0', + value: '52daf0', }, transferInformation: { symbol: 'USDT', @@ -54,4 +54,59 @@ describe('decodeIncomingTransfer', () => { summarySecondaryTotalAmount: undefined, }); }); + + it('should decode an incoming transfer with big number with 10 digits', () => { + // Arrange + const args = { + tx: { + transaction: { + to: '0x77648f1407986479fb1fa5cc3597084b5dbdb057', + from: '0x1440ec793ae50fa046b95bfeca5af475b6003f9e', + value: '3B9ACA00', // 1000000000 in decimal + }, + transferInformation: { + symbol: 'USDT', + decimals: 6, + contractAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7', + }, + transactionHash: + '0x942d7843454266b81bf631022aa5f3f944691731b62d67c4e80c4bb5740058bb', + }, + currentCurrency: 'usd', + contractExchangeRates: {}, + totalGas: '0x64', + actionKey: 'key', + primaryCurrency: 'ETH', + selectedAddress: '0x77648f1407986479fb1fa5cc3597084b5dbdb057', + ticker: 'ETH', + }; + + // Act + const [transactionElement, transactionDetails] = + decodeIncomingTransfer(args); + + // Assert + expect(transactionElement).toEqual({ + actionKey: 'key', + renderFrom: '0x1440ec793aE50fA046B95bFeCa5aF475b6003f9e', + renderTo: '0x77648F1407986479fb1fA5Cc3597084B5dbDB057', + value: '1000 USDT', + fiatValue: undefined, + isIncomingTransfer: true, + transactionType: 'transaction_received_token', + }); + expect(transactionDetails).toEqual({ + renderTotalGas: '< 0.00001 ETH', + renderValue: '1000 USDT', + renderFrom: '0x1440ec793aE50fA046B95bFeCa5aF475b6003f9e', + renderTo: '0x77648F1407986479fb1fA5Cc3597084B5dbDB057', + transactionHash: + '0x942d7843454266b81bf631022aa5f3f944691731b62d67c4e80c4bb5740058bb', + transactionType: 'transaction_received_token', + summaryAmount: '1000 USDT', + summaryFee: '< 0.00001 ETH', + summaryTotalAmount: '1000 USDT / < 0.00001 ETH', + summarySecondaryTotalAmount: undefined, + }); + }); }); From 23ba8b1476f39c58eb40d1c8c56f6fae4cd51ebe Mon Sep 17 00:00:00 2001 From: sahar-fehri Date: Tue, 27 Feb 2024 13:58:53 +0100 Subject: [PATCH 2/7] fix: deprecate goerli network (#8567) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Pr to deprecate goerli network. - Removes instances of goerli network. (From network dropdown and setting) - Updates e2e tests to use Sepolia instead. - Creates a new component (https://www.figma.com/file/KXgbxFucvk3FM5VULGZmzk/Assets%3A-Bug-Fixes?node-id=449%3A2210&mode=dev) for the scenario when a user clicks on a deepling for goerli. ## **Related issues** Fixes: https://github.com/MetaMask/mobile-planning/issues/1368 ## **Manual testing steps** 1. Click on network dropdown list (you should not see Goerli) 2. Click on settings, then network list (you should not see Goerli) 3. Click on a deeplink that is supposed to switch to goerli : https://metamask.app.link/send/0x4701Aa9471d7bfAc765D87dcb1Ea6BB23AD32733@5/approve?address=0x178e3e6c9f547A00E33150F7104427ea02cfc747&uint256=5e8. You should see a modal saying that the network is deprecated. ## **Screenshots/Recordings** ### **Before** https://github.com/MetaMask/metamask-mobile/assets/10994169/d748b713-5157-4d00-8b85-558c1e0164a7 ### **After** When you try to click on a deeplink with goerli https://github.com/MetaMask/metamask-mobile/assets/10994169/622a47c3-5223-4420-84d8-a2aa3274973d When you try to add goerli network as custom network https://github.com/MetaMask/metamask-mobile/assets/10994169/0591d2b9-3299-44aa-9e6b-463ff66cd693 Android: https://github.com/MetaMask/metamask-mobile/assets/10994169/13f4ef7f-adcc-4967-8036-1ceffbf0653a https://github.com/MetaMask/metamask-mobile/assets/10994169/aa6028b1-5ab0-4063-b00f-6c47f941880f ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've clearly explained what problem this PR is solving and how it is solved. - [ ] I've linked related issues - [ ] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [ ] 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. - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **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. --- app/components/Nav/Main/MainNavigator.js | 14 +++ .../DeprecatedNetworkModal.styles.ts | 40 ++++++ .../DeprecatedNetworkModal.tsx | 72 +++++++++++ .../UI/DeprecatedNetworkModal/index.ts | 1 + .../NetworkSelector/NetworkSelector.test.tsx | 5 +- .../NetworksSettings/NetworkSettings/index.js | 9 ++ app/constants/navigation/Routes.ts | 1 + app/constants/urls.ts | 6 +- app/core/Analytics/MetaMetrics.events.ts | 2 + .../Handlers/handleEthereumUrl.test.ts | 25 ++++ .../Handlers/handleEthereumUrl.ts | 12 +- app/images/image-icons.js | 2 - app/lib/ens-ipfs/resolver.js | 3 - app/reducers/collectibles/index.test.ts | 10 +- app/store/migrations/030.test.ts | 119 ++++++++++++++++++ app/store/migrations/030.ts | 66 ++++++++++ app/store/migrations/index.ts | 2 + app/util/blockaid/index.test.ts | 2 +- app/util/networks/index.js | 21 +--- app/util/networks/index.test.ts | 25 ++-- e2e/resources/networks.json | 10 +- e2e/specs/assets/import-nft.spec.js | 97 +++++++------- e2e/specs/networks/add-custom-rpc.spec.js | 6 +- .../networks/connect-test-network.spec.js | 10 +- .../quarantine/contract-nickname.failing.js | 8 +- e2e/specs/swaps/token-details.spec.js | 8 +- e2e/viewHelper.js | 8 +- locales/languages/en.json | 5 +- 28 files changed, 464 insertions(+), 125 deletions(-) create mode 100644 app/components/UI/DeprecatedNetworkModal/DeprecatedNetworkModal.styles.ts create mode 100644 app/components/UI/DeprecatedNetworkModal/DeprecatedNetworkModal.tsx create mode 100644 app/components/UI/DeprecatedNetworkModal/index.ts create mode 100644 app/store/migrations/030.test.ts create mode 100644 app/store/migrations/030.ts diff --git a/app/components/Nav/Main/MainNavigator.js b/app/components/Nav/Main/MainNavigator.js index eb9f1dff629..ac740ed1cfe 100644 --- a/app/components/Nav/Main/MainNavigator.js +++ b/app/components/Nav/Main/MainNavigator.js @@ -74,6 +74,7 @@ import URL from 'url-parse'; import Logger from '../../../util/Logger'; import { getDecimalChainId } from '../../../util/networks'; import { useMetrics } from '../../../components/hooks/useMetrics'; +import DeprecatedNetworkDetails from '../../UI/DeprecatedNetworkModal'; const Stack = createStackNavigator(); const Tab = createBottomTabNavigator(); @@ -624,6 +625,19 @@ const MainNavigator = () => ( }), }} /> + ({ + overlayStyle: { + opacity: 0, + }, + }), + }} + /> diff --git a/app/components/UI/DeprecatedNetworkModal/DeprecatedNetworkModal.styles.ts b/app/components/UI/DeprecatedNetworkModal/DeprecatedNetworkModal.styles.ts new file mode 100644 index 00000000000..7a6f2cb1305 --- /dev/null +++ b/app/components/UI/DeprecatedNetworkModal/DeprecatedNetworkModal.styles.ts @@ -0,0 +1,40 @@ +import Device from '../../../util/device'; +import { StyleSheet, TextStyle } from 'react-native'; +import { Theme } from '../../../util/theme/models'; + +const styleSheet = (params: { theme: Theme }) => { + const { theme } = params; + const { typography } = theme; + + return StyleSheet.create({ + centeredTitle: { + marginTop: 16, + marginBottom: 8, + fontSize: 18, + textAlign: 'center', + }, + centeredDescription: { + fontSize: 14, + textAlign: 'center', + paddingRight: 16, + paddingLeft: 16, + }, + footer: { + flexDirection: 'row', + justifyContent: 'center', + alignItems: 'center', + }, + button: { + flex: 1, + marginLeft: 16, + marginRight: 16, + marginTop: 24, + marginBottom: Device.isAndroid() ? 21 : 0, + }, + buttonLabel: { + ...typography.lBodySMMedium, + } as TextStyle, + }); +}; + +export default styleSheet; diff --git a/app/components/UI/DeprecatedNetworkModal/DeprecatedNetworkModal.tsx b/app/components/UI/DeprecatedNetworkModal/DeprecatedNetworkModal.tsx new file mode 100644 index 00000000000..e1917cade59 --- /dev/null +++ b/app/components/UI/DeprecatedNetworkModal/DeprecatedNetworkModal.tsx @@ -0,0 +1,72 @@ +import { useNavigation } from '@react-navigation/native'; +import React, { useRef } from 'react'; +import { Linking, View } from 'react-native'; +import { useStyles } from '../../../component-library/hooks'; +import { strings } from '../../../../locales/i18n'; +import styleSheet from './DeprecatedNetworkModal.styles'; +import Text, { + TextColor, + TextVariant, +} from '../../../component-library/components/Texts/Text'; +import Button, { + ButtonSize, + ButtonVariants, +} from '../../../component-library/components/Buttons/Button'; +import { CONNECTING_TO_DEPRECATED_NETWORK } from '../../../constants/urls'; +import BottomSheet from '../../../component-library/components/BottomSheets/BottomSheet'; +import { useMetrics } from '../../../components/hooks/useMetrics'; +import { MetaMetricsEvents } from '../../../core/Analytics'; + +const DeprecatedNetworkModal = () => { + const { styles } = useStyles(styleSheet, {}); + const { trackEvent } = useMetrics(); + const navigation = useNavigation(); + + const dismissModal = (): void => { + navigation.goBack(); + }; + + const goToLearnMore = () => { + Linking.openURL(CONNECTING_TO_DEPRECATED_NETWORK); + trackEvent(MetaMetricsEvents.EXTERNAL_LINK_CLICKED, { + location: 'dapp_connection_request', + text: 'Learn More', + url_domain: CONNECTING_TO_DEPRECATED_NETWORK, + }); + }; + + const sheetRef = useRef(null); + + return ( + + + {strings('networks.network_deprecated_title')} + + + {strings('networks.network_deprecated_description')}{' '} + + {strings('accounts.learn_more')} + + + +