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

(Feature) Add RSK support #285

Merged
merged 6 commits into from
Jun 6, 2019
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
8 changes: 8 additions & 0 deletions app/scripts/controllers/network/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const RINKEBY = 'rinkeby'
const KOVAN = 'kovan'
const GOERLI_TESTNET = 'goerli_testnet'
const CLASSIC = 'classic'
const RSK = 'rsk'
const LOCALHOST = 'localhost'

const POA_CODE = 99
Expand All @@ -18,6 +19,7 @@ const RINKEBY_CODE = 4
const KOVAN_CODE = 42
const GOERLI_TESTNET_CODE = 5
const CLASSIC_CODE = 61
const RSK_CODE = 30

const POA_DISPLAY_NAME = 'POA Network'
const DAI_DISPLAY_NAME = 'xDai Chain'
Expand All @@ -28,6 +30,7 @@ const RINKEBY_DISPLAY_NAME = 'Rinkeby'
const KOVAN_DISPLAY_NAME = 'Kovan'
const GOERLI_TESTNET_DISPLAY_NAME = 'Görli Testnet'
const CLASSIC_DISPLAY_NAME = 'Ethereum Classic'
const RSK_DISPLAY_NAME = 'RSK Mainnet'

const DROPDOWN_POA_DISPLAY_NAME = POA_DISPLAY_NAME
const DROPDOWN_DAI_DISPLAY_NAME = DAI_DISPLAY_NAME
Expand All @@ -38,6 +41,7 @@ const DROPDOWN_RINKEBY_DISPLAY_NAME = 'Rinkeby Test Net'
const DROPDOWN_KOVAN_DISPLAY_NAME = 'Kovan Test Net'
const DROPDOWN_GOERLI_TESTNET_DISPLAY_NAME = 'Görli Test Net'
const DROPDOWN_CLASSIC_DISPLAY_NAME = 'Ethereum Classic'
const DROPDOWN_RSK_DISPLAY_NAME = 'RSK Main Net'

