Skip to content

Commit

Permalink
Merge pull request #442 from poanetwork/develop
Browse files Browse the repository at this point in the history
NW release 5.2.3
  • Loading branch information
vbaranov authored Jan 15, 2021
2 parents d42eb7a + e24ad63 commit 1fafa1b
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ notes.txt

.coveralls.yml
.nyc_output

.niftywalletrc
2 changes: 2 additions & 0 deletions .niftywalletrc.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
; Extra environment variables
ETH_MAINNET_RPC_ENDPOINT=00000000000
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Current Master

## 5.2.3 Fri Jan 15 2021

- [#441](https://github.com/poanetwork/nifty-wallet/pull/441) - Replace Infura Mainnet endpoint with custom one

## 5.2.2 Tue Dec 29 2020

- [#437](https://github.com/poanetwork/nifty-wallet/pull/437) - Support getting proxy implementation address by following EIP-1967
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.2.2",
"version": "5.2.3",
"manifest_version": 2,
"author": "POA Network",
"description": "__MSG_appDescription__",
Expand Down
1 change: 1 addition & 0 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ function setupController (initState, initLangCode) {
//

const controller = new MetamaskController({
ethMainnetRpcEndpoint: process.env.ETH_MAINNET_RPC_ENDPOINT,
// User confirmation callbacks:
showUnconfirmedMessage: triggerUi,
unlockAccountMessage: triggerUi,
Expand Down
18 changes: 5 additions & 13 deletions app/scripts/controllers/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,11 @@ class CurrencyController {
try {
currentCurrency = this.getCurrentCurrency()
currentCoin = this.getCurrentCoin()
let conversionRate, conversionDate
if (currentCoin === 'poa' || currentCoin === 'etc' || currentCoin === 'rbtc') {
const apiLink = `https://min-api.cryptocompare.com/data/price?fsym=${currentCoin.toUpperCase()}&tsyms=${currentCurrency.toUpperCase()}`
const response = await fetch(apiLink)
const parsedResponse = await response.json()
conversionRate = Number(parsedResponse[currentCurrency.toUpperCase()])
conversionDate = parseInt((new Date()).getTime() / 1000)
} else {
const response = await fetch(`https://api.infura.io/v1/ticker/eth${currentCurrency.toLowerCase()}`)
const parsedResponse = await response.json()
conversionRate = Number(parsedResponse.bid)
conversionDate = Number(parsedResponse.timestamp)
}
const apiLink = `https://min-api.cryptocompare.com/data/price?fsym=${currentCoin.toUpperCase()}&tsyms=${currentCurrency.toUpperCase()}`
const response = await fetch(apiLink)
const parsedResponse = await response.json()
const conversionRate = Number(parsedResponse[currentCurrency.toUpperCase()])
const conversionDate = parseInt((new Date()).getTime() / 1000)
this.setConversionRate(conversionRate)
this.setConversionDate(conversionDate)
} catch (err) {
Expand Down
19 changes: 18 additions & 1 deletion app/scripts/controllers/network/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const {
RSK_CODE,
RSK_TESTNET_CODE,
} = require('./enums')
const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET]
const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN]
const POCKET_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET, POA, DAI, GOERLI_TESTNET, POA_SOKOL]

const env = process.env.METAMASK_ENV
Expand Down Expand Up @@ -234,6 +234,8 @@ module.exports = class NetworkController extends EventEmitter {
} else if (isInfura) {
this._configureInfuraProvider(opts)
// other type-based rpc endpoints
} else if (type === MAINNET) {
this._configureStandardProvider({ rpcUrl: this._ethMainnetRpcEndpoint, chainId, ticker, nickname })
} else if (type === POA) {
this._configureStandardProvider({ rpcUrl: ethNetProps.RPCEndpoints(POA_CODE)[0], chainId, ticker, nickname })
} else if (type === DAI) {
Expand All @@ -258,6 +260,21 @@ module.exports = class NetworkController extends EventEmitter {
}
}

/**
* Sets the Ethereum Mainnet RPC endpoint
*
* @param {string} endpoint - Ethereum Mainnet RPC endpoint
* @throws {Error} if the endpoint is not a valid string
* @return {void}
*/
setEthMainnetRPCEndpoint (endpoint) {
if (!endpoint || typeof endpoint !== 'string') {
throw new Error('Invalid ETH Mainnet RPC Endpoint')
}

this._ethMainnetRpcEndpoint = endpoint
}

_configureInfuraProvider ({ type }) {
log.info('NetworkController - configureInfuraProvider', type)
const networkClient = createInfuraClient({
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ module.exports = class MetamaskController extends EventEmitter {

// network store
this.networkController = new NetworkController(initState.NetworkController)
this.networkController.setEthMainnetRPCEndpoint(opts.ethMainnetRpcEndpoint)

// preferences controller
this.preferencesController = new PreferencesController({
Expand Down Expand Up @@ -494,7 +495,7 @@ module.exports = class MetamaskController extends EventEmitter {
setPreference: nodeify(preferencesController.setPreference, preferencesController),

// BlacklistController
whitelistPhishingDomain: this.whitelistPhishingDomain.bind(this),
// whitelistPhishingDomain: this.whitelistPhishingDomain.bind(this),

// AddressController
setAddressBook: nodeify(addressBookController.setAddressBook, addressBookController),
Expand Down
5 changes: 5 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function gulpParallel (...args) {
}
}

const conf = require('rc')('niftywallet', {
ETH_MAINNET_RPC_ENDPOINT: process.env.ETH_MAINNET_RPC_ENDPOINT,
})

const browserPlatforms = [
'firefox',
'chrome',
Expand Down Expand Up @@ -425,6 +429,7 @@ function generateBundler (opts, performBundle) {
bundler.transform(envify({
METAMASK_DEBUG: opts.devMode,
NODE_ENV: opts.devMode ? 'development' : 'production',
ETH_MAINNET_RPC_ENDPOINT: conf.ETH_MAINNET_RPC_ENDPOINT,
}))

if (opts.watch) {
Expand Down
5 changes: 3 additions & 2 deletions old-ui/app/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const {
customDPaths,
} = require('../../app/scripts/controllers/network/enums')

const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN]

const valueTable = {
wei: '1000000000000000000',
kwei: '1000000000000000',
Expand Down Expand Up @@ -491,14 +493,13 @@ function isValidChecksumAddress (network, address) {
}

function isInfuraProvider (type) {
const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET]
return INFURA_PROVIDER_TYPES.includes(type)
}

function isKnownProvider (type) {
const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET]
return INFURA_PROVIDER_TYPES.includes(type) ||
type === LOCALHOST ||
type === MAINNET ||
type === POA_SOKOL ||
type === POA ||
type === DAI ||
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
"qs": "^6.2.0",
"qunitjs": "^2.4.1",
"radgrad-jsdoc-template": "^1.1.3",
"rc": "^1.2.8",
"react-redux": "^7.2.0",
"react-test-renderer": "^16.12.0",
"react-testutils-additions": "^16.0.2",
Expand Down
1 change: 1 addition & 0 deletions test/unit/app/controllers/detect-tokens-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('DetectTokensController', () => {

keyringMemStore = new ObservableStore({ isUnlocked: false})
network = new NetworkController()
network.setEthMainnetRPCEndpoint('foo')
preferences = new PreferencesController({ network })
controller = new DetectTokensController({ preferences: preferences, network: network, keyringMemStore: keyringMemStore })

Expand Down
1 change: 1 addition & 0 deletions test/unit/app/controllers/metamask-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('MetaMaskController', function () {
},
initState: cloneDeep(firstTimeState),
platform: { showTransactionNotification: () => {} },
ethMainnetRpcEndpoint: 'foo',
})
// disable diagnostics
metamaskController.diagnostics = null
Expand Down
1 change: 1 addition & 0 deletions test/unit/app/controllers/network-contoller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('# Network Controller', function () {
.reply(200)

networkController = new NetworkController()
networkController.setEthMainnetRPCEndpoint('foo')

networkController.initializeProvider(networkControllerProviderConfig)
})
Expand Down
2 changes: 1 addition & 1 deletion test/unit/old-ui/app/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ describe('normalizing values', function () {
assert(isInfuraProvider('kovan'))
assert(isInfuraProvider('ropsten'))
assert(isInfuraProvider('rinkeby'))
assert(isInfuraProvider('mainnet'))
assert(!isInfuraProvider('mainnet'))
assert(!isInfuraProvider('goerli_testnet'))
assert(!isInfuraProvider('sokol'))
assert(!isInfuraProvider('classic'))
Expand Down
1 change: 1 addition & 0 deletions test/unit/ui/app/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('Actions', () => {
},
},
initState: clone(firstTimeState),
ethMainnetRpcEndpoint: 'foo',
})

await metamaskController.createNewVaultAndRestore(password, TEST_SEED)
Expand Down

0 comments on commit 1fafa1b

Please sign in to comment.