Merge pull request #355 from poanetwork/add-rsk-default-tokens

Add RSK/testnet default tokens
This commit is contained in:
Victor Baranov 2020-04-14 13:47:44 +03:00 committed by GitHub
commit ad0a6898fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 290 additions and 177 deletions

View File

@ -2,8 +2,9 @@
## 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
- [#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

View File

@ -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'}]
@ -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
}

View File

@ -157,7 +157,7 @@ class ShapeshiftController {
const state = this.store.getState()
let { shapeShiftTxList } = state
var shapeShiftTx = {
const shapeShiftTx = {
depositAddress,
depositType,
key: 'shapeshift',

View File

@ -46,8 +46,8 @@ module.exports = class NoticeController extends EventEmitter {
markNoticeRead (noticeToMark, cb) {
cb = cb || function (err) { if (err) throw err }
try {
var notices = this.getNoticesList()
var index = notices.findIndex((currentNotice) => currentNotice.id === noticeToMark.id)
const notices = this.getNoticesList()
const index = notices.findIndex((currentNotice) => currentNotice.id === noticeToMark.id)
notices[index].read = true
notices[index].body = ''
this.setNoticesList(notices)

View File

@ -72,6 +72,14 @@ createCopyTasks('contractImagesPOA', {
source: './node_modules/poa-contract-metadata/images/',
destinations: commonPlatforms.map(platform => `./dist/${platform}/images/contractPOA`),
})
createCopyTasks('contractImagesRSK', {
source: './node_modules/rsk-contract-metadata/images/',
destinations: commonPlatforms.map(platform => `./dist/${platform}/images/contractRSK`),
})
createCopyTasks('contractImagesRSKTest', {
source: './node_modules/rsk-test-contract-metadata/images/',
destinations: commonPlatforms.map(platform => `./dist/${platform}/images/contractRSKTest`),
})
createCopyTasks('fonts', {
source: './app/fonts/',
destinations: commonPlatforms.map(platform => `./dist/${platform}/fonts`),

View File

@ -48,12 +48,12 @@ function AccountDetailScreen () {
}
AccountDetailScreen.prototype.render = function () {
var props = this.props
const props = this.props
const { network, conversionRate, currentCurrency } = props
var selected = props.address || Object.keys(props.accounts)[0]
var checksumAddress = selected && toChecksumAddress(network, selected)
var identity = props.identities[selected]
var account = props.accounts[selected]
const selected = props.address || Object.keys(props.accounts)[0]
const checksumAddress = selected && toChecksumAddress(network, selected)
const identity = props.identities[selected]
const account = props.accounts[selected]
if (Object.keys(props.suggestedTokens).length > 0) {
this.props.dispatch(actions.showAddSuggestedTokenPage())
@ -248,7 +248,7 @@ AccountDetailScreen.prototype.render = function () {
}
AccountDetailScreen.prototype.subview = function () {
var subview
let subview
try {
subview = this.props.accountDetail.subview
} catch (e) {
@ -259,7 +259,7 @@ AccountDetailScreen.prototype.subview = function () {
case 'transactions':
return this.tabSections()
case 'export':
var state = extend({key: 'export'}, this.props)
const state = extend({key: 'export'}, this.props)
return h(ExportAccountView, state)
default:
return this.tabSections()

View File

@ -105,7 +105,7 @@ function mapStateToProps (state) {
}
App.prototype.render = function () {
var props = this.props
const props = this.props
const {
currentView,
isLoading,
@ -163,7 +163,7 @@ App.prototype.renderLoadingIndicator = function ({ isLoading, isLoadingNetwork,
App.prototype.renderPrimary = function () {
log.debug('rendering primary')
var props = this.props
const props = this.props
const {isMascara, isOnboarding} = props
if (isMascara && isOnboarding) {

View File

@ -14,12 +14,12 @@ function AccountPanel () {
}
AccountPanel.prototype.render = function () {
var state = this.props
var identity = state.identity || {}
var account = state.account || {}
var isFauceting = state.isFauceting
const state = this.props
const identity = state.identity || {}
const account = state.account || {}
const isFauceting = state.isFauceting
var panelState = {
const panelState = {
key: `accountPanel${identity.address}`,
identiconKey: identity.address,
identiconLabel: identity.name || '',

View File

@ -8,17 +8,17 @@ const { getCurrentKeyring, ifContractAcc, isValidAddress } = require('../../util
const TokenList = require('./token-list')
const TokenSearch = require('./token-search')
const { tokenInfoGetter } = require('../../../../ui/app/token-util')
const ethUtil = require('ethereumjs-util')
const abi = require('human-standard-token-abi')
const Eth = require('ethjs-query')
const EthContract = require('ethjs-contract')
const PropTypes = require('prop-types')
import ethUtil from 'ethereumjs-util'
import abi from 'human-standard-token-abi'
import Eth from 'ethjs-query'
import EthContract from 'ethjs-contract'
import PropTypes from 'prop-types'
const emptyAddr = '0x0000000000000000000000000000000000000000'
const SEARCH_TAB = 'SEARCH'
const CUSTOM_TOKEN_TAB = 'CUSTOM_TOKEN'
const { POA_CODE, MAINNET_CODE } = require('../../../../app/scripts/controllers/network/enums')
const { POA_CODE, MAINNET_CODE, RSK_CODE, RSK_TESTNET_CODE } = require('../../../../app/scripts/controllers/network/enums')
export default class AddTokenScreen extends Component {
@ -97,7 +97,9 @@ export default class AddTokenScreen extends Component {
const networkID = parseInt(network)
let views = []
const isProdNetworkWithKnownTokens = networkID === MAINNET_CODE ||
networkID === POA_CODE
networkID === POA_CODE ||
networkID === RSK_CODE ||
networkID === RSK_TESTNET_CODE
isProdNetworkWithKnownTokens ? views = [h(TabBar, {
style: {
paddingTop: '0px',

View File

@ -4,6 +4,7 @@ import classnames from 'classnames'
import { checkExistingAddresses } from '../util'
import TokenListPlaceholder from './token-list-placeholder'
import Tooltip from '../../tooltip.js'
const { getTokenImageFolder } = require('../../../util')
export default class InfoBox extends Component {
static contextTypes = {
@ -21,7 +22,7 @@ export default class InfoBox extends Component {
render () {
const { results = [], selectedTokens = {}, onToggleToken, tokens = [], network } = this.props
const networkID = parseInt(network)
const imagesFolder = networkID === 1 ? 'images/contract' : 'images/contractPOA'
const imagesFolder = getTokenImageFolder(networkID)
return results.length === 0
? <TokenListPlaceholder />

View File

@ -2,9 +2,12 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import contractMapETH from 'eth-contract-metadata'
import contractMapPOA from 'poa-contract-metadata'
import contractMapRSK from 'rsk-contract-metadata'
import contractMapRSKTest from 'rsk-test-contract-metadata'
import Fuse from 'fuse.js'
import InputAdornment from '@material-ui/core/InputAdornment'
import TextField from '../../../../../ui/app/components/text-field'
import { MAINNET_CODE, POA_CODE, RSK_CODE, RSK_TESTNET_CODE } from '../../../../../app/scripts/controllers/network/enums'
let contractList
@ -63,7 +66,7 @@ export default class TokenSearch extends Component {
}
updateContractList (newNetworkID) {
const contractMap = newNetworkID === 1 ? contractMapETH : contractMapPOA
const contractMap = this._getContractMap(newNetworkID)
contractList = Object.entries(contractMap)
.map(([ _, tokenData]) => tokenData)
.filter(tokenData => Boolean(tokenData.erc20))
@ -110,4 +113,19 @@ export default class TokenSearch extends Component {
/>
)
}
_getContractMap (networkID) {
switch (networkID) {
case MAINNET_CODE:
return contractMapETH
case POA_CODE:
return contractMapPOA
case RSK_CODE:
return contractMapRSK
case RSK_TESTNET_CODE:
return contractMapRSKTest
default:
return contractMapPOA
}
}
}

View File

@ -161,7 +161,7 @@ BnAsDecimalInput.prototype.downsize = function (number, scale) {
return Number(number)
} else {
// if the scale is the same as the precision, account for this edge case.
var adjustedNumber = number
let adjustedNumber = number
while (adjustedNumber.length < scale) {
adjustedNumber = '0' + adjustedNumber
}
@ -170,9 +170,9 @@ BnAsDecimalInput.prototype.downsize = function (number, scale) {
}
BnAsDecimalInput.prototype.upsize = function (number, scale, precision) {
var stringArray = number.toString().split('.')
var decimalLength = stringArray[1] ? stringArray[1].length : 0
var newString = stringArray[0]
const stringArray = number.toString().split('.')
const decimalLength = stringArray[1] ? stringArray[1].length : 0
let newString = stringArray[0]
// If there is scaling and decimal parts exist, integrate them in.
if ((scale !== 0) && (decimalLength !== 0)) {
@ -180,7 +180,7 @@ BnAsDecimalInput.prototype.upsize = function (number, scale, precision) {
}
// Add 0s to account for the upscaling.
for (var i = decimalLength; i < scale; i++) {
for (let i = decimalLength; i < scale; i++) {
newString += '0'
}
return newString

View File

@ -52,9 +52,9 @@ EditableLabel.prototype.saveIfEnter = function (event) {
EditableLabel.prototype.saveText = function () {
// eslint-disable-next-line react/no-find-dom-node
var container = findDOMNode(this)
var text = container.querySelector('.editable-label input').value
var truncatedText = text.substring(0, 20)
const container = findDOMNode(this)
const text = container.querySelector('.editable-label input').value
const truncatedText = text.substring(0, 20)
this.props.saveText(truncatedText)
this.setState({ isEditingLabel: false, textLabel: truncatedText })
}

View File

@ -14,10 +14,10 @@ function EthBalanceComponent () {
}
EthBalanceComponent.prototype.render = function () {
var props = this.props
const props = this.props
let { value } = props
const { style, width, network, isToken, tokenSymbol } = props
var needsParse = this.props.needsParse !== undefined ? this.props.needsParse : true
const needsParse = this.props.needsParse !== undefined ? this.props.needsParse : true
value = value ? formatBalance(value, 6, needsParse, network, isToken, tokenSymbol) : '...'
return (
@ -36,15 +36,15 @@ EthBalanceComponent.prototype.render = function () {
)
}
EthBalanceComponent.prototype.renderBalance = function (value) {
var props = this.props
const props = this.props
const { conversionRate, shorten, incoming, currentCurrency } = props
if (value === 'None') return value
if (value === '...') return value
var balanceObj = generateBalanceObject(value, shorten ? 1 : 3)
var balance
var splitBalance = value.split(' ')
var ethNumber = splitBalance[0]
var ethSuffix = splitBalance[1]
const balanceObj = generateBalanceObject(value, shorten ? 1 : 3)
let balance
const splitBalance = value.split(' ')
const ethNumber = splitBalance[0]
const ethSuffix = splitBalance[1]
const showFiat = 'showFiat' in props ? props.showFiat : true
if (shorten) {
@ -53,7 +53,7 @@ EthBalanceComponent.prototype.renderBalance = function (value) {
balance = balanceObj.balance
}
var label = balanceObj.label
const { label } = balanceObj
const valueStyle = props.valueStyle ? props.valueStyle : {
color: '#ffffff',
width: '100%',

View File

@ -17,11 +17,11 @@ function IdenticonComponent () {
}
IdenticonComponent.prototype.render = function () {
var props = this.props
var diameter = props.diameter || this.defaultDiameter
const props = this.props
const diameter = props.diameter || this.defaultDiameter
return (
h('div', {
key: 'identicon-' + this.props.address,
key: 'identicon-' + props.address,
style: {
display: 'flex',
alignItems: 'center',
@ -42,7 +42,7 @@ IdenticonComponent.prototype.componentDidMount = function () {
if (!address) return
// eslint-disable-next-line react/no-find-dom-node
var container = findDOMNode(this)
const container = findDOMNode(this)
const diameter = props.diameter || this.defaultDiameter
if (!isNode) {
@ -58,10 +58,10 @@ IdenticonComponent.prototype.componentDidUpdate = function () {
if (!address) return
// eslint-disable-next-line react/no-find-dom-node
var container = findDOMNode(this)
const container = findDOMNode(this)
const children = container.children
for (var i = 0; i < children.length; i++) {
for (let i = 0; i < children.length; i++) {
container.removeChild(children[i])
}

View File

@ -88,7 +88,7 @@ export default class MenuDroppo extends Component {
this.globalClickHandler = this.globalClickOccurred.bind(this)
document.body.addEventListener('click', this.globalClickHandler)
// eslint-disable-next-line react/no-find-dom-node
var container = findDOMNode(this)
const container = findDOMNode(this)
this.container = container
}
@ -136,7 +136,7 @@ export default class MenuDroppo extends Component {
}
isDescendant (parent, child) {
var node = child.parentNode
let node = child.parentNode
while (node !== null) {
if (node === parent) {
return true

View File

@ -12,8 +12,8 @@ function AccountPanel () {
}
AccountPanel.prototype.render = function () {
var props = this.props
var picOrder = props.picOrder || 'left'
const props = this.props
const picOrder = props.picOrder || 'left'
const { imageSeed } = props
return (

View File

@ -85,7 +85,7 @@ Notice.prototype.render = function () {
h('div.markdown', {
key: 'notice-div-key',
onScroll: (e) => {
var object = e.currentTarget
const object = e.currentTarget
if (object.offsetHeight + object.scrollTop + 100 >= object.scrollHeight) {
this.setState({disclaimerDisabled: false})
}
@ -132,7 +132,7 @@ Notice.prototype.setInitialDisclaimerState = function () {
Notice.prototype.componentDidMount = function () {
// eslint-disable-next-line react/no-find-dom-node
var node = findDOMNode(this)
const node = findDOMNode(this)
linker.setupListener(node)
if (document.getElementsByClassName('notice-box')[0].clientHeight < 300) {
this.setState({disclaimerDisabled: false})
@ -151,6 +151,6 @@ Notice.prototype.componentDidUpdate = function (prevProps) {
Notice.prototype.componentWillUnmount = function () {
// eslint-disable-next-line react/no-find-dom-node
var node = findDOMNode(this)
const node = findDOMNode(this)
linker.teardownListener(node)
}

View File

@ -11,13 +11,13 @@ export default class PendingMsgDetails extends Component {
imageifyIdenticons: PropTypes.any,
}
render () {
var state = this.props
var msgData = state.txData
const state = this.props
const msgData = state.txData
var msgParams = msgData.msgParams || {}
var address = msgParams.from || state.selectedAddress
var identity = state.identities[address] || { address: address }
var account = state.accounts[address] || { address: address }
const msgParams = msgData.msgParams || {}
const address = msgParams.from || state.selectedAddress
const identity = state.identities[address] || { address: address }
const account = state.accounts[address] || { address: address }
return (
<div key={msgData.id} style={{margin: '10px 0px'}}>

View File

@ -10,8 +10,8 @@ export default class PendingMsg extends Component {
}
render () {
var state = this.props
var msgData = state.txData
const state = this.props
const msgData = state.txData
return (
<div key={msgData.id} style={{height: '100%'}}>

View File

@ -13,15 +13,15 @@ export default class PendingMsgDetails extends Component {
}
render () {
var state = this.props
var msgData = state.txData
const state = this.props
const msgData = state.txData
var msgParams = msgData.msgParams || {}
var address = msgParams.from || state.selectedAddress
var identity = state.identities[address] || { address: address }
var account = state.accounts[address] || { address: address }
const msgParams = msgData.msgParams || {}
const address = msgParams.from || state.selectedAddress
const identity = state.identities[address] || { address: address }
const account = state.accounts[address] || { address: address }
var { data } = msgParams
const { data } = msgParams
return (
<div key={msgData.id} style={{margin: '10px 0px'}}>

View File

@ -10,8 +10,8 @@ export default class PendingMsg extends Component {
}
render () {
var state = this.props
var msgData = state.txData
const state = this.props
const msgData = state.txData
return (
<div key={msgData.id} style={{height: '100%'}}>

View File

@ -143,7 +143,7 @@ PendingTx.prototype.render = function () {
const buyDisabled = insufficientBalance || !this.state.valid || !isValidAddress || this.state.submitting
const showRejectAll = props.unconfTxListLength > 1
var isNotification = getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION
const isNotification = getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION
this.inputs = []

View File

@ -13,15 +13,15 @@ export default class PendingMsgDetails extends Component {
}
render () {
var state = this.props
var msgData = state.txData
const state = this.props
const msgData = state.txData
var msgParams = msgData.msgParams || {}
var address = msgParams.from || state.selectedAddress
var identity = state.identities[address] || { address: address }
var account = state.accounts[address] || { address: address }
const msgParams = msgData.msgParams || {}
const address = msgParams.from || state.selectedAddress
const identity = state.identities[address] || { address: address }
const account = state.accounts[address] || { address: address }
var { data, version } = msgParams
const { data, version } = msgParams
return (
<div key={msgData.id} style={{margin: '10px 0px'}}>

View File

@ -10,8 +10,8 @@ export default class PendingMsg extends Component {
}
render () {
var state = this.props
var msgData = state.txData
const state = this.props
const msgData = state.txData
return (
<div key={msgData.id} style={{height: '100%'}}>

View File

@ -91,7 +91,7 @@ class SendProfile extends Component {
function mapStateToProps (state) {
const accounts = getMetaMaskAccounts(state)
var result = {
const result = {
address: state.metamask.selectedAddress,
accounts,
identities: state.metamask.identities,

View File

@ -21,7 +21,7 @@ module.exports = connect(mapStateToProps)(SendTransactionScreen)
function mapStateToProps (state) {
const accounts = getMetaMaskAccounts(state)
var result = {
const result = {
address: state.metamask.selectedAddress,
accounts,
identities: state.metamask.identities,
@ -184,7 +184,7 @@ SendTransactionScreen.prototype.onSubmit = function () {
}
if (parts[1]) {
var decimal = parts[1]
const decimal = parts[1]
if (decimal.length > 18) {
message = 'Ether amount is too precise.'
return this.props.dispatch(actions.displayWarning(message))
@ -224,7 +224,7 @@ SendTransactionScreen.prototype.onSubmit = function () {
this.props.dispatch(actions.addToAddressBook(recipient, nickname))
var txParams = {
const txParams = {
from: this.props.address,
value: '0x' + value.toString(16),
}

View File

@ -27,7 +27,7 @@ ShapeshiftForm.prototype.render = function () {
ShapeshiftForm.prototype.renderMain = function () {
const marketinfo = this.props.buyView.formView.marketinfo
const coinOptions = this.props.buyView.formView.coinOptions
var coin = marketinfo.pair.split('_')[0].toUpperCase()
const coin = marketinfo.pair.split('_')[0].toUpperCase()
return h('.flex-column', {
style: {
@ -184,18 +184,18 @@ ShapeshiftForm.prototype.renderRefundAddressForCoin = function (coin) {
}
ShapeshiftForm.prototype.shift = function () {
var props = this.props
var withdrawal = this.props.buyView.buyAddress
var returnAddress = document.getElementById('fromCoinAddress').value
var pair = this.props.buyView.formView.marketinfo.pair
var data = {
const props = this.props
const withdrawal = this.props.buyView.buyAddress
const returnAddress = document.getElementById('fromCoinAddress').value
const pair = this.props.buyView.formView.marketinfo.pair
const data = {
'withdrawal': withdrawal,
'pair': pair,
'returnAddress': returnAddress,
// Public api key
'apiKey': '5efdee9e7d3c99e7c7e8a0f788d6e52205bf00a0e24575fe59df86421f63c477d018840c94f6596cf8946990216073c68144394c384b0ddcbe782351d80d61d7',
}
var message = [
const message = [
`Deposit Limit: ${props.buyView.formView.marketinfo.limit}`,
`Deposit Minimum:${props.buyView.formView.marketinfo.minimum}`,
]
@ -205,7 +205,7 @@ ShapeshiftForm.prototype.shift = function () {
}
ShapeshiftForm.prototype.renderCoinList = function () {
var list = Object.keys(this.props.buyView.formView.coinOptions).map((item) => {
const list = Object.keys(this.props.buyView.formView.coinOptions).map((item) => {
return h('option', {
value: item,
}, item)
@ -221,11 +221,11 @@ ShapeshiftForm.prototype.renderCoinList = function () {
ShapeshiftForm.prototype.updateCoin = function (event) {
event.preventDefault()
const props = this.props
var coinOptions = this.props.buyView.formView.coinOptions
var coin = document.getElementById('fromCoin').value
const coinOptions = this.props.buyView.formView.coinOptions
const coin = document.getElementById('fromCoin').value
if (!coinOptions[coin.toUpperCase()] || coin.toUpperCase() === 'ETH') {
var message = 'Not a valid coin'
const message = 'Not a valid coin'
return props.dispatch(actions.displayWarning(message))
} else {
return props.dispatch(actions.pairUpdate(coin))
@ -234,8 +234,8 @@ ShapeshiftForm.prototype.updateCoin = function (event) {
ShapeshiftForm.prototype.handleLiveInput = function () {
const props = this.props
var coinOptions = this.props.buyView.formView.coinOptions
var coin = document.getElementById('fromCoin').value
const coinOptions = this.props.buyView.formView.coinOptions
const coin = document.getElementById('fromCoin').value
if (!coinOptions[coin.toUpperCase()] || coin.toUpperCase() === 'ETH') {
return null
@ -247,7 +247,7 @@ ShapeshiftForm.prototype.handleLiveInput = function () {
ShapeshiftForm.prototype.renderInfo = function () {
const marketinfo = this.props.buyView.formView.marketinfo
const coinOptions = this.props.buyView.formView.coinOptions
var coin = marketinfo.pair.split('_')[0].toUpperCase()
const coin = marketinfo.pair.split('_')[0].toUpperCase()
return h('span', {
style: {

View File

@ -65,7 +65,7 @@ function formatDate (date) {
}
ShiftListItem.prototype.renderUtilComponents = function () {
var props = this.props
const props = this.props
const { conversionRate, currentCurrency, network } = props
const valueStyle = {
@ -135,7 +135,7 @@ ShiftListItem.prototype.renderUtilComponents = function () {
}
ShiftListItem.prototype.renderInfo = function () {
var props = this.props
const props = this.props
switch (props.response.status) {
case 'no_deposits':
@ -203,7 +203,7 @@ ShiftListItem.prototype.renderInfo = function () {
}, 'Conversion in progress'),
])
case 'complete':
var url = ethNetProps.explorerLinks.getExplorerTxLinkFor(props.response.transaction, parseInt('1'))
const url = ethNetProps.explorerLinks.getExplorerTxLinkFor(props.response.transaction, parseInt('1'))
return h('.flex-column.pointer', {
style: {

View File

@ -1,11 +1,11 @@
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const TokenTracker = require('eth-token-watcher')
import { Component } from 'react'
import h from 'react-hyperscript'
import { inherits } from 'util'
import TokenTracker from 'eth-token-watcher'
import log from 'loglevel'
import { connect } from 'react-redux'
const TokenCell = require('./token-cell.js')
const connect = require('react-redux').connect
const selectors = require('../../../ui/app/selectors')
const log = require('loglevel')
function mapStateToProps (state) {
return {
@ -19,6 +19,8 @@ const defaultTokens = []
const contractsETH = require('eth-contract-metadata')
const contractsPOA = require('poa-contract-metadata')
const contractsRSK = require('rsk-contract-metadata')
const contractsRSKTest = require('rsk-test-contract-metadata')
for (const address in contractsETH) {
const contract = contractsETH[address]
if (contract.erc20) {
@ -33,6 +35,20 @@ for (const address in contractsPOA) {
defaultTokens.push(contract)
}
}
for (const address in contractsRSK) {
const contract = contractsRSK[address]
if (contract.erc20) {
contract.address = address
defaultTokens.push(contract)
}
}
for (const address in contractsRSKTest) {
const contract = contractsRSKTest[address]
if (contract.erc20) {
contract.address = address
defaultTokens.push(contract)
}
}
module.exports = connect(mapStateToProps)(TokenList)

View File

@ -75,7 +75,7 @@ TransactionListItem.prototype.render = function () {
if (transaction.key === 'shapeshift') {
if (Number(network) === MAINNET_CODE) return h(ShiftListItem, transaction)
}
var date = formatDate(transaction.time)
const date = formatDate(transaction.time)
let isLinkable = false
const numericNet = isNaN(network) ? network : parseInt(network)
@ -91,9 +91,9 @@ TransactionListItem.prototype.render = function () {
numericNet === RSK_CODE ||
numericNet === RSK_TESTNET_CODE
var isMsg = ('msgParams' in transaction)
var isTx = ('txParams' in transaction)
var isPending = status === 'unapproved'
const isMsg = ('msgParams' in transaction)
const isTx = ('txParams' in transaction)
const isPending = status === 'unapproved'
let txParams
if (isTx) {
txParams = transaction.txParams

View File

@ -16,7 +16,7 @@ function TransactionList () {
TransactionList.prototype.render = function () {
const { transactions, network, unapprovedMsgs, conversionRate } = this.props
var shapeShiftTxList
let shapeShiftTxList
if (Number(network) === MAINNET_CODE) {
shapeShiftTxList = this.props.shapeShiftTxList
}

View File

@ -65,10 +65,10 @@ ConfirmTxScreen.prototype.render = function () {
conversionRate = 1
}
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, unapprovedTypedMessages, network)
const unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, unapprovedTypedMessages, network)
const ind = props.index || 0
var txData = unconfTxList[ind] || {}
var txParams = txData.params || {}
const txData = unconfTxList[ind] || {}
const txParams = txData.params || {}
log.info(`rendering a combined ${unconfTxList.length} unconf msg & txs`)
if (unconfTxList.length === 0) return h(Loading, { isLoading: true })
@ -180,7 +180,7 @@ ConfirmTxScreen.prototype.cancelAllTransactions = function (unconfTxList, event)
ConfirmTxScreen.prototype.signMessage = function (msgData, event) {
log.info('conf-tx.js: signing message')
var params = msgData.msgParams
const params = msgData.msgParams
params.metamaskId = msgData.id
this.stopPropagation(event)
this.props.dispatch(actions.signMsg(params))
@ -194,7 +194,7 @@ ConfirmTxScreen.prototype.stopPropagation = function (event) {
ConfirmTxScreen.prototype.signPersonalMessage = function (msgData, event) {
log.info('conf-tx.js: signing personal message')
var params = msgData.msgParams
const params = msgData.msgParams
params.metamaskId = msgData.id
this.stopPropagation(event)
this.props.dispatch(actions.signPersonalMsg(params))
@ -202,7 +202,7 @@ ConfirmTxScreen.prototype.signPersonalMessage = function (msgData, event) {
ConfirmTxScreen.prototype.signTypedMessage = function (msgData, event) {
log.info('conf-tx.js: signing typed message')
var params = msgData.msgParams
const params = msgData.msgParams
params.metamaskId = msgData.id
this.stopPropagation(event)
this.props.dispatch(actions.signTypedMsg(params))

View File

@ -23,7 +23,7 @@ function mapStateToProps (state) {
}
InitializeMenuScreen.prototype.render = function () {
var state = this.props
const state = this.props
switch (state.currentView.name) {
@ -162,10 +162,10 @@ InitializeMenuScreen.prototype.showRestoreVault = function () {
}
InitializeMenuScreen.prototype.createNewVaultAndKeychain = function () {
var passwordBox = document.getElementById('password-box')
var password = passwordBox.value
var passwordConfirmBox = document.getElementById('password-box-confirm')
var passwordConfirm = passwordConfirmBox.value
const passwordBox = document.getElementById('password-box')
const password = passwordBox.value
const passwordConfirmBox = document.getElementById('password-box-confirm')
const passwordConfirm = passwordConfirmBox.value
if (password.length < 8) {
this.warning = 'password not long enough'

View File

@ -20,8 +20,8 @@ function mapStateToProps (state) {
}
CreateVaultCompleteScreen.prototype.render = function () {
var state = this.props
var seed = state.seed || state.cachedSeed || ''
const state = this.props
const seed = state.seed || state.cachedSeed || ''
return (

View File

@ -116,6 +116,6 @@ RevealSeedConfirmation.prototype.checkConfirmation = function (event) {
}
RevealSeedConfirmation.prototype.revealSeedWords = function () {
var password = document.getElementById('password-box').value
const password = document.getElementById('password-box').value
this.props.dispatch(actions.requestRevealSeed(password, this.props.dPath))
}

View File

@ -19,7 +19,7 @@ function mapStateToProps (state) {
}
RestoreVaultScreen.prototype.render = function () {
var state = this.props
const state = this.props
this.persistentFormParentId = 'restore-vault-form'
return (
@ -147,10 +147,10 @@ RestoreVaultScreen.prototype.createOnEnter = function (event) {
RestoreVaultScreen.prototype.createNewVaultAndRestore = function () {
// check password
var passwordBox = document.getElementById('password-box')
var password = passwordBox.value
var passwordConfirmBox = document.getElementById('password-box-confirm')
var passwordConfirm = passwordConfirmBox.value
const passwordBox = document.getElementById('password-box')
const password = passwordBox.value
const passwordConfirmBox = document.getElementById('password-box-confirm')
const passwordConfirm = passwordConfirmBox.value
if (password.length < 8) {
this.warning = 'Password not long enough'
this.props.dispatch(actions.displayWarning(this.warning))
@ -162,8 +162,8 @@ RestoreVaultScreen.prototype.createNewVaultAndRestore = function () {
return
}
// check seed
var seedBox = document.querySelector('textarea.twelve-word-phrase')
var seed = seedBox.value.trim()
const seedBox = document.querySelector('textarea.twelve-word-phrase')
const seed = seedBox.value.trim()
// true if the string has more than a space between words.
if (seed.split(' ').length > 1) {

View File

@ -109,8 +109,8 @@ UnlockScreen.prototype.onKeyPress = function (event) {
}
UnlockScreen.prototype.submitPassword = async function (event) {
var element = event.target
var password = element.value
const element = event.target
const password = element.value
// reset input
element.value = ''
try {

View File

@ -97,6 +97,7 @@ module.exports = {
getNetworkID,
getDPath,
setDPath,
getTokenImageFolder,
}
function valuesFor (obj) {
@ -568,3 +569,18 @@ function setDPath (keyring, network) {
keyring.setHdPath(dPath)
}
}
function getTokenImageFolder (networkID) {
switch (networkID) {
case MAINNET_CODE:
return 'images/contract'
case POA_CODE:
return 'images/contractPOA'
case RSK_CODE:
return 'images/contractRSK'
case RSK_TESTNET_CODE:
return 'images/contractRSKTest'
default:
return 'images/contractPOA'
}
}

View File

@ -3,7 +3,7 @@ const path = require('path')
module.exports = bundleCss
var cssFiles = {
const cssFiles = {
'fonts.css': fs.readFileSync(path.join(__dirname, '/app/css/fonts.css'), 'utf8'),
'reset.css': fs.readFileSync(path.join(__dirname, '/app/css/reset.css'), 'utf8'),
'lib.css': fs.readFileSync(path.join(__dirname, '/app/css/lib.css'), 'utf8'),
@ -21,9 +21,9 @@ var cssFiles = {
}
function bundleCss () {
var cssBundle = Object.keys(cssFiles).reduce(function (bundle, fileName) {
var fileContent = cssFiles[fileName]
var output = String()
const cssBundle = Object.keys(cssFiles).reduce(function (bundle, fileName) {
const fileContent = cssFiles[fileName]
let output = String()
output += '/*========== ' + fileName + ' ==========*/\n\n'
output += fileContent

View File

@ -1,9 +1,13 @@
var iconFactory
const isValidAddress = require('ethereumjs-util').isValidAddress
const contractMapETH = require('eth-contract-metadata')
const contractMapPOA = require('poa-contract-metadata')
import { isValidAddress } from 'ethereumjs-util'
import contractMapETH from 'eth-contract-metadata'
import contractMapPOA from 'poa-contract-metadata'
import contractMapRSK from 'rsk-contract-metadata'
import contractMapRSKTest from 'rsk-test-contract-metadata'
import { MAINNET_CODE, POA_CODE, RSK_CODE, RSK_TESTNET_CODE } from '../../app/scripts/controllers/network/enums'
const colors = require('../../colors')
const { toChecksumAddress } = require('../app/util')
const { toChecksumAddress, getTokenImageFolder } = require('../app/util')
let iconFactory
module.exports = function (rockicon) {
if (!iconFactory) {
@ -30,33 +34,33 @@ IconFactory.prototype.iconForAddress = function (address, diameter, network) {
// returns svg dom element
IconFactory.prototype.generateIdenticonSvg = function (address, diameter) {
var cacheId = `${address}:${diameter}`
const cacheId = `${address}:${diameter}`
// check cache, lazily generate and populate cache
var identicon = this.cache[cacheId] || (this.cache[cacheId] = this.generateNewIdenticon(address, diameter))
const identicon = this.cache[cacheId] || (this.cache[cacheId] = this.generateNewIdenticon(address, diameter))
// create a clean copy so you can modify it
var cleanCopy = identicon.cloneNode(true)
const cleanCopy = identicon.cloneNode(true)
return cleanCopy
}
// creates a new identicon
IconFactory.prototype.generateNewIdenticon = function (address, diameter) {
var numericRepresentation = jsNumberForAddress(address)
var identicon = this.rockicon.generateIdenticon(diameter, numericRepresentation)
const numericRepresentation = jsNumberForAddress(address)
const identicon = this.rockicon.generateIdenticon(diameter, numericRepresentation)
return identicon
}
// util
function iconExistsFor (address, networkID) {
const contractMap = networkID === 1 ? contractMapETH : contractMapPOA
const contractMap = _getContractMap(networkID)
return contractMap[address] && isValidAddress(address) && contractMap[address].logo
}
function imageElFor (address, networkID) {
const contractMap = networkID === 1 ? contractMapETH : contractMapPOA
const contractMap = _getContractMap(networkID)
const contract = contractMap[address]
const fileName = contract.logo
const imagesFolder = networkID === 1 ? 'images/contract' : 'images/contractPOA'
const imagesFolder = getTokenImageFolder(networkID)
const path = `${imagesFolder}/${fileName}`
const img = document.createElement('img')
img.src = path
@ -65,8 +69,23 @@ function imageElFor (address, networkID) {
}
function jsNumberForAddress (address) {
var addr = address.slice(2, 10)
var seed = parseInt(addr, 16)
const addr = address.slice(2, 10)
const seed = parseInt(addr, 16)
return seed
}
function _getContractMap (networkID) {
switch (networkID) {
case MAINNET_CODE:
return contractMapETH
case POA_CODE:
return contractMapPOA
case RSK_CODE:
return contractMapRSK
case RSK_TESTNET_CODE:
return contractMapRSKTest
default:
return contractMapPOA
}
}

View File

@ -15,7 +15,7 @@ PersistentForm.prototype.componentDidMount = function () {
const fields = document.querySelectorAll('[data-persistent-formid]')
const store = this.getPersistentStore()
for (var i = 0; i < fields.length; i++) {
for (let i = 0; i < fields.length; i++) {
const field = fields[i]
const key = field.getAttribute('data-persistent-formid')
const cached = store[key]
@ -52,7 +52,7 @@ PersistentForm.prototype.persistentFieldDidUpdate = function (event) {
PersistentForm.prototype.componentWillUnmount = function () {
const fields = document.querySelectorAll('[data-persistent-formid]')
for (var i = 0; i < fields.length; i++) {
for (let i = 0; i < fields.length; i++) {
const field = fields[i]
field.removeEventListener(eventName, this.persistentFieldDidUpdate.bind(this))
}

8
package-lock.json generated
View File

@ -49792,6 +49792,14 @@
"uuid": "^3.3.2"
}
},
"rsk-contract-metadata": {
"version": "github:rsksmart/rsk-contract-metadata#262495abfa6ff83fb9cd46c7fb9f85690e4e5d4b",
"from": "github:rsksmart/rsk-contract-metadata#master"
},
"rsk-test-contract-metadata": {
"version": "github:rsksmart/rsk-testnet-contract-metadata#69ff2d652b286648e9264e2689009e940ec7ccad",
"from": "github:rsksmart/rsk-testnet-contract-metadata#master"
},
"rst-selector-parser": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/rst-selector-parser/-/rst-selector-parser-2.2.3.tgz",

View File

@ -165,6 +165,8 @@
"pify": "^3.0.0",
"ping-pong-stream": "^1.0.0",
"poa-contract-metadata": "github:poanetwork/poa-contract-metadata#master",
"rsk-contract-metadata": "github:rsksmart/rsk-contract-metadata#master",
"rsk-test-contract-metadata": "github:rsksmart/rsk-testnet-contract-metadata#master",
"polyfill-crypto.getrandomvalues": "^1.0.0",
"post-message-stream": "^3.0.0",
"promise-filter": "^1.1.0",

View File

@ -1,7 +1,9 @@
const path = require('path')
const Func = require('./func').Functions
const account1 = '0x2E428ABd9313D256d64D1f69fe3929C3BE18fD1f'
const account1RSK = '0x7a9bc05F7441d862d1B83CB724861a9872FF43fe'
// todo:
// const account1RSK = '0x7a9bc05F7441d862d1B83CB724861a9872FF43fe'
const account1RSK = '0x2E428aBd9313D256d64D1f69fe3929c3Be18Fd1F'
const account2 = '0xd7b7AFeCa35e32594e29504771aC847E2a803742'
const testsFolder = './test-cases'
const setup = require(`${testsFolder}/setup.spec`)

View File

@ -11,7 +11,7 @@ function reduceMetamask (state, action) {
let newState
// clone + defaults
var metamaskState = extend({
const metamaskState = extend({
isInitialized: false,
isUnlocked: false,
isAccountMenuOpen: false,
@ -113,7 +113,7 @@ function reduceMetamask (state, action) {
})
case actions.COMPLETED_TX:
var stringId = String(action.id)
const stringId = String(action.id)
newState = extend(metamaskState, {
unapprovedTxs: {},
unapprovedMsgs: {},

View File

@ -1,8 +1,10 @@
const log = require('loglevel')
const util = require('./util')
const BigNumber = require('bignumber.js')
import log from 'loglevel'
import BigNumber from 'bignumber.js'
import contractMapETH from 'eth-contract-metadata'
import contractMapPOA from 'poa-contract-metadata'
import contractMapRSK from 'rsk-contract-metadata'
import contractMapRSKTest from 'rsk-test-contract-metadata'
const util = require('./util')
const casedContractMapETH = Object.keys(contractMapETH).reduce((acc, base) => {
return {
@ -18,7 +20,21 @@ const casedContractMapPOA = Object.keys(contractMapPOA).reduce((acc, base) => {
}
}, {})
const casedContractMap = Object.assign(casedContractMapETH, casedContractMapPOA)
const casedContractMapRSK = Object.keys(contractMapRSK).reduce((acc, base) => {
return {
...acc,
[base.toLowerCase()]: contractMapRSK[base],
}
}, {})
const casedContractMapRSKTest = Object.keys(contractMapRSKTest).reduce((acc, base) => {
return {
...acc,
[base.toLowerCase()]: contractMapRSKTest[base],
}
}, {})
const casedContractMap = Object.assign(casedContractMapETH, casedContractMapPOA, casedContractMapRSK, casedContractMapRSKTest)
const DEFAULT_SYMBOL = ''
const DEFAULT_DECIMALS = '0'

View File

@ -12,7 +12,7 @@ module.exports = launchMetamaskUi
log.setLevel(global.METAMASK_DEBUG ? 'debug' : 'warn')
function launchMetamaskUi (opts, cb) {
var accountManager = opts.accountManager
const { accountManager } = opts
actions._setBackgroundConnection(accountManager)
// check if we are unlocked first
accountManager.getState(function (err, metamaskState) {

View File

@ -15,7 +15,7 @@ PersistentForm.prototype.componentDidMount = function () {
const fields = document.querySelectorAll('[data-persistent-formid]')
const store = this.getPersistentStore()
for (var i = 0; i < fields.length; i++) {
for (let i = 0; i < fields.length; i++) {
const field = fields[i]
const key = field.getAttribute('data-persistent-formid')
const cached = store[key]
@ -52,7 +52,7 @@ PersistentForm.prototype.persistentFieldDidUpdate = function (event) {
PersistentForm.prototype.componentWillUnmount = function () {
const fields = document.querySelectorAll('[data-persistent-formid]')
for (var i = 0; i < fields.length; i++) {
for (let i = 0; i < fields.length; i++) {
const field = fields[i]
field.removeEventListener(eventName, this.persistentFieldDidUpdate.bind(this))
}