From 0af0bc6b213cf324844d0b5439babce9955beafe Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 07:56:15 -0700 Subject: [PATCH 01/26] chore(js-ts): Convert app/util/browserScripts.js to TypeScript (#11405) Link to Devin run: https://preview.devin.ai/devin/1b5085c4c16446edbf1768153a885382 If you have any feedback, you can leave comments in the PR and I'll address them in the app! Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> parent 5b6a58802bcdb96763c475a1eba3603a9323a0a4 author Kate Johnson 1726169678 -0400 committer Kate Johnson 1727199130 -0400 parent 5b6a58802bcdb96763c475a1eba3603a9323a0a4 author Kate Johnson 1726169678 -0400 committer Kate Johnson 1727199127 -0400 parent 5b6a58802bcdb96763c475a1eba3603a9323a0a4 author Kate Johnson 1726169678 -0400 committer Kate Johnson 1727198968 -0400 parent 5b6a58802bcdb96763c475a1eba3603a9323a0a4 author Kate Johnson 1726169678 -0400 committer Kate Johnson 1727198956 -0400 parent 5b6a58802bcdb96763c475a1eba3603a9323a0a4 author Kate Johnson 1726169678 -0400 committer Kate Johnson 1727198918 -0400 parent 5b6a58802bcdb96763c475a1eba3603a9323a0a4 author Kate Johnson 1726169678 -0400 committer Kate Johnson 1727198912 -0400 parent 5b6a58802bcdb96763c475a1eba3603a9323a0a4 author Kate Johnson 1726169678 -0400 committer Kate Johnson 1727198902 -0400 parent 5b6a58802bcdb96763c475a1eba3603a9323a0a4 author Kate Johnson 1726169678 -0400 committer Kate Johnson 1727198892 -0400 revert: android and settings changes chore: reverted unnecessary changes from main feat: fixed test for new snaps tag --- .../AccountSelector.test.tsx | 28 ++++++++++++++----- .../AccountSelectorList.tsx | 5 +++- ios/MetaMask.xcodeproj/project.pbxproj | 24 ++++++++++------ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/app/components/UI/AccountSelectorList/AccountSelector.test.tsx b/app/components/UI/AccountSelectorList/AccountSelector.test.tsx index 306c88825c4..e957587b678 100644 --- a/app/components/UI/AccountSelectorList/AccountSelector.test.tsx +++ b/app/components/UI/AccountSelectorList/AccountSelector.test.tsx @@ -10,12 +10,12 @@ import { backgroundState } from '../../../util/test/initial-root-state'; import { regex } from '../../../../app/util/regex'; import { createMockAccountsControllerState, - createMockAccountsControllerStateWithSnap, - MOCK_ADDRESS_1, - MOCK_ADDRESS_2, + expectedUuid, + internalAccount1, } from '../../../util/test/accountsControllerTestUtils'; import { mockNetworkState } from '../../../util/test/network'; import { CHAIN_IDS } from '@metamask/transaction-controller'; +import { AccountsControllerState } from '@metamask/accounts-controller'; const BUSINESS_ACCOUNT = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; const PERSONAL_ACCOUNT = '0xd018538C87232FF95acbCe4870629b75640a78E7'; @@ -206,10 +206,24 @@ describe('AccountSelectorList', () => { }); }); it('renders "Snaps (beta)" tag for Snap accounts', async () => { - const mockAccountsWithSnap = createMockAccountsControllerStateWithSnap([ - MOCK_ADDRESS_1, - MOCK_ADDRESS_2, - ]); + const mockAccountsWithSnap: AccountsControllerState = { + ...MOCK_ACCOUNTS_CONTROLLER_STATE, + internalAccounts: { + ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts, + accounts: { + ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts, + [expectedUuid]: { + ...internalAccount1, + metadata: { + ...internalAccount1.metadata, + keyring: { + type: 'Snap Keyring', + }, + }, + }, + }, + }, + }; const stateWithSnapAccount = { ...initialState, diff --git a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx index 75592d6684b..27513d72bb4 100644 --- a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx +++ b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx @@ -157,7 +157,10 @@ const AccountSelectorList = ({ index, }) => { const shortAddress = formatAddress(address, 'short'); - const tagLabel = getLabelTextByAddress(address); + let tagLabel = getLabelTextByAddress(address); + if (type === KeyringTypes.snap) { + tagLabel = 'accounts.snap_account_tag'; + } const ensName = ensByAccountAddress[address]; const accountName = isDefaultAccountName(name) && ensName ? ensName : name; diff --git a/ios/MetaMask.xcodeproj/project.pbxproj b/ios/MetaMask.xcodeproj/project.pbxproj index 314bc34f316..9ea59e6ce1b 100644 --- a/ios/MetaMask.xcodeproj/project.pbxproj +++ b/ios/MetaMask.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 07CBADD9D4B441008304F8D3 /* EuclidCircularB-Light.otf in Resources */ = {isa = PBXBuildFile; fileRef = A98029A3662F4C1391489A6B /* EuclidCircularB-Light.otf */; }; 08B7A641467C4723B98328E9 /* CentraNo1-Medium.otf in Resources */ = {isa = PBXBuildFile; fileRef = F97653CAD1D04E1B8713C428 /* CentraNo1-Medium.otf */; }; - 0FD509E0336BF221F6527B24 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; + 0FD509E0336BF221F6527B24 /* (null) in Frameworks */ = {isa = PBXBuildFile; }; 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; @@ -134,7 +134,7 @@ B339FF2E289ABD70001B89FB /* EuclidCircularB-SemiboldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 9499B01ECAC44DA29AC44E80 /* EuclidCircularB-SemiboldItalic.otf */; }; B339FF32289ABD70001B89FB /* Branch.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 153F84C92319B8DB00C19B63 /* Branch.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B339FF3C289ABF2C001B89FB /* MetaMask-QA-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B339FEA72899852C001B89FB /* MetaMask-QA-Info.plist */; }; - B638844E306CAE9147B52C85 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; + B638844E306CAE9147B52C85 /* (null) in Frameworks */ = {isa = PBXBuildFile; }; BF39E5BAE0F34F9091FF6AC0 /* EuclidCircularB-Semibold.otf in Resources */ = {isa = PBXBuildFile; fileRef = A8DE9C5BC0714D648276E123 /* EuclidCircularB-Semibold.otf */; }; CD13D926E1E84D9ABFE672C0 /* Roboto-BlackItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 3E2492C67CF345CABD7B8601 /* Roboto-BlackItalic.ttf */; }; CF9895772A3B49BE00B4C9B5 /* RCTMinimizer.m in Sources */ = {isa = PBXBuildFile; fileRef = CF9895762A3B49BE00B4C9B5 /* RCTMinimizer.m */; }; @@ -142,7 +142,7 @@ CF98DA9C28D9FEB700096782 /* RCTScreenshotDetect.m in Sources */ = {isa = PBXBuildFile; fileRef = CF98DA9B28D9FEB700096782 /* RCTScreenshotDetect.m */; }; CFD8DFC828EDD4C800CC75F6 /* RCTScreenshotDetect.m in Sources */ = {isa = PBXBuildFile; fileRef = CF98DA9B28D9FEB700096782 /* RCTScreenshotDetect.m */; }; D171C39A8BD44DBEB6B68480 /* EuclidCircularB-MediumItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 42CBA652072F4BE2A8B815C1 /* EuclidCircularB-MediumItalic.otf */; }; - D45BF85DECACCB74EDCBE88A /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; + D45BF85DECACCB74EDCBE88A /* (null) in Frameworks */ = {isa = PBXBuildFile; }; D5BA0E32DFAA451781D5093E /* CentraNo1-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 4560812198A247039A1CF5A5 /* CentraNo1-BoldItalic.otf */; }; DADE8F39CE81410A98B9B805 /* MMSans-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2EBD310362314C3ABFF40AD1 /* MMSans-Regular.otf */; }; DC6A024F56DD43E1A83B47B1 /* Roboto-MediumItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D5FF0FF1DFB74B3C8BB99E09 /* Roboto-MediumItalic.ttf */; }; @@ -337,9 +337,9 @@ 650F2B9D24DC5FF200C3B9C4 /* libRCTAesForked.a in Frameworks */, 153C1ABB2217BCDC0088EFE0 /* JavaScriptCore.framework in Frameworks */, 153F84CA2319B8FD00C19B63 /* Branch.framework in Frameworks */, - 0FD509E0336BF221F6527B24 /* BuildFile in Frameworks */, - D45BF85DECACCB74EDCBE88A /* BuildFile in Frameworks */, - B638844E306CAE9147B52C85 /* BuildFile in Frameworks */, + 0FD509E0336BF221F6527B24 /* (null) in Frameworks */, + D45BF85DECACCB74EDCBE88A /* (null) in Frameworks */, + B638844E306CAE9147B52C85 /* (null) in Frameworks */, ED2E8FE6D71BE9319F3B27D3 /* libPods-MetaMask.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1555,7 +1555,11 @@ ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "$(inherited)"; OTHER_CPLUSPLUSFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; + OTHER_LDFLAGS = ( + "$(inherited)", + "-Wl", + "-ld_classic", + ); REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; }; @@ -1599,7 +1603,11 @@ MTL_ENABLE_DEBUG_INFO = NO; OTHER_CFLAGS = "$(inherited)"; OTHER_CPLUSPLUSFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; + OTHER_LDFLAGS = ( + "$(inherited)", + "-Wl", + "-ld_classic", + ); REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; From 81ed9736eacf930908c6e369dcf451d259c31a57 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Mon, 23 Sep 2024 12:21:49 -0400 Subject: [PATCH 02/26] revert: changes in ios/MetaMask.xcodeproj/project.pbxproj --- ios/MetaMask.xcodeproj/project.pbxproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ios/MetaMask.xcodeproj/project.pbxproj b/ios/MetaMask.xcodeproj/project.pbxproj index 9ea59e6ce1b..39437705987 100644 --- a/ios/MetaMask.xcodeproj/project.pbxproj +++ b/ios/MetaMask.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 07CBADD9D4B441008304F8D3 /* EuclidCircularB-Light.otf in Resources */ = {isa = PBXBuildFile; fileRef = A98029A3662F4C1391489A6B /* EuclidCircularB-Light.otf */; }; 08B7A641467C4723B98328E9 /* CentraNo1-Medium.otf in Resources */ = {isa = PBXBuildFile; fileRef = F97653CAD1D04E1B8713C428 /* CentraNo1-Medium.otf */; }; - 0FD509E0336BF221F6527B24 /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + 0FD509E0336BF221F6527B24 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; @@ -134,7 +134,7 @@ B339FF2E289ABD70001B89FB /* EuclidCircularB-SemiboldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 9499B01ECAC44DA29AC44E80 /* EuclidCircularB-SemiboldItalic.otf */; }; B339FF32289ABD70001B89FB /* Branch.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 153F84C92319B8DB00C19B63 /* Branch.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B339FF3C289ABF2C001B89FB /* MetaMask-QA-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B339FEA72899852C001B89FB /* MetaMask-QA-Info.plist */; }; - B638844E306CAE9147B52C85 /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + B638844E306CAE9147B52C85 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; BF39E5BAE0F34F9091FF6AC0 /* EuclidCircularB-Semibold.otf in Resources */ = {isa = PBXBuildFile; fileRef = A8DE9C5BC0714D648276E123 /* EuclidCircularB-Semibold.otf */; }; CD13D926E1E84D9ABFE672C0 /* Roboto-BlackItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 3E2492C67CF345CABD7B8601 /* Roboto-BlackItalic.ttf */; }; CF9895772A3B49BE00B4C9B5 /* RCTMinimizer.m in Sources */ = {isa = PBXBuildFile; fileRef = CF9895762A3B49BE00B4C9B5 /* RCTMinimizer.m */; }; @@ -142,7 +142,7 @@ CF98DA9C28D9FEB700096782 /* RCTScreenshotDetect.m in Sources */ = {isa = PBXBuildFile; fileRef = CF98DA9B28D9FEB700096782 /* RCTScreenshotDetect.m */; }; CFD8DFC828EDD4C800CC75F6 /* RCTScreenshotDetect.m in Sources */ = {isa = PBXBuildFile; fileRef = CF98DA9B28D9FEB700096782 /* RCTScreenshotDetect.m */; }; D171C39A8BD44DBEB6B68480 /* EuclidCircularB-MediumItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 42CBA652072F4BE2A8B815C1 /* EuclidCircularB-MediumItalic.otf */; }; - D45BF85DECACCB74EDCBE88A /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + D45BF85DECACCB74EDCBE88A /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; D5BA0E32DFAA451781D5093E /* CentraNo1-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 4560812198A247039A1CF5A5 /* CentraNo1-BoldItalic.otf */; }; DADE8F39CE81410A98B9B805 /* MMSans-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2EBD310362314C3ABFF40AD1 /* MMSans-Regular.otf */; }; DC6A024F56DD43E1A83B47B1 /* Roboto-MediumItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D5FF0FF1DFB74B3C8BB99E09 /* Roboto-MediumItalic.ttf */; }; @@ -337,9 +337,9 @@ 650F2B9D24DC5FF200C3B9C4 /* libRCTAesForked.a in Frameworks */, 153C1ABB2217BCDC0088EFE0 /* JavaScriptCore.framework in Frameworks */, 153F84CA2319B8FD00C19B63 /* Branch.framework in Frameworks */, - 0FD509E0336BF221F6527B24 /* (null) in Frameworks */, - D45BF85DECACCB74EDCBE88A /* (null) in Frameworks */, - B638844E306CAE9147B52C85 /* (null) in Frameworks */, + 0FD509E0336BF221F6527B24 /* BuildFile in Frameworks */, + D45BF85DECACCB74EDCBE88A /* BuildFile in Frameworks */, + B638844E306CAE9147B52C85 /* BuildFile in Frameworks */, ED2E8FE6D71BE9319F3B27D3 /* libPods-MetaMask.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; From 74ce63c13581f10805503eb2d97ded4fc1fef1c5 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Mon, 23 Sep 2024 17:16:05 -0400 Subject: [PATCH 03/26] feat: renamed 'getLabelTextByAddress' to 'getLabelTextByKeyring' and moved logic from AccountSelectorList --- .../UI/AccountFromToInfoCard/AddressFrom.tsx | 4 +- app/components/UI/AccountInfoCard/index.js | 4 +- app/components/UI/AccountOverview/index.js | 4 +- .../AccountSelectorList.tsx | 7 +- .../AccountSelector.test.tsx.snap | 2310 +++++++++-------- app/components/UI/AddressInputs/index.js | 6 +- app/components/UI/DrawerView/index.js | 4 +- .../UI/WalletAccount/WalletAccount.tsx | 4 +- .../AccountConnectSingle.tsx | 4 +- .../AddressElement/AddressElement.tsx | 4 +- app/util/address/index.test.ts | 147 +- app/util/address/index.ts | 10 +- ios/MetaMask.xcodeproj/project.pbxproj | 12 +- 13 files changed, 1267 insertions(+), 1253 deletions(-) diff --git a/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx b/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx index 8efc3818213..17a2e556496 100644 --- a/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx +++ b/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx @@ -14,7 +14,7 @@ import { selectNetworkName, } from '../../../selectors/networkInfos'; import { - getLabelTextByAddress, + getLabelTextByKeyring, renderAccountName, } from '../../../util/address'; import useAddressBalance from '../../hooks/useAddressBalance/useAddressBalance'; @@ -76,7 +76,7 @@ const AddressFrom = ({ const networkImage = useSelector(selectNetworkImageSource); - const accountTypeLabel = getLabelTextByAddress(activeAddress); + const accountTypeLabel = getLabelTextByKeyring(activeAddress); return ( diff --git a/app/components/UI/AccountInfoCard/index.js b/app/components/UI/AccountInfoCard/index.js index 321428314fb..e9693925661 100644 --- a/app/components/UI/AccountInfoCard/index.js +++ b/app/components/UI/AccountInfoCard/index.js @@ -16,7 +16,7 @@ import { import { selectTicker } from '../../../selectors/networkController'; import { fontStyles } from '../../../styles/common'; import { - getLabelTextByAddress, + getLabelTextByKeyring, renderAccountName, renderShortAddress, safeToChecksumAddress, @@ -153,7 +153,7 @@ class AccountInfoCard extends PureComponent { } = this.props; const fromAddress = safeToChecksumAddress(rawFromAddress); - const accountLabelTag = getLabelTextByAddress(fromAddress); + const accountLabelTag = getLabelTextByKeyring(fromAddress); const colors = this.context.colors || mockTheme.colors; const styles = createStyles(colors); const weiBalance = accounts?.[fromAddress]?.balance diff --git a/app/components/UI/AccountOverview/index.js b/app/components/UI/AccountOverview/index.js index 73e326e6c8e..fe5ee202dc3 100644 --- a/app/components/UI/AccountOverview/index.js +++ b/app/components/UI/AccountOverview/index.js @@ -22,7 +22,7 @@ import { isDefaultAccountName, } from '../../../util/ENSUtils'; import { - getLabelTextByAddress, + getLabelTextByKeyring, renderAccountName, } from '../../../util/address'; import Device from '../../../util/device'; @@ -339,7 +339,7 @@ class AccountOverview extends PureComponent { if (!address) return null; const { accountLabelEditable, accountLabel, ens } = this.state; - const accountLabelTag = getLabelTextByAddress(address); + const accountLabelTag = getLabelTextByKeyring(address); return ( diff --git a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx index 27513d72bb4..52f285b6078 100644 --- a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx +++ b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx @@ -16,7 +16,7 @@ import AvatarGroup from '../../../component-library/components/Avatars/AvatarGro import { formatAddress, safeToChecksumAddress, - getLabelTextByAddress, + getLabelTextByKeyring, } from '../../../util/address'; import { AvatarAccountType } from '../../../component-library/components/Avatars/Avatar/variants/AvatarAccount'; import { isDefaultAccountName } from '../../../util/ENSUtils'; @@ -157,10 +157,7 @@ const AccountSelectorList = ({ index, }) => { const shortAddress = formatAddress(address, 'short'); - let tagLabel = getLabelTextByAddress(address); - if (type === KeyringTypes.snap) { - tagLabel = 'accounts.snap_account_tag'; - } + const tagLabel = getLabelTextByKeyring(address); const ensName = ensByAccountAddress[address]; const accountName = isDefaultAccountName(name) && ensName ? ensName : name; diff --git a/app/components/UI/AccountSelectorList/__snapshots__/AccountSelector.test.tsx.snap b/app/components/UI/AccountSelectorList/__snapshots__/AccountSelector.test.tsx.snap index 49c9d6e96b1..ecf6585df78 100644 --- a/app/components/UI/AccountSelectorList/__snapshots__/AccountSelector.test.tsx.snap +++ b/app/components/UI/AccountSelectorList/__snapshots__/AccountSelector.test.tsx.snap @@ -65,6 +65,7 @@ exports[`AccountSelectorList renders all accounts with balances 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, + "padding": 16, "position": "relative", } } @@ -75,243 +76,236 @@ exports[`AccountSelectorList renders all accounts with balances 1`] = ` accessible={true} style={ { - "padding": 16, + "alignItems": "center", + "flexDirection": "row", + "padding": 0, } } > - - - - - - + + - - - + } + height={32} + matrix={ + [ + 0.7046342099635947, + -0.7095707365365209, + 0.7095707365365209, + 0.7046342099635947, + -25.225718686778755, + -4.611026307883787, + ] + } + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + + Account 1 + + + 0xC495...D272 + + + - Account 1 - - - 0xC495...D272 - - - - - - $3200.00 + $3200.00 1 ETH - - + @@ -358,6 +352,7 @@ exports[`AccountSelectorList renders all accounts with balances 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, + "padding": 16, "position": "relative", } } @@ -368,200 +363,223 @@ exports[`AccountSelectorList renders all accounts with balances 1`] = ` accessible={true} style={ { - "padding": 16, + "alignItems": "center", + "flexDirection": "row", + "padding": 0, } } > - - - - - - + + - - - + } + height={32} + matrix={ + [ + 0.6704266189587993, + -0.7419758409756162, + 0.7419758409756162, + 0.6704266189587993, + 8.152366664413217, + -0.7899246956676649, + ] + } + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + + Account 2 + + + 0xd018...78E7 + - Account 2 - - - 0xd018...78E7 + Imported + + - - - $6400.00 + $6400.00 2 ETH - - + @@ -681,6 +699,7 @@ exports[`AccountSelectorList renders all accounts with right accessory 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, + "padding": 16, "position": "relative", } } @@ -691,222 +710,215 @@ exports[`AccountSelectorList renders all accounts with right accessory 1`] = ` accessible={true} style={ { - "padding": 16, + "alignItems": "center", + "flexDirection": "row", + "padding": 0, } } > - - - - - - + + - - - + } + height={32} + matrix={ + [ + 0.7046342099635947, + -0.7095707365365209, + 0.7095707365365209, + 0.7046342099635947, + -25.225718686778755, + -4.611026307883787, + ] + } + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + - + + - - Account 1 - - - 0xC495...D272 - - - + - - 0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272 - Account 1 - + 0xC495...D272 + + + + + 0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272 - Account 1 @@ -927,6 +939,7 @@ exports[`AccountSelectorList renders all accounts with right accessory 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, + "padding": 16, "position": "relative", } } @@ -937,200 +950,223 @@ exports[`AccountSelectorList renders all accounts with right accessory 1`] = ` accessible={true} style={ { - "padding": 16, + "alignItems": "center", + "flexDirection": "row", + "padding": 0, } } > - - - - - - + + - - - + } + height={32} + matrix={ + [ + 0.6704266189587993, + -0.7419758409756162, + 0.7419758409756162, + 0.6704266189587993, + 8.152366664413217, + -0.7899246956676649, + ] + } + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + + Account 2 + + + 0xd018...78E7 + - Account 2 - - - 0xd018...78E7 + Imported - + + - - 0xd018538C87232FF95acbCe4870629b75640a78E7 - Account 2 - + 0xd018538C87232FF95acbCe4870629b75640a78E7 - Account 2 @@ -1228,6 +1264,7 @@ exports[`AccountSelectorList renders correctly 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, + "padding": 16, "position": "relative", } } @@ -1238,243 +1275,236 @@ exports[`AccountSelectorList renders correctly 1`] = ` accessible={true} style={ { - "padding": 16, + "alignItems": "center", + "flexDirection": "row", + "padding": 0, } } > - - - - - - + + - - - + } + height={32} + matrix={ + [ + 0.7046342099635947, + -0.7095707365365209, + 0.7095707365365209, + 0.7046342099635947, + -25.225718686778755, + -4.611026307883787, + ] + } + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + + Account 1 + + + 0xC495...D272 + + + - Account 1 - - - 0xC495...D272 - - - - - - $3200.00 + $3200.00 1 ETH - - + @@ -1521,6 +1551,7 @@ exports[`AccountSelectorList renders correctly 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, + "padding": 16, "position": "relative", } } @@ -1531,200 +1562,223 @@ exports[`AccountSelectorList renders correctly 1`] = ` accessible={true} style={ { - "padding": 16, + "alignItems": "center", + "flexDirection": "row", + "padding": 0, } } > - - - - - - + + - - - + } + height={32} + matrix={ + [ + 0.6704266189587993, + -0.7419758409756162, + 0.7419758409756162, + 0.6704266189587993, + 8.152366664413217, + -0.7899246956676649, + ] + } + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + + Account 2 + + + 0xd018...78E7 + - Account 2 - - - 0xd018...78E7 + Imported + + - - - $6400.00 + $6400.00 2 ETH - - + @@ -1840,6 +1894,7 @@ exports[`AccountSelectorList should render all accounts but only the balance for "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, + "padding": 16, "position": "relative", } } @@ -1850,127 +1905,120 @@ exports[`AccountSelectorList should render all accounts but only the balance for accessible={true} style={ { - "padding": 16, + "alignItems": "center", + "flexDirection": "row", + "padding": 0, } } > - - + + Account 1 + + - + } + > + 0xC495...D272 + + + - Account 1 - - - 0xC495...D272 - - - - - - $3200.00 + $3200.00 1 ETH - - + @@ -2017,6 +2065,7 @@ exports[`AccountSelectorList should render all accounts but only the balance for "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, + "padding": 16, "position": "relative", } } @@ -2027,84 +2076,107 @@ exports[`AccountSelectorList should render all accounts but only the balance for accessible={true} style={ { - "padding": 16, + "alignItems": "center", + "flexDirection": "row", + "padding": 0, } } > - - + + Account 2 + + - + } + > + 0xd018...78E7 + - Account 2 - - - 0xd018...78E7 + Imported diff --git a/app/components/UI/AddressInputs/index.js b/app/components/UI/AddressInputs/index.js index 3f2ad375619..b117c7ed43e 100644 --- a/app/components/UI/AddressInputs/index.js +++ b/app/components/UI/AddressInputs/index.js @@ -9,7 +9,7 @@ import { renderShortAddress, renderSlightlyLongAddress, isENS, - getLabelTextByAddress, + getLabelTextByKeyring, } from '../../../util/address'; import { strings } from '../../../../locales/i18n'; import { hasZeroWidthPoints } from '../../../util/confusables'; @@ -252,7 +252,7 @@ export const AddressTo = (props) => { isFromAddressBook = false, layout = 'horizontal', } = props; - const accountLabel = getLabelTextByAddress(toSelectedAddress); + const accountLabel = getLabelTextByKeyring(toSelectedAddress); const { colors, themeAppearance } = useTheme(); const styles = createStyles(colors, layout); @@ -582,7 +582,7 @@ export const AddressFrom = (props) => { fromAccountAddress, layout = 'horizontal', } = props; - const accountLabel = getLabelTextByAddress(fromAccountAddress); + const accountLabel = getLabelTextByKeyring(fromAccountAddress); const { colors } = useTheme(); const styles = createStyles(colors, layout); diff --git a/app/components/UI/DrawerView/index.js b/app/components/UI/DrawerView/index.js index 7b3ba218e01..e393915ead9 100644 --- a/app/components/UI/DrawerView/index.js +++ b/app/components/UI/DrawerView/index.js @@ -61,7 +61,7 @@ import { ScrollView } from 'react-native-gesture-handler'; import { isZero } from '../../../util/lodash'; import { Authentication } from '../../../core/'; import { ThemeContext, mockTheme } from '../../../util/theme'; -import { getLabelTextByAddress } from '../../../util/address'; +import { getLabelTextByKeyring } from '../../../util/address'; import { onboardNetworkAction, networkSwitched, @@ -485,7 +485,7 @@ class DrawerView extends PureComponent { renderTag() { const colors = this.context.colors || mockTheme.colors; const styles = createStyles(colors); - const label = getLabelTextByAddress(this.selectedChecksummedAddress); + const label = getLabelTextByKeyring(this.selectedChecksummedAddress); return label ? ( diff --git a/app/components/UI/WalletAccount/WalletAccount.tsx b/app/components/UI/WalletAccount/WalletAccount.tsx index e96ea0e1e29..d4363386bd9 100644 --- a/app/components/UI/WalletAccount/WalletAccount.tsx +++ b/app/components/UI/WalletAccount/WalletAccount.tsx @@ -16,7 +16,7 @@ import ButtonIcon from '../../../component-library/components/Buttons/ButtonIcon import { ButtonIconSizes } from '../../../component-library/components/Buttons/ButtonIcon'; import Routes from '../../../constants/navigation/Routes'; import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors'; -import { getLabelTextByAddress } from '../../../util/address'; +import { getLabelTextByKeyring } from '../../../util/address'; import { selectSelectedInternalAccount } from '../../../selectors/accountsController'; import useEnsNameByAddress from '../../../components/hooks/useEnsNameByAddress'; import Logger from '../../../util/Logger'; @@ -81,7 +81,7 @@ const WalletAccount = ({ style }: WalletAccountProps, ref: React.Ref) => { navigate(...createAccountSelectorNavDetails({})); }} accountTypeLabel={ - getLabelTextByAddress(selectedAccount?.address) || undefined + getLabelTextByKeyring(selectedAccount?.address) || undefined } showAddress={false} cellAccountContainerStyle={styles.account} diff --git a/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx b/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx index 64574d6fcac..608c68ea83b 100644 --- a/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx +++ b/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx @@ -26,7 +26,7 @@ import Text, { TextColor, } from '../../../../component-library/components/Texts/Text'; import { useStyles } from '../../../../component-library/hooks'; -import { formatAddress, getLabelTextByAddress } from '../../../../util/address'; +import { formatAddress, getLabelTextByKeyring } from '../../../../util/address'; import { AccountConnectScreens } from '../AccountConnect.types'; // Internal dependencies. @@ -132,7 +132,7 @@ const AccountConnectSingle = ({ if (!defaultSelectedAccount) return null; const { name, address, balanceError } = defaultSelectedAccount; const shortAddress = formatAddress(address, 'short'); - const tagLabel = getLabelTextByAddress(address); + const tagLabel = getLabelTextByKeyring(address); return ( = ({ : renderShortAddress(address); const secondaryLabel = displayName && !displayName.startsWith(' ') && renderShortAddress(address); - const accountTypeLabel = getLabelTextByAddress(address); + const accountTypeLabel = getLabelTextByKeyring(address); return ( { - const { KeyringTypes } = jest.requireActual('@metamask/keyring-controller'); - const { MOCK_KEYRING_CONTROLLER_STATE } = jest.requireActual( - '../test/keyringControllerTestUtils', - ); - return { - context: { - KeyringController: { - ...MOCK_KEYRING_CONTROLLER_STATE, - state: { - keyrings: [ - ...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings, - { - accounts: [snapAddress], - index: 0, - type: KeyringTypes.snap, - }, - ], - }, - }, - }, - }; -}); describe('isENS', () => { it('should return false by default', () => { @@ -200,30 +169,19 @@ describe('getAddress', () => { }); describe('shouldShowBlockExplorer', () => { - const networkConfigurations: NetworkState['networkConfigurationsByChainId'] = - { - '0x1': { - blockExplorerUrls: [], - chainId: '0x1', - defaultRpcEndpointIndex: 0, - name: 'Main Ethereum Network', - nativeCurrency: 'USD', - rpcEndpoints: [ - { - networkClientId: 'networkId1', - type: RpcEndpointType.Custom, - url: 'https://mainnet.infura.io/v3/123', - }, - ], - }, - }; + const networkConfigurations: NetworkState['networkConfigurations'] = { + networkId1: { + id: 'networkId1', + chainId: '0x1', + nickname: 'Main Ethereum Network', + ticker: 'USD', + rpcUrl: 'https://mainnet.infura.io/v3/123', + }, + }; it('returns true if provider type is not rpc', () => { const providerType = 'mainnet'; - - const providerRpcTarget = networkConfigurations['0x1'].rpcEndpoints.find( - ({ networkClientId }) => networkClientId === 'networkId1', - )?.url as string; + const providerRpcTarget = networkConfigurations.networkId1.rpcUrl; const result = shouldShowBlockExplorer( providerType, @@ -236,14 +194,9 @@ describe('shouldShowBlockExplorer', () => { it('returns block explorer URL if defined', () => { const providerType = 'rpc'; - const providerRpcTarget = networkConfigurations['0x1'].rpcEndpoints.find( - ({ networkClientId }) => networkClientId === 'networkId1', - )?.url as string; - + const providerRpcTarget = networkConfigurations.networkId1.rpcUrl; const blockExplorerUrl = 'https://rpc.testnet.fantom.network'; - - networkConfigurations['0x1'].blockExplorerUrls = [blockExplorerUrl]; - networkConfigurations['0x1'].defaultBlockExplorerUrlIndex = 0; + networkConfigurations.networkId1.rpcPrefs = { blockExplorerUrl }; const result = shouldShowBlockExplorer( providerType, @@ -256,12 +209,8 @@ describe('shouldShowBlockExplorer', () => { it('returns undefined if block explorer URL is not defined', () => { const providerType = 'rpc'; - - const providerRpcTarget = networkConfigurations['0x1'].rpcEndpoints.find( - ({ networkClientId }) => networkClientId === 'networkId1', - )?.url as string; - - networkConfigurations['0x1'].blockExplorerUrls = []; + const providerRpcTarget = networkConfigurations.networkId1.rpcUrl; + networkConfigurations.networkId1.rpcPrefs = undefined; const result = shouldShowBlockExplorer( providerType, @@ -283,13 +232,19 @@ describe('isQRHardwareAccount', () => { }); it('should return false if address is from keyring type simple', () => { - expect(isQRHardwareAccount(mockSimpleKeyringAddress)).toBeFalsy(); + expect( + isQRHardwareAccount('0xd018538C87232FF95acbCe4870629b75640a78E7'), + ).toBeFalsy(); }); it('should return false if address is from keyring type hd', () => { - expect(isQRHardwareAccount(mockHDKeyringAddress)).toBeFalsy(); + expect( + isQRHardwareAccount('0x71C7656EC7ab88b098defB751B7401B5f6d8976F'), + ).toBeFalsy(); }); it('should return true if address is from keyring type qr', () => { - expect(isQRHardwareAccount(mockQrKeyringAddress)).toBeTruthy(); + expect( + isQRHardwareAccount('0xB374Ca013934e498e5baD3409147F34E6c462389'), + ).toBeTruthy(); }); }); describe('getKeyringByAddress', () => { @@ -302,7 +257,9 @@ describe('getKeyringByAddress', () => { expect(getKeyringByAddress('ens.eth')).toBeUndefined(); }); it('should return address if found', () => { - expect(getKeyringByAddress(mockQrKeyringAddress)).not.toBe(undefined); + expect( + getKeyringByAddress('0xB374Ca013934e498e5baD3409147F34E6c462389'), + ).not.toBe(undefined); }); it('should return null if address not found', () => { expect( @@ -312,7 +269,9 @@ describe('getKeyringByAddress', () => { }); describe('isHardwareAccount,', () => { it('should return true if account is a QR keyring', () => { - expect(isHardwareAccount(mockQrKeyringAddress)).toBeTruthy(); + expect( + isHardwareAccount('0xB374Ca013934e498e5baD3409147F34E6c462389'), + ).toBeTruthy(); }); it('should return false if account is not a hardware keyring', () => { @@ -321,36 +280,26 @@ describe('isHardwareAccount,', () => { ).toBeFalsy(); }); }); -describe('getLabelTextByAddress,', () => { - beforeEach(() => { - jest.resetAllMocks(); - }); - +describe('getLabelTextByKeyring,', () => { it('should return accounts.qr_hardware if account is a QR keyring', () => { - expect(getLabelTextByAddress(mockQrKeyringAddress)).toBe( - 'accounts.qr_hardware', - ); + expect( + getLabelTextByKeyring('0xB374Ca013934e498e5baD3409147F34E6c462389'), + ).toBe('accounts.qr_hardware'); }); it('should return KeyringTypes.simple if address is a imported account', () => { - expect(getLabelTextByAddress(mockSimpleKeyringAddress)).toBe( - 'accounts.imported', - ); - }); - - it('returns "Snaps (beta)" if account is a Snap keyring', () => { - expect(getLabelTextByAddress(snapAddress)).toBe( - 'accounts.snap_account_tag', - ); + expect( + getLabelTextByKeyring('0xd018538C87232FF95acbCe4870629b75640a78E7'), + ).toBe('accounts.imported'); }); it('should return null if address is empty', () => { - expect(getLabelTextByAddress('')).toBe(null); + expect(getLabelTextByKeyring('')).toBe(null); }); it('should return null if account not found', () => { expect( - getLabelTextByAddress('0xD5955C0d639D99699Bfd7Ec54d9FaFEe40e4D278'), + getLabelTextByKeyring('0xD5955C0d639D99699Bfd7Ec54d9FaFEe40e4D278'), ).toBe(null); }); }); @@ -363,13 +312,19 @@ describe('getAddressAccountType', () => { ); }); it('should return QR if address is from a keyring type qr', () => { - expect(getAddressAccountType(mockQrKeyringAddress)).toBe('QR'); + expect( + getAddressAccountType('0xB374Ca013934e498e5baD3409147F34E6c462389'), + ).toBe('QR'); }); it('should return imported if address is from a keyring type simple', () => { - expect(getAddressAccountType(mockSimpleKeyringAddress)).toBe('Imported'); + expect( + getAddressAccountType('0xd018538C87232FF95acbCe4870629b75640a78E7'), + ).toBe('Imported'); }); it('should return MetaMask if address is not qr or simple', () => { - expect(getAddressAccountType(mockHDKeyringAddress)).toBe('MetaMask'); + expect( + getAddressAccountType('0x71C7656EC7ab88b098defB751B7401B5f6d8976F'), + ).toBe('MetaMask'); }); }); describe('resemblesAddress', () => { @@ -382,6 +337,8 @@ describe('resemblesAddress', () => { expect(resemblesAddress('address-stub-1')).toBeFalsy(); }); it('should return true if address resemble an eth address', () => { - expect(resemblesAddress(mockHDKeyringAddress)).toBeTruthy(); + expect( + resemblesAddress('0x71C7656EC7ab88b098defB751B7401B5f6d8976F'), + ).toBeTruthy(); }); }); diff --git a/app/util/address/index.ts b/app/util/address/index.ts index d34f848d195..50cf982d85f 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -39,9 +39,7 @@ import { NetworkType, toChecksumHexAddress } from '@metamask/controller-utils'; import { NetworkClientId, NetworkState } from '@metamask/network-controller'; import { AccountImportStrategy, - ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) KeyringTypes, - ///: END:ONLY_INCLUDE_IF } from '@metamask/keyring-controller'; import { Hex, isHexString } from '@metamask/utils'; @@ -233,12 +231,12 @@ export function isExternalHardwareAccount(address: string) { } /** - * gets i18n account label tag text based on address + * gets i18n account label tag text based on keyring type * * @param {String} address - String corresponding to an address * @returns {String} - Returns address's i18n label text */ -export function getLabelTextByAddress(address: string) { +export function getLabelTextByKeyring(address: string) { if (!address) return null; const keyring = getKeyringByAddress(address); if (keyring) { @@ -249,10 +247,8 @@ export function getLabelTextByAddress(address: string) { return 'accounts.qr_hardware'; case ExtendedKeyringTypes.simple: return 'accounts.imported'; - ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) case KeyringTypes.snap: return 'accounts.snap_account_tag'; - ///: END:ONLY_INCLUDE_IF } } return null; @@ -635,7 +631,7 @@ export const getTokenDecimal = async ( export const shouldShowBlockExplorer = ( providerType: NetworkType, providerRpcTarget: string, - networkConfigurations: NetworkState['networkConfigurationsByChainId'], + networkConfigurations: NetworkState['networkConfigurations'], ) => { if (providerType === RPC) { return findBlockExplorerForRpc(providerRpcTarget, networkConfigurations); diff --git a/ios/MetaMask.xcodeproj/project.pbxproj b/ios/MetaMask.xcodeproj/project.pbxproj index 39437705987..314bc34f316 100644 --- a/ios/MetaMask.xcodeproj/project.pbxproj +++ b/ios/MetaMask.xcodeproj/project.pbxproj @@ -1555,11 +1555,7 @@ ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "$(inherited)"; OTHER_CPLUSPLUSFLAGS = "$(inherited)"; - OTHER_LDFLAGS = ( - "$(inherited)", - "-Wl", - "-ld_classic", - ); + OTHER_LDFLAGS = "$(inherited)"; REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; }; @@ -1603,11 +1599,7 @@ MTL_ENABLE_DEBUG_INFO = NO; OTHER_CFLAGS = "$(inherited)"; OTHER_CPLUSPLUSFLAGS = "$(inherited)"; - OTHER_LDFLAGS = ( - "$(inherited)", - "-Wl", - "-ld_classic", - ); + OTHER_LDFLAGS = "$(inherited)"; REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; From 96d9b212624708e952bf9905e1e4db61de58da48 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Mon, 23 Sep 2024 17:32:53 -0400 Subject: [PATCH 04/26] feat: added 'createMockAccountsControllerStateWithSnap' to accounts controller test utils --- .../AccountSelector.test.tsx | 28 +++++-------------- app/util/address/index.ts | 2 ++ app/util/test/accountsControllerTestUtils.ts | 3 +- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/app/components/UI/AccountSelectorList/AccountSelector.test.tsx b/app/components/UI/AccountSelectorList/AccountSelector.test.tsx index e957587b678..306c88825c4 100644 --- a/app/components/UI/AccountSelectorList/AccountSelector.test.tsx +++ b/app/components/UI/AccountSelectorList/AccountSelector.test.tsx @@ -10,12 +10,12 @@ import { backgroundState } from '../../../util/test/initial-root-state'; import { regex } from '../../../../app/util/regex'; import { createMockAccountsControllerState, - expectedUuid, - internalAccount1, + createMockAccountsControllerStateWithSnap, + MOCK_ADDRESS_1, + MOCK_ADDRESS_2, } from '../../../util/test/accountsControllerTestUtils'; import { mockNetworkState } from '../../../util/test/network'; import { CHAIN_IDS } from '@metamask/transaction-controller'; -import { AccountsControllerState } from '@metamask/accounts-controller'; const BUSINESS_ACCOUNT = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; const PERSONAL_ACCOUNT = '0xd018538C87232FF95acbCe4870629b75640a78E7'; @@ -206,24 +206,10 @@ describe('AccountSelectorList', () => { }); }); it('renders "Snaps (beta)" tag for Snap accounts', async () => { - const mockAccountsWithSnap: AccountsControllerState = { - ...MOCK_ACCOUNTS_CONTROLLER_STATE, - internalAccounts: { - ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts, - accounts: { - ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts, - [expectedUuid]: { - ...internalAccount1, - metadata: { - ...internalAccount1.metadata, - keyring: { - type: 'Snap Keyring', - }, - }, - }, - }, - }, - }; + const mockAccountsWithSnap = createMockAccountsControllerStateWithSnap([ + MOCK_ADDRESS_1, + MOCK_ADDRESS_2, + ]); const stateWithSnapAccount = { ...initialState, diff --git a/app/util/address/index.ts b/app/util/address/index.ts index 50cf982d85f..61d43a406ce 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -247,8 +247,10 @@ export function getLabelTextByKeyring(address: string) { return 'accounts.qr_hardware'; case ExtendedKeyringTypes.simple: return 'accounts.imported'; + ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) case KeyringTypes.snap: return 'accounts.snap_account_tag'; + ///: END:ONLY_INCLUDE_IF } } return null; diff --git a/app/util/test/accountsControllerTestUtils.ts b/app/util/test/accountsControllerTestUtils.ts index 983a0ba94f9..63ef4cce59e 100644 --- a/app/util/test/accountsControllerTestUtils.ts +++ b/app/util/test/accountsControllerTestUtils.ts @@ -1,7 +1,6 @@ import { v4 as uuidV4 } from 'uuid'; import { EthMethod, InternalAccount } from '@metamask/keyring-api'; import { AccountsControllerState } from '@metamask/accounts-controller'; -import { KeyringTypes } from '@metamask/keyring-controller'; export function createMockUuidFromAddress(address: string): string { const fakeShaFromAddress = Array.from( @@ -122,7 +121,7 @@ export function createMockAccountsControllerStateWithSnap( addresses[snapAccountIndex].toLowerCase(), ); state.internalAccounts.accounts[snapAccountUuid].metadata.keyring = { - type: KeyringTypes.snap, + type: 'Snap Keyring', }; return state; From 06061352dd305896a1842d8a6c25fa22fe5a027f Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Mon, 23 Sep 2024 17:35:51 -0400 Subject: [PATCH 05/26] revert: changes in xcodeproj --- .../UI/AccountFromToInfoCard/AddressFrom.tsx | 4 ++-- app/components/UI/AccountInfoCard/index.js | 4 ++-- app/components/UI/AccountOverview/index.js | 4 ++-- .../AccountSelectorList.tsx | 4 ++-- app/components/UI/AddressInputs/index.js | 6 +++--- app/components/UI/DrawerView/index.js | 4 ++-- .../UI/WalletAccount/WalletAccount.tsx | 4 ++-- .../AccountConnectSingle.tsx | 7 +++++-- .../SendFlow/AddressElement/AddressElement.tsx | 4 ++-- app/util/address/index.test.ts | 18 ++++++++++++------ app/util/address/index.ts | 2 +- ios/MetaMask.xcodeproj/project.pbxproj | 12 ++++++++++-- 12 files changed, 45 insertions(+), 28 deletions(-) diff --git a/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx b/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx index 17a2e556496..a1fd929b8b6 100644 --- a/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx +++ b/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx @@ -14,7 +14,7 @@ import { selectNetworkName, } from '../../../selectors/networkInfos'; import { - getLabelTextByKeyring, + getAccountLabelTextByKeyring, renderAccountName, } from '../../../util/address'; import useAddressBalance from '../../hooks/useAddressBalance/useAddressBalance'; @@ -76,7 +76,7 @@ const AddressFrom = ({ const networkImage = useSelector(selectNetworkImageSource); - const accountTypeLabel = getLabelTextByKeyring(activeAddress); + const accountTypeLabel = getAccountLabelTextByKeyring(activeAddress); return ( diff --git a/app/components/UI/AccountInfoCard/index.js b/app/components/UI/AccountInfoCard/index.js index e9693925661..4c227cc6cad 100644 --- a/app/components/UI/AccountInfoCard/index.js +++ b/app/components/UI/AccountInfoCard/index.js @@ -16,7 +16,7 @@ import { import { selectTicker } from '../../../selectors/networkController'; import { fontStyles } from '../../../styles/common'; import { - getLabelTextByKeyring, + getAccountLabelTextByKeyring, renderAccountName, renderShortAddress, safeToChecksumAddress, @@ -153,7 +153,7 @@ class AccountInfoCard extends PureComponent { } = this.props; const fromAddress = safeToChecksumAddress(rawFromAddress); - const accountLabelTag = getLabelTextByKeyring(fromAddress); + const accountLabelTag = getAccountLabelTextByKeyring(fromAddress); const colors = this.context.colors || mockTheme.colors; const styles = createStyles(colors); const weiBalance = accounts?.[fromAddress]?.balance diff --git a/app/components/UI/AccountOverview/index.js b/app/components/UI/AccountOverview/index.js index fe5ee202dc3..5f620518441 100644 --- a/app/components/UI/AccountOverview/index.js +++ b/app/components/UI/AccountOverview/index.js @@ -22,7 +22,7 @@ import { isDefaultAccountName, } from '../../../util/ENSUtils'; import { - getLabelTextByKeyring, + getAccountLabelTextByKeyring, renderAccountName, } from '../../../util/address'; import Device from '../../../util/device'; @@ -339,7 +339,7 @@ class AccountOverview extends PureComponent { if (!address) return null; const { accountLabelEditable, accountLabel, ens } = this.state; - const accountLabelTag = getLabelTextByKeyring(address); + const accountLabelTag = getAccountLabelTextByKeyring(address); return ( diff --git a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx index 52f285b6078..98c94f58cbd 100644 --- a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx +++ b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx @@ -16,7 +16,7 @@ import AvatarGroup from '../../../component-library/components/Avatars/AvatarGro import { formatAddress, safeToChecksumAddress, - getLabelTextByKeyring, + getAccountLabelTextByKeyring, } from '../../../util/address'; import { AvatarAccountType } from '../../../component-library/components/Avatars/Avatar/variants/AvatarAccount'; import { isDefaultAccountName } from '../../../util/ENSUtils'; @@ -157,7 +157,7 @@ const AccountSelectorList = ({ index, }) => { const shortAddress = formatAddress(address, 'short'); - const tagLabel = getLabelTextByKeyring(address); + const tagLabel = getAccountLabelTextByKeyring(address); const ensName = ensByAccountAddress[address]; const accountName = isDefaultAccountName(name) && ensName ? ensName : name; diff --git a/app/components/UI/AddressInputs/index.js b/app/components/UI/AddressInputs/index.js index b117c7ed43e..394378820bd 100644 --- a/app/components/UI/AddressInputs/index.js +++ b/app/components/UI/AddressInputs/index.js @@ -9,7 +9,7 @@ import { renderShortAddress, renderSlightlyLongAddress, isENS, - getLabelTextByKeyring, + getAccountLabelTextByKeyring, } from '../../../util/address'; import { strings } from '../../../../locales/i18n'; import { hasZeroWidthPoints } from '../../../util/confusables'; @@ -252,7 +252,7 @@ export const AddressTo = (props) => { isFromAddressBook = false, layout = 'horizontal', } = props; - const accountLabel = getLabelTextByKeyring(toSelectedAddress); + const accountLabel = getAccountLabelTextByKeyring(toSelectedAddress); const { colors, themeAppearance } = useTheme(); const styles = createStyles(colors, layout); @@ -582,7 +582,7 @@ export const AddressFrom = (props) => { fromAccountAddress, layout = 'horizontal', } = props; - const accountLabel = getLabelTextByKeyring(fromAccountAddress); + const accountLabel = getAccountLabelTextByKeyring(fromAccountAddress); const { colors } = useTheme(); const styles = createStyles(colors, layout); diff --git a/app/components/UI/DrawerView/index.js b/app/components/UI/DrawerView/index.js index e393915ead9..e46d11fa33c 100644 --- a/app/components/UI/DrawerView/index.js +++ b/app/components/UI/DrawerView/index.js @@ -61,7 +61,7 @@ import { ScrollView } from 'react-native-gesture-handler'; import { isZero } from '../../../util/lodash'; import { Authentication } from '../../../core/'; import { ThemeContext, mockTheme } from '../../../util/theme'; -import { getLabelTextByKeyring } from '../../../util/address'; +import { getAccountLabelTextByKeyring } from '../../../util/address'; import { onboardNetworkAction, networkSwitched, @@ -485,7 +485,7 @@ class DrawerView extends PureComponent { renderTag() { const colors = this.context.colors || mockTheme.colors; const styles = createStyles(colors); - const label = getLabelTextByKeyring(this.selectedChecksummedAddress); + const label = getAccountLabelTextByKeyring(this.selectedChecksummedAddress); return label ? ( diff --git a/app/components/UI/WalletAccount/WalletAccount.tsx b/app/components/UI/WalletAccount/WalletAccount.tsx index d4363386bd9..6470805e602 100644 --- a/app/components/UI/WalletAccount/WalletAccount.tsx +++ b/app/components/UI/WalletAccount/WalletAccount.tsx @@ -16,7 +16,7 @@ import ButtonIcon from '../../../component-library/components/Buttons/ButtonIcon import { ButtonIconSizes } from '../../../component-library/components/Buttons/ButtonIcon'; import Routes from '../../../constants/navigation/Routes'; import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors'; -import { getLabelTextByKeyring } from '../../../util/address'; +import { getAccountLabelTextByKeyring } from '../../../util/address'; import { selectSelectedInternalAccount } from '../../../selectors/accountsController'; import useEnsNameByAddress from '../../../components/hooks/useEnsNameByAddress'; import Logger from '../../../util/Logger'; @@ -81,7 +81,7 @@ const WalletAccount = ({ style }: WalletAccountProps, ref: React.Ref) => { navigate(...createAccountSelectorNavDetails({})); }} accountTypeLabel={ - getLabelTextByKeyring(selectedAccount?.address) || undefined + getAccountLabelTextByKeyring(selectedAccount?.address) || undefined } showAddress={false} cellAccountContainerStyle={styles.account} diff --git a/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx b/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx index 608c68ea83b..1521a90f76f 100644 --- a/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx +++ b/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx @@ -26,7 +26,10 @@ import Text, { TextColor, } from '../../../../component-library/components/Texts/Text'; import { useStyles } from '../../../../component-library/hooks'; -import { formatAddress, getLabelTextByKeyring } from '../../../../util/address'; +import { + formatAddress, + getAccountLabelTextByKeyring, +} from '../../../../util/address'; import { AccountConnectScreens } from '../AccountConnect.types'; // Internal dependencies. @@ -132,7 +135,7 @@ const AccountConnectSingle = ({ if (!defaultSelectedAccount) return null; const { name, address, balanceError } = defaultSelectedAccount; const shortAddress = formatAddress(address, 'short'); - const tagLabel = getLabelTextByKeyring(address); + const tagLabel = getAccountLabelTextByKeyring(address); return ( = ({ : renderShortAddress(address); const secondaryLabel = displayName && !displayName.startsWith(' ') && renderShortAddress(address); - const accountTypeLabel = getLabelTextByKeyring(address); + const accountTypeLabel = getAccountLabelTextByKeyring(address); return ( { @@ -280,26 +280,32 @@ describe('isHardwareAccount,', () => { ).toBeFalsy(); }); }); -describe('getLabelTextByKeyring,', () => { +describe('getAccountLabelTextByKeyring,', () => { it('should return accounts.qr_hardware if account is a QR keyring', () => { expect( - getLabelTextByKeyring('0xB374Ca013934e498e5baD3409147F34E6c462389'), + getAccountLabelTextByKeyring( + '0xB374Ca013934e498e5baD3409147F34E6c462389', + ), ).toBe('accounts.qr_hardware'); }); it('should return KeyringTypes.simple if address is a imported account', () => { expect( - getLabelTextByKeyring('0xd018538C87232FF95acbCe4870629b75640a78E7'), + getAccountLabelTextByKeyring( + '0xd018538C87232FF95acbCe4870629b75640a78E7', + ), ).toBe('accounts.imported'); }); it('should return null if address is empty', () => { - expect(getLabelTextByKeyring('')).toBe(null); + expect(getAccountLabelTextByKeyring('')).toBe(null); }); it('should return null if account not found', () => { expect( - getLabelTextByKeyring('0xD5955C0d639D99699Bfd7Ec54d9FaFEe40e4D278'), + getAccountLabelTextByKeyring( + '0xD5955C0d639D99699Bfd7Ec54d9FaFEe40e4D278', + ), ).toBe(null); }); }); diff --git a/app/util/address/index.ts b/app/util/address/index.ts index 61d43a406ce..c488d6aca76 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -236,7 +236,7 @@ export function isExternalHardwareAccount(address: string) { * @param {String} address - String corresponding to an address * @returns {String} - Returns address's i18n label text */ -export function getLabelTextByKeyring(address: string) { +export function getAccountLabelTextByKeyring(address: string) { if (!address) return null; const keyring = getKeyringByAddress(address); if (keyring) { diff --git a/ios/MetaMask.xcodeproj/project.pbxproj b/ios/MetaMask.xcodeproj/project.pbxproj index 314bc34f316..39437705987 100644 --- a/ios/MetaMask.xcodeproj/project.pbxproj +++ b/ios/MetaMask.xcodeproj/project.pbxproj @@ -1555,7 +1555,11 @@ ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "$(inherited)"; OTHER_CPLUSPLUSFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; + OTHER_LDFLAGS = ( + "$(inherited)", + "-Wl", + "-ld_classic", + ); REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; }; @@ -1599,7 +1603,11 @@ MTL_ENABLE_DEBUG_INFO = NO; OTHER_CFLAGS = "$(inherited)"; OTHER_CPLUSPLUSFLAGS = "$(inherited)"; - OTHER_LDFLAGS = "$(inherited)"; + OTHER_LDFLAGS = ( + "$(inherited)", + "-Wl", + "-ld_classic", + ); REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; From 7da9cb1af80e0e1417456f6bf5f77b68bd95a897 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Mon, 23 Sep 2024 18:13:40 -0400 Subject: [PATCH 06/26] fix: code fence on KeyringTypes import --- app/util/address/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/util/address/index.ts b/app/util/address/index.ts index c488d6aca76..21d72e55666 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -39,7 +39,9 @@ import { NetworkType, toChecksumHexAddress } from '@metamask/controller-utils'; import { NetworkClientId, NetworkState } from '@metamask/network-controller'; import { AccountImportStrategy, + ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) KeyringTypes, + ///: END:ONLY_INCLUDE_IF } from '@metamask/keyring-controller'; import { Hex, isHexString } from '@metamask/utils'; From 7d7fa9896f1120ad64404ca384fd2bc17c4da209 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Mon, 23 Sep 2024 19:40:43 -0400 Subject: [PATCH 07/26] feat: debugging mocked testing --- app/util/address/index.test.ts | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index 1e8e0e1b222..50e818b8626 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -15,6 +15,34 @@ import { getKeyringByAddress, getAccountLabelTextByKeyring, } from '.'; +import mockedEngine from '../../core/__mocks__/MockedEngine'; +import { MOCK_KEYRING_CONTROLLER_STATE } from '../test/keyringControllerTestUtils'; +import Engine from '../../core/Engine'; + +const snapAddress = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; + +const mockKeyringControllerState = { + KeyringController: { + ...MOCK_KEYRING_CONTROLLER_STATE, + state: { + ...MOCK_KEYRING_CONTROLLER_STATE.state, + keyrings: [ + ...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings, + { + accounts: [snapAddress], + index: 0, + type: 'Snap Keyring', + }, + ], + }, + }, +}; + +jest.mock('../../core/Engine', () => ({ + context: { + KeyringController: mockKeyringControllerState, + }, +})); describe('isENS', () => { it('should return false by default', () => { @@ -281,6 +309,10 @@ describe('isHardwareAccount,', () => { }); }); describe('getAccountLabelTextByKeyring,', () => { + beforeEach(() => { + jest.resetAllMocks(); + }); + it('should return accounts.qr_hardware if account is a QR keyring', () => { expect( getAccountLabelTextByKeyring( @@ -297,6 +329,12 @@ describe('getAccountLabelTextByKeyring,', () => { ).toBe('accounts.imported'); }); + it('should return "Snaps (beta)" if account is a Snap keyring', () => { + expect(getAccountLabelTextByKeyring(snapAddress)).toBe( + 'accounts.snap_account_tag', + ); + }); + it('should return null if address is empty', () => { expect(getAccountLabelTextByKeyring('')).toBe(null); }); From 104029148fc4a0846fe5cceca0bd5ec2a57b2027 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Tue, 24 Sep 2024 10:55:34 -0400 Subject: [PATCH 08/26] fix: unit test for 'getAccountLabelTextByKeyring' --- app/util/address/index.test.ts | 101 +++++++++++++-------------------- 1 file changed, 41 insertions(+), 60 deletions(-) diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index 50e818b8626..2904e6d6c0e 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -15,34 +15,37 @@ import { getKeyringByAddress, getAccountLabelTextByKeyring, } from '.'; -import mockedEngine from '../../core/__mocks__/MockedEngine'; -import { MOCK_KEYRING_CONTROLLER_STATE } from '../test/keyringControllerTestUtils'; -import Engine from '../../core/Engine'; +import { + mockHDKeyringAddress, + mockQrKeyringAddress, + mockSimpleKeyringAddress, +} from '../test/keyringControllerTestUtils'; const snapAddress = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; -const mockKeyringControllerState = { - KeyringController: { - ...MOCK_KEYRING_CONTROLLER_STATE, - state: { - ...MOCK_KEYRING_CONTROLLER_STATE.state, - keyrings: [ - ...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings, - { - accounts: [snapAddress], - index: 0, - type: 'Snap Keyring', +jest.mock('../../core/Engine', () => { + const { KeyringTypes } = jest.requireActual('@metamask/keyring-controller'); + const { MOCK_KEYRING_CONTROLLER_STATE } = jest.requireActual( + '../test/keyringControllerTestUtils', + ); + return { + context: { + KeyringController: { + ...MOCK_KEYRING_CONTROLLER_STATE, + state: { + keyrings: [ + ...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings, + { + accounts: [snapAddress], + index: 0, + type: KeyringTypes.snap, + }, + ], }, - ], + }, }, - }, -}; - -jest.mock('../../core/Engine', () => ({ - context: { - KeyringController: mockKeyringControllerState, - }, -})); + }; +}); describe('isENS', () => { it('should return false by default', () => { @@ -260,19 +263,13 @@ describe('isQRHardwareAccount', () => { }); it('should return false if address is from keyring type simple', () => { - expect( - isQRHardwareAccount('0xd018538C87232FF95acbCe4870629b75640a78E7'), - ).toBeFalsy(); + expect(isQRHardwareAccount(mockSimpleKeyringAddress)).toBeFalsy(); }); it('should return false if address is from keyring type hd', () => { - expect( - isQRHardwareAccount('0x71C7656EC7ab88b098defB751B7401B5f6d8976F'), - ).toBeFalsy(); + expect(isQRHardwareAccount(mockHDKeyringAddress)).toBeFalsy(); }); it('should return true if address is from keyring type qr', () => { - expect( - isQRHardwareAccount('0xB374Ca013934e498e5baD3409147F34E6c462389'), - ).toBeTruthy(); + expect(isQRHardwareAccount(mockQrKeyringAddress)).toBeTruthy(); }); }); describe('getKeyringByAddress', () => { @@ -285,9 +282,7 @@ describe('getKeyringByAddress', () => { expect(getKeyringByAddress('ens.eth')).toBeUndefined(); }); it('should return address if found', () => { - expect( - getKeyringByAddress('0xB374Ca013934e498e5baD3409147F34E6c462389'), - ).not.toBe(undefined); + expect(getKeyringByAddress(mockQrKeyringAddress)).not.toBe(undefined); }); it('should return null if address not found', () => { expect( @@ -297,9 +292,7 @@ describe('getKeyringByAddress', () => { }); describe('isHardwareAccount,', () => { it('should return true if account is a QR keyring', () => { - expect( - isHardwareAccount('0xB374Ca013934e498e5baD3409147F34E6c462389'), - ).toBeTruthy(); + expect(isHardwareAccount(mockQrKeyringAddress)).toBeTruthy(); }); it('should return false if account is not a hardware keyring', () => { @@ -314,19 +307,15 @@ describe('getAccountLabelTextByKeyring,', () => { }); it('should return accounts.qr_hardware if account is a QR keyring', () => { - expect( - getAccountLabelTextByKeyring( - '0xB374Ca013934e498e5baD3409147F34E6c462389', - ), - ).toBe('accounts.qr_hardware'); + expect(getAccountLabelTextByKeyring(mockQrKeyringAddress)).toBe( + 'accounts.qr_hardware', + ); }); it('should return KeyringTypes.simple if address is a imported account', () => { - expect( - getAccountLabelTextByKeyring( - '0xd018538C87232FF95acbCe4870629b75640a78E7', - ), - ).toBe('accounts.imported'); + expect(getAccountLabelTextByKeyring(mockSimpleKeyringAddress)).toBe( + 'accounts.imported', + ); }); it('should return "Snaps (beta)" if account is a Snap keyring', () => { @@ -356,19 +345,13 @@ describe('getAddressAccountType', () => { ); }); it('should return QR if address is from a keyring type qr', () => { - expect( - getAddressAccountType('0xB374Ca013934e498e5baD3409147F34E6c462389'), - ).toBe('QR'); + expect(getAddressAccountType(mockQrKeyringAddress)).toBe('QR'); }); it('should return imported if address is from a keyring type simple', () => { - expect( - getAddressAccountType('0xd018538C87232FF95acbCe4870629b75640a78E7'), - ).toBe('Imported'); + expect(getAddressAccountType(mockSimpleKeyringAddress)).toBe('Imported'); }); it('should return MetaMask if address is not qr or simple', () => { - expect( - getAddressAccountType('0x71C7656EC7ab88b098defB751B7401B5f6d8976F'), - ).toBe('MetaMask'); + expect(getAddressAccountType(mockHDKeyringAddress)).toBe('MetaMask'); }); }); describe('resemblesAddress', () => { @@ -381,8 +364,6 @@ describe('resemblesAddress', () => { expect(resemblesAddress('address-stub-1')).toBeFalsy(); }); it('should return true if address resemble an eth address', () => { - expect( - resemblesAddress('0x71C7656EC7ab88b098defB751B7401B5f6d8976F'), - ).toBeTruthy(); + expect(resemblesAddress(mockHDKeyringAddress)).toBeTruthy(); }); }); From 23988bd7b8d2a84b7f246071a7375970974bdb7c Mon Sep 17 00:00:00 2001 From: Kate Johnson <91970214+k-g-j@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:40:56 -0400 Subject: [PATCH 09/26] feat: use KeyringTypes in accounts controller test utils Co-authored-by: Gustavo Antunes <17601467+gantunesr@users.noreply.github.com> --- app/util/test/accountsControllerTestUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/util/test/accountsControllerTestUtils.ts b/app/util/test/accountsControllerTestUtils.ts index 63ef4cce59e..3d3e8bccb01 100644 --- a/app/util/test/accountsControllerTestUtils.ts +++ b/app/util/test/accountsControllerTestUtils.ts @@ -121,7 +121,7 @@ export function createMockAccountsControllerStateWithSnap( addresses[snapAccountIndex].toLowerCase(), ); state.internalAccounts.accounts[snapAccountUuid].metadata.keyring = { - type: 'Snap Keyring', + type: KeyringTypes.snap, }; return state; From 79aa332ceb35b92a4d256e7900f639965cad22f9 Mon Sep 17 00:00:00 2001 From: Kate Johnson <91970214+k-g-j@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:41:21 -0400 Subject: [PATCH 10/26] feat: remove 'should' from test description Co-authored-by: Gustavo Antunes <17601467+gantunesr@users.noreply.github.com> --- app/util/address/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index 2904e6d6c0e..1ad7d236647 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -318,7 +318,7 @@ describe('getAccountLabelTextByKeyring,', () => { ); }); - it('should return "Snaps (beta)" if account is a Snap keyring', () => { + it('returns "Snaps (beta)" if account is a Snap keyring', () => { expect(getAccountLabelTextByKeyring(snapAddress)).toBe( 'accounts.snap_account_tag', ); From e4564c1f86d352f44c8a66b14e6de4a1231b5173 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Tue, 24 Sep 2024 12:42:13 -0400 Subject: [PATCH 11/26] fix: import KeyringTypes --- android/.project | 11 +++++++++++ android/.settings/org.eclipse.buildship.core.prefs | 11 +++++++++++ app/util/test/accountsControllerTestUtils.ts | 1 + 3 files changed, 23 insertions(+) diff --git a/android/.project b/android/.project index 3cf8618bf4c..708aba325aa 100644 --- a/android/.project +++ b/android/.project @@ -14,4 +14,15 @@ org.eclipse.buildship.core.gradleprojectnature + + + 1727190301267 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs index e8895216fd3..124792b65e1 100644 --- a/android/.settings/org.eclipse.buildship.core.prefs +++ b/android/.settings/org.eclipse.buildship.core.prefs @@ -1,2 +1,13 @@ +arguments=--init-script /var/folders/qx/hx5lzss962v1z0g1gwp6zl1m0000gn/T/db3b08fc4a9ef609cb16b96b200fa13e563f396e9bb1ed0905fdab7bc3bc513b.gradle --init-script /var/folders/qx/hx5lzss962v1z0g1gwp6zl1m0000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 +gradle.user.home= +java.home=/Users/katejohnson/Library/Java/JavaVirtualMachines/corretto-11.0.20.1/Contents/Home +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/app/util/test/accountsControllerTestUtils.ts b/app/util/test/accountsControllerTestUtils.ts index 3d3e8bccb01..983a0ba94f9 100644 --- a/app/util/test/accountsControllerTestUtils.ts +++ b/app/util/test/accountsControllerTestUtils.ts @@ -1,6 +1,7 @@ import { v4 as uuidV4 } from 'uuid'; import { EthMethod, InternalAccount } from '@metamask/keyring-api'; import { AccountsControllerState } from '@metamask/accounts-controller'; +import { KeyringTypes } from '@metamask/keyring-controller'; export function createMockUuidFromAddress(address: string): string { const fakeShaFromAddress = Array.from( From 99c574081b0507b0977cf3d2485547f5e888f9cf Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Tue, 24 Sep 2024 13:09:39 -0400 Subject: [PATCH 12/26] feat: updated 'getAccountLabelTextByKeyring' JSDOC --- android/.project | 11 ----------- android/.settings/org.eclipse.buildship.core.prefs | 11 ----------- app/util/address/index.ts | 2 +- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/android/.project b/android/.project index 708aba325aa..3cf8618bf4c 100644 --- a/android/.project +++ b/android/.project @@ -14,15 +14,4 @@ org.eclipse.buildship.core.gradleprojectnature - - - 1727190301267 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs index 124792b65e1..e8895216fd3 100644 --- a/android/.settings/org.eclipse.buildship.core.prefs +++ b/android/.settings/org.eclipse.buildship.core.prefs @@ -1,13 +1,2 @@ -arguments=--init-script /var/folders/qx/hx5lzss962v1z0g1gwp6zl1m0000gn/T/db3b08fc4a9ef609cb16b96b200fa13e563f396e9bb1ed0905fdab7bc3bc513b.gradle --init-script /var/folders/qx/hx5lzss962v1z0g1gwp6zl1m0000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle -auto.sync=false -build.scans.enabled=false -connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 -gradle.user.home= -java.home=/Users/katejohnson/Library/Java/JavaVirtualMachines/corretto-11.0.20.1/Contents/Home -jvm.arguments= -offline.mode=false -override.workspace.settings=true -show.console.view=true -show.executions.view=true diff --git a/app/util/address/index.ts b/app/util/address/index.ts index 21d72e55666..9fe72489b1d 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -233,7 +233,7 @@ export function isExternalHardwareAccount(address: string) { } /** - * gets i18n account label tag text based on keyring type + * gets i18n account label tag text based on the keyring type for that address * * @param {String} address - String corresponding to an address * @returns {String} - Returns address's i18n label text From adc12d6c490404e7c687a0417c309077840b2848 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Tue, 24 Sep 2024 13:35:42 -0400 Subject: [PATCH 13/26] revert: changes in ios/MetaMask.xcodeproj/project.pbxproj --- ios/MetaMask.xcodeproj/project.pbxproj | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/ios/MetaMask.xcodeproj/project.pbxproj b/ios/MetaMask.xcodeproj/project.pbxproj index 39437705987..314bc34f316 100644 --- a/ios/MetaMask.xcodeproj/project.pbxproj +++ b/ios/MetaMask.xcodeproj/project.pbxproj @@ -1555,11 +1555,7 @@ ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "$(inherited)"; OTHER_CPLUSPLUSFLAGS = "$(inherited)"; - OTHER_LDFLAGS = ( - "$(inherited)", - "-Wl", - "-ld_classic", - ); + OTHER_LDFLAGS = "$(inherited)"; REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; }; @@ -1603,11 +1599,7 @@ MTL_ENABLE_DEBUG_INFO = NO; OTHER_CFLAGS = "$(inherited)"; OTHER_CPLUSPLUSFLAGS = "$(inherited)"; - OTHER_LDFLAGS = ( - "$(inherited)", - "-Wl", - "-ld_classic", - ); + OTHER_LDFLAGS = "$(inherited)"; REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; From 40096a2e624cc26aa0e2775bb50ff35639242ac9 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Tue, 24 Sep 2024 15:28:24 -0400 Subject: [PATCH 14/26] feat: added getInternalAccount by address util --- .../AccountSelectorList.tsx | 2 +- app/util/address/index.ts | 22 ++++++++++++++----- ios/MetaMask.xcodeproj/project.pbxproj | 12 +++++----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx index 98c94f58cbd..79655ced3f1 100644 --- a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx +++ b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx @@ -200,7 +200,7 @@ const AccountSelectorList = ({ type: accountAvatarType, accountAddress: address, }} - tagLabel={tagLabel ? strings(tagLabel) : tagLabel} + tagLabel={tagLabel} disabled={isDisabled} style={cellStyle} > diff --git a/app/util/address/index.ts b/app/util/address/index.ts index 9fe72489b1d..108d7ee093b 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -232,6 +232,14 @@ export function isExternalHardwareAccount(address: string) { return isHardwareAccount(address, [ExtendedKeyringTypes.ledger]); } +function getInternalAccountByAddress(address: string): InternalAccount | null { + const { accounts } = Engine.context.AccountsController.state.internalAccounts; + const account = Object.values(accounts).find( + (a: InternalAccount) => a.address === address, + ); + return account || null; +} + /** * gets i18n account label tag text based on the keyring type for that address * @@ -240,18 +248,22 @@ export function isExternalHardwareAccount(address: string) { */ export function getAccountLabelTextByKeyring(address: string) { if (!address) return null; - const keyring = getKeyringByAddress(address); + const internalAccount = getInternalAccountByAddress(address); + const keyring = internalAccount?.metadata.keyring; if (keyring) { switch (keyring.type) { case ExtendedKeyringTypes.ledger: - return 'accounts.ledger'; + return strings('accounts.ledger'); case ExtendedKeyringTypes.qr: - return 'accounts.qr_hardware'; + return strings('accounts.qr_hardware'); case ExtendedKeyringTypes.simple: - return 'accounts.imported'; + return strings('accounts.imported'); ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) case KeyringTypes.snap: - return 'accounts.snap_account_tag'; + return ( + internalAccount?.metadata.snap?.name || + strings('account.snap_account_tag') + ); ///: END:ONLY_INCLUDE_IF } } diff --git a/ios/MetaMask.xcodeproj/project.pbxproj b/ios/MetaMask.xcodeproj/project.pbxproj index 314bc34f316..04eecdb3974 100644 --- a/ios/MetaMask.xcodeproj/project.pbxproj +++ b/ios/MetaMask.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 07CBADD9D4B441008304F8D3 /* EuclidCircularB-Light.otf in Resources */ = {isa = PBXBuildFile; fileRef = A98029A3662F4C1391489A6B /* EuclidCircularB-Light.otf */; }; 08B7A641467C4723B98328E9 /* CentraNo1-Medium.otf in Resources */ = {isa = PBXBuildFile; fileRef = F97653CAD1D04E1B8713C428 /* CentraNo1-Medium.otf */; }; - 0FD509E0336BF221F6527B24 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; + 0FD509E0336BF221F6527B24 /* (null) in Frameworks */ = {isa = PBXBuildFile; }; 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; @@ -134,7 +134,7 @@ B339FF2E289ABD70001B89FB /* EuclidCircularB-SemiboldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 9499B01ECAC44DA29AC44E80 /* EuclidCircularB-SemiboldItalic.otf */; }; B339FF32289ABD70001B89FB /* Branch.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 153F84C92319B8DB00C19B63 /* Branch.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B339FF3C289ABF2C001B89FB /* MetaMask-QA-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B339FEA72899852C001B89FB /* MetaMask-QA-Info.plist */; }; - B638844E306CAE9147B52C85 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; + B638844E306CAE9147B52C85 /* (null) in Frameworks */ = {isa = PBXBuildFile; }; BF39E5BAE0F34F9091FF6AC0 /* EuclidCircularB-Semibold.otf in Resources */ = {isa = PBXBuildFile; fileRef = A8DE9C5BC0714D648276E123 /* EuclidCircularB-Semibold.otf */; }; CD13D926E1E84D9ABFE672C0 /* Roboto-BlackItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 3E2492C67CF345CABD7B8601 /* Roboto-BlackItalic.ttf */; }; CF9895772A3B49BE00B4C9B5 /* RCTMinimizer.m in Sources */ = {isa = PBXBuildFile; fileRef = CF9895762A3B49BE00B4C9B5 /* RCTMinimizer.m */; }; @@ -142,7 +142,7 @@ CF98DA9C28D9FEB700096782 /* RCTScreenshotDetect.m in Sources */ = {isa = PBXBuildFile; fileRef = CF98DA9B28D9FEB700096782 /* RCTScreenshotDetect.m */; }; CFD8DFC828EDD4C800CC75F6 /* RCTScreenshotDetect.m in Sources */ = {isa = PBXBuildFile; fileRef = CF98DA9B28D9FEB700096782 /* RCTScreenshotDetect.m */; }; D171C39A8BD44DBEB6B68480 /* EuclidCircularB-MediumItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 42CBA652072F4BE2A8B815C1 /* EuclidCircularB-MediumItalic.otf */; }; - D45BF85DECACCB74EDCBE88A /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; + D45BF85DECACCB74EDCBE88A /* (null) in Frameworks */ = {isa = PBXBuildFile; }; D5BA0E32DFAA451781D5093E /* CentraNo1-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 4560812198A247039A1CF5A5 /* CentraNo1-BoldItalic.otf */; }; DADE8F39CE81410A98B9B805 /* MMSans-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2EBD310362314C3ABFF40AD1 /* MMSans-Regular.otf */; }; DC6A024F56DD43E1A83B47B1 /* Roboto-MediumItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D5FF0FF1DFB74B3C8BB99E09 /* Roboto-MediumItalic.ttf */; }; @@ -337,9 +337,9 @@ 650F2B9D24DC5FF200C3B9C4 /* libRCTAesForked.a in Frameworks */, 153C1ABB2217BCDC0088EFE0 /* JavaScriptCore.framework in Frameworks */, 153F84CA2319B8FD00C19B63 /* Branch.framework in Frameworks */, - 0FD509E0336BF221F6527B24 /* BuildFile in Frameworks */, - D45BF85DECACCB74EDCBE88A /* BuildFile in Frameworks */, - B638844E306CAE9147B52C85 /* BuildFile in Frameworks */, + 0FD509E0336BF221F6527B24 /* (null) in Frameworks */, + D45BF85DECACCB74EDCBE88A /* (null) in Frameworks */, + B638844E306CAE9147B52C85 /* (null) in Frameworks */, ED2E8FE6D71BE9319F3B27D3 /* libPods-MetaMask.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; From b19e128acb51d99028246a28c24147ef86210e28 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Thu, 26 Sep 2024 12:49:25 -0400 Subject: [PATCH 15/26] feat: JSDOC for 'getInternalAccountByAddress' --- app/util/address/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/util/address/index.ts b/app/util/address/index.ts index 108d7ee093b..ce51678bb63 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -232,6 +232,12 @@ export function isExternalHardwareAccount(address: string) { return isHardwareAccount(address, [ExtendedKeyringTypes.ledger]); } +/** + * gets the internal account by address + * + * @param {String} address - String corresponding to an address + * @returns {InternalAccount | null} - Returns the internal account by address + */ function getInternalAccountByAddress(address: string): InternalAccount | null { const { accounts } = Engine.context.AccountsController.state.internalAccounts; const account = Object.values(accounts).find( From a071a3a3a925fbf52e3a187cd435f163d7001094 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Mon, 30 Sep 2024 16:50:56 -0400 Subject: [PATCH 16/26] feat: update getLabelTextByAddress to apply translation and remove strings function from components --- .../Accounts/AccountBase/AccountBase.tsx | 2 +- .../Pickers/PickerAccount/PickerAccount.tsx | 2 +- .../components/Tags/Tag/Tag.tsx | 2 ++ .../UI/AccountFromToInfoCard/AddressFrom.tsx | 4 ++-- app/components/UI/AccountInfoCard/index.js | 6 ++--- app/components/UI/AccountOverview/index.js | 6 ++--- .../AccountSelectorList.tsx | 23 +++++++++++++++++-- app/components/UI/AddressInputs/index.js | 10 ++++---- app/components/UI/DrawerView/index.js | 6 ++--- .../UI/WalletAccount/WalletAccount.tsx | 4 ++-- .../AccountConnectSingle.tsx | 9 +++----- .../AddressElement/AddressElement.tsx | 6 ++--- app/util/address/index.ts | 21 +++++++++-------- 13 files changed, 61 insertions(+), 40 deletions(-) diff --git a/app/component-library/components-temp/Accounts/AccountBase/AccountBase.tsx b/app/component-library/components-temp/Accounts/AccountBase/AccountBase.tsx index 88e0f809d05..5f72f4e27fc 100644 --- a/app/component-library/components-temp/Accounts/AccountBase/AccountBase.tsx +++ b/app/component-library/components-temp/Accounts/AccountBase/AccountBase.tsx @@ -56,7 +56,7 @@ const AccountBase = ({ variant={TextVariant.BodyMDBold} style={styles.accountNameLabelText} > - {strings(accountTypeLabel)} + {accountTypeLabel} )} diff --git a/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx b/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx index ce9a9ab9014..59d4f8bbb98 100644 --- a/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx +++ b/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx @@ -62,7 +62,7 @@ const PickerAccount: React.ForwardRefRenderFunction< style={styles.accountNameLabelText} testID={AccountListViewSelectorsIDs.ACCOUNT_TYPE_LABEL} > - {strings(accountTypeLabel)} + {accountTypeLabel} )} {showAddress && ( diff --git a/app/component-library/components/Tags/Tag/Tag.tsx b/app/component-library/components/Tags/Tag/Tag.tsx index dc894af71e9..7e9cb9e40f6 100644 --- a/app/component-library/components/Tags/Tag/Tag.tsx +++ b/app/component-library/components/Tags/Tag/Tag.tsx @@ -15,6 +15,8 @@ import { TagProps } from './Tag.types'; const Tag = ({ label, style, ...props }: TagProps) => { const { styles } = useStyles(styleSheet, { style }); + console.log('label', label); + return ( {label} diff --git a/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx b/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx index a1fd929b8b6..8efc3818213 100644 --- a/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx +++ b/app/components/UI/AccountFromToInfoCard/AddressFrom.tsx @@ -14,7 +14,7 @@ import { selectNetworkName, } from '../../../selectors/networkInfos'; import { - getAccountLabelTextByKeyring, + getLabelTextByAddress, renderAccountName, } from '../../../util/address'; import useAddressBalance from '../../hooks/useAddressBalance/useAddressBalance'; @@ -76,7 +76,7 @@ const AddressFrom = ({ const networkImage = useSelector(selectNetworkImageSource); - const accountTypeLabel = getAccountLabelTextByKeyring(activeAddress); + const accountTypeLabel = getLabelTextByAddress(activeAddress); return ( diff --git a/app/components/UI/AccountInfoCard/index.js b/app/components/UI/AccountInfoCard/index.js index 4c227cc6cad..acc0ca47a9e 100644 --- a/app/components/UI/AccountInfoCard/index.js +++ b/app/components/UI/AccountInfoCard/index.js @@ -16,7 +16,7 @@ import { import { selectTicker } from '../../../selectors/networkController'; import { fontStyles } from '../../../styles/common'; import { - getAccountLabelTextByKeyring, + getLabelTextByAddress, renderAccountName, renderShortAddress, safeToChecksumAddress, @@ -153,7 +153,7 @@ class AccountInfoCard extends PureComponent { } = this.props; const fromAddress = safeToChecksumAddress(rawFromAddress); - const accountLabelTag = getAccountLabelTextByKeyring(fromAddress); + const accountLabelTag = getLabelTextByAddress(fromAddress); const colors = this.context.colors || mockTheme.colors; const styles = createStyles(colors); const weiBalance = accounts?.[fromAddress]?.balance @@ -233,7 +233,7 @@ class AccountInfoCard extends PureComponent { {accountLabelTag && ( - {strings(accountLabelTag)} + {accountLabelTag} )} diff --git a/app/components/UI/AccountOverview/index.js b/app/components/UI/AccountOverview/index.js index 5f620518441..1a73bb38746 100644 --- a/app/components/UI/AccountOverview/index.js +++ b/app/components/UI/AccountOverview/index.js @@ -22,7 +22,7 @@ import { isDefaultAccountName, } from '../../../util/ENSUtils'; import { - getAccountLabelTextByKeyring, + getLabelTextByAddress, renderAccountName, } from '../../../util/address'; import Device from '../../../util/device'; @@ -339,7 +339,7 @@ class AccountOverview extends PureComponent { if (!address) return null; const { accountLabelEditable, accountLabel, ens } = this.state; - const accountLabelTag = getAccountLabelTextByKeyring(address); + const accountLabelTag = getLabelTextByAddress(address); return ( @@ -417,7 +417,7 @@ class AccountOverview extends PureComponent { variant={TextVariant.BodySMBold} style={styles.tagText} > - {strings(accountLabelTag)} + {accountLabelTag} )} diff --git a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx index 79655ced3f1..ec712bf7474 100644 --- a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx +++ b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx @@ -16,7 +16,7 @@ import AvatarGroup from '../../../component-library/components/Avatars/AvatarGro import { formatAddress, safeToChecksumAddress, - getAccountLabelTextByKeyring, + getLabelTextByAddress, } from '../../../util/address'; import { AvatarAccountType } from '../../../component-library/components/Avatars/Avatar/variants/AvatarAccount'; import { isDefaultAccountName } from '../../../util/ENSUtils'; @@ -151,13 +151,31 @@ const AccountSelectorList = ({ ], ); + const getTagLabel = useCallback((address: string) => { + const label = getLabelTextByAddress(address); + console.log( + '[LABEL DEBUG] getTagLabel called for address:', + address, + 'label:', + label, + ); + return label; + }, []); + const renderAccountItem: ListRenderItem = useCallback( ({ item: { name, address, assets, type, isSelected, balanceError }, index, }) => { + console.log('[LABEL DEBUG] Rendering account item for address:', address); const shortAddress = formatAddress(address, 'short'); - const tagLabel = getAccountLabelTextByKeyring(address); + const tagLabel = getTagLabel(address); + console.log( + '[LABEL DEBUG] tagLabel for address:', + address, + 'is:', + tagLabel, + ); const ensName = ensByAccountAddress[address]; const accountName = isDefaultAccountName(name) && ensName ? ensName : name; @@ -220,6 +238,7 @@ const AccountSelectorList = ({ renderRightAccessory, isSelectionDisabled, onLongPress, + getTagLabel, ], ); diff --git a/app/components/UI/AddressInputs/index.js b/app/components/UI/AddressInputs/index.js index 394378820bd..47c7103657e 100644 --- a/app/components/UI/AddressInputs/index.js +++ b/app/components/UI/AddressInputs/index.js @@ -9,7 +9,7 @@ import { renderShortAddress, renderSlightlyLongAddress, isENS, - getAccountLabelTextByKeyring, + getLabelTextByAddress, } from '../../../util/address'; import { strings } from '../../../../locales/i18n'; import { hasZeroWidthPoints } from '../../../util/confusables'; @@ -219,7 +219,7 @@ const AddressName = ({ variant={TextVariant.BodySMBold} style={styles.accountNameLabelText} > - {strings(accountLabel)} + {accountLabel} )} @@ -252,7 +252,7 @@ export const AddressTo = (props) => { isFromAddressBook = false, layout = 'horizontal', } = props; - const accountLabel = getAccountLabelTextByKeyring(toSelectedAddress); + const accountLabel = getLabelTextByAddress(toSelectedAddress); const { colors, themeAppearance } = useTheme(); const styles = createStyles(colors, layout); @@ -582,7 +582,7 @@ export const AddressFrom = (props) => { fromAccountAddress, layout = 'horizontal', } = props; - const accountLabel = getAccountLabelTextByKeyring(fromAccountAddress); + const accountLabel = getLabelTextByAddress(fromAccountAddress); const { colors } = useTheme(); const styles = createStyles(colors, layout); @@ -608,7 +608,7 @@ export const AddressFrom = (props) => { variant={TextVariant.BodySMBold} style={styles.accountNameLabelText} > - {strings(accountLabel)} + {accountLabel} )} diff --git a/app/components/UI/DrawerView/index.js b/app/components/UI/DrawerView/index.js index e46d11fa33c..d3aea2d1ba5 100644 --- a/app/components/UI/DrawerView/index.js +++ b/app/components/UI/DrawerView/index.js @@ -61,7 +61,7 @@ import { ScrollView } from 'react-native-gesture-handler'; import { isZero } from '../../../util/lodash'; import { Authentication } from '../../../core/'; import { ThemeContext, mockTheme } from '../../../util/theme'; -import { getAccountLabelTextByKeyring } from '../../../util/address'; +import { getLabelTextByAddress } from '../../../util/address'; import { onboardNetworkAction, networkSwitched, @@ -485,12 +485,12 @@ class DrawerView extends PureComponent { renderTag() { const colors = this.context.colors || mockTheme.colors; const styles = createStyles(colors); - const label = getAccountLabelTextByKeyring(this.selectedChecksummedAddress); + const label = getLabelTextByAddress(this.selectedChecksummedAddress); return label ? ( - {strings(label)} + {label} ) : null; diff --git a/app/components/UI/WalletAccount/WalletAccount.tsx b/app/components/UI/WalletAccount/WalletAccount.tsx index 6470805e602..e96ea0e1e29 100644 --- a/app/components/UI/WalletAccount/WalletAccount.tsx +++ b/app/components/UI/WalletAccount/WalletAccount.tsx @@ -16,7 +16,7 @@ import ButtonIcon from '../../../component-library/components/Buttons/ButtonIcon import { ButtonIconSizes } from '../../../component-library/components/Buttons/ButtonIcon'; import Routes from '../../../constants/navigation/Routes'; import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors'; -import { getAccountLabelTextByKeyring } from '../../../util/address'; +import { getLabelTextByAddress } from '../../../util/address'; import { selectSelectedInternalAccount } from '../../../selectors/accountsController'; import useEnsNameByAddress from '../../../components/hooks/useEnsNameByAddress'; import Logger from '../../../util/Logger'; @@ -81,7 +81,7 @@ const WalletAccount = ({ style }: WalletAccountProps, ref: React.Ref) => { navigate(...createAccountSelectorNavDetails({})); }} accountTypeLabel={ - getAccountLabelTextByKeyring(selectedAccount?.address) || undefined + getLabelTextByAddress(selectedAccount?.address) || undefined } showAddress={false} cellAccountContainerStyle={styles.account} diff --git a/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx b/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx index 1521a90f76f..11215f3b902 100644 --- a/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx +++ b/app/components/Views/AccountConnect/AccountConnectSingle/AccountConnectSingle.tsx @@ -26,10 +26,7 @@ import Text, { TextColor, } from '../../../../component-library/components/Texts/Text'; import { useStyles } from '../../../../component-library/hooks'; -import { - formatAddress, - getAccountLabelTextByKeyring, -} from '../../../../util/address'; +import { formatAddress, getLabelTextByAddress } from '../../../../util/address'; import { AccountConnectScreens } from '../AccountConnect.types'; // Internal dependencies. @@ -135,7 +132,7 @@ const AccountConnectSingle = ({ if (!defaultSelectedAccount) return null; const { name, address, balanceError } = defaultSelectedAccount; const shortAddress = formatAddress(address, 'short'); - const tagLabel = getAccountLabelTextByKeyring(address); + const tagLabel = getLabelTextByAddress(address); return ( diff --git a/app/components/Views/confirmations/SendFlow/AddressElement/AddressElement.tsx b/app/components/Views/confirmations/SendFlow/AddressElement/AddressElement.tsx index 04a57fca6d6..f6a77ebcf89 100644 --- a/app/components/Views/confirmations/SendFlow/AddressElement/AddressElement.tsx +++ b/app/components/Views/confirmations/SendFlow/AddressElement/AddressElement.tsx @@ -7,7 +7,7 @@ import { View, TouchableOpacity } from 'react-native'; // Exgernal dependencies import { renderShortAddress, - getAccountLabelTextByKeyring, + getLabelTextByAddress, } from '../../../../../util/address'; import Identicon from '../../../../UI/Identicon'; import { useSelector } from 'react-redux'; @@ -58,7 +58,7 @@ const AddressElement: React.FC = ({ : renderShortAddress(address); const secondaryLabel = displayName && !displayName.startsWith(' ') && renderShortAddress(address); - const accountTypeLabel = getAccountLabelTextByKeyring(address); + const accountTypeLabel = getLabelTextByAddress(address); return ( = ({ variant={TextVariant.BodySM} style={styles.accountNameLabelText} > - {strings(accountTypeLabel)} + {accountTypeLabel} )} diff --git a/app/util/address/index.ts b/app/util/address/index.ts index ce51678bb63..c41e605aa46 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -48,6 +48,7 @@ import { Hex, isHexString } from '@metamask/utils'; const { ASSET: { ERC721, ERC1155 }, } = TransactionTypes; + /** * Returns full checksummed address * @@ -236,26 +237,27 @@ export function isExternalHardwareAccount(address: string) { * gets the internal account by address * * @param {String} address - String corresponding to an address - * @returns {InternalAccount | null} - Returns the internal account by address + * @returns {InternalAccount | undefined} - Returns the internal account by address */ -function getInternalAccountByAddress(address: string): InternalAccount | null { +function getInternalAccountByAddress( + address: string, +): InternalAccount | undefined { const { accounts } = Engine.context.AccountsController.state.internalAccounts; - const account = Object.values(accounts).find( + return Object.values(accounts).find( (a: InternalAccount) => a.address === address, ); - return account || null; } /** - * gets i18n account label tag text based on the keyring type for that address + * gets account label tag text based on address * * @param {String} address - String corresponding to an address - * @returns {String} - Returns address's i18n label text + * @returns {String} - Returns address's translated label text */ -export function getAccountLabelTextByKeyring(address: string) { +export function getLabelTextByAddress(address: string) { if (!address) return null; const internalAccount = getInternalAccountByAddress(address); - const keyring = internalAccount?.metadata.keyring; + const keyring = internalAccount?.metadata?.keyring; if (keyring) { switch (keyring.type) { case ExtendedKeyringTypes.ledger: @@ -268,7 +270,7 @@ export function getAccountLabelTextByKeyring(address: string) { case KeyringTypes.snap: return ( internalAccount?.metadata.snap?.name || - strings('account.snap_account_tag') + strings('accounts.snap_account_tag') ); ///: END:ONLY_INCLUDE_IF } @@ -560,6 +562,7 @@ export async function validateAddressOrENS( confusableCollection, }; } + /** Method to evaluate if an input is a valid ethereum address * via QR code scanning. * From c43ccab550b923d90ec76a4f9798902c6caa7353 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Thu, 3 Oct 2024 10:21:58 -0400 Subject: [PATCH 17/26] debugging --- .../AccountSelectorList.tsx | 19 +++---------------- app/util/address/index.ts | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx index ec712bf7474..c7eae53d715 100644 --- a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx +++ b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx @@ -15,8 +15,8 @@ import Text from '../../../component-library/components/Texts/Text'; import AvatarGroup from '../../../component-library/components/Avatars/AvatarGroup'; import { formatAddress, - safeToChecksumAddress, getLabelTextByAddress, + safeToChecksumAddress, } from '../../../util/address'; import { AvatarAccountType } from '../../../component-library/components/Avatars/Avatar/variants/AvatarAccount'; import { isDefaultAccountName } from '../../../util/ENSUtils'; @@ -151,27 +151,15 @@ const AccountSelectorList = ({ ], ); - const getTagLabel = useCallback((address: string) => { - const label = getLabelTextByAddress(address); - console.log( - '[LABEL DEBUG] getTagLabel called for address:', - address, - 'label:', - label, - ); - return label; - }, []); - const renderAccountItem: ListRenderItem = useCallback( ({ item: { name, address, assets, type, isSelected, balanceError }, index, }) => { - console.log('[LABEL DEBUG] Rendering account item for address:', address); const shortAddress = formatAddress(address, 'short'); - const tagLabel = getTagLabel(address); + const tagLabel = getLabelTextByAddress(address); console.log( - '[LABEL DEBUG] tagLabel for address:', + '[SNAP TAG LABEL DEBUG] tagLabel for address:', address, 'is:', tagLabel, @@ -238,7 +226,6 @@ const AccountSelectorList = ({ renderRightAccessory, isSelectionDisabled, onLongPress, - getTagLabel, ], ); diff --git a/app/util/address/index.ts b/app/util/address/index.ts index c41e605aa46..de491d593fe 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -268,13 +268,25 @@ export function getLabelTextByAddress(address: string) { return strings('accounts.imported'); ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) case KeyringTypes.snap: - return ( - internalAccount?.metadata.snap?.name || - strings('accounts.snap_account_tag') + console.log( + '[SNAP TAG LABEL DEBUG] getLabelTextByAddress: Snap name:', + internalAccount?.metadata.snap?.name, ); + const snapName = + internalAccount?.metadata.snap?.name || + strings('accounts.snap_account_tag'); + console.log('[SNAP TAG LABEL DEBUG] Returning label:', snapName); + return snapName; ///: END:ONLY_INCLUDE_IF + default: + console.log( + '[SNAP TAG LABEL DEBUG] Unexpected keyring type:', + keyring.type, + ); + return null; } } + console.log('[SNAP TAG LABEL DEBUG] Returning null'); return null; } From 5641df02d169db79dd38cdd2fa6255ba35e8f8a6 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Wed, 9 Oct 2024 10:53:31 -0400 Subject: [PATCH 18/26] feat: testing wip --- .../AccountSelector.test.tsx | 12 ++-- .../AccountSelectorList.tsx | 6 -- app/util/address/index.test.ts | 59 +++++++++++++++---- app/util/address/index.ts | 20 ++----- app/util/test/accountsControllerTestUtils.ts | 14 ++++- 5 files changed, 70 insertions(+), 41 deletions(-) diff --git a/app/components/UI/AccountSelectorList/AccountSelector.test.tsx b/app/components/UI/AccountSelectorList/AccountSelector.test.tsx index 306c88825c4..f2fe0c4eb69 100644 --- a/app/components/UI/AccountSelectorList/AccountSelector.test.tsx +++ b/app/components/UI/AccountSelectorList/AccountSelector.test.tsx @@ -205,11 +205,11 @@ describe('AccountSelectorList', () => { expect(within(accountNameItems[1]).getByText('Account 2')).toBeDefined(); }); }); - it('renders "Snaps (beta)" tag for Snap accounts', async () => { - const mockAccountsWithSnap = createMockAccountsControllerStateWithSnap([ - MOCK_ADDRESS_1, - MOCK_ADDRESS_2, - ]); + it('renders the snap name tag for Snap accounts', async () => { + const mockAccountsWithSnap = createMockAccountsControllerStateWithSnap( + [MOCK_ADDRESS_1, MOCK_ADDRESS_2], + 'MetaMask Simple Snap Keyring', + ); const stateWithSnapAccount = { ...initialState, @@ -225,7 +225,7 @@ describe('AccountSelectorList', () => { const { queryByText } = renderComponent(stateWithSnapAccount); await waitFor(async () => { - const snapTag = await queryByText('Snaps (beta)'); + const snapTag = await queryByText('MetaMask Simple Snap Keyring'); expect(snapTag).toBeDefined(); }); }); diff --git a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx index c7eae53d715..4b9ca3ecc53 100644 --- a/app/components/UI/AccountSelectorList/AccountSelectorList.tsx +++ b/app/components/UI/AccountSelectorList/AccountSelectorList.tsx @@ -158,12 +158,6 @@ const AccountSelectorList = ({ }) => { const shortAddress = formatAddress(address, 'short'); const tagLabel = getLabelTextByAddress(address); - console.log( - '[SNAP TAG LABEL DEBUG] tagLabel for address:', - address, - 'is:', - tagLabel, - ); const ensName = ensByAccountAddress[address]; const accountName = isDefaultAccountName(name) && ensName ? ensName : name; diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index 1ad7d236647..d61db5fa669 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -13,7 +13,7 @@ import { isHardwareAccount, resemblesAddress, getKeyringByAddress, - getAccountLabelTextByKeyring, + getLabelTextByAddress, } from '.'; import { mockHDKeyringAddress, @@ -22,27 +22,60 @@ import { } from '../test/keyringControllerTestUtils'; const snapAddress = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; +const namedSnapAddress = '0xC4966c0D659D99699BFD7EB54D8fafEE40e4a756'; jest.mock('../../core/Engine', () => { const { KeyringTypes } = jest.requireActual('@metamask/keyring-controller'); const { MOCK_KEYRING_CONTROLLER_STATE } = jest.requireActual( '../test/keyringControllerTestUtils', ); + const { MOCK_ACCOUNTS_CONTROLLER_STATE, expectedUuid2 } = jest.requireActual( + '../test/accountsControllerTestUtils', + ); return { + ...jest.requireActual('../../core/Engine'), context: { + ...jest.requireActual('../../core/Engine').context, KeyringController: { ...MOCK_KEYRING_CONTROLLER_STATE, state: { keyrings: [ ...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings, { - accounts: [snapAddress], + accounts: [snapAddress, namedSnapAddress], index: 0, type: KeyringTypes.snap, }, ], }, }, + AccountsController: { + ...jest.requireActual('../../core/Engine').context.AccountsController, + internalAccounts: { + ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts, + accounts: { + ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts, + [expectedUuid2]: { + ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ + expectedUuid2 + ], + metadata: { + ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ + expectedUuid2 + ].metadata, + keyring: { + type: KeyringTypes.snap, + }, + snap: { + id: 'metamask-snap-keyring', + name: 'MetaMask Simple Snap Keyring', + enabled: true, + }, + }, + }, + }, + }, + }, }, }; }); @@ -301,38 +334,42 @@ describe('isHardwareAccount,', () => { ).toBeFalsy(); }); }); -describe('getAccountLabelTextByKeyring,', () => { +describe('getLabelTextByAddress,', () => { beforeEach(() => { jest.resetAllMocks(); }); it('should return accounts.qr_hardware if account is a QR keyring', () => { - expect(getAccountLabelTextByKeyring(mockQrKeyringAddress)).toBe( + expect(getLabelTextByAddress(mockQrKeyringAddress)).toBe( 'accounts.qr_hardware', ); }); it('should return KeyringTypes.simple if address is a imported account', () => { - expect(getAccountLabelTextByKeyring(mockSimpleKeyringAddress)).toBe( + expect(getLabelTextByAddress(mockSimpleKeyringAddress)).toBe( 'accounts.imported', ); }); - it('returns "Snaps (beta)" if account is a Snap keyring', () => { - expect(getAccountLabelTextByKeyring(snapAddress)).toBe( + it('returns the snap name if account is a Snap keyring and there is a snap name', () => { + expect(getLabelTextByAddress(namedSnapAddress)).toBe( + 'MetaMask Simple Snap Keyring', + ); + }); + + it('returns "Snaps (beta)" if account is a Snap keyring and there is no snap name', () => { + expect(getLabelTextByAddress(snapAddress)).toBe( 'accounts.snap_account_tag', ); }); it('should return null if address is empty', () => { - expect(getAccountLabelTextByKeyring('')).toBe(null); + expect(getLabelTextByAddress('')).toBe(null); }); it('should return null if account not found', () => { expect( - getAccountLabelTextByKeyring( - '0xD5955C0d639D99699Bfd7Ec54d9FaFEe40e4D278', - ), + getLabelTextByAddress('0xD5955C0d639D99699Bfd7Ec54d9FaFEe40e4D278'), ).toBe(null); }); }); diff --git a/app/util/address/index.ts b/app/util/address/index.ts index de491d593fe..25a771c3097 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -244,7 +244,7 @@ function getInternalAccountByAddress( ): InternalAccount | undefined { const { accounts } = Engine.context.AccountsController.state.internalAccounts; return Object.values(accounts).find( - (a: InternalAccount) => a.address === address, + (a: InternalAccount) => a.address.toLowerCase() === address.toLowerCase(), ); } @@ -268,25 +268,13 @@ export function getLabelTextByAddress(address: string) { return strings('accounts.imported'); ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) case KeyringTypes.snap: - console.log( - '[SNAP TAG LABEL DEBUG] getLabelTextByAddress: Snap name:', - internalAccount?.metadata.snap?.name, - ); - const snapName = + return ( internalAccount?.metadata.snap?.name || - strings('accounts.snap_account_tag'); - console.log('[SNAP TAG LABEL DEBUG] Returning label:', snapName); - return snapName; - ///: END:ONLY_INCLUDE_IF - default: - console.log( - '[SNAP TAG LABEL DEBUG] Unexpected keyring type:', - keyring.type, + strings('accounts.snap_account_tag') ); - return null; + ///: END:ONLY_INCLUDE_IF } } - console.log('[SNAP TAG LABEL DEBUG] Returning null'); return null; } diff --git a/app/util/test/accountsControllerTestUtils.ts b/app/util/test/accountsControllerTestUtils.ts index 983a0ba94f9..e21cababa9d 100644 --- a/app/util/test/accountsControllerTestUtils.ts +++ b/app/util/test/accountsControllerTestUtils.ts @@ -103,6 +103,7 @@ export function createMockAccountsControllerState( export function createMockAccountsControllerStateWithSnap( addresses: string[], + snapName: string = '', snapAccountIndex: number = 0, ): AccountsControllerState { if (addresses.length === 0) { @@ -121,8 +122,17 @@ export function createMockAccountsControllerStateWithSnap( const snapAccountUuid = createMockUuidFromAddress( addresses[snapAccountIndex].toLowerCase(), ); - state.internalAccounts.accounts[snapAccountUuid].metadata.keyring = { - type: KeyringTypes.snap, + + state.internalAccounts.accounts[snapAccountUuid].metadata = { + ...state.internalAccounts.accounts[snapAccountUuid].metadata, + keyring: { + type: KeyringTypes.snap, + }, + snap: { + id: snapName, + name: snapName, + enabled: true, + }, }; return state; From c6ac84a9b3d86493b1f073ebb8b7b7373f98601b Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Wed, 9 Oct 2024 13:43:48 -0400 Subject: [PATCH 19/26] test: debugging address utils test --- app/util/address/index.test.ts | 108 ++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 36 deletions(-) diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index d61db5fa669..688b43f51e7 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -20,11 +20,14 @@ import { mockQrKeyringAddress, mockSimpleKeyringAddress, } from '../test/keyringControllerTestUtils'; - +import { RootState } from '../../reducers'; const snapAddress = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; const namedSnapAddress = '0xC4966c0D659D99699BFD7EB54D8fafEE40e4a756'; jest.mock('../../core/Engine', () => { + const { engine } = jest.requireActual( + '../test/initial-root-state', + ) as RootState; const { KeyringTypes } = jest.requireActual('@metamask/keyring-controller'); const { MOCK_KEYRING_CONTROLLER_STATE } = jest.requireActual( '../test/keyringControllerTestUtils', @@ -32,44 +35,46 @@ jest.mock('../../core/Engine', () => { const { MOCK_ACCOUNTS_CONTROLLER_STATE, expectedUuid2 } = jest.requireActual( '../test/accountsControllerTestUtils', ); - return { - ...jest.requireActual('../../core/Engine'), - context: { - ...jest.requireActual('../../core/Engine').context, - KeyringController: { - ...MOCK_KEYRING_CONTROLLER_STATE, - state: { - keyrings: [ - ...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings, - { - accounts: [snapAddress, namedSnapAddress], - index: 0, - type: KeyringTypes.snap, - }, - ], + const initialState = { + engine: { + backgroundState: { + ...engine.backgroundState, + KeyringController: { + ...MOCK_KEYRING_CONTROLLER_STATE, + state: { + keyrings: [ + ...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings, + { + accounts: [snapAddress], + index: 0, + type: KeyringTypes.snap, + }, + ], + }, }, - }, - AccountsController: { - ...jest.requireActual('../../core/Engine').context.AccountsController, - internalAccounts: { - ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts, - accounts: { - ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts, - [expectedUuid2]: { - ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ - expectedUuid2 - ], - metadata: { + AccountsController: { + ...engine.backgroundState.AccountsController, + internalAccounts: { + ...engine.backgroundState.AccountsController.internalAccounts, + accounts: { + ...engine.backgroundState.AccountsController.internalAccounts + .accounts, + [expectedUuid2]: { ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ expectedUuid2 - ].metadata, - keyring: { - type: KeyringTypes.snap, - }, - snap: { - id: 'metamask-snap-keyring', - name: 'MetaMask Simple Snap Keyring', - enabled: true, + ], + metadata: { + ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ + expectedUuid2 + ].metadata, + keyring: { + type: KeyringTypes.snap, + }, + snap: { + id: 'metamask-snap-keyring', + name: 'MetaMask Simple Snap Keyring', + enabled: true, + }, }, }, }, @@ -78,6 +83,11 @@ jest.mock('../../core/Engine', () => { }, }, }; + return { + context: { + ...initialState.engine.backgroundState, + }, + }; }); describe('isENS', () => { @@ -352,6 +362,32 @@ describe('getLabelTextByAddress,', () => { }); it('returns the snap name if account is a Snap keyring and there is a snap name', () => { + // Engine.context.AccountsController = { + // internalAccounts: { + // ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts, + // accounts: { + // ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts, + // [expectedUuid2]: { + // ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ + // expectedUuid2 + // ], + // metadata: { + // ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ + // expectedUuid2 + // ].metadata, + // keyring: { + // type: KeyringTypes.snap, + // }, + // snap: { + // id: 'metamask-snap-keyring', + // name: 'MetaMask Simple Snap Keyring', + // enabled: true, + // }, + // }, + // }, + // }, + // }, + // } as Partial as AccountsController; expect(getLabelTextByAddress(namedSnapAddress)).toBe( 'MetaMask Simple Snap Keyring', ); From f01bbd00354a3c816048ff59e0305d17473bfebb Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Wed, 9 Oct 2024 14:59:42 -0400 Subject: [PATCH 20/26] test: debugging unit tests --- app/util/address/index.test.ts | 122 +++++++++++---------------------- 1 file changed, 41 insertions(+), 81 deletions(-) diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index 688b43f51e7..4e6a75f6dbd 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -20,74 +20,34 @@ import { mockQrKeyringAddress, mockSimpleKeyringAddress, } from '../test/keyringControllerTestUtils'; -import { RootState } from '../../reducers'; +import initialRootState from '../test/initial-root-state'; +import { expectedUuid2 } from '../test/accountsControllerTestUtils'; + const snapAddress = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; const namedSnapAddress = '0xC4966c0D659D99699BFD7EB54D8fafEE40e4a756'; jest.mock('../../core/Engine', () => { - const { engine } = jest.requireActual( - '../test/initial-root-state', - ) as RootState; const { KeyringTypes } = jest.requireActual('@metamask/keyring-controller'); const { MOCK_KEYRING_CONTROLLER_STATE } = jest.requireActual( '../test/keyringControllerTestUtils', ); - const { MOCK_ACCOUNTS_CONTROLLER_STATE, expectedUuid2 } = jest.requireActual( - '../test/accountsControllerTestUtils', - ); - const initialState = { - engine: { - backgroundState: { - ...engine.backgroundState, - KeyringController: { - ...MOCK_KEYRING_CONTROLLER_STATE, - state: { - keyrings: [ - ...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings, - { - accounts: [snapAddress], - index: 0, - type: KeyringTypes.snap, - }, - ], - }, - }, - AccountsController: { - ...engine.backgroundState.AccountsController, - internalAccounts: { - ...engine.backgroundState.AccountsController.internalAccounts, - accounts: { - ...engine.backgroundState.AccountsController.internalAccounts - .accounts, - [expectedUuid2]: { - ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ - expectedUuid2 - ], - metadata: { - ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ - expectedUuid2 - ].metadata, - keyring: { - type: KeyringTypes.snap, - }, - snap: { - id: 'metamask-snap-keyring', - name: 'MetaMask Simple Snap Keyring', - enabled: true, - }, - }, - }, + return { + context: { + KeyringController: { + ...MOCK_KEYRING_CONTROLLER_STATE, + state: { + keyrings: [ + ...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings, + { + accounts: [snapAddress], + index: 0, + type: KeyringTypes.snap, }, - }, + ], }, }, }, }; - return { - context: { - ...initialState.engine.backgroundState, - }, - }; }); describe('isENS', () => { @@ -346,6 +306,32 @@ describe('isHardwareAccount,', () => { }); describe('getLabelTextByAddress,', () => { beforeEach(() => { + const { engine } = initialRootState; + engine.backgroundState.AccountsController = { + internalAccounts: { + ...engine.backgroundState.AccountsController.internalAccounts, + accounts: { + ...engine.backgroundState.AccountsController.internalAccounts + .accounts, + [expectedUuid2]: { + ...engine.backgroundState.AccountsController.internalAccounts + .accounts[expectedUuid2], + metadata: { + ...engine.backgroundState.AccountsController.internalAccounts + .accounts[expectedUuid2].metadata, + keyring: { + type: 'Snap Keyring', + }, + snap: { + id: 'metamask-snap-keyring', + name: 'MetaMask Simple Snap Keyring', + enabled: true, + }, + }, + }, + }, + }, + }; jest.resetAllMocks(); }); @@ -362,32 +348,6 @@ describe('getLabelTextByAddress,', () => { }); it('returns the snap name if account is a Snap keyring and there is a snap name', () => { - // Engine.context.AccountsController = { - // internalAccounts: { - // ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts, - // accounts: { - // ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts, - // [expectedUuid2]: { - // ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ - // expectedUuid2 - // ], - // metadata: { - // ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[ - // expectedUuid2 - // ].metadata, - // keyring: { - // type: KeyringTypes.snap, - // }, - // snap: { - // id: 'metamask-snap-keyring', - // name: 'MetaMask Simple Snap Keyring', - // enabled: true, - // }, - // }, - // }, - // }, - // }, - // } as Partial as AccountsController; expect(getLabelTextByAddress(namedSnapAddress)).toBe( 'MetaMask Simple Snap Keyring', ); From 368fd195a79409c57547fa924a6e20bd37522ff9 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Tue, 15 Oct 2024 16:45:17 -0400 Subject: [PATCH 21/26] feat: updated test to not use translation key --- app/util/address/index.test.ts | 44 +++------------------------------- 1 file changed, 3 insertions(+), 41 deletions(-) diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index 4e6a75f6dbd..d6dde3f7384 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -20,8 +20,6 @@ import { mockQrKeyringAddress, mockSimpleKeyringAddress, } from '../test/keyringControllerTestUtils'; -import initialRootState from '../test/initial-root-state'; -import { expectedUuid2 } from '../test/accountsControllerTestUtils'; const snapAddress = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; const namedSnapAddress = '0xC4966c0D659D99699BFD7EB54D8fafEE40e4a756'; @@ -305,46 +303,12 @@ describe('isHardwareAccount,', () => { }); }); describe('getLabelTextByAddress,', () => { - beforeEach(() => { - const { engine } = initialRootState; - engine.backgroundState.AccountsController = { - internalAccounts: { - ...engine.backgroundState.AccountsController.internalAccounts, - accounts: { - ...engine.backgroundState.AccountsController.internalAccounts - .accounts, - [expectedUuid2]: { - ...engine.backgroundState.AccountsController.internalAccounts - .accounts[expectedUuid2], - metadata: { - ...engine.backgroundState.AccountsController.internalAccounts - .accounts[expectedUuid2].metadata, - keyring: { - type: 'Snap Keyring', - }, - snap: { - id: 'metamask-snap-keyring', - name: 'MetaMask Simple Snap Keyring', - enabled: true, - }, - }, - }, - }, - }, - }; - jest.resetAllMocks(); - }); - it('should return accounts.qr_hardware if account is a QR keyring', () => { - expect(getLabelTextByAddress(mockQrKeyringAddress)).toBe( - 'accounts.qr_hardware', - ); + expect(getLabelTextByAddress(mockQrKeyringAddress)).toBe('QR hardware'); }); it('should return KeyringTypes.simple if address is a imported account', () => { - expect(getLabelTextByAddress(mockSimpleKeyringAddress)).toBe( - 'accounts.imported', - ); + expect(getLabelTextByAddress(mockSimpleKeyringAddress)).toBe('Imported'); }); it('returns the snap name if account is a Snap keyring and there is a snap name', () => { @@ -354,9 +318,7 @@ describe('getLabelTextByAddress,', () => { }); it('returns "Snaps (beta)" if account is a Snap keyring and there is no snap name', () => { - expect(getLabelTextByAddress(snapAddress)).toBe( - 'accounts.snap_account_tag', - ); + expect(getLabelTextByAddress(snapAddress)).toBe('Snaps (beta)'); }); it('should return null if address is empty', () => { From 8039293617b8dc509ae7fde4ad8089f452927bf8 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Tue, 15 Oct 2024 17:09:23 -0400 Subject: [PATCH 22/26] feat: remove console logs in Tag --- .../components/Tags/Tag/Tag.tsx | 2 - app/util/address/index.test.ts | 50 +++++++++++++------ app/util/address/index.ts | 4 +- ios/MetaMask.xcodeproj/project.pbxproj | 12 ++--- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/app/component-library/components/Tags/Tag/Tag.tsx b/app/component-library/components/Tags/Tag/Tag.tsx index 7e9cb9e40f6..dc894af71e9 100644 --- a/app/component-library/components/Tags/Tag/Tag.tsx +++ b/app/component-library/components/Tags/Tag/Tag.tsx @@ -15,8 +15,6 @@ import { TagProps } from './Tag.types'; const Tag = ({ label, style, ...props }: TagProps) => { const { styles } = useStyles(styleSheet, { style }); - console.log('label', label); - return ( {label} diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index d6dde3f7384..ce5c97c6890 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -1,4 +1,4 @@ -import { NetworkState } from '@metamask/network-controller'; +import { NetworkState, RpcEndpointType } from '@metamask/network-controller'; import { isENS, renderSlightlyLongAddress, @@ -201,19 +201,30 @@ describe('getAddress', () => { }); describe('shouldShowBlockExplorer', () => { - const networkConfigurations: NetworkState['networkConfigurations'] = { - networkId1: { - id: 'networkId1', - chainId: '0x1', - nickname: 'Main Ethereum Network', - ticker: 'USD', - rpcUrl: 'https://mainnet.infura.io/v3/123', - }, - }; + const networkConfigurations: NetworkState['networkConfigurationsByChainId'] = + { + '0x1': { + blockExplorerUrls: [], + chainId: '0x1', + defaultRpcEndpointIndex: 0, + name: 'Main Ethereum Network', + nativeCurrency: 'USD', + rpcEndpoints: [ + { + networkClientId: 'networkId1', + type: RpcEndpointType.Custom, + url: 'https://mainnet.infura.io/v3/123', + }, + ], + }, + }; it('returns true if provider type is not rpc', () => { const providerType = 'mainnet'; - const providerRpcTarget = networkConfigurations.networkId1.rpcUrl; + + const providerRpcTarget = networkConfigurations['0x1'].rpcEndpoints.find( + ({ networkClientId }) => networkClientId === 'networkId1', + )?.url as string; const result = shouldShowBlockExplorer( providerType, @@ -226,9 +237,14 @@ describe('shouldShowBlockExplorer', () => { it('returns block explorer URL if defined', () => { const providerType = 'rpc'; - const providerRpcTarget = networkConfigurations.networkId1.rpcUrl; + const providerRpcTarget = networkConfigurations['0x1'].rpcEndpoints.find( + ({ networkClientId }) => networkClientId === 'networkId1', + )?.url as string; + const blockExplorerUrl = 'https://rpc.testnet.fantom.network'; - networkConfigurations.networkId1.rpcPrefs = { blockExplorerUrl }; + + networkConfigurations['0x1'].blockExplorerUrls = [blockExplorerUrl]; + networkConfigurations['0x1'].defaultBlockExplorerUrlIndex = 0; const result = shouldShowBlockExplorer( providerType, @@ -241,8 +257,12 @@ describe('shouldShowBlockExplorer', () => { it('returns undefined if block explorer URL is not defined', () => { const providerType = 'rpc'; - const providerRpcTarget = networkConfigurations.networkId1.rpcUrl; - networkConfigurations.networkId1.rpcPrefs = undefined; + + const providerRpcTarget = networkConfigurations['0x1'].rpcEndpoints.find( + ({ networkClientId }) => networkClientId === 'networkId1', + )?.url as string; + + networkConfigurations['0x1'].blockExplorerUrls = []; const result = shouldShowBlockExplorer( providerType, diff --git a/app/util/address/index.ts b/app/util/address/index.ts index 25a771c3097..92163eb5aad 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -48,7 +48,6 @@ import { Hex, isHexString } from '@metamask/utils'; const { ASSET: { ERC721, ERC1155 }, } = TransactionTypes; - /** * Returns full checksummed address * @@ -562,7 +561,6 @@ export async function validateAddressOrENS( confusableCollection, }; } - /** Method to evaluate if an input is a valid ethereum address * via QR code scanning. * @@ -656,7 +654,7 @@ export const getTokenDecimal = async ( export const shouldShowBlockExplorer = ( providerType: NetworkType, providerRpcTarget: string, - networkConfigurations: NetworkState['networkConfigurations'], + networkConfigurations: NetworkState['networkConfigurationsByChainId'], ) => { if (providerType === RPC) { return findBlockExplorerForRpc(providerRpcTarget, networkConfigurations); diff --git a/ios/MetaMask.xcodeproj/project.pbxproj b/ios/MetaMask.xcodeproj/project.pbxproj index 04eecdb3974..314bc34f316 100644 --- a/ios/MetaMask.xcodeproj/project.pbxproj +++ b/ios/MetaMask.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 07CBADD9D4B441008304F8D3 /* EuclidCircularB-Light.otf in Resources */ = {isa = PBXBuildFile; fileRef = A98029A3662F4C1391489A6B /* EuclidCircularB-Light.otf */; }; 08B7A641467C4723B98328E9 /* CentraNo1-Medium.otf in Resources */ = {isa = PBXBuildFile; fileRef = F97653CAD1D04E1B8713C428 /* CentraNo1-Medium.otf */; }; - 0FD509E0336BF221F6527B24 /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + 0FD509E0336BF221F6527B24 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; @@ -134,7 +134,7 @@ B339FF2E289ABD70001B89FB /* EuclidCircularB-SemiboldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 9499B01ECAC44DA29AC44E80 /* EuclidCircularB-SemiboldItalic.otf */; }; B339FF32289ABD70001B89FB /* Branch.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 153F84C92319B8DB00C19B63 /* Branch.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; B339FF3C289ABF2C001B89FB /* MetaMask-QA-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B339FEA72899852C001B89FB /* MetaMask-QA-Info.plist */; }; - B638844E306CAE9147B52C85 /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + B638844E306CAE9147B52C85 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; BF39E5BAE0F34F9091FF6AC0 /* EuclidCircularB-Semibold.otf in Resources */ = {isa = PBXBuildFile; fileRef = A8DE9C5BC0714D648276E123 /* EuclidCircularB-Semibold.otf */; }; CD13D926E1E84D9ABFE672C0 /* Roboto-BlackItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 3E2492C67CF345CABD7B8601 /* Roboto-BlackItalic.ttf */; }; CF9895772A3B49BE00B4C9B5 /* RCTMinimizer.m in Sources */ = {isa = PBXBuildFile; fileRef = CF9895762A3B49BE00B4C9B5 /* RCTMinimizer.m */; }; @@ -142,7 +142,7 @@ CF98DA9C28D9FEB700096782 /* RCTScreenshotDetect.m in Sources */ = {isa = PBXBuildFile; fileRef = CF98DA9B28D9FEB700096782 /* RCTScreenshotDetect.m */; }; CFD8DFC828EDD4C800CC75F6 /* RCTScreenshotDetect.m in Sources */ = {isa = PBXBuildFile; fileRef = CF98DA9B28D9FEB700096782 /* RCTScreenshotDetect.m */; }; D171C39A8BD44DBEB6B68480 /* EuclidCircularB-MediumItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 42CBA652072F4BE2A8B815C1 /* EuclidCircularB-MediumItalic.otf */; }; - D45BF85DECACCB74EDCBE88A /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + D45BF85DECACCB74EDCBE88A /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; D5BA0E32DFAA451781D5093E /* CentraNo1-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 4560812198A247039A1CF5A5 /* CentraNo1-BoldItalic.otf */; }; DADE8F39CE81410A98B9B805 /* MMSans-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2EBD310362314C3ABFF40AD1 /* MMSans-Regular.otf */; }; DC6A024F56DD43E1A83B47B1 /* Roboto-MediumItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D5FF0FF1DFB74B3C8BB99E09 /* Roboto-MediumItalic.ttf */; }; @@ -337,9 +337,9 @@ 650F2B9D24DC5FF200C3B9C4 /* libRCTAesForked.a in Frameworks */, 153C1ABB2217BCDC0088EFE0 /* JavaScriptCore.framework in Frameworks */, 153F84CA2319B8FD00C19B63 /* Branch.framework in Frameworks */, - 0FD509E0336BF221F6527B24 /* (null) in Frameworks */, - D45BF85DECACCB74EDCBE88A /* (null) in Frameworks */, - B638844E306CAE9147B52C85 /* (null) in Frameworks */, + 0FD509E0336BF221F6527B24 /* BuildFile in Frameworks */, + D45BF85DECACCB74EDCBE88A /* BuildFile in Frameworks */, + B638844E306CAE9147B52C85 /* BuildFile in Frameworks */, ED2E8FE6D71BE9319F3B27D3 /* libPods-MetaMask.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; From 6d8867c3d0a7e909393e9d58342470f8926b702b Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Tue, 15 Oct 2024 17:11:00 -0400 Subject: [PATCH 23/26] chore: update AccountsSelector snapshot --- .../AccountSelector.test.tsx.snap | 2310 ++++++++--------- 1 file changed, 1119 insertions(+), 1191 deletions(-) diff --git a/app/components/UI/AccountSelectorList/__snapshots__/AccountSelector.test.tsx.snap b/app/components/UI/AccountSelectorList/__snapshots__/AccountSelector.test.tsx.snap index ecf6585df78..49c9d6e96b1 100644 --- a/app/components/UI/AccountSelectorList/__snapshots__/AccountSelector.test.tsx.snap +++ b/app/components/UI/AccountSelectorList/__snapshots__/AccountSelector.test.tsx.snap @@ -65,7 +65,6 @@ exports[`AccountSelectorList renders all accounts with balances 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, - "padding": 16, "position": "relative", } } @@ -76,237 +75,244 @@ exports[`AccountSelectorList renders all accounts with balances 1`] = ` accessible={true} style={ { - "alignItems": "center", - "flexDirection": "row", - "padding": 0, + "padding": 16, } } > - - - - + - - - + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + - - - - Account 1 - - - 0xC495...D272 - - - + Account 1 + + - $3200.00 -1 ETH + 0xC495...D272 + + + + $3200.00 +1 ETH + + + @@ -352,7 +358,6 @@ exports[`AccountSelectorList renders all accounts with balances 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, - "padding": 16, "position": "relative", } } @@ -363,223 +368,200 @@ exports[`AccountSelectorList renders all accounts with balances 1`] = ` accessible={true} style={ { - "alignItems": "center", - "flexDirection": "row", - "padding": 0, + "padding": 16, } } > - - - - + - - - + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + - - - - Account 2 - - - 0xd018...78E7 - + Account 2 + + - Imported + 0xd018...78E7 - - - - $6400.00 + + $6400.00 2 ETH - + + @@ -699,7 +681,6 @@ exports[`AccountSelectorList renders all accounts with right accessory 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, - "padding": 16, "position": "relative", } } @@ -710,215 +691,222 @@ exports[`AccountSelectorList renders all accounts with right accessory 1`] = ` accessible={true} style={ { - "alignItems": "center", - "flexDirection": "row", - "padding": 0, + "padding": 16, } } > - - - - + - - - + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + - - - - Account 1 - - + Account 1 + + + 0xC495...D272 + + + - 0xC495...D272 - - - - - 0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272 - Account 1 + + 0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272 - Account 1 + @@ -939,7 +927,6 @@ exports[`AccountSelectorList renders all accounts with right accessory 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, - "padding": 16, "position": "relative", } } @@ -950,223 +937,200 @@ exports[`AccountSelectorList renders all accounts with right accessory 1`] = ` accessible={true} style={ { - "alignItems": "center", - "flexDirection": "row", - "padding": 0, + "padding": 16, } } > - - - - + - - - + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + - - - - Account 2 - - - 0xd018...78E7 - + Account 2 + + - Imported + 0xd018...78E7 - - - 0xd018538C87232FF95acbCe4870629b75640a78E7 - Account 2 + + 0xd018538C87232FF95acbCe4870629b75640a78E7 - Account 2 + @@ -1264,7 +1228,6 @@ exports[`AccountSelectorList renders correctly 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, - "padding": 16, "position": "relative", } } @@ -1275,237 +1238,244 @@ exports[`AccountSelectorList renders correctly 1`] = ` accessible={true} style={ { - "alignItems": "center", - "flexDirection": "row", - "padding": 0, + "padding": 16, } } > - - - - + - - - + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + - - - - Account 1 - - - 0xC495...D272 - - - + Account 1 + + - $3200.00 -1 ETH + 0xC495...D272 + + + + $3200.00 +1 ETH + + + @@ -1551,7 +1521,6 @@ exports[`AccountSelectorList renders correctly 1`] = ` "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, - "padding": 16, "position": "relative", } } @@ -1562,223 +1531,200 @@ exports[`AccountSelectorList renders correctly 1`] = ` accessible={true} style={ { - "alignItems": "center", - "flexDirection": "row", - "padding": 0, + "padding": 16, } } > - - - - + - - - + propList={ + [ + "fill", + ] + } + width={32} + x={0} + y={0} + /> + + + + + - - - - Account 2 - - - 0xd018...78E7 - + Account 2 + + - Imported + 0xd018...78E7 - - - - $6400.00 + + $6400.00 2 ETH - + + @@ -1894,7 +1840,6 @@ exports[`AccountSelectorList should render all accounts but only the balance for "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, - "padding": 16, "position": "relative", } } @@ -1905,121 +1850,128 @@ exports[`AccountSelectorList should render all accounts but only the balance for accessible={true} style={ { - "alignItems": "center", - "flexDirection": "row", - "padding": 0, + "padding": 16, } } > - - - - - Account 1 - - + style={ + { + "flex": 1, + } + } + /> + + Account 1 + + - $3200.00 -1 ETH + 0xC495...D272 + + + + $3200.00 +1 ETH + + + @@ -2065,7 +2017,6 @@ exports[`AccountSelectorList should render all accounts but only the balance for "backgroundColor": "#ffffff", "borderRadius": 4, "opacity": 1, - "padding": 16, "position": "relative", } } @@ -2076,107 +2027,84 @@ exports[`AccountSelectorList should render all accounts but only the balance for accessible={true} style={ { - "alignItems": "center", - "flexDirection": "row", - "padding": 0, + "padding": 16, } } > - - - - - Account 2 - - + + Account 2 + + - Imported + 0xd018...78E7 From bc2c2dffd17cab08b555c1d727ebc5783ed46231 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Tue, 15 Oct 2024 17:54:31 -0400 Subject: [PATCH 24/26] feat: testing getLabelTextByAddress modifying test utils wip --- app/util/address/index.test.ts | 22 ++--- app/util/test/accountsControllerTestUtils.ts | 93 ++++++++++++++++++-- app/util/test/keyringControllerTestUtils.ts | 6 ++ 3 files changed, 97 insertions(+), 24 deletions(-) diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index ce5c97c6890..50042e241f1 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -25,24 +25,12 @@ const snapAddress = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; const namedSnapAddress = '0xC4966c0D659D99699BFD7EB54D8fafEE40e4a756'; jest.mock('../../core/Engine', () => { - const { KeyringTypes } = jest.requireActual('@metamask/keyring-controller'); - const { MOCK_KEYRING_CONTROLLER_STATE } = jest.requireActual( - '../test/keyringControllerTestUtils', - ); + const { MOCK_ACCOUNTS_CONTROLLER_STATE_WITH_KEYRING_TYPES } = + jest.requireActual('../test/accountsControllerTestUtils'); return { context: { - KeyringController: { - ...MOCK_KEYRING_CONTROLLER_STATE, - state: { - keyrings: [ - ...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings, - { - accounts: [snapAddress], - index: 0, - type: KeyringTypes.snap, - }, - ], - }, + AccountsController: { + state: MOCK_ACCOUNTS_CONTROLLER_STATE_WITH_KEYRING_TYPES, }, }, }; @@ -322,7 +310,7 @@ describe('isHardwareAccount,', () => { ).toBeFalsy(); }); }); -describe('getLabelTextByAddress,', () => { +describe.only('getLabelTextByAddress,', () => { it('should return accounts.qr_hardware if account is a QR keyring', () => { expect(getLabelTextByAddress(mockQrKeyringAddress)).toBe('QR hardware'); }); diff --git a/app/util/test/accountsControllerTestUtils.ts b/app/util/test/accountsControllerTestUtils.ts index e21cababa9d..278d1c22f02 100644 --- a/app/util/test/accountsControllerTestUtils.ts +++ b/app/util/test/accountsControllerTestUtils.ts @@ -2,6 +2,12 @@ import { v4 as uuidV4 } from 'uuid'; import { EthMethod, InternalAccount } from '@metamask/keyring-api'; import { AccountsControllerState } from '@metamask/accounts-controller'; import { KeyringTypes } from '@metamask/keyring-controller'; +import { + mockQrKeyringAddress, + mockSimpleKeyringAddress, + mockSnapAddress1, + mockSnapAddress2, +} from './keyringControllerTestUtils'; export function createMockUuidFromAddress(address: string): string { const fakeShaFromAddress = Array.from( @@ -16,17 +22,31 @@ export function createMockUuidFromAddress(address: string): string { export function createMockInternalAccount( address: string, nickname: string, + keyringType: KeyringTypes = KeyringTypes.hd, ): InternalAccount { + const genericMetadata = { + name: nickname, + importTime: 1684232000456, + keyring: { + type: keyringType, + }, + }; + const snapMetadata = { + name: nickname, + importTime: 1684232000456, + keyring: { + type: KeyringTypes.snap, + }, + snap: { + id: 'snap-id', + enabled: true, + }, + }; return { address, id: createMockUuidFromAddress(address), - metadata: { - name: nickname, - importTime: 1684232000456, - keyring: { - type: 'HD Key Tree', - }, - }, + metadata: + keyringType === KeyringTypes.snap ? snapMetadata : genericMetadata, options: {}, methods: [ EthMethod.PersonalSign, @@ -71,6 +91,65 @@ export const MOCK_ACCOUNTS_CONTROLLER_STATE: AccountsControllerState = { }, }; +// account IDs for different account types from MOCK_KEYRING_CONTROLLER_STATE +export const mockQRHardwareAccountId = + createMockUuidFromAddress(mockQrKeyringAddress); +export const mockSimpleKeyringAccountId = createMockUuidFromAddress( + mockSimpleKeyringAddress, +); +export const mockSnapAccount1Id = createMockUuidFromAddress(mockSnapAddress1); +export const mockSnapAccount2Id = createMockUuidFromAddress(mockSnapAddress2); +// internal accounts for different account types from MOCK_KEYRING_CONTROLLER_STATE +const mockQRHardwareInternalAccount: InternalAccount = + createMockInternalAccount( + mockQrKeyringAddress, + 'QR Hardware Account', + KeyringTypes.qr, + ); +const mockSimpleKeyringInternalAccount: InternalAccount = + createMockInternalAccount( + mockSimpleKeyringAddress, + 'Simple Keyring Account', + KeyringTypes.simple, + ); +const mockSnapAccount1InternalAccount: InternalAccount = + createMockInternalAccount( + mockSnapAddress1, + 'Snap Account 1', + KeyringTypes.snap, + ); +const mockSnapAccount2InternalAccount: InternalAccount = + createMockInternalAccount( + mockSnapAddress2, + 'Snap Account 2', + KeyringTypes.snap, + ); + +export const MOCK_ACCOUNTS_CONTROLLER_STATE_WITH_KEYRING_TYPES: AccountsControllerState = + { + ...MOCK_ACCOUNTS_CONTROLLER_STATE, + internalAccounts: { + ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts, + accounts: { + ...MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts, + [mockQRHardwareAccountId]: mockQRHardwareInternalAccount, + [mockSimpleKeyringAccountId]: mockSimpleKeyringInternalAccount, + [mockSnapAccount1Id]: mockSnapAccount1InternalAccount, + [mockSnapAccount2Id]: { + ...mockSnapAccount2InternalAccount, + metadata: { + ...mockSnapAccount2InternalAccount.metadata, + snap: { + id: 'metamask-simple-snap-keyring', + name: 'MetaMask Simple Snap Keyring', + enabled: true, + }, + }, + }, + }, + }, + }; + export function createMockAccountsControllerState( addresses: string[], selectedAddress?: string, diff --git a/app/util/test/keyringControllerTestUtils.ts b/app/util/test/keyringControllerTestUtils.ts index 4e5075cef4b..cd8f6c73bdf 100644 --- a/app/util/test/keyringControllerTestUtils.ts +++ b/app/util/test/keyringControllerTestUtils.ts @@ -6,6 +6,8 @@ export const mockQrKeyringAddress = '0xB374Ca013934e498e5baD3409147F34E6c462389'; export const mockHDKeyringAddress = '0x71C7656EC7ab88b098defB751B7401B5f6d8976F'; +export const mockSnapAddress1 = '0x6f92dC30B1e8E71D4A33B5dF06a812B9aAbCD2e9'; +export const mockSnapAddress2 = '0x8A4bD37F19C94A72E8Fe0fA97dD1422a65E53b718'; const MOCK_DEFAULT_KEYRINGS: KeyringObject[] = [ { @@ -20,6 +22,10 @@ const MOCK_DEFAULT_KEYRINGS: KeyringObject[] = [ accounts: [mockHDKeyringAddress], type: KeyringTypes.hd, }, + { + accounts: [mockSnapAddress1, mockSnapAddress2], + type: KeyringTypes.snap, + }, ]; export const MOCK_KEYRING_CONTROLLER_STATE = { From 9877ea07e13a3f8fa65207b9ca8f35a2c9a13604 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Wed, 16 Oct 2024 11:03:54 -0400 Subject: [PATCH 25/26] feat: remove unused strings functions and fix address util tests --- .../Accounts/AccountBase/AccountBase.tsx | 1 - .../Pickers/PickerAccount/PickerAccount.tsx | 1 - .../Wallet/__snapshots__/index.test.tsx.snap | 659 ++++++++---------- .../AddressElement/AddressElement.tsx | 1 - app/util/address/index.test.ts | 27 +- 5 files changed, 320 insertions(+), 369 deletions(-) diff --git a/app/component-library/components-temp/Accounts/AccountBase/AccountBase.tsx b/app/component-library/components-temp/Accounts/AccountBase/AccountBase.tsx index 5f72f4e27fc..c2313af3bda 100644 --- a/app/component-library/components-temp/Accounts/AccountBase/AccountBase.tsx +++ b/app/component-library/components-temp/Accounts/AccountBase/AccountBase.tsx @@ -11,7 +11,6 @@ import { ACCOUNT_BASE_TEST_ID, } from './AccountBase.constants'; import styles from './AccountBase.styles'; -import { strings } from '../../../../../locales/i18n'; import { AccountBaseProps } from './AccountBase.types'; const AccountBase = ({ diff --git a/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx b/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx index 59d4f8bbb98..eee9f20d577 100644 --- a/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx +++ b/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx @@ -9,7 +9,6 @@ import Avatar, { AvatarSize, AvatarVariant } from '../../Avatars/Avatar'; import Text, { TextVariant } from '../../Texts/Text'; import { formatAddress } from '../../../../util/address'; import { useStyles } from '../../../hooks'; -import { strings } from '../../../../../locales/i18n'; // Internal dependencies. import PickerBase from '../PickerBase'; diff --git a/app/components/Views/Wallet/__snapshots__/index.test.tsx.snap b/app/components/Views/Wallet/__snapshots__/index.test.tsx.snap index 3ec9cf2c174..84e84e457d0 100644 --- a/app/components/Views/Wallet/__snapshots__/index.test.tsx.snap +++ b/app/components/Views/Wallet/__snapshots__/index.test.tsx.snap @@ -479,463 +479,408 @@ exports[`Wallet should render correctly 1`] = ` } } > - - - + - + - + - - + Your information can't be shown. Don’t worry, your wallet and funds are safe. + + + + - + + + - Basic functionality is off - + } + > - Turn on basic functionality + +  + + + Try again - + - - - + + + Please report this issue so we can fix it: + + - - - - - - - - - - - - + + Take a screenshot of this screen. + + +  + + + - Account 1 + Copy - - - - - - - + + the error message to clipboard. + - Address - : - - - +  + + + Submit a ticket + + - + + Please include the error message and the screenshot. + + + - 0xC495...D272 - - +  + + + Send us a bug report + + - - + } + > + here. + + + Please include details about what happened. + - - - + > + save your Secret Recovery Phrase + + + & re-install the app. Note: you can NOT restore your wallet without your Secret Recovery Phrase. + - - + + diff --git a/app/components/Views/confirmations/SendFlow/AddressElement/AddressElement.tsx b/app/components/Views/confirmations/SendFlow/AddressElement/AddressElement.tsx index f6a77ebcf89..a16ce4c799d 100644 --- a/app/components/Views/confirmations/SendFlow/AddressElement/AddressElement.tsx +++ b/app/components/Views/confirmations/SendFlow/AddressElement/AddressElement.tsx @@ -16,7 +16,6 @@ import Text from '../../../../../component-library/components/Texts/Text/Text'; import { TextVariant } from '../../../../../component-library/components/Texts/Text'; import { selectChainId } from '../../../../../selectors/networkController'; import { doENSReverseLookup } from '../../../../../util/ENSUtils'; -import { strings } from '../../../../../../locales/i18n'; import Icon, { IconName, IconSize, diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index 50042e241f1..07dc4acd3ce 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -19,17 +19,26 @@ import { mockHDKeyringAddress, mockQrKeyringAddress, mockSimpleKeyringAddress, + mockSnapAddress1, + mockSnapAddress2, } from '../test/keyringControllerTestUtils'; -const snapAddress = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'; -const namedSnapAddress = '0xC4966c0D659D99699BFD7EB54D8fafEE40e4a756'; - jest.mock('../../core/Engine', () => { + const { MOCK_KEYRING_CONTROLLER_STATE } = jest.requireActual( + '../test/keyringControllerTestUtils', + ); const { MOCK_ACCOUNTS_CONTROLLER_STATE_WITH_KEYRING_TYPES } = jest.requireActual('../test/accountsControllerTestUtils'); return { context: { + KeyringController: { + ...MOCK_KEYRING_CONTROLLER_STATE, + state: { + keyrings: [...MOCK_KEYRING_CONTROLLER_STATE.state.keyrings], + }, + }, AccountsController: { + ...MOCK_ACCOUNTS_CONTROLLER_STATE_WITH_KEYRING_TYPES, state: MOCK_ACCOUNTS_CONTROLLER_STATE_WITH_KEYRING_TYPES, }, }, @@ -310,7 +319,7 @@ describe('isHardwareAccount,', () => { ).toBeFalsy(); }); }); -describe.only('getLabelTextByAddress,', () => { +describe('getLabelTextByAddress,', () => { it('should return accounts.qr_hardware if account is a QR keyring', () => { expect(getLabelTextByAddress(mockQrKeyringAddress)).toBe('QR hardware'); }); @@ -319,16 +328,16 @@ describe.only('getLabelTextByAddress,', () => { expect(getLabelTextByAddress(mockSimpleKeyringAddress)).toBe('Imported'); }); + it('returns "Snaps (Beta)" if account is a Snap keyring and there is no snap name', () => { + expect(getLabelTextByAddress(mockSnapAddress1)).toBe('Snaps (Beta)'); + }); + it('returns the snap name if account is a Snap keyring and there is a snap name', () => { - expect(getLabelTextByAddress(namedSnapAddress)).toBe( + expect(getLabelTextByAddress(mockSnapAddress2)).toBe( 'MetaMask Simple Snap Keyring', ); }); - it('returns "Snaps (beta)" if account is a Snap keyring and there is no snap name', () => { - expect(getLabelTextByAddress(snapAddress)).toBe('Snaps (beta)'); - }); - it('should return null if address is empty', () => { expect(getLabelTextByAddress('')).toBe(null); }); From 7e1653b9782cd15f6eb608c427f7f0fd0b5497d2 Mon Sep 17 00:00:00 2001 From: Kate Johnson Date: Thu, 17 Oct 2024 15:50:15 -0400 Subject: [PATCH 26/26] fix: unused import in PickerAccount --- .../Pickers/PickerAccount/PickerAccount.tsx | 10 ------- app/components/UI/AddressInputs/index.js | 27 +------------------ 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx b/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx index eee9f20d577..4093e7da1ae 100644 --- a/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx +++ b/app/component-library/components/Pickers/PickerAccount/PickerAccount.tsx @@ -15,7 +15,6 @@ import PickerBase from '../PickerBase'; import { PickerAccountProps } from './PickerAccount.types'; import styleSheet from './PickerAccount.styles'; import { WalletViewSelectorsIDs } from '../../../../../e2e/selectors/wallet/WalletView.selectors'; -import { AccountListViewSelectorsIDs } from '../../../../../e2e/selectors/AccountListView.selectors'; const PickerAccount: React.ForwardRefRenderFunction< TouchableOpacity, @@ -55,15 +54,6 @@ const PickerAccount: React.ForwardRefRenderFunction< > {accountName} - {accountTypeLabel && ( - - {accountTypeLabel} - - )} {showAddress && ( {shortenedAddress} diff --git a/app/components/UI/AddressInputs/index.js b/app/components/UI/AddressInputs/index.js index 47c7103657e..f1f59b4af4f 100644 --- a/app/components/UI/AddressInputs/index.js +++ b/app/components/UI/AddressInputs/index.js @@ -178,11 +178,7 @@ const createStyles = (colors, layout = 'horizontal') => { }); }; -const AddressName = ({ - toAddressName, - confusableCollection = [], - accountLabel, -}) => { +const AddressName = ({ toAddressName, confusableCollection = [] }) => { const { colors } = useTheme(); const styles = createStyles(colors); if (confusableCollection.length) { @@ -214,14 +210,6 @@ const AddressName = ({ {toAddressName} - {accountLabel && ( - - {accountLabel} - - )} ); }; @@ -229,7 +217,6 @@ const AddressName = ({ AddressName.propTypes = { toAddressName: PropTypes.string, confusableCollection: PropTypes.array, - accountLabel: PropTypes.string, }; export const AddressTo = (props) => { @@ -252,7 +239,6 @@ export const AddressTo = (props) => { isFromAddressBook = false, layout = 'horizontal', } = props; - const accountLabel = getLabelTextByAddress(toSelectedAddress); const { colors, themeAppearance } = useTheme(); const styles = createStyles(colors, layout); @@ -292,7 +278,6 @@ export const AddressTo = (props) => { )} @@ -414,7 +399,6 @@ export const AddressTo = (props) => { @@ -582,7 +566,6 @@ export const AddressFrom = (props) => { fromAccountAddress, layout = 'horizontal', } = props; - const accountLabel = getLabelTextByAddress(fromAccountAddress); const { colors } = useTheme(); const styles = createStyles(colors, layout); @@ -603,14 +586,6 @@ export const AddressFrom = (props) => { {fromAccountName} - {accountLabel && ( - - {accountLabel} - - )} {`${strings( 'transactions.address_from_balance',