-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(snap-keyring): handle
displayAccountNameSuggestion
flag (#30531)
<!-- 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** This PR handles the `displayAccountNameSuggestion` flag that can be set by pre-installed Snaps in the `accountCreated` event. <!-- **BREAKING**: By default, dialogs are displayed now. --> [](https://codespaces.new/MetaMask/metamask-extension/pull/30531?quickstart=1) ## **Related issues** Fixes: MetaMask/accounts-planning#829 ## **Manual testing steps** 1. Update a pre-installed Snap to set `displayAccountNameSuggestion` to false: ```diff diff --git a/packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts b/packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts index 27238e7..6edabc7 100644 --- a/packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts +++ b/packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts @@ -224,7 +224,8 @@ export class SolanaKeyring implements Keyring { * and the snaps sdk does not allow extra properties. */ account: keyringAccount, - accountNameSuggestion: `Solana Account ${index + 1}`, + accountNameSuggestion: `Solana Account`, + displayAccountNameSuggestion: false, }); return keyringAccount; ``` 2. Build the Snap and add a resolution in the extension's `package.json`: ``` "@metamask/solana-wallet-snap@^1.2.0": "file:../snap-solana-wallet/packages/snap" ``` 3. Start the extension: `yarn && yarn start:flask` 4. Create an account 5. The account name dialog should not be shown ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [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/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.
- Loading branch information
Showing
8 changed files
with
105 additions
and
44 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { InternalAccount } from '@metamask/keyring-internal-api'; | ||
|
||
/** | ||
* Get the next available account name based on the suggestion and the list of | ||
* accounts. | ||
* | ||
* @param accounts - The list of accounts to check for name availability | ||
* @param nameSuggestion - The suggested name for the account | ||
* @returns The next available account name based on the suggestion | ||
*/ | ||
export function getUniqueAccountName( | ||
accounts: InternalAccount[], | ||
nameSuggestion: string, | ||
): string { | ||
let suffix = 1; | ||
let candidateName = nameSuggestion; | ||
|
||
const isNameTaken = (name: string) => | ||
accounts.some((account) => account.metadata.name === name); | ||
|
||
while (isNameTaken(candidateName)) { | ||
suffix += 1; | ||
candidateName = `${nameSuggestion} ${suffix}`; | ||
} | ||
|
||
return candidateName; | ||
} |
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,4 @@ | ||
export * from './accounts'; | ||
export * from './bitcoin-wallet-snap'; | ||
export * from './snaps'; | ||
export * from './solana-wallet-snap'; |
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