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

Fix accountsChanged event emittance (a part of EIP-1193) #354

Merged
merged 1 commit into from
Apr 14, 2020
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
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)
}
})
}
})
}

// Work around for web3@1.0 deleting the bound `sendAsync` but not the unbound
// `sendAsync` method on the prototype, causing `this` reference issues
const proxiedInpageProvider = new Proxy(inpageProvider, {
Expand Down
30 changes: 1 addition & 29 deletions app/scripts/lib/ComposableObservableStore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ObservableStore = require('obs-store')
import ObservableStore from 'obs-store'

/**
* An ObservableStore that can composes a flat
Expand Down Expand Up @@ -46,34 +46,6 @@ class ComposableObservableStore extends ObservableStore {
}
return flatState
}

/**
* Merges all child store state into a single object rather than
* returning an object keyed by child store class name
* Removes heavy objects that are not needed on UI
*
* @returns {Object} - Object containing merged child store state
*/
getFilteredFlatState () {
let flatState = {}
for (const key in this.config) {
let nextState
if (key === 'RecentBlocksController') {
nextState = {}
} else if (key === 'TxController') {
const state = this.config[key].getState()
const txList = state.selectedAddressTxList.map(item => ({...item, history: null, nonceDetails: null}))
nextState = {
...state,
selectedAddressTxList: txList,
}
} else {
nextState = this.config[key].getState()
}
flatState = { ...flatState, ...nextState }
}
return flatState
}
}

module.exports = ComposableObservableStore
Loading