Skip to content

Commit ab34f97

Browse files
fix: Prevent race condition in preinstalled example Snap (#3725)
Prevent a race condition in the preinstalled example Snap by using `snap_setState`. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Use snap_setState for settings updates in the preinstalled example snap and update the manifest shasum. > > - **Preinstalled example snap**: > - Replace settings input change flow to use `snap_setState` with `key`/`value`, removing prior `snap_manageState` get+update sequence. > - **Manifest**: > - Update `source.shasum` in `packages/examples/packages/preinstalled/snap.manifest.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 807ef4c. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent e5f394c commit ab34f97

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

packages/examples/packages/preinstalled/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "5GjC5OYTtXLw1aHztViZ2Xf1dZIgvqP4xCgw4gPT1JY=",
10+
"shasum": "BHcDBSLqllDgqbTjvlpoZLw5M13p4mK+d8b/yMMeHoU=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/preinstalled/src/index.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,12 @@ export const onUserInput: OnUserInputHandler = async ({
190190
event.name === 'setting2' ||
191191
event.name === 'setting3')
192192
) {
193-
const state = await snap.request({
194-
method: 'snap_manageState',
195-
params: {
196-
operation: 'get',
197-
encrypted: false,
198-
},
199-
});
200-
201193
await snap.request({
202-
method: 'snap_manageState',
194+
method: 'snap_setState',
203195
params: {
204-
operation: 'update',
205196
encrypted: false,
206-
newState: {
207-
...state,
208-
[event.name]: event.value,
209-
},
197+
key: event.name,
198+
value: event.value,
210199
},
211200
});
212201
}

0 commit comments

Comments
 (0)