Skip to content

Commit

Permalink
Merge pull request #354 from poanetwork/vb-fix-accounts_changged_even…
Browse files Browse the repository at this point in the history
…t_emitting

Fix `accountsChanged` event emittance (a part of EIP-1193)
  • Loading branch information
vbaranov committed Apr 14, 2020
2 parents 29cf01c + b40bcbd commit c755023
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 260 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Current Master

- [#354](https://github.com/poanetwork/nifty-wallet/pull/354) - Fix `accountsChanged` event emittance (a part of EIP-1193)
- [#353](https://github.com/poanetwork/nifty-wallet/pull/353) - Fix synchronous eth_accounts request

## 5.0.1 Mon Apr 06 2020
Expand Down
4 changes: 3 additions & 1 deletion app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ setupMetamaskMeshMetrics()
* @property {Object} infuraNetworkStatus - An object of infura network status checks.
* @property {Block[]} recentBlocks - An array of recent blocks, used to calculate an effective but cheap gas price.
* @property {Array} shapeShiftTxList - An array of objects describing shapeshift exchange attempts.
* @property {Array} lostAccounts - TODO: Remove this feature. A leftover from the version-3 migration where our seed-phrase library changed to fix a bug where some accounts were mis-generated, but we recovered the old accounts as "lost" instead of losing them.
* @property {boolean} forgottenPassword - Returns true if the user has initiated the password recovery screen, is recovering from seed phrase.
*/

Expand Down Expand Up @@ -267,6 +266,9 @@ function setupController (initState, initLangCode) {
getRequestAccountTabIds: () => {
return requestAccountTabIds
},
getOpenMetamaskTabsIds: () => {
return openMetamaskTabsIDs
},
encryptor: isEdge ? new EdgeEncryptor() : undefined,
})
global.metamaskController = controller
Expand Down
35 changes: 20 additions & 15 deletions app/scripts/controllers/permissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,18 @@ export class PermissionsController {
*/
async updatePermittedAccounts (origin, accounts) {

await this.validatePermittedAccounts(accounts)
// await this.validatePermittedAccounts(accounts)

this.permissions.updateCaveatFor(
origin, 'eth_accounts', CAVEAT_NAMES.exposedAccounts, accounts,
)
// this.permissions.updateCaveatFor(
// origin, 'eth_accounts', CAVEAT_NAMES.exposedAccounts, accounts,
// )

// this.notifyDomain(origin, {
// method: NOTIFICATION_NAMES.accountsChanged,
// result: accounts,
// })

this.notifyDomain(origin, {
this.notifyAllDomains({
method: NOTIFICATION_NAMES.accountsChanged,
result: accounts,
})
Expand Down Expand Up @@ -378,14 +383,14 @@ export class PermissionsController {
// if the accounts changed from the perspective of the dapp,
// update "last seen" time for the origin and account(s)
// exception: no accounts -> no times to update
if (
payload.method === NOTIFICATION_NAMES.accountsChanged &&
Array.isArray(payload.result)
) {
this.permissionsLog.updateAccountsHistory(
origin, payload.result,
)
}
// if (
// payload.method === NOTIFICATION_NAMES.accountsChanged &&
// Array.isArray(payload.result)
// ) {
// this.permissionsLog.updateAccountsHistory(
// origin, payload.result,
// )
// }

this._notifyDomain(origin, payload)

Expand Down Expand Up @@ -448,8 +453,8 @@ export class PermissionsController {
// do nothing if the account is not permitted for the origin, or
// if it's already first in the array of permitted accounts
if (
!permittedAccounts.includes(account) ||
permittedAccounts[0] === account
!permittedAccounts.includes(account)
// || permittedAccounts[0] === account
) {
return
}
Expand Down
17 changes: 0 additions & 17 deletions app/scripts/inpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,6 @@ const inpageProvider = new MetamaskInpageProvider(metamaskStream)
// set a high max listener count to avoid unnecesary warnings
inpageProvider.setMaxListeners(100)

// Augment the provider with its enable method
inpageProvider.enable = function (options = {}) {
return new Promise((resolve, reject) => {
if (options.mockRejection) {
reject('User rejected account access')
} else {
inpageProvider.sendAsync({ method: 'eth_accounts', params: [] }, (error, response) => {
if (error) {
reject(error)
} else {
resolve(response.result)
}
})