Skip to content

chore: cherry-pick #9162#9168

Merged
owencraston merged 1 commit intorelease/7.20.0from
chore/cherry-pick-9162
Apr 8, 2024
Merged

chore: cherry-pick #9162#9168
owencraston merged 1 commit intorelease/7.20.0from
chore/cherry-pick-9162

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 8, 2024

This PR cherry-picks #9162

…ler (#9162)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**


1. What is the reason for the change?
- the internal state of the accounts controller and the preferences
controller was getting out of sync when editing the account names in the
UI
- this meant that the users preferred name was not reflected in the
AccountsController
- although there is currently no user impact because of this issue, it
will lead to problems in the future and will require a new migration to
be written in coming releases.
2. What is the improvement/solution?
- Created a new Engine utility method called `setAccountLabel` (similar
to what we are doing for `setSelectedAccount`) that changes both the
PreferencesController and the AccountsController label.
- Updated the use of `PreferencesController.setAccountLabel` in the UI
to be `Engine.setAccountLabel`
- added tests


## **Related issues**

Fixes: N/A

## **Manual testing steps**

1. Create or import a wallet
2. add the following code block to the `useAccounts.ts` hook

```ts
  // TODO remove this useEffect before merging
  useEffect(() => {
    // eslint-disable-next-line no-console
    console.log(
      'Accounts/ AccountController',
      JSON.stringify(Engine.context.AccountsController.state, null, 2),
    );
    // eslint-disable-next-line no-console
    console.log(
      'Accounts/ PreferencesController',
      JSON.stringify(
        Engine.context.PreferencesController.state.identities,
        null,
        2,
      ),
    );
  }, [
    Engine.context.AccountsController.state,
    Engine.context.PreferencesController.identities,
    Engine.context.PreferencesController.state.identities,
  ]);
```
3. reload the app and inspect the logs. the names and addresses should
match 1:1
4. add an account via the account picker from the main wallet view
5. change the names of your accounts
6. refresh the wallet
7. all the account names should match along with the selected account
8. the state logged in the console should still match 1:1

**- Double check that there are NO other direct calls to other
preferences controller methods like
`PreferencesController.setAccountLabel`**

### **Before**

- Notice different account names in each controller
```json
 Accounts/ AccountController {
  "internalAccounts": {
    "accounts": {
      "6ffaed06-b348-4fc1-a227-972de373effd": {
        "id": "6ffaed06-b348-4fc1-a227-972de373effd",
        "address": "0x4a29682b2636147f608cf7554f47bd9877117bdd",
        "options": {},
        "methods": [
          "personal_sign",
          "eth_sign",
          "eth_signTransaction",
          "eth_signTypedData_v1",
          "eth_signTypedData_v3",
          "eth_signTypedData_v4"
        ],
        "type": "eip155:eoa",
        "metadata": {
          "name": "Account 1",
          "keyring": {
            "type": "HD Key Tree"
          },
          "lastSelected": 1712528808432
        }
      },
      "59e23a68-b6b7-43a8-90f8-7236f748fe00": {
        "id": "59e23a68-b6b7-43a8-90f8-7236f748fe00",
        "address": "0x769dde14f7d7d48ed431d727801620f46d7ae29e",
        "options": {},
        "methods": [
          "personal_sign",
          "eth_sign",
          "eth_signTransaction",
          "eth_signTypedData_v1",
          "eth_signTypedData_v3",
          "eth_signTypedData_v4"
        ],
        "type": "eip155:eoa",
        "metadata": {
          "name": "Account 2",
          "keyring": {
            "type": "HD Key Tree"
          },
          "lastSelected": 1712528808551
        }
      },
      "04cc2134-f9f6-4a42-b07b-3ebc40078f4f": {
        "id": "04cc2134-f9f6-4a42-b07b-3ebc40078f4f",
        "address": "0x9351164ed35ace26f345f749b9cb85b5c699e2b7",
        "options": {},
        "methods": [
          "personal_sign",
          "eth_sign",
          "eth_signTransaction",
          "eth_signTypedData_v1",
          "eth_signTypedData_v3",
          "eth_signTypedData_v4"
        ],
        "type": "eip155:eoa",
        "metadata": {
          "name": "Account 3",
          "keyring": {
            "type": "HD Key Tree"
          },
          "lastSelected": 1712528808747
        }
      }
    },
    "selectedAccount": "04cc2134-f9f6-4a42-b07b-3ebc40078f4f"
  }
}
 LOG  Accounts/ PreferencesController {
  "0x4A29682b2636147F608CF7554F47bd9877117bDd": {
    "address": "0x4A29682b2636147F608CF7554F47bd9877117bDd",
    "name": "Account 1",
    "importTime": 1712527955387
  },
  "0x769ddE14f7D7D48eD431d727801620F46d7aE29e": {
    "address": "0x769ddE14f7D7D48eD431d727801620F46d7aE29e",
    "name": "Cool 2",
    "importTime": 1712528157517
  },
  "0x9351164ED35aCe26F345F749B9Cb85b5C699E2b7": {
    "address": "0x9351164ED35aCe26F345F749B9Cb85b5C699E2b7",
    "name": "Gyro 3",
    "importTime": 1712528160433
  }
}
```

### **After**

- Notice that the account names in both controllers match

```json
Accounts/ AccountController {
  "internalAccounts": {
    "accounts": {
      "6ffaed06-b348-4fc1-a227-972de373effd": {
        "id": "6ffaed06-b348-4fc1-a227-972de373effd",
        "address": "0x4a29682b2636147f608cf7554f47bd9877117bdd",
        "options": {},
        "methods": [
          "personal_sign",
          "eth_sign",
          "eth_signTransaction",
          "eth_signTypedData_v1",
          "eth_signTypedData_v3",
          "eth_signTypedData_v4"
        ],
        "type": "eip155:eoa",
        "metadata": {
          "name": "Cool Account 1",
          "keyring": {
            "type": "HD Key Tree"
          },
          "lastSelected": 1712575526370
        }
      },
      "59e23a68-b6b7-43a8-90f8-7236f748fe00": {
        "id": "59e23a68-b6b7-43a8-90f8-7236f748fe00",
        "address": "0x769dde14f7d7d48ed431d727801620f46d7ae29e",
        "options": {},
        "methods": [
          "personal_sign",
          "eth_sign",
          "eth_signTransaction",
          "eth_signTypedData_v1",
          "eth_signTypedData_v3",
          "eth_signTypedData_v4"
        ],
        "type": "eip155:eoa",
        "metadata": {
          "name": "Cool Account 2",
          "keyring": {
            "type": "HD Key Tree"
          },
          "lastSelected": 1712575539858
        }
      },
      "04cc2134-f9f6-4a42-b07b-3ebc40078f4f": {
        "id": "04cc2134-f9f6-4a42-b07b-3ebc40078f4f",
        "address": "0x9351164ed35ace26f345f749b9cb85b5c699e2b7",
        "options": {},
        "methods": [
          "personal_sign",
          "eth_sign",
          "eth_signTransaction",
          "eth_signTypedData_v1",
          "eth_signTypedData_v3",
          "eth_signTypedData_v4"
        ],
        "type": "eip155:eoa",
        "metadata": {
          "name": "Cool Account 3",
          "keyring": {
            "type": "HD Key Tree"
          },
          "lastSelected": 1712575552843
        }
      }
    },
    "selectedAccount": "04cc2134-f9f6-4a42-b07b-3ebc40078f4f"
  }
}
 LOG  Accounts/ PreferencesController {
  "0x4A29682b2636147F608CF7554F47bd9877117bDd": {
    "address": "0x4A29682b2636147F608CF7554F47bd9877117bDd",
    "name": "Cool Account 1",
    "importTime": 1712527955387
  },
  "0x769ddE14f7D7D48eD431d727801620F46d7aE29e": {
    "address": "0x769ddE14f7D7D48eD431d727801620F46d7aE29e",
    "name": "Cool Account 2",
    "importTime": 1712528157517
  },
  "0x9351164ED35aCe26F345F749B9Cb85b5C699E2b7": {
    "address": "0x9351164ED35aCe26F345F749B9Cb85b5C699E2b7",
    "name": "Cool Account 3",
    "importTime": 1712528160433
  }
}
```

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@owencraston owencraston marked this pull request as ready for review April 8, 2024 17:46
@owencraston owencraston requested a review from a team as a code owner April 8, 2024 17:46
@chrisleewilcox chrisleewilcox added needs-qa Any New Features that needs a full manual QA prior to being added to a release. release-7.20.0 Issue or pull request that will be included in release 7.20.0 regression-RC DEPRECATED: Please use "regresssion-RC-x.y.z" label instead team-accounts-framework Accounts team labels Apr 8, 2024
@owencraston owencraston merged commit c7d70d6 into release/7.20.0 Apr 8, 2024
@owencraston owencraston deleted the chore/cherry-pick-9162 branch April 8, 2024 19:40
@github-actions github-actions bot locked and limited conversation to collaborators Apr 8, 2024
@github-actions github-actions bot removed the needs-qa Any New Features that needs a full manual QA prior to being added to a release. label Apr 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

regression-RC DEPRECATED: Please use "regresssion-RC-x.y.z" label instead release-7.20.0 Issue or pull request that will be included in release 7.20.0 team-accounts-framework Accounts team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants