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 ()

* 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.requests.set(id, cb);
this.connectionStream.write(payload); this.connectionStream.write(payload);
this.responseHandled[id] = false; this.responseHandled[id] = false;
setTimeout(() => { if (payload.method === 'getState') {
if (!this.responseHandled[id] && cb) { setTimeout(() => {
delete this.responseHandled[id]; if (!this.responseHandled[id] && cb) {
return cb(new Error('No response from RPC'), null); delete this.responseHandled[id];
} return cb(new Error('No response from RPC'), null);
}
delete this.responseHandled[id]; delete this.responseHandled[id];
// needed for linter to pass // needed for linter to pass
return true; return true;
}, TEN_SECONDS_IN_MILLISECONDS); }, TEN_SECONDS_IN_MILLISECONDS);
}
} }
onNotification(handler) { onNotification(handler) {

View File

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