1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Only have timeout for when payload is getState (#14972)

* Only have timeout for when payload is getState

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Fix test

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
This commit is contained in:
Olusegun Akintayo 2022-06-17 15:04:44 +04:00 committed by ryanml
parent 5168538afe
commit 3267d6ecc4
2 changed files with 12 additions and 10 deletions

View File

@ -18,16 +18,18 @@ class MetaRPCClient {
this.requests.set(id, cb);
this.connectionStream.write(payload);
this.responseHandled[id] = false;
setTimeout(() => {
if (!this.responseHandled[id] && cb) {
delete this.responseHandled[id];
return cb(new Error('No response from RPC'), null);
}
if (payload.method === 'getState') {
setTimeout(() => {
if (!this.responseHandled[id] && cb) {
delete this.responseHandled[id];
return cb(new Error('No response from RPC'), null);
}
delete this.responseHandled[id];
// needed for linter to pass
return true;
}, TEN_SECONDS_IN_MILLISECONDS);
delete this.responseHandled[id];
// needed for linter to pass
return true;
}, TEN_SECONDS_IN_MILLISECONDS);
}
}
onNotification(handler) {

View File

@ -138,7 +138,7 @@ describe('metaRPCClientFactory', () => {
const metaRPCClient = metaRPCClientFactory(streamTest);
const errorPromise = new Promise((_resolve, reject) =>
metaRPCClient.foo('bad', (error, _) => {
metaRPCClient.getState('bad', (error, _) => {
reject(error);
}),
);