const chainTypes = {
TEST: 1,
Expand All @@ -54,6 +58,7 @@ module.exports = {
KOVAN,
GOERLI_TESTNET,
CLASSIC,
RSK,
LOCALHOST,
POA_CODE,
DAI_CODE,
Expand All @@ -64,6 +69,7 @@ module.exports = {
KOVAN_CODE,
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
POA_DISPLAY_NAME,
DAI_DISPLAY_NAME,
POA_SOKOL_DISPLAY_NAME,
Expand All @@ -73,6 +79,7 @@ module.exports = {
KOVAN_DISPLAY_NAME,
GOERLI_TESTNET_DISPLAY_NAME,
CLASSIC_DISPLAY_NAME,
RSK_DISPLAY_NAME,
DROPDOWN_POA_DISPLAY_NAME,
DROPDOWN_DAI_DISPLAY_NAME,
DROPDOWN_POA_SOKOL_DISPLAY_NAME,
Expand All @@ -82,5 +89,6 @@ module.exports = {
DROPDOWN_KOVAN_DISPLAY_NAME,
DROPDOWN_GOERLI_TESTNET_DISPLAY_NAME,
DROPDOWN_CLASSIC_DISPLAY_NAME,
DROPDOWN_RSK_DISPLAY_NAME,
chainTypes,
}
7 changes: 6 additions & 1 deletion app/scripts/controllers/network/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ const {
DAI,
GOERLI_TESTNET,
CLASSIC,
RSK,
POA_CODE,
DAI_CODE,
POA_SOKOL_CODE,
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
} = require('./enums')
const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET]

Expand Down Expand Up @@ -127,7 +129,8 @@ module.exports = class NetworkController extends EventEmitter {
type === POA ||
type === DAI ||
type === GOERLI_TESTNET ||
type === CLASSIC
type === CLASSIC ||
type === RSK
, `NetworkController - Unknown rpc type "${type}"`)
const providerConfig = { type }
this.providerConfig = providerConfig
Expand Down Expand Up @@ -173,6 +176,8 @@ module.exports = class NetworkController extends EventEmitter {
this._configureStandardProvider({ rpcUrl: ethNetProps.RPCEndpoints(GOERLI_TESTNET_CODE)[0] })
} else if (type === CLASSIC) {
this._configureStandardProvider({ rpcUrl: ethNetProps.RPCEndpoints(CLASSIC_CODE)[0] })
} else if (type === RSK) {
this._configureStandardProvider({ rpcUrl: ethNetProps.RPCEndpoints(RSK_CODE)[0] })
} else if (type === LOCALHOST) {
this._configureLocalhostProvider()
// url-based rpc endpoints
Expand Down
14 changes: 14 additions & 0 deletions app/scripts/controllers/network/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
KOVAN,
GOERLI_TESTNET,
CLASSIC,
RSK,
POA_CODE,
DAI_CODE,
POA_SOKOL_CODE,
Expand All @@ -17,6 +18,7 @@ const {
KOVAN_CODE,
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
POA_DISPLAY_NAME,
DAI_DISPLAY_NAME,
POA_SOKOL_DISPLAY_NAME,
Expand All @@ -26,6 +28,7 @@ const {
KOVAN_DISPLAY_NAME,
GOERLI_TESTNET_DISPLAY_NAME,
CLASSIC_DISPLAY_NAME,
RSK_DISPLAY_NAME,
DROPDOWN_POA_DISPLAY_NAME,
DROPDOWN_DAI_DISPLAY_NAME,
DROPDOWN_POA_SOKOL_DISPLAY_NAME,
Expand All @@ -35,6 +38,7 @@ const {
DROPDOWN_KOVAN_DISPLAY_NAME,
DROPDOWN_GOERLI_TESTNET_DISPLAY_NAME,
DROPDOWN_CLASSIC_DISPLAY_NAME,
DROPDOWN_RSK_DISPLAY_NAME,
chainTypes,
} = require('./enums')

Expand Down Expand Up @@ -139,6 +143,16 @@ const GOERLI_TESTNET_OBJ = {
networks[GOERLI_TESTNET_CODE] = GOERLI_TESTNET_OBJ
networks[GOERLI_TESTNET] = GOERLI_TESTNET_OBJ

const RSK_OBJ = {
order: 10,
providerName: RSK,
networkID: RSK_CODE,
displayName: RSK_DISPLAY_NAME,
displayNameDropdown: DROPDOWN_RSK_DISPLAY_NAME,
}
networks[RSK_CODE] = RSK_OBJ
networks[RSK] = RSK_OBJ

const getNetworkDisplayName = key => networks[key].displayName

module.exports = {
Expand Down
19 changes: 18 additions & 1 deletion app/scripts/lib/buy-eth-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const {
ROPSTEN_CODE,
RINKEBY_CODE,
KOVAN_CODE,
GOERLI_TESTNET_CODE} = require('../controllers/network/enums')
GOERLI_TESTNET_CODE,
RSK_CODE} = require('../controllers/network/enums')

/**
* Gives the caller a url at which the user can acquire coin, depending on the network they are in
Expand All @@ -35,6 +36,7 @@ function getBuyEthUrl ({ network, amount, address, ind }) {
case POA_CODE:
case DAI_CODE:
case CLASSIC_CODE:
case RSK_CODE:
url = getExchanges({network, amount, address})[ind].link
break
case ROPSTEN_CODE:
Expand Down Expand Up @@ -109,6 +111,21 @@ function getExchanges ({network, amount, address}) {
link: 'https://dai-bridge.poa.network/',
},
]
case RSK_CODE:
return [
{
name: 'Huobi',
link: 'https://www.huobi.com/',
},
{
name: 'Bitfinex',
link: 'https://www.bitfinex.com/',
},
{
name: 'Bitso',
link: 'https://bitso.com/',
},
]
default:
return []
}
Expand Down
4 changes: 3 additions & 1 deletion old-ui/app/components/transaction-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const { POA_CODE,
KOVAN_CODE,
GOERLI_TESTNET_CODE,
CLASSIC_CODE,
RSK_CODE,
} = require('../../../app/scripts/controllers/network/enums')

const mapDispatchToProps = dispatch => {
Expand Down Expand Up @@ -84,7 +85,8 @@ TransactionListItem.prototype.render = function () {
numericNet === POA_CODE ||
numericNet === DAI_CODE ||
numericNet === GOERLI_TESTNET_CODE ||
numericNet === CLASSIC_CODE
numericNet === CLASSIC_CODE ||
numericNet === RSK_CODE

var isMsg = ('msgParams' in transaction)
var isTx = ('txParams' in transaction)
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
"brfs": "^1.6.1",
"browserify": "^16.2.3",
"chai": "^4.1.0",
"chromedriver": "^2.41.0",
"chromedriver": "^74.0.0",
"clipboardy": "^1.2.3",
"compression": "^1.7.1",
"coveralls": "^3.0.0",
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ module.exports = {
buttons: {
send: By.css('#app-content > div > div.app-primary.from-right > div > div > div.flex-row > button:nth-child(4)'),
buy: By.css('#app-content > div > div.app-primary.from-right > div > div > div.flex-row > button:nth-child(3)'),
sendRSK: By.css('#app-content > div > div.app-primary.from-left > div > div > div.flex-row > button:nth-child(4)'),
buyRSK: By.css('#app-content > div > div.app-primary.from-left > div > div > div.flex-row > button:nth-child(3)'),
sendText: 'Send',
save: By.className('editable-button'),
},
Expand Down Expand Up @@ -323,6 +325,7 @@ module.exports = {
},
buyEther: {
title: By.className('flex-center buy-title'),
faucetLinkRSK: By.className('buy-option cursor-pointer'),
buttonArrow: By.className('fa fa-arrow-left fa-lg cursor-pointer'),
},
info: {
Expand Down Expand Up @@ -400,6 +403,7 @@ module.exports = {
KOVAN: 'kovan',
RINKEBY: 'rinkeby',
GOERLI: 'goerli',
RSK: 'rsk',
LOCALHOST: 'localhost',
CUSTOM: 'http://test.com',
},
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,17 @@ class Functions {
case NETWORKS.GOERLI:
counter = 8
break
case NETWORKS.LOCALHOST:
case NETWORKS.RSK:
counter = 9
break
case NETWORKS.CUSTOM:
case NETWORKS.LOCALHOST:
counter = 10
break
case NETWORKS.CUSTOM:
counter = 11
break
default:
counter = 9
counter = 10
}
await this.driver.executeScript("document.getElementsByClassName('dropdown-menu-item')[" + counter + '].click();')
}
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/test-cases/add-token-custom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ const addCustomToken = async (f, account1, account2) => {
await f.setProvider(NETWORKS.RINKEBY)
assert.equal(await f.assertTokensNotDisplayed(), true, 'tokens are displayed')
})

it('token should not be displayed in RSK network', async () => {
await f.setProvider(NETWORKS.RSK)
assert.equal(await f.assertTokensNotDisplayed(), true, 'tokens are displayed')
})
})

describe.skip('Custom tokens validation ', async () => {
Expand Down Expand Up @@ -200,6 +205,11 @@ const addCustomToken = async (f, account1, account2) => {
assert(await f.isDisabledAddInexistentToken(tokenAddress), true, 'can add inexistent token in MAINNET')
})

it('can not add inexistent token to RSK mainnet', async () => {
await f.setProvider(NETWORKS.RSK)
assert(await f.isDisabledAddInexistentToken(tokenAddress), true, 'can add inexistent token in RSK mainnet')
})

it('can not add inexistent token to LOCALHOST network', async () => {
await f.setProvider(NETWORKS.LOCALHOST)
assert(await f.isDisabledAddInexistentToken(tokenAddress.slice(0, tokenAddress.length - 2) + '0'), true, 'can add inexistent token in LOCALHOST network')
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/test-cases/add-token-search.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ const addTokeFromSearch = async (f) => {
await f.setProvider(NETWORKS.RINKEBY)
assert.equal(await f.assertTokensNotDisplayed(), true, 'tokens are displayed')
})

it('token should not be displayed in RSK mainnet', async () => {
await f.setProvider(NETWORKS.RSK)
assert.equal(await f.assertTokensNotDisplayed(), true, 'tokens are displayed')
})
})
describe('remove Mainnet\'s tokens', function () {

Expand Down
4 changes: 3 additions & 1 deletion ui/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { ENVIRONMENT_TYPE_NOTIFICATION } = require('../../app/scripts/lib/enums')
const { POA,
DAI,
POA_SOKOL,
RSK,
CLASSIC } = require('../../app/scripts/controllers/network/enums')
const { hasUnconfirmedTransactions } = require('./helpers/confirm-transaction/util')
const WebcamUtils = require('../lib/webcam-utils')
Expand Down Expand Up @@ -2014,7 +2015,8 @@ function setProviderType (type) {
const newCoin = type === POA || type === POA_SOKOL ?
'poa' : type === DAI ?
'dai' : type === CLASSIC ?
'etc' : 'eth'
'etc' : type === RSK ?
'rbtc' : 'eth'
background.setCurrentCoin(newCoin, (err, data) => {
if (err) {
log.error(err.stack)
Expand Down