-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UX: Added Account list pinning and Unpinning (#21865)
This PR is to add accounts pinning in the account list menu ## **Description** List management for accounts has been one of the most [requested features](https://docs.google.com/presentation/d/1mpgU2Zixmn6bb8Y3LPMFRUCQxFiEbYwGEWuzNx8jvBo/edit#slide=id.g2588819e87c_6_0) from the community. In this iteration, we'll implement account list management through pin and unpinning accounts. ## **Related issues** Fixes: #20918 ## **Manual testing steps** 1. Run the extension with `NETWORK_ACCOUNT_DND=1` yarn start command 2. Go to account list menu 3. Click on the options 4. Click on Pin Account to Top 5. See the pinned account is on top 6. Click on Pin Account for a new account, this account should be on second position from top 7. Unpin Accounts ## **Screenshots/Recordings** ### **Before** ![Screenshot 2023-11-17 at 1 11 16 PM](https://github.com/MetaMask/metamask-extension/assets/39872794/0fa9bbe1-c614-44a3-a0a2-14bc0976dc9a) ### **After** https://github.com/MetaMask/metamask-extension/assets/39872794/abf07bf3-9baf-49d4-b27e-20ed3504d493 ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [x] I've linked related issues - [x] I've included manual testing steps - [x] I've included screenshots/recordings if applicable - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [x] I’ve properly set the pull request status: - [x] In case it's not yet "ready for review", I've set it to "draft". - [x] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information
Showing
23 changed files
with
336 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { | ||
BaseControllerV2, | ||
RestrictedControllerMessenger, | ||
} from '@metamask/base-controller'; | ||
|
||
// Unique name for the controller | ||
const controllerName = 'AccountOrderController'; | ||
|
||
/** | ||
* The account ID of a account. | ||
*/ | ||
export type AccountAddress = string; | ||
|
||
// State shape for AccountOrderController | ||
export type AccountOrderControllerState = { | ||
pinnedAccountList: AccountAddress[]; | ||
}; | ||
|
||
// Describes the action for updating the accounts list | ||
export type AccountOrderControllerupdateAccountsListAction = { | ||
type: `${typeof controllerName}:updateAccountsList`; | ||
handler: AccountOrderController['updateAccountsList']; | ||
}; | ||
|
||
// Union of all possible actions for the messenger | ||
export type AccountOrderControllerMessengerActions = | ||
AccountOrderControllerupdateAccountsListAction; | ||
|
||
// Type for the messenger of AccountOrderController | ||
export type AccountOrderControllerMessenger = RestrictedControllerMessenger< | ||
typeof controllerName, | ||
AccountOrderControllerMessengerActions, | ||
never, | ||
never, | ||
never | ||
>; | ||
|
||
// Default state for the controller | ||
const defaultState = { | ||
pinnedAccountList: [], | ||
}; | ||
|
||
// Metadata for the controller state | ||
const metadata = { | ||
pinnedAccountList: { | ||
persist: true, | ||
anonymous: true, | ||
}, | ||
}; | ||
|
||
/** | ||
* Controller that updates the order of the account list. | ||
* This controller subscribes to account state changes and ensures | ||
* that the account list is updated based on the latest account configurations. | ||
*/ | ||
export class AccountOrderController extends BaseControllerV2< | ||
typeof controllerName, | ||
AccountOrderControllerState, | ||
AccountOrderControllerMessenger | ||
> { | ||
/** | ||
* Creates a AccountOrderController instance. | ||
* | ||
* @param args - The arguments to this function. | ||
* @param args.messenger - Messenger used to communicate with BaseV2 controller. | ||
* @param args.state - Initial state to set on this controller. | ||
*/ | ||
constructor({ | ||
messenger, | ||
state, | ||
}: { | ||
messenger: AccountOrderControllerMessenger; | ||
state?: AccountOrderControllerState; | ||
}) { | ||
// Call the constructor of BaseControllerV2 | ||
super({ | ||
messenger, | ||
metadata, | ||
name: controllerName, | ||
state: { ...defaultState, ...state }, | ||
}); | ||
} | ||
|
||
/** | ||
* Updates the accounts list in the state with the provided list of accounts. | ||
* | ||
* @param accountList - The list of accounts to update in the state. | ||
*/ | ||
|
||
updateAccountsList(accountList: []) { | ||
this.update((state) => { | ||
state.pinnedAccountList = accountList; | ||
return state; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/e2e/tests/state-snapshots/errors-after-init-opt-in-background-state.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.