Skip to content

fix: Update account name in PreferencesController AND AccountsController#9162

Merged
owencraston merged 1 commit intomainfrom
fix/update-account-labels-in-accounts-controller
Apr 8, 2024
Merged

fix: Update account name in PreferencesController AND AccountsController#9162
owencraston merged 1 commit intomainfrom
fix/update-account-labels-in-accounts-controller

Conversation

@owencraston
Copy link
Copy Markdown
Contributor

@owencraston owencraston commented Apr 8, 2024

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.
  1. 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
  // 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,
  ]);
  1. reload the app and inspect the logs. the names and addresses should match 1:1
  2. add an account via the account picker from the main wallet view
  3. change the names of your accounts
  4. refresh the wallet
  5. all the account names should match along with the selected account
  6. 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
 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
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.
  • 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 format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). 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.

- created a new engine method that updates the account names in both the
  AccountsController and the PreferencesController
- this is needed to keep the account labels in sync while we slowly
  migrate accounts data to use the new accounts PreferencesController
- this was missed in the following pr: #8759
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2024

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@owencraston owencraston marked this pull request as ready for review April 8, 2024 12:13
@owencraston owencraston requested a review from a team as a code owner April 8, 2024 12:13
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Apr 8, 2024
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2024

@metamaskbot
Copy link
Copy Markdown
Collaborator

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 36f93ee
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/8523b534-6b82-4057-9435-020b737ace64

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Copy link
Copy Markdown
Contributor

@tommasini tommasini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Awesome work!

@owencraston owencraston merged commit 38efcf9 into main Apr 8, 2024
@owencraston owencraston deleted the fix/update-account-labels-in-accounts-controller branch April 8, 2024 16:51
@github-actions github-actions bot locked and limited conversation to collaborators Apr 8, 2024
@metamaskbot metamaskbot added release-7.21.0 Issue or pull request that will be included in release 7.21.0 release-7.20.0 Issue or pull request that will be included in release 7.20.0 and removed release-7.21.0 Issue or pull request that will be included in release 7.21.0 labels Apr 8, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

Missing release label release-7.20.0 on PR. Adding release label release-7.20.0 on PR and removing other release labels(release-7.21.0), as PR was cherry-picked in branch 7.20.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template 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