Skip to content

Commit

Permalink
deep clone flattened scopeObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Sep 25, 2024
1 parent 450ec01 commit b336213
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions app/scripts/lib/multichain-api/scope/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ describe('Scope Transform', () => {
'eip155:64': validScopeObject,
});
});

it('returns one deep cloned scope per `scopes` element', () => {
const flattenedScopes = flattenScope('eip155', {
...validScopeObject,
scopes: ['eip155:1', 'eip155:5'],
});

expect(flattenedScopes['eip155:1']).not.toBe(
flattenedScopes['eip155:5'],
);
expect(flattenedScopes['eip155:1'].methods).not.toBe(
flattenedScopes['eip155:5'].methods,
);
});
});
});

Expand Down
3 changes: 2 additions & 1 deletion app/scripts/lib/multichain-api/scope/transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CaipChainId, isCaipChainId } from '@metamask/utils';
import { cloneDeep } from 'lodash';
import {
ExternalScopeObject,
ExternalScopesObject,
Expand Down Expand Up @@ -35,7 +36,7 @@ export const flattenScope = (

const scopeMap: ScopesObject = {};
scopes.forEach((nestedScopeString: CaipChainId) => {
scopeMap[nestedScopeString] = restScopeObject;
scopeMap[nestedScopeString] = cloneDeep(restScopeObject);
});
return scopeMap;
};
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6221,7 +6221,7 @@ export default class MetamaskController extends EventEmitter {
this.networkController,
),
updateNetwork: this.networkController.updateNetwork.bind(
this.networkController
this.networkController,
),
setActiveNetwork: async (networkClientId) => {
await this.networkController.setActiveNetwork(networkClientId);
Expand Down

0 comments on commit b336213

Please sign in to comment.