Skip to content

Commit 815f352

Browse files
authored
Remove legacy signature/code for createFetchMiddleware (#402)
Now that `createFetchMiddleware` takes an `RpcService`, there is no need for it to take its old signature (`fetch`, `btoa`, `rpcUrl`, and `originHttpHeaderKey`), and there is no need for the old logic (as that has been integrated into `RpcService`).
1 parent 965644b commit 815f352

File tree

4 files changed

+15
-361
lines changed

4 files changed

+15
-361
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- **BREAKING:** `createFetchMiddleware` no longer takes `fetch`, `btoa`, `rpcUrl`, and `originHttpHeaderKey` ([#402](https://github.com/MetaMask/eth-json-rpc-middleware/pull/402))
13+
- The existing signature (`rpcService` and `options`) is now the only way to use this function; please use that instead.
14+
15+
### Removed
16+
17+
- **BREAKING:** Remove `PayloadWithOrigin` type ([#402](https://github.com/MetaMask/eth-json-rpc-middleware/pull/402))
18+
- There is no equivalent.
19+
- **BREAKING:** Remove `createFetchConfigFromReq` function ([#402](https://github.com/MetaMask/eth-json-rpc-middleware/pull/402))
20+
- There is no equivalent.
21+
1022
## [17.1.0]
1123

1224
### Added

src/fetch.test.ts

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
import { JsonRpcEngine } from '@metamask/json-rpc-engine';
22
import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';
33

4-
import { createFetchConfigFromReq } from '.';
54
import { createFetchMiddleware } from './fetch';
65
import type { AbstractRpcService } from './types';
76

8-
/**
9-
* Generate a base64-encoded string from a binary string. This should be equivalent to
10-
* `window.btoa`.
11-
*
12-
* @param stringToEncode - The string to encode.
13-
* @returns The base64-encoded string.
14-
*/
15-
// eslint-disable-next-line @typescript-eslint/no-shadow
16-
function btoa(stringToEncode: string) {
17-
return Buffer.from(stringToEncode).toString('base64');
18-
}
19-
207
describe('createFetchMiddleware', () => {
218
it('calls the RPC service with the correct request headers and body when no `originHttpHeaderKey` option given', async () => {
229
const rpcService = buildRpcService();
@@ -244,60 +231,6 @@ describe('createFetchMiddleware', () => {
244231
});
245232
});
246233

247-
describe('createFetchConfigFromReq', () => {
248-
it('should create a fetch config from a request', async () => {
249-
const req = {
250-
id: 1,
251-
jsonrpc: '2.0' as const,
252-
method: 'eth_getBlockByNumber',
253-
params: ['0x482103', true],
254-
};
255-
const rpcUrl = 'http://www.xyz.io/rabbit:3456?id=100';
256-
const { fetchUrl, fetchParams } = createFetchConfigFromReq({
257-
btoa,
258-
req,
259-
rpcUrl,
260-
});
261-
expect(fetchUrl).toStrictEqual(rpcUrl);
262-
expect(fetchParams).toStrictEqual({
263-
method: 'POST',
264-
headers: {
265-
Accept: 'application/json',
266-
'Content-Type': 'application/json',
267-
},
268-
body: JSON.stringify(req),
269-
});
270-
});
271-
272-
it('should create a fetch config with origin header', async () => {
273-
const request = {
274-
id: 1,
275-
jsonrpc: '2.0' as const,
276-
method: 'eth_getBlockByNumber',
277-
params: ['0x482103', true],
278-
};
279-
const requestWithOrigin = { ...request, origin: 'happydapp.gov' };
280-
const rpcUrl = 'http://www.xyz.io/rabbit:3456?id=100';
281-
const originHttpHeaderKey = 'x-dapp-origin';
282-
const { fetchUrl, fetchParams } = createFetchConfigFromReq({
283-
btoa,
284-
req: requestWithOrigin,
285-
rpcUrl,
286-
originHttpHeaderKey,
287-
});
288-
expect(fetchUrl).toStrictEqual(rpcUrl);
289-
expect(fetchParams).toStrictEqual({
290-
method: 'POST',
291-
headers: {
292-
Accept: 'application/json',
293-
'Content-Type': 'application/json',
294-
'x-dapp-origin': 'happydapp.gov',
295-
},
296-
body: JSON.stringify(request),
297-
});
298-
});
299-
});
300-
301234
/**
302235
* Constructs a fake RPC service for use as a failover in tests.
303236
*

0 commit comments

Comments
 (0)