DAI chain support
This commit is contained in:
parent
220b3579b8
commit
51ac2a0437
|
@ -4,6 +4,7 @@ const KOVAN = 'kovan'
|
|||
const MAINNET = 'mainnet'
|
||||
const POA_SOKOL = 'sokol'
|
||||
const POA = 'poa'
|
||||
const DAI = 'dai'
|
||||
const LOCALHOST = 'localhost'
|
||||
|
||||
const MAINNET_CODE = 1
|
||||
|
@ -12,12 +13,14 @@ const RINKEYBY_CODE = 4
|
|||
const KOVAN_CODE = 42
|
||||
const POA_SOKOL_CODE = 77
|
||||
const POA_CODE = 99
|
||||
const DAI_CODE = 100
|
||||
|
||||
const ROPSTEN_DISPLAY_NAME = 'Ropsten'
|
||||
const RINKEBY_DISPLAY_NAME = 'Rinkeby'
|
||||
const KOVAN_DISPLAY_NAME = 'Kovan'
|
||||
const POA_SOKOL_DISPLAY_NAME = 'Sokol'
|
||||
const POA_DISPLAY_NAME = 'POA Network'
|
||||
const DAI_DISPLAY_NAME = 'Dai Chain'
|
||||
const MAINNET_DISPLAY_NAME = 'Main Ethereum Network'
|
||||
|
||||
module.exports = {
|
||||
|
@ -27,6 +30,7 @@ module.exports = {
|
|||
MAINNET,
|
||||
POA_SOKOL,
|
||||
POA,
|
||||
DAI,
|
||||
LOCALHOST,
|
||||
MAINNET_CODE,
|
||||
ROPSTEN_CODE,
|
||||
|
@ -34,10 +38,12 @@ module.exports = {
|
|||
KOVAN_CODE,
|
||||
POA_SOKOL_CODE,
|
||||
POA_CODE,
|
||||
DAI_CODE,
|
||||
ROPSTEN_DISPLAY_NAME,
|
||||
RINKEBY_DISPLAY_NAME,
|
||||
KOVAN_DISPLAY_NAME,
|
||||
MAINNET_DISPLAY_NAME,
|
||||
POA_SOKOL_DISPLAY_NAME,
|
||||
POA_DISPLAY_NAME,
|
||||
DAI_DISPLAY_NAME,
|
||||
}
|
||||
|
|
|
@ -18,9 +18,11 @@ const {
|
|||
LOCALHOST,
|
||||
POA_SOKOL,
|
||||
POA,
|
||||
DAI,
|
||||
} = require('./enums')
|
||||
const LOCALHOST_RPC_URL = 'http://localhost:8545'
|
||||
const POA_RPC_URL = 'https://core.poa.network'
|
||||
const DAI_RPC_URL = 'https://dai.poa.network'
|
||||
const SOKOL_RPC_URL = 'https://sokol.poa.network'
|
||||
const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET]
|
||||
|
||||
|
@ -99,7 +101,7 @@ module.exports = class NetworkController extends EventEmitter {
|
|||
|
||||
async setProviderType (type) {
|
||||
assert.notEqual(type, 'rpc', `NetworkController - cannot call "setProviderType" with type 'rpc'. use "setRpcTarget"`)
|
||||
assert(INFURA_PROVIDER_TYPES.includes(type) || type === LOCALHOST || type === POA_SOKOL || type === POA, `NetworkController - Unknown rpc type "${type}"`)
|
||||
assert(INFURA_PROVIDER_TYPES.includes(type) || type === LOCALHOST || type === POA_SOKOL || type === POA || type === DAI, `NetworkController - Unknown rpc type "${type}"`)
|
||||
const providerConfig = { type }
|
||||
this.providerConfig = providerConfig
|
||||
}
|
||||
|
@ -136,6 +138,8 @@ module.exports = class NetworkController extends EventEmitter {
|
|||
// other type-based rpc endpoints
|
||||
} else if (type === POA) {
|
||||
this._configureStandardProvider({ rpcUrl: POA_RPC_URL })
|
||||
} else if (type === DAI) {
|
||||
this._configureStandardProvider({ rpcUrl: DAI_RPC_URL })
|
||||
} else if (type === POA_SOKOL) {
|
||||
this._configureStandardProvider({ rpcUrl: SOKOL_RPC_URL })
|
||||
} else if (type === LOCALHOST) {
|
||||
|
|
|
@ -287,6 +287,23 @@ App.prototype.renderNetworkDropdown = function () {
|
|||
]
|
||||
),
|
||||
|
||||
h(
|
||||
DropdownMenuItem,
|
||||
{
|
||||
key: 'dai',
|
||||
closeMenu: () => this.setState({ isNetworkMenuOpen: !isOpen }),
|
||||
onClick: () => props.dispatch(actions.setProviderType('dai')),
|
||||
style: {
|
||||
paddingLeft: '20px',
|
||||
fontSize: '16px',
|
||||
color: providerType === 'dai' ? 'white' : '',
|
||||
},
|
||||
},
|
||||
[h(providerType === 'dai' ? 'div.selected-network' : ''),
|
||||
ethNetProps.props.getNetworkDisplayName(100),
|
||||
]
|
||||
),
|
||||
|
||||
h(
|
||||
DropdownMenuItem,
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ const Loading = require('./loading')
|
|||
const AccountPanel = require('./account-panel')
|
||||
const RadioList = require('./custom-radio-list')
|
||||
const { getNetworkDisplayName } = require('../../../app/scripts/controllers/network/util')
|
||||
const ethNetProps = require('eth-net-props')
|
||||
|
||||
module.exports = connect(mapStateToProps)(BuyButtonSubview)
|
||||
|
||||
|
@ -47,9 +48,7 @@ BuyButtonSubview.prototype.headerSubview = function () {
|
|||
const props = this.props
|
||||
const { network } = props
|
||||
const isLoading = props.isSubLoading
|
||||
const isSokol = parseInt(network) === 77
|
||||
const isPOA = parseInt(network) === 99
|
||||
const coinName = isPOA ? 'POA' : isSokol ? 'SPOA' : 'ETH'
|
||||
const coinName = ethNetProps.props.getNetworkCoinName(network)
|
||||
return (
|
||||
|
||||
h('.flex-column', {
|
||||
|
@ -143,12 +142,13 @@ BuyButtonSubview.prototype.primarySubview = function () {
|
|||
case '1':
|
||||
return this.mainnetSubview()
|
||||
|
||||
// Ropsten, Rinkeby, Kovan, Sokol, POA
|
||||
// Ropsten, Rinkeby, Kovan, Sokol, POA, DAI
|
||||
case '3':
|
||||
case '4':
|
||||
case '42':
|
||||
case '77':
|
||||
case '99':
|
||||
case '100':
|
||||
const networkName = getNetworkDisplayName(network)
|
||||
const label = `${networkName} Test Faucet`
|
||||
return (
|
||||
|
@ -157,7 +157,7 @@ BuyButtonSubview.prototype.primarySubview = function () {
|
|||
margin: '20px 30px',
|
||||
},
|
||||
}, [
|
||||
network !== '99' ? h('p.exchanges.cursor-pointer', {
|
||||
network !== '99' && network !== '100' ? h('p.exchanges.cursor-pointer', {
|
||||
onClick: () => this.props.dispatch(actions.buyEth({ network })),
|
||||
},
|
||||
[h('span', {style: {marginRight: '10px', color: '#6729a8'}}, label)]) : null,
|
||||
|
|
|
@ -15,8 +15,11 @@ FiatValue.prototype.render = function () {
|
|||
let { conversionRate } = props
|
||||
const { currentCurrency, network } = props
|
||||
const isSokol = parseInt(network) === 77
|
||||
const isDai = parseInt(network) === 100
|
||||
if (isSokol) {
|
||||
conversionRate = 0
|
||||
} else if (isDai) {
|
||||
conversionRate = 1
|
||||
}
|
||||
const renderedCurrency = currentCurrency || ''
|
||||
|
||||
|
|
|
@ -60,6 +60,9 @@ Network.prototype.render = function () {
|
|||
} else if (providerName === 'poa' || parseInt(networkNumber) === 99) {
|
||||
displayName = 'POA Network'
|
||||
hoverText = ethNetProps.props.getNetworkDisplayName(networkNumber)
|
||||
} else if (providerName === 'dai' || parseInt(networkNumber) === 100) {
|
||||
displayName = 'Dai Chain'
|
||||
hoverText = ethNetProps.props.getNetworkDisplayName(networkNumber)
|
||||
} else {
|
||||
displayName = 'Private Network'
|
||||
hoverText = `Private Network (${provider.rpcTarget})`
|
||||
|
|
|
@ -53,8 +53,11 @@ ConfirmTxScreen.prototype.render = function () {
|
|||
let { conversionRate } = props
|
||||
|
||||
const isSokol = parseInt(network) === 77
|
||||
const isDai = parseInt(network) === 100
|
||||
if (isSokol) {
|
||||
conversionRate = 0
|
||||
} else if (isDai) {
|
||||
conversionRate = 1
|
||||
}
|
||||
|
||||
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, unapprovedTypedMessages, network)
|
||||
|
|
|
@ -315,6 +315,11 @@ function currentProviderDisplay (metamaskState, state) {
|
|||
value = ethNetProps.props.getNetworkDisplayName(99)
|
||||
break
|
||||
|
||||
case 'dai':
|
||||
title = 'Current Network'
|
||||
value = ethNetProps.props.getNetworkDisplayName(100)
|
||||
break
|
||||
|
||||
default:
|
||||
title = 'Current RPC'
|
||||
value = metamaskState.provider.rpcTarget
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const ethUtil = require('ethereumjs-util')
|
||||
const ethNetProps = require('eth-net-props')
|
||||
|
||||
var valueTable = {
|
||||
wei: '1000000000000000000',
|
||||
|
@ -112,9 +113,7 @@ function parseBalance (balance) {
|
|||
// Takes wei hex, returns an object with three properties.
|
||||
// Its "formatted" property is what we generally use to render values.
|
||||
function formatBalance (balance, decimalsToKeep, needsParse = true, network, isToken, tokenSymbol) {
|
||||
const isSokol = parseInt(network) === 77
|
||||
const isPOA = parseInt(network) === 99
|
||||
const coinName = isPOA ? 'POA' : isSokol ? 'SPOA' : 'ETH'
|
||||
const coinName = ethNetProps.props.getNetworkCoinName(network)
|
||||
const assetName = isToken ? tokenSymbol : coinName
|
||||
var parsed = needsParse ? parseBalance(balance) : balance.split('.')
|
||||
var beforeDecimal = parsed[0]
|
||||
|
|
|
@ -8754,9 +8754,9 @@
|
|||
}
|
||||
},
|
||||
"eth-net-props": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/eth-net-props/-/eth-net-props-1.0.3.tgz",
|
||||
"integrity": "sha512-iHY/o2/JwEk+HOTFmn5ju1LXsMf+qNsJZ30SdD3WZ9PJH9jc7lqI6fh80xQHWqV7Q2pkZqD5YvO3G6fdrKzQ0Q==",
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/eth-net-props/-/eth-net-props-1.0.5.tgz",
|
||||
"integrity": "sha512-dTOKMhsvoY1JKQFJ7chFddIgrofKsSP93xIbFHJCprUuzjdzOGjMBGGJU4ehkBXLRjJ3kfXIL12UkwkYi4k3sg==",
|
||||
"requires": {
|
||||
"chai": "^4.1.2"
|
||||
}
|
||||
|
@ -8867,7 +8867,7 @@
|
|||
"dependencies": {
|
||||
"babelify": {
|
||||
"version": "7.3.0",
|
||||
"resolved": "https://registry.npmjs.org/babelify/-/babelify-7.3.0.tgz",
|
||||
"resolved": "http://registry.npmjs.org/babelify/-/babelify-7.3.0.tgz",
|
||||
"integrity": "sha1-qlau3nBn/XvVSWZu4W3ChQh+iOU=",
|
||||
"requires": {
|
||||
"babel-core": "^6.0.14",
|
||||
|
|
|
@ -109,7 +109,7 @@
|
|||
"eth-json-rpc-filters": "^1.2.6",
|
||||
"eth-json-rpc-infura": "^3.0.0",
|
||||
"eth-method-registry": "^1.0.0",
|
||||
"eth-net-props": "^1.0.3",
|
||||
"eth-net-props": "^1.0.5",
|
||||
"eth-phishing-detect": "^1.1.4",
|
||||
"eth-query": "^2.1.2",
|
||||
"eth-sig-util": "^1.4.2",
|
||||
|
|
|
@ -1759,7 +1759,7 @@ function setProviderType (type) {
|
|||
dispatch(actions.setSelectedToken())
|
||||
})
|
||||
|
||||
const newCoin = type === 'poa' || type === 'sokol' ? 'poa' : 'eth'
|
||||
const newCoin = type === 'poa' || type === 'sokol' ? 'poa' : type === 'dai' ? 'dai' : 'eth'
|
||||
background.setCurrentCoin(newCoin, (err, data) => {
|
||||
if (err) {
|
||||
log.error(err.stack)
|
||||
|
|
Loading…
Reference in New Issue