Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chain when no account selected #576

Merged
merged 2 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions main/accounts/Account/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 4 additions & 3 deletions main/accounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
3 changes: 2 additions & 1 deletion main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
28 changes: 28 additions & 0 deletions test/main/accounts/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})