Skip to content

Commit f92835f

Browse files
authored
refactor: import 5792 middleware from monorepo package (#19320)
<!-- 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** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/WAPI-691 ## **Manual testing steps** 1. No user facing changes, but for extra confirmation, we can make sure using EIP 5792 methods via https://metamask.github.io/test-dapp/ still works! ## **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** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/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.
1 parent 57e5e62 commit f92835f

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed
Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import {
2-
createWalletMiddleware,
3-
ProcessSendCallsHook,
4-
GetCapabilitiesHook,
5-
GetCallsStatusHook,
6-
} from '@metamask/eth-json-rpc-middleware';
7-
import { JsonRpcRequest } from '@metamask/utils';
2+
type ProcessSendCallsHook,
3+
type GetCapabilitiesHook,
4+
type GetCallsStatusHook,
5+
walletGetCallsStatus,
6+
walletGetCapabilities,
7+
walletSendCalls,
8+
} from '@metamask/eip-5792-middleware';
9+
import {
10+
createAsyncMiddleware,
11+
createScaffoldMiddleware,
12+
} from '@metamask/json-rpc-engine';
13+
import type { JsonRpcRequest } from '@metamask/utils';
814

915
export function createEip5792Middleware({
1016
getAccounts,
@@ -17,10 +23,23 @@ export function createEip5792Middleware({
1723
getCapabilities: GetCapabilitiesHook;
1824
processSendCalls: ProcessSendCallsHook;
1925
}) {
20-
return createWalletMiddleware({
21-
getAccounts,
22-
getCallsStatus,
23-
getCapabilities,
24-
processSendCalls,
26+
return createScaffoldMiddleware({
27+
wallet_getCapabilities: createAsyncMiddleware(async (req, res) =>
28+
walletGetCapabilities(req, res, {
29+
getAccounts,
30+
getCapabilities,
31+
}),
32+
),
33+
wallet_sendCalls: createAsyncMiddleware(async (req, res) =>
34+
walletSendCalls(req, res, {
35+
getAccounts,
36+
processSendCalls,
37+
}),
38+
),
39+
wallet_getCallsStatus: createAsyncMiddleware(async (req, res) =>
40+
walletGetCallsStatus(req, res, {
41+
getCallsStatus,
42+
}),
43+
),
2544
});
2645
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@
233233
"@metamask/design-system-twrnc-preset": "^0.2.1",
234234
"@metamask/design-tokens": "^8.1.1",
235235
"@metamask/earn-controller": "^7.0.0",
236-
"@metamask/eip-5792-middleware": "^1.0.0",
236+
"@metamask/eip-5792-middleware": "^1.1.0",
237237
"@metamask/eip1193-permission-middleware": "^1.0.0",
238238
"@metamask/error-reporting-service": "^2.0.0",
239239
"@metamask/eth-hd-keyring": "^12.1.0",
240240
"@metamask/eth-json-rpc-filters": "^9.0.0",
241-
"@metamask/eth-json-rpc-middleware": "^17.0.1",
241+
"@metamask/eth-json-rpc-middleware": "^18.0.0",
242242
"@metamask/eth-ledger-bridge-keyring": "11.1.0",
243243
"@metamask/eth-query": "^4.0.0",
244244
"@metamask/eth-sig-util": "^8.0.0",

yarn.lock

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5129,12 +5129,13 @@
51295129
"@metamask/stake-sdk" "^3.2.1"
51305130
reselect "^5.1.1"
51315131

5132-
"@metamask/eip-5792-middleware@^1.0.0":
5133-
version "1.0.0"
5134-
resolved "https://registry.yarnpkg.com/@metamask/eip-5792-middleware/-/eip-5792-middleware-1.0.0.tgz#6df7cb47999661585e592e7758b80c4652f4cd7a"
5135-
integrity sha512-NL98QBjE9CEVpfQskdoqBYhZmz3pIyujjTt4Pyp2Vlxz7PYzm1qrkSj0MrENaXkOMy0IClj8ZxoIJpMJuoAcRQ==
5132+
"@metamask/eip-5792-middleware@^1.1.0":
5133+
version "1.1.0"
5134+
resolved "https://registry.yarnpkg.com/@metamask/eip-5792-middleware/-/eip-5792-middleware-1.1.0.tgz#3dc25e31711f0045766da9d473ae9306de75d2df"
5135+
integrity sha512-zgI9uLSwi+U2x2fkIFMViI/RFJQFGp2B38YoWSgIQ1L7kshy0p0eNYrkOXnNX5Y+oDfbZLTSJeeAYBQ+suSNcA==
51365136
dependencies:
51375137
"@metamask/eth-json-rpc-middleware" "^17.0.1"
5138+
"@metamask/superstruct" "^3.1.0"
51385139
"@metamask/transaction-controller" "^60.2.0"
51395140
"@metamask/utils" "^11.4.2"
51405141
uuid "^8.3.2"
@@ -5230,6 +5231,24 @@
52305231
pify "^5.0.0"
52315232
safe-stable-stringify "^2.4.3"
52325233

5234+
"@metamask/eth-json-rpc-middleware@^18.0.0":
5235+
version "18.0.0"
5236+
resolved "https://registry.yarnpkg.com/@metamask/eth-json-rpc-middleware/-/eth-json-rpc-middleware-18.0.0.tgz#7a6fdf83dd7400d7e9dd45bfd145a5e5b2c0109e"
5237+
integrity sha512-5Cje8BW8IEshkJYV/I6QPazv9xMVJWGFYjD48K70oYty2qEKGCHpUbbuinEyLmFFqi4YzpvK5PfRBMmf93hTYQ==
5238+
dependencies:
5239+
"@metamask/eth-block-tracker" "^12.0.0"
5240+
"@metamask/eth-json-rpc-provider" "^4.1.7"
5241+
"@metamask/eth-sig-util" "^8.1.2"
5242+
"@metamask/json-rpc-engine" "^10.0.2"
5243+
"@metamask/rpc-errors" "^7.0.2"
5244+
"@metamask/superstruct" "^3.1.0"
5245+
"@metamask/utils" "^11.7.0"
5246+
"@types/bn.js" "^5.1.5"
5247+
bn.js "^5.2.1"
5248+
klona "^2.0.6"
5249+
pify "^5.0.0"
5250+
safe-stable-stringify "^2.4.3"
5251+
52335252
"@metamask/eth-json-rpc-provider@^4.1.5", "@metamask/eth-json-rpc-provider@^4.1.6", "@metamask/eth-json-rpc-provider@^4.1.7", "@metamask/eth-json-rpc-provider@^4.1.8":
52345253
version "4.1.8"
52355254
resolved "https://registry.yarnpkg.com/@metamask/eth-json-rpc-provider/-/eth-json-rpc-provider-4.1.8.tgz#1ff84270b240b75d14064bcc2ecb3bb14e718401"

0 commit comments

Comments
 (0)