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

Add RSK/testnet default tokens #355

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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
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
4 changes: 2 additions & 2 deletions app/scripts/notice-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
Expand Down
14 changes: 7 additions & 7 deletions old-ui/app/account-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -248,7 +248,7 @@ AccountDetailScreen.prototype.render = function () {
}

AccountDetailScreen.prototype.subview = function () {
var subview
let subview
try {
subview = this.props.accountDetail.subview
} catch (e) {
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions old-ui/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function mapStateToProps (state) {
}

App.prototype.render = function () {
var props = this.props
const props = this.props
const {
currentView,
isLoading,
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions old-ui/app/components/account-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '',
Expand Down
16 changes: 9 additions & 7 deletions old-ui/app/components/add-token/add-token.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
}
}
10 changes: 5 additions & 5 deletions old-ui/app/components/bn-as-decimal-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -170,17 +170,17 @@ 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)) {
newString += stringArray[1].slice(0, 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
Expand Down
6 changes: 3 additions & 3 deletions old-ui/app/components/editable-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
18 changes: 9 additions & 9 deletions old-ui/app/components/eth-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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) {
Expand All @@ -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%',
Expand Down
12 changes: 6 additions & 6 deletions old-ui/app/components/identicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) {
Expand All @@ -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])
}

Expand Down
4 changes: 2 additions & 2 deletions old-ui/app/components/menu-droppo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions old-ui/app/components/mini-account-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Loading