-
-
Notifications
You must be signed in to change notification settings - Fork 276
feat: add sortAccountIdsByLastSelected to getSessionScopes, wallet_getSession, and wallet_createSession #8255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,14 +45,19 @@ export const getInternalScopesObject = ( | |
| * @param internalScopesObject - The InternalScopesObject to convert. | ||
| * @param hooks - An object containing the following properties: | ||
| * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope. | ||
| * @param [hooks.sortAccountIdsByLastSelected] - Optional function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by last selected. | ||
| * @returns A NormalizedScopesObject. | ||
| */ | ||
| const getNormalizedScopesObject = ( | ||
| internalScopesObject: InternalScopesObject, | ||
| { | ||
| getNonEvmSupportedMethods, | ||
| sortAccountIdsByLastSelected, | ||
| }: { | ||
| getNonEvmSupportedMethods: (scope: CaipChainId) => string[]; | ||
| sortAccountIdsByLastSelected?: ( | ||
| accounts: CaipAccountId[], | ||
| ) => CaipAccountId[]; | ||
| }, | ||
| ) => { | ||
| const normalizedScopes: NormalizedScopesObject = {}; | ||
|
|
@@ -83,10 +88,14 @@ const getNormalizedScopesObject = ( | |
| notifications = []; | ||
| } | ||
|
|
||
| const sortedAccounts = sortAccountIdsByLastSelected | ||
| ? sortAccountIdsByLastSelected(accounts) | ||
| : accounts; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorting before merge loses order for overlapping scopesLow Severity
Additional Locations (1) |
||
|
|
||
| normalizedScopes[scopeString] = { | ||
| methods, | ||
| notifications, | ||
| accounts, | ||
| accounts: sortedAccounts, | ||
| }; | ||
| }, | ||
| ); | ||
|
|
@@ -101,6 +110,7 @@ const getNormalizedScopesObject = ( | |
| * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert. | ||
| * @param hooks - An object containing the following properties: | ||
| * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope. | ||
| * @param [hooks.sortAccountIdsByLastSelected] - Optional function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by last selected. | ||
| * @returns A NormalizedScopesObject. | ||
| */ | ||
| export const getSessionScopes = ( | ||
|
|
@@ -110,16 +120,22 @@ export const getSessionScopes = ( | |
| >, | ||
| { | ||
| getNonEvmSupportedMethods, | ||
| sortAccountIdsByLastSelected, | ||
| }: { | ||
| getNonEvmSupportedMethods: (scope: CaipChainId) => string[]; | ||
| sortAccountIdsByLastSelected?: ( | ||
| accounts: CaipAccountId[], | ||
| ) => CaipAccountId[]; | ||
| }, | ||
| ) => { | ||
| return mergeNormalizedScopes( | ||
| getNormalizedScopesObject(caip25CaveatValue.requiredScopes, { | ||
| getNonEvmSupportedMethods, | ||
| sortAccountIdsByLastSelected, | ||
| }), | ||
| getNormalizedScopesObject(caip25CaveatValue.optionalScopes, { | ||
| getNonEvmSupportedMethods, | ||
| sortAccountIdsByLastSelected, | ||
| }), | ||
| ); | ||
| }; | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] this name can be misleading, since we are not always sorting these accounts,
sortedAccountscould actually be unsorted ifsortAccountIdsByLastSelectedis not provided.we could name the function param
caipAccountIds, and this variableaccountsfor example (open to other suggestions)