diff --git a/main/accounts/Account/index.js b/main/accounts/Account/index.js index 1c1b8e3df..0dd12bc02 100644 --- a/main/accounts/Account/index.js +++ b/main/accounts/Account/index.js @@ -119,8 +119,7 @@ class Account { } } - addChain (chain, req = {}) { - if (chain) store.addNetwork(chain) + resolveRequest (req = {}) { if (this.requests[req.handlerId]) { if (this.requests[req.handlerId].res) this.requests[req.handlerId].res() delete this.requests[req.handlerId] diff --git a/main/accounts/index.js b/main/accounts/index.js index e7c188700..059d7b3a4 100644 --- a/main/accounts/index.js +++ b/main/accounts/index.js @@ -502,9 +502,10 @@ class Accounts extends EventEmitter { } } - addChain (chain, req) { - if (this.current() && this.current().addChain) { - this.current().addChain(chain, req) + resolveRequest (req) { + const currentAccount = this.current() + if (currentAccount && currentAccount.resolveRequest) { + currentAccount.resolveRequest(req) } } diff --git a/main/index.js b/main/index.js index a20c10328..ec0ac4958 100644 --- a/main/index.js +++ b/main/index.js @@ -133,7 +133,8 @@ ipcMain.on('tray:giveAccess', (e, req, access) => { }) ipcMain.on('tray:addChain', (e, chain, req) => { - accounts.addChain(chain, req) + if (chain) store.addNetwork(chain) + accounts.resolveRequest(req) }) ipcMain.on('tray:adjustNonce', (e, handlerId, nonceAdjust) => { diff --git a/test/main/accounts/index.test.js b/test/main/accounts/index.test.js index d2219e4e0..ca57f53ba 100644 --- a/test/main/accounts/index.test.js +++ b/test/main/accounts/index.test.js @@ -704,3 +704,31 @@ describe('#adjustNonce', () => { expect(Accounts.current().requests[1].data.nonce).toBe(expectedNonce) }) }) + +describe('#resolveRequest', () => { + it ('does nothing with an unknown request', () => { + Accounts.addRequest(request, () => { + throw new Error('unexpected callback!') + }) + + Accounts.resolveRequest({ handlerId: '-1' }) + + expect(Object.keys(Accounts.current().requests)).toHaveLength(1) + }) + + it ('resolves a request with a callback', done => { + Accounts.addRequest(request, done) + + Accounts.resolveRequest(request) + + expect(Object.keys(Accounts.current().requests)).toHaveLength(0) + }) + + it ('resolves a request with no callback', () => { + Accounts.addRequest(request) + + Accounts.resolveRequest(request) + + expect(Object.keys(Accounts.current().requests)).toHaveLength(0) + }) +})