Skip to content

Commit

Permalink
Merge pull request #360 from poanetwork/develop
Browse files Browse the repository at this point in the history
NW release 5.0.2
  • Loading branch information
vbaranov authored Apr 16, 2020
2 parents 8f97f15 + 85e4de4 commit 5baead5
Show file tree
Hide file tree
Showing 58 changed files with 774 additions and 617 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Current Master

## 5.0.2 Thu Apr 16 2020

- [#359](https://github.com/poanetwork/nifty-wallet/pull/359) - (Fix) Fix exposed accounts in wallet locked state
- [#355](https://github.com/poanetwork/nifty-wallet/pull/355) - (Feature) Add RSK/testnet default tokens
- [#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

- [#347](https://github.com/poanetwork/nifty-wallet/pull/347) - Rollback custom dPath for RSK/ETC
Expand Down
2 changes: 1 addition & 1 deletion app/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "__MSG_appName__",
"short_name": "__MSG_appName__",
"version": "5.0.1",
"version": "5.0.2",
"manifest_version": 2,
"author": "POA Network",
"description": "__MSG_appDescription__",
Expand Down
29 changes: 27 additions & 2 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const isEdge = !isIE && !!window.StyleMedia
let popupIsOpen = false
let notificationIsOpen = false
const openMetamaskTabsIDs = {}
const requestAccountTabIds = {}

// state persistence
const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY })
Expand Down Expand Up @@ -144,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 @@ -263,6 +263,12 @@ function setupController (initState, initLangCode) {
initLangCode,
// platform specific api
platform,
getRequestAccountTabIds: () => {
return requestAccountTabIds
},
getOpenMetamaskTabsIds: () => {
return openMetamaskTabsIDs
},
encryptor: isEdge ? new EdgeEncryptor() : undefined,
})
global.metamaskController = controller
Expand Down Expand Up @@ -328,6 +334,10 @@ function setupController (initState, initLangCode) {
[ENVIRONMENT_TYPE_FULLSCREEN]: true,
}

const metamaskBlacklistedPorts = [
'trezor-connect',
]

const isClientOpenStatus = () => {
return popupIsOpen || Boolean(Object.keys(openMetamaskTabsIDs).length) || notificationIsOpen
}
Expand All @@ -348,11 +358,15 @@ function setupController (initState, initLangCode) {
const processName = remotePort.name
const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName]

if (metamaskBlacklistedPorts.includes(remotePort.name)) {
return false
}

if (isMetaMaskInternalProcess) {
const portStream = new PortStream(remotePort)
// communication with popup
controller.isClientOpen = true
controller.setupTrustedCommunication(portStream, 'MetaMask')
controller.setupTrustedCommunication(portStream, remotePort.sender)

if (processName === ENVIRONMENT_TYPE_POPUP) {
popupIsOpen = true
Expand Down Expand Up @@ -382,6 +396,17 @@ function setupController (initState, initLangCode) {
})
}
} else {
if (remotePort.sender && remotePort.sender.tab && remotePort.sender.url) {
const tabId = remotePort.sender.tab.id
const url = new URL(remotePort.sender.url)
const origin = url.hostname

remotePort.onMessage.addListener((msg) => {
if (msg.data && msg.data.method === 'eth_requestAccounts') {
requestAccountTabIds[origin] = tabId
}
})
}
connectExternal(remotePort)
}
}
Expand Down
16 changes: 10 additions & 6 deletions app/scripts/controllers/detect-tokens.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const Web3 = require('web3')
const contractsETH = require('eth-contract-metadata')
const contractsPOA = require('poa-contract-metadata')
const { warn } = require('loglevel')
const { MAINNET, POA } = require('./network/enums')
import Web3 from 'web3'
import contractsETH from 'eth-contract-metadata'
import contractsPOA from 'poa-contract-metadata'
import contractsRSK from 'rsk-contract-metadata'
import contractsRSKTest from 'rsk-test-contract-metadata'
import { warn } from 'loglevel'
const { MAINNET, POA, RSK, RSK_TESTNET } = require('./network/enums')
// By default, poll every 3 minutes
const DEFAULT_INTERVAL = 180 * 1000
const ERC20_ABI = [{'constant': true, 'inputs': [{'name': '_owner', 'type': 'address'}], 'name': 'balanceOf', 'outputs': [{'name': 'balance', 'type': 'uint256'}], 'payable': false, 'type': 'function'}]
Expand Down Expand Up @@ -71,8 +73,10 @@ class DetectTokensController {
getContracts () {
const isMainnet = this._network.store.getState().provider.type === MAINNET
const isPOA = this._network.store.getState().provider.type === POA
const isRSK = this._network.store.getState().provider.type === RSK
const isRSKTestnet = this._network.store.getState().provider.type === RSK_TESTNET
// todo: isDAI
const contracts = isMainnet ? contractsETH : isPOA ? contractsPOA : {}
const contracts = isMainnet ? contractsETH : isPOA ? contractsPOA : isRSK ? contractsRSK : isRSKTestnet ? contractsRSKTest : {}
return contracts
}

Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/permissions/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const SAFE_METHODS = [
'eth_signTypedData',
'eth_signTypedData_v1',
'eth_signTypedData_v3',
'eth_signTypedData_v4',
'eth_submitHashrate',
'eth_submitWork',
'eth_syncing',
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
2 changes: 1 addition & 1 deletion app/scripts/controllers/shapeshift.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class ShapeshiftController {
const state = this.store.getState()
let { shapeShiftTxList } = state

var shapeShiftTx = {
const shapeShiftTx = {
depositAddress,
depositType,
key: 'shapeshift',
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

0 comments on commit 5baead5

Please sign in to comment.