Extend line width to 120 (#174)
* Extend line width to 120 * Lint fixes
This commit is contained in:
parent
a2e9dae43d
commit
40be5a5f8e
@ -1,6 +1,6 @@
|
||||
{
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"printWidth": 100,
|
||||
"printWidth": 120,
|
||||
"bracketSpacing": true
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
const HOME_NATIVE_TO_ERC_ABI = require('../contracts/build/contracts/HomeBridgeNativeToErc').abi
|
||||
const FOREIGN_NATIVE_TO_ERC_ABI = require('../contracts/build/contracts/ForeignBridgeNativeToErc')
|
||||
.abi
|
||||
const FOREIGN_NATIVE_TO_ERC_ABI = require('../contracts/build/contracts/ForeignBridgeNativeToErc').abi
|
||||
const HOME_ERC_TO_ERC_ABI = require('../contracts/build/contracts/HomeBridgeErcToErc').abi
|
||||
const FOREIGN_ERC_TO_ERC_ABI = require('../contracts/build/contracts/ForeignBridgeErc677ToErc677')
|
||||
.abi
|
||||
const FOREIGN_ERC_TO_ERC_ABI = require('../contracts/build/contracts/ForeignBridgeErc677ToErc677').abi
|
||||
const HOME_ERC_TO_NATIVE_ABI = require('../contracts/build/contracts/HomeBridgeErcToNative').abi
|
||||
const FOREIGN_ERC_TO_NATIVE_ABI = require('../contracts/build/contracts/ForeignBridgeErcToNative')
|
||||
.abi
|
||||
const FOREIGN_ERC_TO_NATIVE_ABI = require('../contracts/build/contracts/ForeignBridgeErcToNative').abi
|
||||
const ERC20_ABI = require('../contracts/build/contracts/ERC20').abi
|
||||
const ERC677_ABI = require('../contracts/build/contracts/ERC677').abi
|
||||
const ERC677_BRIDGE_TOKEN_ABI = require('../contracts/build/contracts/ERC677BridgeToken').abi
|
||||
|
@ -30,25 +30,15 @@ async function main() {
|
||||
)
|
||||
|
||||
logger.debug('extracting most recent transactionHash')
|
||||
const { transactionHash: xSignaturesMostRecentTxHash = '' } =
|
||||
xSignatures.sort(sortEvents).reverse()[0] || {}
|
||||
const { transactionHash: xAffirmationsMostRecentTxHash = '' } =
|
||||
xAffirmations.sort(sortEvents).reverse()[0] || {}
|
||||
const { transactionHash: xSignaturesMostRecentTxHash = '' } = xSignatures.sort(sortEvents).reverse()[0] || {}
|
||||
const { transactionHash: xAffirmationsMostRecentTxHash = '' } = xAffirmations.sort(sortEvents).reverse()[0] || {}
|
||||
|
||||
logger.debug('building transaction objects')
|
||||
const foreignValidators = await Promise.all(
|
||||
xSignatures.map(event => findTxSender(web3Foreign)(event))
|
||||
)
|
||||
const homeValidators = await Promise.all(
|
||||
xAffirmations.map(event => findTxSender(web3Home)(event))
|
||||
)
|
||||
const foreignValidators = await Promise.all(xSignatures.map(event => findTxSender(web3Foreign)(event)))
|
||||
const homeValidators = await Promise.all(xAffirmations.map(event => findTxSender(web3Home)(event)))
|
||||
|
||||
const xSignaturesTxs = xSignatures
|
||||
.map(normalizeEventInformation)
|
||||
.reduce(buildTxList(foreignValidators), {})
|
||||
const xAffirmationsTxs = xAffirmations
|
||||
.map(normalizeEventInformation)
|
||||
.reduce(buildTxList(homeValidators), {})
|
||||
const xSignaturesTxs = xSignatures.map(normalizeEventInformation).reduce(buildTxList(foreignValidators), {})
|
||||
const xAffirmationsTxs = xAffirmations.map(normalizeEventInformation).reduce(buildTxList(homeValidators), {})
|
||||
|
||||
logger.debug('Done')
|
||||
|
||||
@ -166,9 +156,7 @@ const findDifferences = src => dest => {
|
||||
return (
|
||||
src
|
||||
.map(normalizeEventInformation)
|
||||
.filter(
|
||||
a => a.referenceTx === b.referenceTx && a.recipient === b.recipient && a.value === b.value
|
||||
).length === 0
|
||||
.filter(a => a.referenceTx === b.referenceTx && a.recipient === b.recipient && a.value === b.value).length === 0
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -26,18 +26,12 @@ async function checkWorker() {
|
||||
const foreign = Object.assign({}, balances.foreign, events.foreign)
|
||||
const status = Object.assign({}, balances, events, { home }, { foreign })
|
||||
if (!status) throw new Error('status is empty: ' + JSON.stringify(status))
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '/responses/getBalances.json'),
|
||||
JSON.stringify(status, null, 4)
|
||||
)
|
||||
fs.writeFileSync(path.join(__dirname, '/responses/getBalances.json'), JSON.stringify(status, null, 4))
|
||||
|
||||
logger.debug('calling validators()')
|
||||
const vBalances = await validators(bridgeMode)
|
||||
if (!vBalances) throw new Error('vBalances is empty: ' + JSON.stringify(vBalances))
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '/responses/validators.json'),
|
||||
JSON.stringify(vBalances, null, 4)
|
||||
)
|
||||
fs.writeFileSync(path.join(__dirname, '/responses/validators.json'), JSON.stringify(vBalances, null, 4))
|
||||
logger.debug('Done')
|
||||
} catch (e) {
|
||||
logger.error(e)
|
||||
|
@ -9,17 +9,11 @@ async function checkWorker2() {
|
||||
logger.debug('calling eventsStats()')
|
||||
const evStats = await eventsStats()
|
||||
if (!evStats) throw new Error('evStats is empty: ' + JSON.stringify(evStats))
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '/responses/eventsStats.json'),
|
||||
JSON.stringify(evStats, null, 4)
|
||||
)
|
||||
fs.writeFileSync(path.join(__dirname, '/responses/eventsStats.json'), JSON.stringify(evStats, null, 4))
|
||||
logger.debug('calling alerts()')
|
||||
const _alerts = await alerts()
|
||||
if (!_alerts) throw new Error('alerts is empty: ' + JSON.stringify(_alerts))
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '/responses/alerts.json'),
|
||||
JSON.stringify(_alerts, null, 4)
|
||||
)
|
||||
fs.writeFileSync(path.join(__dirname, '/responses/alerts.json'), JSON.stringify(_alerts, null, 4))
|
||||
logger.debug('Done x2')
|
||||
} catch (e) {
|
||||
logger.error(e)
|
||||
|
@ -9,10 +9,7 @@ async function checkWorker3() {
|
||||
const transfers = await stuckTransfers()
|
||||
// console.log(transfers)
|
||||
if (!transfers) throw new Error('transfers is empty: ' + JSON.stringify(transfers))
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '/responses/stuckTransfers.json'),
|
||||
JSON.stringify(transfers, null, 4)
|
||||
)
|
||||
fs.writeFileSync(path.join(__dirname, '/responses/stuckTransfers.json'), JSON.stringify(transfers, null, 4))
|
||||
logger.debug('Done')
|
||||
} catch (e) {
|
||||
logger.error('checkWorker3.js', e)
|
||||
|
@ -57,18 +57,10 @@ function compareTransferForeign(home) {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const {
|
||||
foreignDeposits,
|
||||
homeDeposits,
|
||||
homeWithdrawals,
|
||||
foreignWithdrawals,
|
||||
isExternalErc20
|
||||
} = await eventsInfo()
|
||||
const { foreignDeposits, homeDeposits, homeWithdrawals, foreignWithdrawals, isExternalErc20 } = await eventsInfo()
|
||||
|
||||
const onlyInHomeDeposits = homeDeposits.filter(compareDepositsHome(foreignDeposits))
|
||||
const onlyInForeignDeposits = foreignDeposits
|
||||
.concat([])
|
||||
.filter(compareDepositsForeign(homeDeposits))
|
||||
const onlyInForeignDeposits = foreignDeposits.concat([]).filter(compareDepositsForeign(homeDeposits))
|
||||
|
||||
const onlyInHomeWithdrawals = isExternalErc20
|
||||
? homeWithdrawals.filter(compareTransferHome(foreignWithdrawals))
|
||||
|
@ -27,10 +27,7 @@ const {
|
||||
|
||||
async function main(bridgeMode) {
|
||||
if (bridgeMode === BRIDGE_MODES.ERC_TO_ERC) {
|
||||
const foreignBridge = new web3Foreign.eth.Contract(
|
||||
FOREIGN_ERC_TO_ERC_ABI,
|
||||
FOREIGN_BRIDGE_ADDRESS
|
||||
)
|
||||
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ERC_TO_ERC_ABI, FOREIGN_BRIDGE_ADDRESS)
|
||||
const erc20Address = await foreignBridge.methods.erc20token().call()
|
||||
const erc20Contract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
|
||||
logger.debug('calling erc20Contract.methods.balanceOf')
|
||||
@ -55,15 +52,9 @@ async function main(bridgeMode) {
|
||||
balanceDiff: Number(Web3Utils.fromWei(diff)),
|
||||
lastChecked: Math.floor(Date.now() / 1000)
|
||||
}
|
||||
} else if (
|
||||
bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC ||
|
||||
bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1
|
||||
) {
|
||||
} else if (bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1) {
|
||||
logger.debug('calling web3Home.eth.getBalance')
|
||||
const foreignBridge = new web3Foreign.eth.Contract(
|
||||
FOREIGN_NATIVE_TO_ERC_ABI,
|
||||
FOREIGN_BRIDGE_ADDRESS
|
||||
)
|
||||
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_NATIVE_TO_ERC_ABI, FOREIGN_BRIDGE_ADDRESS)
|
||||
const erc20Address = await foreignBridge.methods.erc677token().call()
|
||||
const homeBalance = await web3Home.eth.getBalance(HOME_BRIDGE_ADDRESS)
|
||||
const tokenContract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
|
||||
@ -84,10 +75,7 @@ async function main(bridgeMode) {
|
||||
lastChecked: Math.floor(Date.now() / 1000)
|
||||
}
|
||||
} else if (bridgeMode === BRIDGE_MODES.ERC_TO_NATIVE) {
|
||||
const foreignBridge = new web3Foreign.eth.Contract(
|
||||
FOREIGN_ERC_TO_NATIVE_ABI,
|
||||
FOREIGN_BRIDGE_ADDRESS
|
||||
)
|
||||
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, FOREIGN_BRIDGE_ADDRESS)
|
||||
const erc20Address = await foreignBridge.methods.erc20token().call()
|
||||
const erc20Contract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
|
||||
logger.debug('calling erc20Contract.methods.balanceOf')
|
||||
|
@ -2,9 +2,7 @@ require('dotenv').config()
|
||||
const eventsInfo = require('./utils/events')
|
||||
|
||||
async function main(bridgeMode) {
|
||||
const { foreignDeposits, homeDeposits, homeWithdrawals, foreignWithdrawals } = await eventsInfo(
|
||||
bridgeMode
|
||||
)
|
||||
const { foreignDeposits, homeDeposits, homeWithdrawals, foreignWithdrawals } = await eventsInfo(bridgeMode)
|
||||
|
||||
return {
|
||||
depositsDiff: homeDeposits.length - foreignDeposits.length,
|
||||
|
@ -91,8 +91,7 @@ app.get('/eventsStats', async (req, res, next) => {
|
||||
app.get('/alerts', async (req, res, next) => {
|
||||
try {
|
||||
const results = await readFile('./responses/alerts.json')
|
||||
results.ok =
|
||||
!results.executeAffirmations.mostRecentTxHash && !results.executeSignatures.mostRecentTxHash
|
||||
results.ok = !results.executeAffirmations.mostRecentTxHash && !results.executeSignatures.mostRecentTxHash
|
||||
res.json(results)
|
||||
} catch (e) {
|
||||
next(e)
|
||||
|
@ -3,12 +3,7 @@ module.exports = function logger(name) {
|
||||
|
||||
function log(...args) {
|
||||
const now = new Date()
|
||||
console.log(
|
||||
now.toISOString(),
|
||||
`(+${lastlog ? now.getTime() - lastlog : 0}ms)`,
|
||||
`[${name}]`,
|
||||
...args
|
||||
)
|
||||
console.log(now.toISOString(), `(+${lastlog ? now.getTime() - lastlog : 0}ms)`, `[${name}]`, ...args)
|
||||
lastlog = now.getTime()
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,7 @@ async function main(mode) {
|
||||
const homeBridge = new web3Home.eth.Contract(HOME_ABI, HOME_BRIDGE_ADDRESS)
|
||||
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, FOREIGN_BRIDGE_ADDRESS)
|
||||
const v1Bridge = bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1
|
||||
const erc20MethodName =
|
||||
bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || v1Bridge ? 'erc677token' : 'erc20token'
|
||||
const erc20MethodName = bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || v1Bridge ? 'erc677token' : 'erc20token'
|
||||
const erc20Address = await foreignBridge.methods[erc20MethodName]().call()
|
||||
const tokenType = await getTokenType(
|
||||
new web3Foreign.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, erc20Address),
|
||||
|
@ -72,20 +72,14 @@ async function main(bridgeMode) {
|
||||
const homeBridge = new web3Home.eth.Contract(HOME_ABI, HOME_BRIDGE_ADDRESS)
|
||||
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, FOREIGN_BRIDGE_ADDRESS)
|
||||
const homeValidatorsAddress = await homeBridge.methods.validatorContract().call()
|
||||
const homeBridgeValidators = new web3Home.eth.Contract(
|
||||
BRIDGE_VALIDATORS_ABI,
|
||||
homeValidatorsAddress
|
||||
)
|
||||
const homeBridgeValidators = new web3Home.eth.Contract(BRIDGE_VALIDATORS_ABI, homeValidatorsAddress)
|
||||
|
||||
logger.debug('getting last block numbers')
|
||||
const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign)
|
||||
|
||||
logger.debug('calling foreignBridge.methods.validatorContract().call()')
|
||||
const foreignValidatorsAddress = await foreignBridge.methods.validatorContract().call()
|
||||
const foreignBridgeValidators = new web3Foreign.eth.Contract(
|
||||
BRIDGE_VALIDATORS_ABI,
|
||||
foreignValidatorsAddress
|
||||
)
|
||||
const foreignBridgeValidators = new web3Foreign.eth.Contract(BRIDGE_VALIDATORS_ABI, foreignValidatorsAddress)
|
||||
|
||||
logger.debug('calling foreignBridgeValidators getValidatorList()')
|
||||
const foreignValidators = await getValidatorList(
|
||||
|
@ -16,10 +16,7 @@ const { toBN } = foreignWeb3.utils
|
||||
homeWeb3.eth.accounts.wallet.add(user.privateKey)
|
||||
foreignWeb3.eth.accounts.wallet.add(user.privateKey)
|
||||
|
||||
const erc20Token = new foreignWeb3.eth.Contract(
|
||||
ERC677_BRIDGE_TOKEN_ABI,
|
||||
ercToErcBridge.foreignToken
|
||||
)
|
||||
const erc20Token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToErcBridge.foreignToken)
|
||||
const erc677Token = new homeWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToErcBridge.homeToken)
|
||||
|
||||
describe('erc to erc', () => {
|
||||
|
@ -16,10 +16,7 @@ const { toBN } = foreignWeb3.utils
|
||||
homeWeb3.eth.accounts.wallet.add(user.privateKey)
|
||||
foreignWeb3.eth.accounts.wallet.add(user.privateKey)
|
||||
|
||||
const erc20Token = new foreignWeb3.eth.Contract(
|
||||
ERC677_BRIDGE_TOKEN_ABI,
|
||||
ercToNativeBridge.foreignToken
|
||||
)
|
||||
const erc20Token = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ercToNativeBridge.foreignToken)
|
||||
|
||||
describe('erc to native', () => {
|
||||
it('should convert tokens in foreign to coins in home', async () => {
|
||||
|
@ -21,8 +21,7 @@ if (baseConfig.id === 'erc-erc' && initialChecks.foreignERC === ERC_TYPES.ERC677
|
||||
const id = `${baseConfig.id}-affirmation-request`
|
||||
|
||||
module.exports =
|
||||
(baseConfig.id === 'erc-erc' && initialChecks.foreignERC === ERC_TYPES.ERC20) ||
|
||||
baseConfig.id === 'erc-native'
|
||||
(baseConfig.id === 'erc-erc' && initialChecks.foreignERC === ERC_TYPES.ERC20) || baseConfig.id === 'erc-native'
|
||||
? {
|
||||
...baseConfig.bridgeConfig,
|
||||
...baseConfig.foreignConfig,
|
||||
|
@ -49,8 +49,7 @@ let maxProcessingTime = null
|
||||
if (String(process.env.MAX_PROCESSING_TIME) === '0') {
|
||||
maxProcessingTime = 0
|
||||
} else if (!process.env.MAX_PROCESSING_TIME) {
|
||||
maxProcessingTime =
|
||||
4 * Math.max(process.env.HOME_POLLING_INTERVAL, process.env.FOREIGN_POLLING_INTERVAL)
|
||||
maxProcessingTime = 4 * Math.max(process.env.HOME_POLLING_INTERVAL, process.env.FOREIGN_POLLING_INTERVAL)
|
||||
} else {
|
||||
maxProcessingTime = Number(process.env.MAX_PROCESSING_TIME)
|
||||
}
|
||||
|
@ -61,10 +61,7 @@ async function main() {
|
||||
console.log('Signature Requests')
|
||||
console.log(signatureRequestsStats)
|
||||
|
||||
const collectedSignaturesStats = computeCollectedSignaturesStats(
|
||||
collectedSignatures,
|
||||
senderForeign
|
||||
)
|
||||
const collectedSignaturesStats = computeCollectedSignaturesStats(collectedSignatures, senderForeign)
|
||||
console.log('Collected Signatures')
|
||||
console.log(collectedSignaturesStats)
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ const {
|
||||
HOME_TEST_TX_GAS_PRICE
|
||||
} = process.env
|
||||
|
||||
const NUMBER_OF_WITHDRAWALS_TO_SEND =
|
||||
process.argv[2] || process.env.NUMBER_OF_WITHDRAWALS_TO_SEND || 1
|
||||
const NUMBER_OF_WITHDRAWALS_TO_SEND = process.argv[2] || process.env.NUMBER_OF_WITHDRAWALS_TO_SEND || 1
|
||||
|
||||
const BRIDGEABLE_TOKEN_ABI = [
|
||||
{
|
||||
|
@ -17,10 +17,7 @@ async function getStartBlock(rpcUrl, bridgeAddress, bridgeAbi) {
|
||||
const deployedAtBlock = await bridgeContract.methods.deployedAtBlock().call()
|
||||
|
||||
const validatorContractAddress = await bridgeContract.methods.validatorContract().call()
|
||||
const validatorContract = new web3Instance.eth.Contract(
|
||||
BRIDGE_VALIDATORS_ABI,
|
||||
validatorContractAddress
|
||||
)
|
||||
const validatorContract = new web3Instance.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorContractAddress)
|
||||
|
||||
const validatorDeployedAtBlock = await validatorContract.methods.deployedAtBlock().call()
|
||||
|
||||
|
@ -8,10 +8,7 @@ async function initialChecks() {
|
||||
|
||||
if (BRIDGE_MODE === 'ERC_TO_ERC') {
|
||||
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(FOREIGN_RPC_URL))
|
||||
const bridgeTokenContract = new foreignWeb3.eth.Contract(
|
||||
ERC677_BRIDGE_TOKEN_ABI,
|
||||
ERC20_TOKEN_ADDRESS
|
||||
)
|
||||
const bridgeTokenContract = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ERC20_TOKEN_ADDRESS)
|
||||
|
||||
result.foreignERC = await getTokenType(bridgeTokenContract, FOREIGN_BRIDGE_ADDRESS)
|
||||
}
|
||||
|
@ -13,8 +13,7 @@ const {
|
||||
FOREIGN_TEST_TX_GAS_PRICE
|
||||
} = process.env
|
||||
|
||||
const NUMBER_OF_WITHDRAWALS_TO_SEND =
|
||||
process.argv[2] || process.env.NUMBER_OF_WITHDRAWALS_TO_SEND || 1
|
||||
const NUMBER_OF_WITHDRAWALS_TO_SEND = process.argv[2] || process.env.NUMBER_OF_WITHDRAWALS_TO_SEND || 1
|
||||
|
||||
const ERC677_ABI = [
|
||||
{
|
||||
|
@ -1,26 +1,12 @@
|
||||
const { HttpListProviderError } = require('http-list-provider')
|
||||
const {
|
||||
AlreadyProcessedError,
|
||||
AlreadySignedError,
|
||||
InvalidValidatorError
|
||||
} = require('../../utils/errors')
|
||||
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
|
||||
const logger = require('../../services/logger').child({
|
||||
module: 'processAffirmationRequests:estimateGas'
|
||||
})
|
||||
|
||||
async function estimateGas({
|
||||
web3,
|
||||
homeBridge,
|
||||
validatorContract,
|
||||
recipient,
|
||||
value,
|
||||
txHash,
|
||||
address
|
||||
}) {
|
||||
async function estimateGas({ web3, homeBridge, validatorContract, recipient, value, txHash, address }) {
|
||||
try {
|
||||
const gasEstimate = await homeBridge.methods
|
||||
.executeAffirmation(recipient, value, txHash)
|
||||
.estimateGas({
|
||||
const gasEstimate = await homeBridge.methods.executeAffirmation(recipient, value, txHash).estimateGas({
|
||||
from: address
|
||||
})
|
||||
|
||||
@ -36,9 +22,7 @@ async function estimateGas({
|
||||
// Check if minimum number of validations was already reached
|
||||
logger.debug('Check if minimum number of validations was already reached')
|
||||
const numAffirmationsSigned = await homeBridge.methods.numAffirmationsSigned(messageHash).call()
|
||||
const alreadyProcessed = await homeBridge.methods
|
||||
.isAlreadyProcessed(numAffirmationsSigned)
|
||||
.call()
|
||||
const alreadyProcessed = await homeBridge.methods.isAlreadyProcessed(numAffirmationsSigned).call()
|
||||
|
||||
if (alreadyProcessed) {
|
||||
throw new AlreadyProcessedError(e.message)
|
||||
|
@ -7,11 +7,7 @@ const { web3Home } = require('../../services/web3')
|
||||
const { BRIDGE_VALIDATORS_ABI } = require('../../../../commons')
|
||||
const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
|
||||
const estimateGas = require('./estimateGas')
|
||||
const {
|
||||
AlreadyProcessedError,
|
||||
AlreadySignedError,
|
||||
InvalidValidatorError
|
||||
} = require('../../utils/errors')
|
||||
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
|
||||
|
||||
const limit = promiseLimit(MAX_CONCURRENT_EVENTS)
|
||||
|
||||
@ -40,10 +36,7 @@ function processAffirmationRequestsBuilder(config) {
|
||||
eventTransactionHash: affirmationRequest.transactionHash
|
||||
})
|
||||
|
||||
logger.info(
|
||||
{ sender: recipient, value },
|
||||
`Processing affirmationRequest ${affirmationRequest.transactionHash}`
|
||||
)
|
||||
logger.info({ sender: recipient, value }, `Processing affirmationRequest ${affirmationRequest.transactionHash}`)
|
||||
|
||||
let gasEstimate
|
||||
try {
|
||||
@ -60,9 +53,7 @@ function processAffirmationRequestsBuilder(config) {
|
||||
logger.debug({ gasEstimate }, 'Gas estimated')
|
||||
} catch (e) {
|
||||
if (e instanceof HttpListProviderError) {
|
||||
throw new Error(
|
||||
'RPC Connection Error: submitSignature Gas Estimate cannot be obtained.'
|
||||
)
|
||||
throw new Error('RPC Connection Error: submitSignature Gas Estimate cannot be obtained.')
|
||||
} else if (e instanceof InvalidValidatorError) {
|
||||
logger.fatal({ address: config.validatorAddress }, 'Invalid validator')
|
||||
process.exit(EXIT_CODES.INCOMPATIBILITY)
|
||||
@ -71,9 +62,7 @@ function processAffirmationRequestsBuilder(config) {
|
||||
return
|
||||
} else if (e instanceof AlreadyProcessedError) {
|
||||
logger.info(
|
||||
`affirmationRequest ${
|
||||
affirmationRequest.transactionHash
|
||||
} was already processed by other validators`
|
||||
`affirmationRequest ${affirmationRequest.transactionHash} was already processed by other validators`
|
||||
)
|
||||
return
|
||||
} else {
|
||||
|
@ -1,10 +1,6 @@
|
||||
const Web3 = require('web3')
|
||||
const { HttpListProviderError } = require('http-list-provider')
|
||||
const {
|
||||
AlreadyProcessedError,
|
||||
IncompatibleContractError,
|
||||
InvalidValidatorError
|
||||
} = require('../../utils/errors')
|
||||
const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError } = require('../../utils/errors')
|
||||
const { parseMessage } = require('../../utils/message')
|
||||
const logger = require('../../services/logger').child({
|
||||
module: 'processCollectedSignatures:estimateGas'
|
||||
@ -13,19 +9,9 @@ const logger = require('../../services/logger').child({
|
||||
const web3 = new Web3()
|
||||
const { toBN } = Web3.utils
|
||||
|
||||
async function estimateGas({
|
||||
foreignBridge,
|
||||
validatorContract,
|
||||
message,
|
||||
numberOfCollectedSignatures,
|
||||
v,
|
||||
r,
|
||||
s
|
||||
}) {
|
||||
async function estimateGas({ foreignBridge, validatorContract, message, numberOfCollectedSignatures, v, r, s }) {
|
||||
try {
|
||||
const gasEstimate = await foreignBridge.methods
|
||||
.executeSignatures(v, r, s, message)
|
||||
.estimateGas()
|
||||
const gasEstimate = await foreignBridge.methods.executeSignatures(v, r, s, message).estimateGas()
|
||||
return gasEstimate
|
||||
} catch (e) {
|
||||
if (e instanceof HttpListProviderError) {
|
||||
|
@ -6,11 +6,7 @@ const rootLogger = require('../../services/logger')
|
||||
const { web3Home, web3Foreign } = require('../../services/web3')
|
||||
const { signatureToVRS } = require('../../utils/message')
|
||||
const estimateGas = require('./estimateGas')
|
||||
const {
|
||||
AlreadyProcessedError,
|
||||
IncompatibleContractError,
|
||||
InvalidValidatorError
|
||||
} = require('../../utils/errors')
|
||||
const { AlreadyProcessedError, IncompatibleContractError, InvalidValidatorError } = require('../../utils/errors')
|
||||
const { MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
|
||||
|
||||
const limit = promiseLimit(MAX_CONCURRENT_EVENTS)
|
||||
@ -20,10 +16,7 @@ let validatorContract = null
|
||||
function processCollectedSignaturesBuilder(config) {
|
||||
const homeBridge = new web3Home.eth.Contract(config.homeBridgeAbi, config.homeBridgeAddress)
|
||||
|
||||
const foreignBridge = new web3Foreign.eth.Contract(
|
||||
config.foreignBridgeAbi,
|
||||
config.foreignBridgeAddress
|
||||
)
|
||||
const foreignBridge = new web3Foreign.eth.Contract(config.foreignBridgeAbi, config.foreignBridgeAddress)
|
||||
|
||||
return async function processCollectedSignatures(signatures) {
|
||||
const txToSend = []
|
||||
@ -33,28 +26,19 @@ function processCollectedSignaturesBuilder(config) {
|
||||
const validatorContractAddress = await foreignBridge.methods.validatorContract().call()
|
||||
rootLogger.debug({ validatorContractAddress }, 'Validator contract address obtained')
|
||||
|
||||
validatorContract = new web3Foreign.eth.Contract(
|
||||
BRIDGE_VALIDATORS_ABI,
|
||||
validatorContractAddress
|
||||
)
|
||||
validatorContract = new web3Foreign.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorContractAddress)
|
||||
}
|
||||
|
||||
rootLogger.debug(`Processing ${signatures.length} CollectedSignatures events`)
|
||||
const callbacks = signatures.map(colSignature =>
|
||||
limit(async () => {
|
||||
const {
|
||||
authorityResponsibleForRelay,
|
||||
messageHash,
|
||||
NumberOfCollectedSignatures
|
||||
} = colSignature.returnValues
|
||||
const { authorityResponsibleForRelay, messageHash, NumberOfCollectedSignatures } = colSignature.returnValues
|
||||
|
||||
const logger = rootLogger.child({
|
||||
eventTransactionHash: colSignature.transactionHash
|
||||
})
|
||||
|
||||
if (
|
||||
authorityResponsibleForRelay === web3Home.utils.toChecksumAddress(config.validatorAddress)
|
||||
) {
|
||||
if (authorityResponsibleForRelay === web3Home.utils.toChecksumAddress(config.validatorAddress)) {
|
||||
logger.info(`Processing CollectedSignatures ${colSignature.transactionHash}`)
|
||||
const message = await homeBridge.methods.message(messageHash).call()
|
||||
|
||||
@ -90,16 +74,11 @@ function processCollectedSignaturesBuilder(config) {
|
||||
logger.debug({ gasEstimate }, 'Gas estimated')
|
||||
} catch (e) {
|
||||
if (e instanceof HttpListProviderError) {
|
||||
throw new Error(
|
||||
'RPC Connection Error: submitSignature Gas Estimate cannot be obtained.'
|
||||
)
|
||||
throw new Error('RPC Connection Error: submitSignature Gas Estimate cannot be obtained.')
|
||||
} else if (e instanceof AlreadyProcessedError) {
|
||||
logger.info(`Already processed CollectedSignatures ${colSignature.transactionHash}`)
|
||||
return
|
||||
} else if (
|
||||
e instanceof IncompatibleContractError ||
|
||||
e instanceof InvalidValidatorError
|
||||
) {
|
||||
} else if (e instanceof IncompatibleContractError || e instanceof InvalidValidatorError) {
|
||||
logger.error(`The message couldn't be processed; skipping: ${e.message}`)
|
||||
return
|
||||
} else {
|
||||
@ -115,11 +94,7 @@ function processCollectedSignaturesBuilder(config) {
|
||||
to: config.foreignBridgeAddress
|
||||
})
|
||||
} else {
|
||||
logger.info(
|
||||
`Validator not responsible for relaying CollectedSignatures ${
|
||||
colSignature.transactionHash
|
||||
}`
|
||||
)
|
||||
logger.info(`Validator not responsible for relaying CollectedSignatures ${colSignature.transactionHash}`)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
@ -1,9 +1,5 @@
|
||||
const { HttpListProviderError } = require('http-list-provider')
|
||||
const {
|
||||
AlreadyProcessedError,
|
||||
AlreadySignedError,
|
||||
InvalidValidatorError
|
||||
} = require('../../utils/errors')
|
||||
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
|
||||
const logger = require('../../services/logger').child({
|
||||
module: 'processSignatureRequests:estimateGas'
|
||||
})
|
||||
|
@ -6,11 +6,7 @@ const rootLogger = require('../../services/logger')
|
||||
const { web3Home } = require('../../services/web3')
|
||||
const { createMessage } = require('../../utils/message')
|
||||
const estimateGas = require('./estimateGas')
|
||||
const {
|
||||
AlreadyProcessedError,
|
||||
AlreadySignedError,
|
||||
InvalidValidatorError
|
||||
} = require('../../utils/errors')
|
||||
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
|
||||
const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
|
||||
|
||||
const { VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env
|
||||
@ -47,10 +43,7 @@ function processSignatureRequestsBuilder(config) {
|
||||
eventTransactionHash: signatureRequest.transactionHash
|
||||
})
|
||||
|
||||
logger.info(
|
||||
{ sender: recipient, value },
|
||||
`Processing signatureRequest ${signatureRequest.transactionHash}`
|
||||
)
|
||||
logger.info({ sender: recipient, value }, `Processing signatureRequest ${signatureRequest.transactionHash}`)
|
||||
|
||||
const message = createMessage({
|
||||
recipient,
|
||||
@ -76,9 +69,7 @@ function processSignatureRequestsBuilder(config) {
|
||||
logger.debug({ gasEstimate }, 'Gas estimated')
|
||||
} catch (e) {
|
||||
if (e instanceof HttpListProviderError) {
|
||||
throw new Error(
|
||||
'RPC Connection Error: submitSignature Gas Estimate cannot be obtained.'
|
||||
)
|
||||
throw new Error('RPC Connection Error: submitSignature Gas Estimate cannot be obtained.')
|
||||
} else if (e instanceof InvalidValidatorError) {
|
||||
logger.fatal({ address: config.validatorAddress }, 'Invalid validator')
|
||||
process.exit(EXIT_CODES.INCOMPATIBILITY)
|
||||
@ -87,9 +78,7 @@ function processSignatureRequestsBuilder(config) {
|
||||
return
|
||||
} else if (e instanceof AlreadyProcessedError) {
|
||||
logger.info(
|
||||
`signatureRequest ${
|
||||
signatureRequest.transactionHash
|
||||
} was already processed by other validators`
|
||||
`signatureRequest ${signatureRequest.transactionHash} was already processed by other validators`
|
||||
)
|
||||
return
|
||||
} else {
|
||||
|
@ -4,11 +4,7 @@ const { HttpListProviderError } = require('http-list-provider')
|
||||
const { BRIDGE_VALIDATORS_ABI } = require('../../../../commons')
|
||||
const rootLogger = require('../../services/logger')
|
||||
const { web3Home } = require('../../services/web3')
|
||||
const {
|
||||
AlreadyProcessedError,
|
||||
AlreadySignedError,
|
||||
InvalidValidatorError
|
||||
} = require('../../utils/errors')
|
||||
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
|
||||
const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
|
||||
const estimateGas = require('../processAffirmationRequests/estimateGas')
|
||||
|
||||
@ -56,9 +52,7 @@ function processTransfersBuilder(config) {
|
||||
logger.debug({ gasEstimate }, 'Gas estimated')
|
||||
} catch (e) {
|
||||
if (e instanceof HttpListProviderError) {
|
||||
throw new Error(
|
||||
'RPC Connection Error: submitSignature Gas Estimate cannot be obtained.'
|
||||
)
|
||||
throw new Error('RPC Connection Error: submitSignature Gas Estimate cannot be obtained.')
|
||||
} else if (e instanceof InvalidValidatorError) {
|
||||
logger.fatal({ address: config.validatorAddress }, 'Invalid validator')
|
||||
process.exit(EXIT_CODES.INCOMPATIBILITY)
|
||||
@ -66,9 +60,7 @@ function processTransfersBuilder(config) {
|
||||
logger.info(`Already signed transfer ${transfer.transactionHash}`)
|
||||
return
|
||||
} else if (e instanceof AlreadyProcessedError) {
|
||||
logger.info(
|
||||
`transfer ${transfer.transactionHash} was already processed by other validators`
|
||||
)
|
||||
logger.info(`transfer ${transfer.transactionHash} was already processed by other validators`)
|
||||
return
|
||||
} else {
|
||||
logger.error(e, 'Unknown error while processing transaction')
|
||||
|
@ -63,9 +63,7 @@ async function initialize() {
|
||||
}
|
||||
|
||||
function resume(newBalance) {
|
||||
logger.info(
|
||||
`Validator balance changed. New balance is ${newBalance}. Resume messages processing.`
|
||||
)
|
||||
logger.info(`Validator balance changed. New balance is ${newBalance}. Resume messages processing.`)
|
||||
initialize()
|
||||
}
|
||||
|
||||
@ -164,9 +162,7 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry }) {
|
||||
logger.debug(`Finished processing msg`)
|
||||
|
||||
if (insufficientFunds) {
|
||||
logger.warn(
|
||||
'Insufficient funds. Stop sending transactions until the account has the minimum balance'
|
||||
)
|
||||
logger.warn('Insufficient funds. Stop sending transactions until the account has the minimum balance')
|
||||
channel.close()
|
||||
waitForFunds(web3Instance, VALIDATOR_ADDRESS, minimumBalance, resume, logger)
|
||||
}
|
||||
|
@ -59,14 +59,7 @@ function connectSenderToQueue({ queueName, cb }) {
|
||||
})
|
||||
}
|
||||
|
||||
async function generateRetry({
|
||||
data,
|
||||
msgRetries,
|
||||
channelWrapper,
|
||||
channel,
|
||||
queueName,
|
||||
deadLetterExchange
|
||||
}) {
|
||||
async function generateRetry({ data, msgRetries, channelWrapper, channel, queueName, deadLetterExchange }) {
|
||||
const retries = msgRetries + 1
|
||||
const delay = getRetrySequence(retries) * 1000
|
||||
const retryQueue = `${queueName}-retry-${delay}`
|
||||
|
@ -7,11 +7,7 @@ const logger = require('../services/logger').child({
|
||||
module: 'gasPrice'
|
||||
})
|
||||
const { setIntervalAndRun } = require('../utils/utils')
|
||||
const {
|
||||
DEFAULT_UPDATE_INTERVAL,
|
||||
GAS_PRICE_BOUNDARIES,
|
||||
DEFAULT_GAS_PRICE_FACTOR
|
||||
} = require('../utils/constants')
|
||||
const { DEFAULT_UPDATE_INTERVAL, GAS_PRICE_BOUNDARIES, DEFAULT_GAS_PRICE_FACTOR } = require('../utils/constants')
|
||||
|
||||
const HomeABI = bridgeConfig.homeBridgeAbi
|
||||
const ForeignABI = bridgeConfig.foreignBridgeAbi
|
||||
|
@ -1,8 +1,7 @@
|
||||
const pino = require('pino')
|
||||
const path = require('path')
|
||||
|
||||
const config =
|
||||
process.env.NODE_ENV !== 'test' ? require(path.join('../../config/', process.argv[2])) : {}
|
||||
const config = process.env.NODE_ENV !== 'test' ? require(path.join('../../config/', process.argv[2])) : {}
|
||||
|
||||
const logger = pino({
|
||||
enabled: process.env.NODE_ENV !== 'test',
|
||||
|
@ -3,18 +3,7 @@ const fetch = require('node-fetch')
|
||||
const rpcUrlsManager = require('../services/getRpcUrlsManager')
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
async function sendTx({
|
||||
chain,
|
||||
privateKey,
|
||||
data,
|
||||
nonce,
|
||||
gasPrice,
|
||||
amount,
|
||||
gasLimit,
|
||||
to,
|
||||
chainId,
|
||||
web3
|
||||
}) {
|
||||
async function sendTx({ chain, privateKey, data, nonce, gasPrice, amount, gasLimit, to, chainId, web3 }) {
|
||||
const serializedTx = await web3.eth.accounts.signTransaction(
|
||||
{
|
||||
nonce: Number(nonce),
|
||||
|
@ -47,10 +47,7 @@ async function getRequiredBlockConfirmations(contract) {
|
||||
const contractAddress = contract.options.address
|
||||
logger.debug({ contractAddress }, 'Getting required block confirmations')
|
||||
const requiredBlockConfirmations = await contract.methods.requiredBlockConfirmations().call()
|
||||
logger.debug(
|
||||
{ contractAddress, requiredBlockConfirmations },
|
||||
'Required block confirmations obtained'
|
||||
)
|
||||
logger.debug({ contractAddress, requiredBlockConfirmations }, 'Required block confirmations obtained')
|
||||
return requiredBlockConfirmations
|
||||
} catch (e) {
|
||||
throw new Error(`Required block confirmations cannot be obtained`)
|
||||
|
@ -6,13 +6,7 @@ function strip0x(input) {
|
||||
return input.replace(/^0x/, '')
|
||||
}
|
||||
|
||||
function createMessage({
|
||||
recipient,
|
||||
value,
|
||||
transactionHash,
|
||||
bridgeAddress,
|
||||
expectedMessageLength
|
||||
}) {
|
||||
function createMessage({ recipient, value, transactionHash, bridgeAddress, expectedMessageLength }) {
|
||||
recipient = strip0x(recipient)
|
||||
assert.strictEqual(recipient.length, 20 * 2)
|
||||
|
||||
@ -50,10 +44,7 @@ function parseMessage(message) {
|
||||
|
||||
const contractAddressStart = txHashStart + txHashLength
|
||||
const contractAddressLength = 32 * 2
|
||||
const contractAddress = `0x${message.slice(
|
||||
contractAddressStart,
|
||||
contractAddressStart + contractAddressLength
|
||||
)}`
|
||||
const contractAddress = `0x${message.slice(contractAddressStart, contractAddressStart + contractAddressLength)}`
|
||||
|
||||
return {
|
||||
recipient,
|
||||
|
@ -5,9 +5,7 @@ const Web3 = require('web3')
|
||||
const retrySequence = [1, 2, 3, 5, 8, 13, 21, 34, 55, 60]
|
||||
|
||||
function getRetrySequence(count) {
|
||||
return count > retrySequence.length
|
||||
? retrySequence[retrySequence.length - 1]
|
||||
: retrySequence[count - 1]
|
||||
return count > retrySequence.length ? retrySequence[retrySequence.length - 1] : retrySequence[count - 1]
|
||||
}
|
||||
|
||||
async function syncForEach(array, callback) {
|
||||
@ -23,9 +21,7 @@ function checkHTTPS(ALLOW_HTTP, logger) {
|
||||
if (ALLOW_HTTP !== 'yes') {
|
||||
throw new Error(`http is not allowed: ${url}`)
|
||||
} else {
|
||||
logger.warn(
|
||||
`You are using http (${url}) on ${network} network. In production https must be used instead.`
|
||||
)
|
||||
logger.warn(`You are using http (${url}) on ${network} network. In production https must be used instead.`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -38,16 +34,10 @@ async function waitForFunds(web3, address, minimumBalance, cb, logger) {
|
||||
logger.debug('Getting balance of validator account')
|
||||
const newBalance = web3.utils.toBN(await web3.eth.getBalance(address))
|
||||
if (newBalance.gte(minimumBalance)) {
|
||||
logger.debug(
|
||||
{ balance: newBalance, minimumBalance },
|
||||
'Validator has minimum necessary balance'
|
||||
)
|
||||
logger.debug({ balance: newBalance, minimumBalance }, 'Validator has minimum necessary balance')
|
||||
cb(newBalance)
|
||||
} else {
|
||||
logger.debug(
|
||||
{ balance: newBalance, minimumBalance },
|
||||
'Balance of validator is still less than the minimum'
|
||||
)
|
||||
logger.debug({ balance: newBalance, minimumBalance }, 'Balance of validator is still less than the minimum')
|
||||
retry()
|
||||
}
|
||||
},
|
||||
@ -99,9 +89,7 @@ function add0xPrefix(s) {
|
||||
}
|
||||
|
||||
function privateKeyToAddress(privateKey) {
|
||||
return privateKey
|
||||
? new Web3().eth.accounts.privateKeyToAccount(add0xPrefix(privateKey)).address
|
||||
: null
|
||||
return privateKey ? new Web3().eth.accounts.privateKeyToAccount(add0xPrefix(privateKey)).address : null
|
||||
}
|
||||
|
||||
function nonceError(e) {
|
||||
|
@ -72,10 +72,7 @@ async function runMain({ sendToQueue }) {
|
||||
|
||||
async function getLastProcessedBlock() {
|
||||
const result = await redis.get(lastBlockRedisKey)
|
||||
logger.debug(
|
||||
{ fromRedis: result, fromConfig: lastProcessedBlock.toString() },
|
||||
'Last Processed block obtained'
|
||||
)
|
||||
logger.debug({ fromRedis: result, fromConfig: lastProcessedBlock.toString() }, 'Last Processed block obtained')
|
||||
lastProcessedBlock = result ? toBN(result) : lastProcessedBlock
|
||||
}
|
||||
|
||||
@ -146,10 +143,7 @@ async function main({ sendToQueue }) {
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
{ lastProcessedBlock: lastBlockToProcess.toString() },
|
||||
'Updating last processed block'
|
||||
)
|
||||
logger.debug({ lastProcessedBlock: lastBlockToProcess.toString() }, 'Updating last processed block')
|
||||
await updateLastProcessedBlock(lastBlockToProcess)
|
||||
} catch (e) {
|
||||
logger.error(e)
|
||||
|
@ -2,11 +2,7 @@ const sinon = require('sinon')
|
||||
const { expect } = require('chai')
|
||||
const proxyquire = require('proxyquire').noPreserveCache()
|
||||
const Web3Utils = require('web3-utils')
|
||||
const {
|
||||
fetchGasPrice,
|
||||
gasPriceWithinLimits,
|
||||
normalizeGasPrice
|
||||
} = require('../src/services/gasPrice')
|
||||
const { fetchGasPrice, gasPriceWithinLimits, normalizeGasPrice } = require('../src/services/gasPrice')
|
||||
const { DEFAULT_UPDATE_INTERVAL, GAS_PRICE_BOUNDARIES } = require('../src/utils/constants')
|
||||
|
||||
describe('gasPrice', () => {
|
||||
@ -94,12 +90,8 @@ describe('gasPrice', () => {
|
||||
|
||||
// then
|
||||
expect(process.env.HOME_GAS_PRICE_UPDATE_INTERVAL).to.equal('15000')
|
||||
expect(process.env.HOME_GAS_PRICE_UPDATE_INTERVAL).to.not.equal(
|
||||
DEFAULT_UPDATE_INTERVAL.toString()
|
||||
)
|
||||
expect(utils.setIntervalAndRun.args[0][1]).to.equal(
|
||||
process.env.HOME_GAS_PRICE_UPDATE_INTERVAL.toString()
|
||||
)
|
||||
expect(process.env.HOME_GAS_PRICE_UPDATE_INTERVAL).to.not.equal(DEFAULT_UPDATE_INTERVAL.toString())
|
||||
expect(utils.setIntervalAndRun.args[0][1]).to.equal(process.env.HOME_GAS_PRICE_UPDATE_INTERVAL.toString())
|
||||
})
|
||||
it('should call setIntervalAndRun with FOREIGN_GAS_PRICE_UPDATE_INTERVAL interval value on Foreign', async () => {
|
||||
// given
|
||||
@ -111,12 +103,8 @@ describe('gasPrice', () => {
|
||||
|
||||
// then
|
||||
expect(process.env.FOREIGN_GAS_PRICE_UPDATE_INTERVAL).to.equal('15000')
|
||||
expect(process.env.HOME_GAS_PRICE_UPDATE_INTERVAL).to.not.equal(
|
||||
DEFAULT_UPDATE_INTERVAL.toString()
|
||||
)
|
||||
expect(utils.setIntervalAndRun.args[0][1]).to.equal(
|
||||
process.env.FOREIGN_GAS_PRICE_UPDATE_INTERVAL.toString()
|
||||
)
|
||||
expect(process.env.HOME_GAS_PRICE_UPDATE_INTERVAL).to.not.equal(DEFAULT_UPDATE_INTERVAL.toString())
|
||||
expect(utils.setIntervalAndRun.args[0][1]).to.equal(process.env.FOREIGN_GAS_PRICE_UPDATE_INTERVAL.toString())
|
||||
})
|
||||
it('should call setIntervalAndRun with default interval value on Home', async () => {
|
||||
// given
|
||||
|
@ -148,8 +148,7 @@ describe('message utils', () => {
|
||||
const transactionHash = '0x4a298455c1ccb17de77718fc045a876e1b4e063afaad361dcdef142a8ee48d5a'
|
||||
|
||||
// when
|
||||
const messageThunk = () =>
|
||||
createMessage({ recipient, value, transactionHash, expectedMessageLength })
|
||||
const messageThunk = () => createMessage({ recipient, value, transactionHash, expectedMessageLength })
|
||||
|
||||
// then
|
||||
expect(messageThunk).to.throw()
|
||||
@ -162,8 +161,7 @@ describe('message utils', () => {
|
||||
const transactionHash = '0x4a298455c1ccb17de77718fc045a876e1b4e063afaad361dcdef142a8ee48d5a'
|
||||
|
||||
// when
|
||||
const messageThunk = () =>
|
||||
createMessage({ recipient, value, transactionHash, expectedMessageLength })
|
||||
const messageThunk = () => createMessage({ recipient, value, transactionHash, expectedMessageLength })
|
||||
|
||||
// then
|
||||
expect(messageThunk).to.throw()
|
||||
@ -176,8 +174,7 @@ describe('message utils', () => {
|
||||
const transactionHash = '0x4a298455c1ccb17de77718fc045a876e1b4e063afaad361dcdef142a8ee48d5'
|
||||
|
||||
// when
|
||||
const messageThunk = () =>
|
||||
createMessage({ recipient, value, transactionHash, expectedMessageLength })
|
||||
const messageThunk = () => createMessage({ recipient, value, transactionHash, expectedMessageLength })
|
||||
|
||||
// then
|
||||
expect(messageThunk).to.throw()
|
||||
@ -190,8 +187,7 @@ describe('message utils', () => {
|
||||
const transactionHash = '0x4a298455c1ccb17de77718fc045a876e1b4e063afaad361dcdef142a8ee48d5aa'
|
||||
|
||||
// when
|
||||
const messageThunk = () =>
|
||||
createMessage({ recipient, value, transactionHash, expectedMessageLength })
|
||||
const messageThunk = () => createMessage({ recipient, value, transactionHash, expectedMessageLength })
|
||||
|
||||
// then
|
||||
expect(messageThunk).to.throw()
|
||||
@ -232,8 +228,7 @@ describe('message utils', () => {
|
||||
// given
|
||||
const originalRecipient = '0xe3D952Ad4B96A756D65790393128FA359a7CD888'
|
||||
const originalValue = '0x2a'
|
||||
const originalTransactionHash =
|
||||
'0x4a298455c1ccb17de77718fc045a876e1b4e063afaad361dcdef142a8ee48d5a'
|
||||
const originalTransactionHash = '0x4a298455c1ccb17de77718fc045a876e1b4e063afaad361dcdef142a8ee48d5a'
|
||||
const originalBridgeAddress = '0xfA79875FB0828c1FBD438583ED23fF5a956D80a1'
|
||||
|
||||
// when
|
||||
|
@ -74,9 +74,7 @@ class MetaMask extends Page {
|
||||
await this.setNetwork(user.networkID)
|
||||
await super.clickWithWait(popupAccount)
|
||||
await this.driver.executeScript(
|
||||
"document.getElementsByClassName('dropdown-menu-item')[" +
|
||||
user.accountOrderInMetamask +
|
||||
'].click();'
|
||||
"document.getElementsByClassName('dropdown-menu-item')[" + user.accountOrderInMetamask + '].click();'
|
||||
)
|
||||
await this.switchToNextPage()
|
||||
return true
|
||||
@ -89,9 +87,7 @@ class MetaMask extends Page {
|
||||
try {
|
||||
await super.clickWithWait(popupAccount)
|
||||
await this.driver.executeScript(
|
||||
"document.getElementsByClassName('dropdown-menu-item')[" +
|
||||
(accountOrderNumber + 1) +
|
||||
'].click();'
|
||||
"document.getElementsByClassName('dropdown-menu-item')[" + (accountOrderNumber + 1) + '].click();'
|
||||
)
|
||||
accountOrderNumber++
|
||||
return true
|
||||
@ -121,8 +117,7 @@ class MetaMask extends Page {
|
||||
try {
|
||||
await super.clickWithWait(popupNetwork)
|
||||
const orderNumber = networks.indexOf(provider)
|
||||
const script =
|
||||
"document.getElementsByClassName('dropdown-menu-item')[" + orderNumber + '].click();'
|
||||
const script = "document.getElementsByClassName('dropdown-menu-item')[" + orderNumber + '].click();'
|
||||
if (orderNumber < 0) await this.addNetwork(provider)
|
||||
else await this.driver.executeScript(script)
|
||||
return true
|
||||
|
116
ui-e2e/test.js
116
ui-e2e/test.js
@ -59,22 +59,14 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
foreignBalanceBefore = await mainPage.getForeignPOABalance()
|
||||
console.log('foreignBalanceBefore = ' + foreignBalanceBefore)
|
||||
const result = foreignBalanceBefore === 0
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Foreign POA balance is zero or not displayed '
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Foreign POA balance is zero or not displayed ')
|
||||
})
|
||||
|
||||
test.it('Main page: home POA balance is displayed', async () => {
|
||||
homeBalanceBefore = await mainPage.getHomePOABalance()
|
||||
console.log('homeBalanceBefore = ' + homeBalanceBefore)
|
||||
const result = homeBalanceBefore !== 0
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Home POA balance is zero or not displayed '
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Home POA balance is zero or not displayed ')
|
||||
})
|
||||
|
||||
test.it('User is able to send tokens from Home account to Foreign account', async () => {
|
||||
@ -93,16 +85,10 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100
|
||||
homeBalanceBefore = newHomeBalance
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Home POA balance is not correct after transaction'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Home POA balance is not correct after transaction')
|
||||
})
|
||||
|
||||
test.it(
|
||||
'Foreign account has received correct amount of tokens after transaction ',
|
||||
async () => {
|
||||
test.it('Foreign account has received correct amount of tokens after transaction ', async () => {
|
||||
const newForeignBalance = await mainPage.getForeignPOABalance()
|
||||
|
||||
const shouldBe = foreignBalanceBefore + maxAmountPerTransactionLimit
|
||||
@ -110,13 +96,8 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
|
||||
const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED. Foreign POA balance is not correct after transaction'
|
||||
)
|
||||
}
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED. Foreign POA balance is not correct after transaction')
|
||||
})
|
||||
|
||||
test.it('User is able to send tokens from Foreign account to Home account', async () => {
|
||||
await foreignAccount.setMetaMaskNetwork()
|
||||
@ -135,11 +116,7 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('newForeignBalance = ' + newForeignBalance)
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Foreign POA balance is not correct after transaction'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Foreign POA balance is not correct after transaction')
|
||||
})
|
||||
|
||||
test.it('Home account has received correct amount of tokens after transaction', async () => {
|
||||
@ -148,11 +125,7 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('newHomeBalance = ' + newHomeBalance)
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Home POA balance is not correct after transaction'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Home POA balance is not correct after transaction')
|
||||
})
|
||||
})
|
||||
|
||||
@ -173,22 +146,14 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
foreignBalanceBefore = await mainPage.getForeignPOABalance()
|
||||
console.log('foreignBalanceBefore = ' + foreignBalanceBefore)
|
||||
const result = foreignBalanceBefore === 0
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED. Foreign erc20 balance is not zero'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED. Foreign erc20 balance is not zero')
|
||||
})
|
||||
|
||||
test.it('Main page: home erc20 balance is displayed', async () => {
|
||||
homeBalanceBefore = await mainPage.getHomePOABalance()
|
||||
console.log('homeBalanceBefore = ' + homeBalanceBefore)
|
||||
const result = homeBalanceBefore !== 0
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED. Home erc20 balance is zero or not displayed '
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED. Home erc20 balance is zero or not displayed ')
|
||||
})
|
||||
|
||||
test.it('User is able to send tokens from Foreign account to Home account ', async () => {
|
||||
@ -208,11 +173,7 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('newForeignBalance = ' + newForeignBalance)
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Foreign POA balance is not correct after transaction'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Foreign POA balance is not correct after transaction')
|
||||
})
|
||||
|
||||
test.it('Home account has received correct amount of tokens after transaction ', async () => {
|
||||
@ -221,11 +182,7 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('newHomeBalance = ' + newHomeBalance)
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Home POA balance is not correct after transaction'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Home POA balance is not correct after transaction')
|
||||
})
|
||||
test.it('User is able to send tokens from Home account to Foreign account ', async () => {
|
||||
await homeAccount.setMetaMaskNetwork()
|
||||
@ -246,16 +203,10 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100
|
||||
homeBalanceBefore = newHomeBalance
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Home POA balance is not correct after transaction'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Home POA balance is not correct after transaction')
|
||||
})
|
||||
|
||||
test.it(
|
||||
'Foreign account has received correct amount of tokens after transaction ',
|
||||
async () => {
|
||||
test.it('Foreign account has received correct amount of tokens after transaction ', async () => {
|
||||
const newForeignBalance = await mainPage.getForeignPOABalance()
|
||||
|
||||
const shouldBe = foreignBalanceBefore + maxAmountPerTransactionLimit
|
||||
@ -263,13 +214,8 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
|
||||
const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED. Foreign POA balance is not correct after transaction'
|
||||
)
|
||||
}
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED. Foreign POA balance is not correct after transaction')
|
||||
})
|
||||
})
|
||||
|
||||
test.describe('ERC TO NATIVE', async () => {
|
||||
@ -297,11 +243,7 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
homeBalanceBefore = await mainPage.getHomePOABalance()
|
||||
console.log('homeBalanceBefore = ' + homeBalanceBefore)
|
||||
const result = homeBalanceBefore !== 0
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED. Home erc20 balance is zero or not displayed '
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED. Home erc20 balance is zero or not displayed ')
|
||||
})
|
||||
|
||||
test.it('User is able to send tokens from Foreign account to Home account', async () => {
|
||||
@ -321,11 +263,7 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('newForeignBalance = ' + newForeignBalance)
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Foreign POA balance is not correct after transaction'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Foreign POA balance is not correct after transaction')
|
||||
})
|
||||
|
||||
test.it('Home account has received correct amount of tokens after transaction', async () => {
|
||||
@ -334,11 +272,7 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('newHomeBalance = ' + newHomeBalance)
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Home POA balance is not correct after transaction'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Home POA balance is not correct after transaction')
|
||||
})
|
||||
test.it('User is able to send tokens from Home account to Foreign account', async () => {
|
||||
await homeAccount.setMetaMaskNetwork()
|
||||
@ -359,11 +293,7 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
const result = Math.abs(shouldBe - newHomeBalance) < maxAmountPerTransactionLimit / 100
|
||||
homeBalanceBefore = newHomeBalance
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED.Home POA balance is not correct after transaction'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED.Home POA balance is not correct after transaction')
|
||||
})
|
||||
|
||||
test.it('Foreign account has received correct amount of tokens after transaction', async () => {
|
||||
@ -374,11 +304,7 @@ test.describe('e2e-test for bridge.poa, version 1.5.0', async function() {
|
||||
console.log('shouldBe = ' + shouldBe)
|
||||
|
||||
const result = Math.abs(shouldBe - newForeignBalance) < maxAmountPerTransactionLimit / 100
|
||||
return await assert.strictEqual(
|
||||
result,
|
||||
true,
|
||||
'Test FAILED. Foreign POA balance is not correct after transaction'
|
||||
)
|
||||
return await assert.strictEqual(result, true, 'Test FAILED. Foreign POA balance is not correct after transaction')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -2,9 +2,7 @@ const { addDecoratorsLegacy, disableEsLint, override } = require('customize-cra'
|
||||
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin')
|
||||
|
||||
const disableModuleScopePlugin = () => config => {
|
||||
config.resolve.plugins = config.resolve.plugins.filter(
|
||||
plugin => !(plugin instanceof ModuleScopePlugin)
|
||||
)
|
||||
config.resolve.plugins = config.resolve.plugins.filter(plugin => !(plugin instanceof ModuleScopePlugin))
|
||||
return config
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,5 @@
|
||||
import React from 'react'
|
||||
import {
|
||||
Header,
|
||||
Bridge,
|
||||
RelayEvents,
|
||||
Footer,
|
||||
SweetAlert,
|
||||
Loading,
|
||||
StatusPage,
|
||||
StatisticsPage
|
||||
} from './components'
|
||||
import { Header, Bridge, RelayEvents, Footer, SweetAlert, Loading, StatusPage, StatisticsPage } from './components'
|
||||
import { Route } from 'react-router-dom'
|
||||
import './assets/stylesheets/application.css'
|
||||
import { Disclaimer } from './components'
|
||||
@ -45,11 +36,7 @@ export class App extends React.Component {
|
||||
<div className={showMobileMenu ? 'mobile-menu-is-open' : ''}>
|
||||
<Route component={Loading} />
|
||||
<Route component={SweetAlert} />
|
||||
<Route
|
||||
render={() => (
|
||||
<Header onMenuToggle={this.toggleMobileMenu} showMobileMenu={showMobileMenu} />
|
||||
)}
|
||||
/>
|
||||
<Route render={() => <Header onMenuToggle={this.toggleMobileMenu} showMobileMenu={showMobileMenu} />} />
|
||||
<div className="app-container">
|
||||
{showMobileMenu && <Route render={() => <div className="mobile-menu-open" />} />}
|
||||
<Route exact path="/" component={Bridge} />
|
||||
|
@ -87,9 +87,9 @@ export class Bridge extends React.Component {
|
||||
}
|
||||
if (isGreaterThan(amount, homeStore.maxCurrentDeposit)) {
|
||||
alertStore.pushError(
|
||||
`The amount is above current daily limit.\nThe max deposit today: ${
|
||||
homeStore.maxCurrentDeposit
|
||||
} ${homeStore.symbol}`
|
||||
`The amount is above current daily limit.\nThe max deposit today: ${homeStore.maxCurrentDeposit} ${
|
||||
homeStore.symbol
|
||||
}`
|
||||
)
|
||||
return
|
||||
}
|
||||
@ -140,24 +140,22 @@ export class Bridge extends React.Component {
|
||||
}
|
||||
if (!isExternalErc20 && isGreaterThan(amount, foreignStore.maxPerTx)) {
|
||||
alertStore.pushError(
|
||||
`The amount is above maximum amount per transaction.\nThe max per transaction is: ${
|
||||
foreignStore.maxPerTx
|
||||
} ${foreignStore.symbol}`
|
||||
`The amount is above maximum amount per transaction.\nThe max per transaction is: ${foreignStore.maxPerTx} ${
|
||||
foreignStore.symbol
|
||||
}`
|
||||
)
|
||||
return
|
||||
}
|
||||
if (!isExternalErc20 && isGreaterThan(amount, foreignStore.maxCurrentDeposit)) {
|
||||
alertStore.pushError(
|
||||
`The amount is above current daily limit.\nThe max withdrawal today: ${
|
||||
foreignStore.maxCurrentDeposit
|
||||
} ${foreignStore.symbol}`
|
||||
`The amount is above current daily limit.\nThe max withdrawal today: ${foreignStore.maxCurrentDeposit} ${
|
||||
foreignStore.symbol
|
||||
}`
|
||||
)
|
||||
return
|
||||
}
|
||||
if (isGreaterThan(amount, foreignStore.balance)) {
|
||||
alertStore.pushError(
|
||||
`Insufficient token balance. Your balance is ${foreignStore.balance} ${foreignStore.symbol}`
|
||||
)
|
||||
alertStore.pushError(`Insufficient token balance. Your balance is ${foreignStore.balance} ${foreignStore.symbol}`)
|
||||
} else {
|
||||
try {
|
||||
alertStore.setLoading(true)
|
||||
@ -262,8 +260,7 @@ export class Bridge extends React.Component {
|
||||
loadHomeDetails = () => {
|
||||
const { web3Store, homeStore, bridgeMode } = this.props.RootStore
|
||||
const isErcToErcMode = bridgeMode === BRIDGE_MODES.ERC_TO_ERC
|
||||
const isExternalErc20 =
|
||||
bridgeMode === BRIDGE_MODES.ERC_TO_ERC || bridgeMode === BRIDGE_MODES.ERC_TO_NATIVE
|
||||
const isExternalErc20 = bridgeMode === BRIDGE_MODES.ERC_TO_ERC || bridgeMode === BRIDGE_MODES.ERC_TO_NATIVE
|
||||
|
||||
const modalData = {
|
||||
isHome: true,
|
||||
|
@ -2,11 +2,7 @@ import React from 'react'
|
||||
|
||||
export const BridgeAddress = ({ isHome, reverse }) => {
|
||||
const getAddress = () =>
|
||||
isHome ? (
|
||||
<div className="home-address-container" />
|
||||
) : (
|
||||
<div className="foreign-address-container" />
|
||||
)
|
||||
isHome ? <div className="home-address-container" /> : <div className="foreign-address-container" />
|
||||
|
||||
return isHome ? (
|
||||
<div className="bridge-home">
|
||||
|
@ -2,15 +2,7 @@ import React from 'react'
|
||||
import numeral from 'numeral'
|
||||
import { InfoIcon } from './icons/InfoIcon'
|
||||
|
||||
export const BridgeNetwork = ({
|
||||
balance,
|
||||
currency,
|
||||
isHome,
|
||||
networkSubtitle,
|
||||
networkTitle,
|
||||
showModal,
|
||||
side
|
||||
}) => {
|
||||
export const BridgeNetwork = ({ balance, currency, isHome, networkSubtitle, networkTitle, showModal, side }) => {
|
||||
const containerName = isHome ? 'home' : 'foreign'
|
||||
const formattedBalance = isNaN(numeral(balance).format('0.00', Math.floor))
|
||||
? numeral(0).format('0,0.00', Math.floor)
|
||||
|
@ -2,19 +2,9 @@ import React from 'react'
|
||||
import numeral from 'numeral'
|
||||
import { DataBlock } from './DataBlock'
|
||||
|
||||
export const Configuration = ({
|
||||
requiredSignatures,
|
||||
authorities,
|
||||
symbol,
|
||||
maxSingleDeposit,
|
||||
maxTotalBalance
|
||||
}) => (
|
||||
export const Configuration = ({ requiredSignatures, authorities, symbol, maxSingleDeposit, maxTotalBalance }) => (
|
||||
<div className="status-configuration-data">
|
||||
<DataBlock
|
||||
description="Required Signatures"
|
||||
value={numeral(requiredSignatures).format('0')}
|
||||
type=""
|
||||
/>
|
||||
<DataBlock description="Required Signatures" value={numeral(requiredSignatures).format('0')} type="" />
|
||||
<div className="separator" />
|
||||
<DataBlock description="Authorities" value={numeral(authorities).format('0')} type="" />
|
||||
{maxSingleDeposit &&
|
||||
|
@ -12,22 +12,18 @@ export const Disclaimer = ({ onConfirmation }) => (
|
||||
<br /> TokenBridge UI App Beta+
|
||||
</span>
|
||||
<p className="disclaimer-description">
|
||||
We’re launching our TokenBridge and our UI App on a beta-testing basis. While we’ve worked
|
||||
long and hard to develop the core features of the software, we expect that our users may
|
||||
detect bugs and other issues. Help us improve by posting any difficulties to our
|
||||
<a
|
||||
href="https://forum.poa.network/c/support/tokenbridge-support"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
We’re launching our TokenBridge and our UI App on a beta-testing basis. While we’ve worked long and hard to
|
||||
develop the core features of the software, we expect that our users may detect bugs and other issues. Help us
|
||||
improve by posting any difficulties to our
|
||||
<a href="https://forum.poa.network/c/support/tokenbridge-support" target="_blank" rel="noopener noreferrer">
|
||||
{' '}
|
||||
support page
|
||||
</a>
|
||||
.<br />
|
||||
<br />
|
||||
Use of this app and the TokenBridge is at your own risk. Users may experience unexpected
|
||||
delays, unexpected visual artifacts, unexpected loss of tokens or funds from improper app
|
||||
configuration, or other negative outcomes.
|
||||
Use of this app and the TokenBridge is at your own risk. Users may experience unexpected delays, unexpected
|
||||
visual artifacts, unexpected loss of tokens or funds from improper app configuration, or other negative
|
||||
outcomes.
|
||||
<br />
|
||||
<br />
|
||||
By hitting the "continue" button, you are representing that you’ve read our
|
||||
|
@ -16,8 +16,7 @@ export const FeeStatistics = ({ depositFeeCollected, withdrawFeeCollected }) =>
|
||||
dataTestid="deposit-fees-block"
|
||||
/>
|
||||
)}
|
||||
{depositFeeCollected.shouldDisplay &&
|
||||
withdrawFeeCollected.shouldDisplay && <div className="separator" />}
|
||||
{depositFeeCollected.shouldDisplay && withdrawFeeCollected.shouldDisplay && <div className="separator" />}
|
||||
{withdrawFeeCollected.shouldDisplay && (
|
||||
<DataBlock
|
||||
description="Withdrawal Fees"
|
||||
|
@ -16,18 +16,12 @@ export class Header extends React.Component {
|
||||
onMenuToggle,
|
||||
RootStore: { alertStore, web3Store }
|
||||
} = this.props
|
||||
const {
|
||||
REACT_APP_HOME_WITHOUT_EVENTS: HOME,
|
||||
REACT_APP_FOREIGN_WITHOUT_EVENTS: FOREIGN
|
||||
} = process.env
|
||||
const withoutEvents =
|
||||
web3Store.metamaskNet.id === web3Store.homeNet.id.toString() ? yn(HOME) : yn(FOREIGN)
|
||||
const { REACT_APP_HOME_WITHOUT_EVENTS: HOME, REACT_APP_FOREIGN_WITHOUT_EVENTS: FOREIGN } = process.env
|
||||
const withoutEvents = web3Store.metamaskNet.id === web3Store.homeNet.id.toString() ? yn(HOME) : yn(FOREIGN)
|
||||
|
||||
return (
|
||||
<header className="header">
|
||||
{showMobileMenu ? (
|
||||
<MobileMenu withoutEvents={withoutEvents} onMenuToggle={onMenuToggle} />
|
||||
) : null}
|
||||
{showMobileMenu ? <MobileMenu withoutEvents={withoutEvents} onMenuToggle={onMenuToggle} /> : null}
|
||||
<div className="container">
|
||||
<Link to="/" onClick={showMobileMenu ? onMenuToggle : null} className="header-logo" />
|
||||
<HeaderMenu withoutEvents={withoutEvents} onMenuToggle={onMenuToggle} />
|
||||
|
@ -13,10 +13,7 @@ export class Loading extends React.Component {
|
||||
const progress = loadingStepIndex === 3 ? 100 : loadingStepIndex * 25 + blockConfirmations * 4
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`loading-container ${loadingStepIndex > 0 ? 'mobile-container' : ''}`}
|
||||
style={style}
|
||||
>
|
||||
<div className={`loading-container ${loadingStepIndex > 0 ? 'mobile-container' : ''}`} style={style}>
|
||||
{loadingStepIndex > 0 && (
|
||||
<ProgressRing
|
||||
confirmationNumber={blockConfirmations}
|
||||
@ -28,9 +25,7 @@ export class Loading extends React.Component {
|
||||
)}
|
||||
{loadingStepIndex === 0 && <div className="loading-logo" />}
|
||||
{loadingStepIndex === 0 && <div className="loading-i" />}
|
||||
{loadingStepIndex > 0 && (
|
||||
<div className="loading-text">{loadingSteps[loadingStepIndex]}</div>
|
||||
)}
|
||||
{loadingStepIndex > 0 && <div className="loading-text">{loadingSteps[loadingStepIndex]}</div>}
|
||||
{alertStore.showLoading && <PreventExit />}
|
||||
</div>
|
||||
)
|
||||
|
@ -48,11 +48,7 @@ export const NetworkDetails = ({
|
||||
<p className="details-data-container">
|
||||
<span className="details-label">{networkTitle} Address</span>
|
||||
<span className="details-description details-copy">
|
||||
<a
|
||||
className="details-description"
|
||||
href={getExplorerAddressUrl(address)}
|
||||
target="_blank"
|
||||
>
|
||||
<a className="details-description" href={getExplorerAddressUrl(address)} target="_blank">
|
||||
{address.slice(0, 27).concat('...')}
|
||||
</a>
|
||||
<CopyToClipboard text={address}>
|
||||
@ -90,11 +86,7 @@ export const NetworkDetails = ({
|
||||
<p className="details-data-container">
|
||||
<span className="details-label">Token Address</span>
|
||||
<span className="details-description details-copy">
|
||||
<a
|
||||
className="details-description"
|
||||
href={getExplorerAddressUrl(tokenAddress)}
|
||||
target="_blank"
|
||||
>
|
||||
<a className="details-description" href={getExplorerAddressUrl(tokenAddress)} target="_blank">
|
||||
{tokenAddress.slice(0, 27).concat('...')}
|
||||
</a>
|
||||
<CopyToClipboard text={tokenAddress}>
|
||||
|
@ -34,12 +34,11 @@ export class NoWallet extends Component {
|
||||
<div className="noWallet-alert-container">
|
||||
<h2 className="noWallet-title">Wallet not found</h2>
|
||||
<p className="noWallet-description">
|
||||
A wallet is not installed. Before continue, please install one (AlphaWallet, Metamask
|
||||
or Nifty Wallet) and return to this page to continue using the application.
|
||||
A wallet is not installed. Before continue, please install one (AlphaWallet, Metamask or Nifty Wallet) and
|
||||
return to this page to continue using the application.
|
||||
</p>
|
||||
<p className="noWallet-description">
|
||||
For further information on how to install any of both wallets, please click the
|
||||
buttons below.
|
||||
For further information on how to install any of both wallets, please click the buttons below.
|
||||
</p>
|
||||
<div className="noWallet-buttons">
|
||||
<a
|
||||
|
@ -107,9 +107,7 @@ export class RelayEvents extends React.Component {
|
||||
}
|
||||
|
||||
getHomeEvents = homeStore => {
|
||||
return homeStore.events
|
||||
.slice()
|
||||
.map(({ event, transactionHash, blockNumber, returnValues }) => ({
|
||||
return homeStore.events.slice().map(({ event, transactionHash, blockNumber, returnValues }) => ({
|
||||
color: this.colors[event],
|
||||
eventName: event,
|
||||
transactionHash,
|
||||
@ -120,9 +118,7 @@ export class RelayEvents extends React.Component {
|
||||
}
|
||||
|
||||
getForeignEvents = foreignStore => {
|
||||
return foreignStore.events
|
||||
.slice()
|
||||
.map(({ event, transactionHash, signedTxHash, blockNumber, returnValues }) => {
|
||||
return foreignStore.events.slice().map(({ event, transactionHash, signedTxHash, blockNumber, returnValues }) => {
|
||||
return {
|
||||
color: this.colors[event],
|
||||
eventName: event,
|
||||
@ -143,12 +139,8 @@ export class RelayEvents extends React.Component {
|
||||
const { selectedList } = this.state
|
||||
const home = this.getHomeEvents(homeStore, foreignStore)
|
||||
const foreign = this.getForeignEvents(foreignStore, homeStore)
|
||||
const {
|
||||
REACT_APP_HOME_WITHOUT_EVENTS: HOME,
|
||||
REACT_APP_FOREIGN_WITHOUT_EVENTS: FOREIGN
|
||||
} = process.env
|
||||
const withoutEvents =
|
||||
web3Store.metamaskNet.id === web3Store.homeNet.id.toString() ? yn(HOME) : yn(FOREIGN)
|
||||
const { REACT_APP_HOME_WITHOUT_EVENTS: HOME, REACT_APP_FOREIGN_WITHOUT_EVENTS: FOREIGN } = process.env
|
||||
const withoutEvents = web3Store.metamaskNet.id === web3Store.homeNet.id.toString() ? yn(HOME) : yn(FOREIGN)
|
||||
|
||||
return withoutEvents ? (
|
||||
<Redirect to="/" />
|
||||
@ -156,12 +148,8 @@ export class RelayEvents extends React.Component {
|
||||
<div className="events-page">
|
||||
<div className="events-container">
|
||||
<EventsListHeader
|
||||
handleChange={
|
||||
selectedList === this.homeValue ? this.handleChangeHome : this.handleChangeForeign
|
||||
}
|
||||
handleKeyDown={
|
||||
selectedList === this.homeValue ? this.handleKeyDownHome : this.handleKeyDownForeign
|
||||
}
|
||||
handleChange={selectedList === this.homeValue ? this.handleChangeHome : this.handleChangeForeign}
|
||||
handleKeyDown={selectedList === this.homeValue ? this.handleKeyDownHome : this.handleKeyDownForeign}
|
||||
onChangeList={this.onChangeList}
|
||||
selected={selectedList}
|
||||
homeName={homeStore.networkName}
|
||||
|
@ -15,12 +15,8 @@ export class StatisticsPage extends React.Component {
|
||||
const isNativeToErc = bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC
|
||||
const leftTitle = isNativeToErc ? 'Deposits' : 'Withdraws'
|
||||
const rightTitle = isNativeToErc ? 'Withdraws' : 'Deposits'
|
||||
const {
|
||||
REACT_APP_HOME_WITHOUT_EVENTS: HOME,
|
||||
REACT_APP_FOREIGN_WITHOUT_EVENTS: FOREIGN
|
||||
} = process.env
|
||||
const withoutEvents =
|
||||
web3Store.metamaskNet.id === web3Store.homeNet.id.toString() ? yn(HOME) : yn(FOREIGN)
|
||||
const { REACT_APP_HOME_WITHOUT_EVENTS: HOME, REACT_APP_FOREIGN_WITHOUT_EVENTS: FOREIGN } = process.env
|
||||
const withoutEvents = web3Store.metamaskNet.id === web3Store.homeNet.id.toString() ? yn(HOME) : yn(FOREIGN)
|
||||
|
||||
return withoutEvents ? (
|
||||
<Redirect to="/" />
|
||||
@ -32,9 +28,7 @@ export class StatisticsPage extends React.Component {
|
||||
<span className="statistics-bridge-title statistics-title">Bridge Statistics</span>
|
||||
<BridgeStatistics
|
||||
users={homeStore.statistics.finished ? homeStore.statistics.users.size : ''}
|
||||
totalBridged={
|
||||
homeStore.statistics.finished ? homeStore.statistics.totalBridged.toString() : ''
|
||||
}
|
||||
totalBridged={homeStore.statistics.finished ? homeStore.statistics.totalBridged.toString() : ''}
|
||||
homeBalance={homeStore.balance}
|
||||
homeSymbol={homeStore.symbol}
|
||||
homeNativeSupplyTitle={isNativeToErc}
|
||||
@ -44,8 +38,7 @@ export class StatisticsPage extends React.Component {
|
||||
</div>
|
||||
{homeStore.depositFeeCollected.finished &&
|
||||
homeStore.withdrawFeeCollected.finished &&
|
||||
(homeStore.depositFeeCollected.shouldDisplay ||
|
||||
homeStore.withdrawFeeCollected.shouldDisplay) && (
|
||||
(homeStore.depositFeeCollected.shouldDisplay || homeStore.withdrawFeeCollected.shouldDisplay) && (
|
||||
<FeeStatistics
|
||||
depositFeeCollected={homeStore.depositFeeCollected}
|
||||
withdrawFeeCollected={homeStore.withdrawFeeCollected}
|
||||
@ -61,9 +54,7 @@ export class StatisticsPage extends React.Component {
|
||||
/>
|
||||
</div>
|
||||
<div className="statistics-withdraw-container">
|
||||
<span className="statistics-withdraw-title statistics-title">
|
||||
Tokens {rightTitle}
|
||||
</span>
|
||||
<span className="statistics-withdraw-title statistics-title">Tokens {rightTitle}</span>
|
||||
<TransactionsStatistics
|
||||
txNumber={homeStore.statistics.finished ? homeStore.statistics.withdraws : ''}
|
||||
type={foreignStore.symbol}
|
||||
|
@ -10,20 +10,14 @@ export class StatusPage extends React.Component {
|
||||
render() {
|
||||
const { homeStore, foreignStore, web3Store } = this.props.RootStore
|
||||
const isHome = web3Store.metamaskNet.id.toString() === web3Store.homeNet.id.toString()
|
||||
const requiredSignatures = isHome
|
||||
? homeStore.requiredSignatures
|
||||
: foreignStore.requiredSignatures
|
||||
const requiredSignatures = isHome ? homeStore.requiredSignatures : foreignStore.requiredSignatures
|
||||
const authorities = isHome ? homeStore.validatorsCount : foreignStore.validatorsCount
|
||||
const symbol = isHome ? homeStore.symbol : foreignStore.symbol
|
||||
const maxSingleDeposit = isHome ? homeStore.maxPerTx : foreignStore.maxPerTx
|
||||
const maxTotalBalance = isHome ? homeStore.maxCurrentDeposit : foreignStore.maxCurrentDeposit
|
||||
const validatorsList = isHome ? homeStore.validators : foreignStore.validators
|
||||
const {
|
||||
REACT_APP_HOME_WITHOUT_EVENTS: HOME,
|
||||
REACT_APP_FOREIGN_WITHOUT_EVENTS: FOREIGN
|
||||
} = process.env
|
||||
const withoutEvents =
|
||||
web3Store.metamaskNet.id === web3Store.homeNet.id.toString() ? yn(HOME) : yn(FOREIGN)
|
||||
const { REACT_APP_HOME_WITHOUT_EVENTS: HOME, REACT_APP_FOREIGN_WITHOUT_EVENTS: FOREIGN } = process.env
|
||||
const withoutEvents = web3Store.metamaskNet.id === web3Store.homeNet.id.toString() ? yn(HOME) : yn(FOREIGN)
|
||||
|
||||
return (
|
||||
<div className="status-page">
|
||||
|
@ -6,10 +6,6 @@ export const TransactionsStatistics = ({ txNumber, value, type }) => (
|
||||
<div className="statistics-bridge-data">
|
||||
<DataBlock description="Transactions" value={numeral(txNumber).format('0,0 a')} type="" />
|
||||
<div className="separator" />
|
||||
<DataBlock
|
||||
description="Total Value"
|
||||
value={numeral(value).format('0,0.00 a', Math.floor)}
|
||||
type={type}
|
||||
/>
|
||||
<DataBlock description="Total Value" value={numeral(value).format('0,0.00 a', Math.floor)} type={type} />
|
||||
</div>
|
||||
)
|
||||
|
@ -42,9 +42,8 @@ export const TransferAlert = ({
|
||||
<p className="transfer-description" data-testid="transfer-description">
|
||||
<strong>{fee && `Fee: ${fee.toString()}%`}</strong>
|
||||
<br />
|
||||
Please confirm that you would like to send <strong>{formattedFromAmount}</strong>{' '}
|
||||
{fromCurrency} from {from} to receive <strong>{formattedToAmount}</strong> {toCurrency} on{' '}
|
||||
{to}.
|
||||
Please confirm that you would like to send <strong>{formattedFromAmount}</strong> {fromCurrency} from {from}{' '}
|
||||
to receive <strong>{formattedToAmount}</strong> {toCurrency} on {to}.
|
||||
</p>
|
||||
<div className="transfer-buttons">
|
||||
<button className="transfer-confirm" onClick={onConfirmation}>
|
||||
|
@ -12,9 +12,7 @@ export class Wallet extends React.Component {
|
||||
const explorerAddressUrl = isHome
|
||||
? homeStore.getExplorerAddressUrl(address)
|
||||
: foreignStore.getExplorerAddressUrl(address)
|
||||
const completed = isHome
|
||||
? homeStore.getDailyQuotaCompleted()
|
||||
: foreignStore.getDailyQuotaCompleted()
|
||||
const completed = isHome ? homeStore.getDailyQuotaCompleted() : foreignStore.getDailyQuotaCompleted()
|
||||
const width = `${completed}%`
|
||||
|
||||
const wallet =
|
||||
|
@ -23,10 +23,7 @@ describe('FeeStatistics', () => {
|
||||
|
||||
// When
|
||||
const { queryByTestId } = render(
|
||||
<FeeStatistics
|
||||
depositFeeCollected={depositFeeCollected}
|
||||
withdrawFeeCollected={withdrawFeeCollected}
|
||||
/>
|
||||
<FeeStatistics depositFeeCollected={depositFeeCollected} withdrawFeeCollected={withdrawFeeCollected} />
|
||||
)
|
||||
|
||||
// Then
|
||||
@ -61,10 +58,7 @@ describe('FeeStatistics', () => {
|
||||
|
||||
// When
|
||||
const { queryByTestId } = render(
|
||||
<FeeStatistics
|
||||
depositFeeCollected={depositFeeCollected}
|
||||
withdrawFeeCollected={withdrawFeeCollected}
|
||||
/>
|
||||
<FeeStatistics depositFeeCollected={depositFeeCollected} withdrawFeeCollected={withdrawFeeCollected} />
|
||||
)
|
||||
|
||||
// Then
|
||||
@ -96,10 +90,7 @@ describe('FeeStatistics', () => {
|
||||
|
||||
// When
|
||||
const { queryByTestId } = render(
|
||||
<FeeStatistics
|
||||
depositFeeCollected={depositFeeCollected}
|
||||
withdrawFeeCollected={withdrawFeeCollected}
|
||||
/>
|
||||
<FeeStatistics depositFeeCollected={depositFeeCollected} withdrawFeeCollected={withdrawFeeCollected} />
|
||||
)
|
||||
|
||||
// Then
|
||||
@ -131,10 +122,7 @@ describe('FeeStatistics', () => {
|
||||
|
||||
// When
|
||||
const { queryByTestId } = render(
|
||||
<FeeStatistics
|
||||
depositFeeCollected={depositFeeCollected}
|
||||
withdrawFeeCollected={withdrawFeeCollected}
|
||||
/>
|
||||
<FeeStatistics depositFeeCollected={depositFeeCollected} withdrawFeeCollected={withdrawFeeCollected} />
|
||||
)
|
||||
|
||||
// Then
|
||||
|
@ -4,16 +4,7 @@ import numeral from 'numeral'
|
||||
import { CopyIcon } from '../icons/CopyIcon'
|
||||
import { CopyToClipboard } from 'react-copy-to-clipboard'
|
||||
|
||||
export const Event = ({
|
||||
color,
|
||||
eventName,
|
||||
transactionHash,
|
||||
recipient,
|
||||
value,
|
||||
blockNumber,
|
||||
txUrl,
|
||||
accountUrl
|
||||
}) => (
|
||||
export const Event = ({ color, eventName, transactionHash, recipient, value, blockNumber, txUrl, accountUrl }) => (
|
||||
<div>
|
||||
<div className="event">
|
||||
<div className="event-tx-container txhash-column">
|
||||
|
@ -186,28 +186,18 @@ class ForeignStore {
|
||||
this.rootStore.bridgeMode === BRIDGE_MODES.ERC_TO_NATIVE
|
||||
? await getErc20TokenAddress(this.foreignBridge)
|
||||
: await getErc677TokenAddress(this.foreignBridge)
|
||||
this.tokenContract = new this.foreignWeb3.eth.Contract(
|
||||
ERC677_BRIDGE_TOKEN_ABI,
|
||||
this.tokenAddress
|
||||
)
|
||||
this.tokenContract = new this.foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, this.tokenAddress)
|
||||
this.tokenType = await getTokenType(this.tokenContract, this.FOREIGN_BRIDGE_ADDRESS)
|
||||
const alternativeContract = new this.foreignWeb3.eth.Contract(
|
||||
ERC20_BYTES32_ABI,
|
||||
this.tokenAddress
|
||||
)
|
||||
const alternativeContract = new this.foreignWeb3.eth.Contract(ERC20_BYTES32_ABI, this.tokenAddress)
|
||||
try {
|
||||
this.symbol = await getSymbol(this.tokenContract)
|
||||
} catch (e) {
|
||||
this.symbol = this.foreignWeb3.utils
|
||||
.hexToAscii(await getSymbol(alternativeContract))
|
||||
.replace(/\u0000*$/, '')
|
||||
this.symbol = this.foreignWeb3.utils.hexToAscii(await getSymbol(alternativeContract)).replace(/\u0000*$/, '')
|
||||
}
|
||||
try {
|
||||
this.tokenName = await getName(this.tokenContract)
|
||||
} catch (e) {
|
||||
this.tokenName = this.foreignWeb3.utils
|
||||
.hexToAscii(await getName(alternativeContract))
|
||||
.replace(/\u0000*$/, '')
|
||||
this.tokenName = this.foreignWeb3.utils.hexToAscii(await getName(alternativeContract)).replace(/\u0000*$/, '')
|
||||
}
|
||||
|
||||
this.tokenDecimals = await getDecimals(this.tokenContract)
|
||||
@ -269,17 +259,11 @@ class ForeignStore {
|
||||
if (this.waitingForConfirmation.size) {
|
||||
const confirmationEvents = foreignEvents.filter(
|
||||
event =>
|
||||
event.event === 'RelayedMessage' &&
|
||||
this.waitingForConfirmation.has(event.returnValues.transactionHash)
|
||||
event.event === 'RelayedMessage' && this.waitingForConfirmation.has(event.returnValues.transactionHash)
|
||||
)
|
||||
confirmationEvents.forEach(async event => {
|
||||
const TxReceipt = await this.getTxReceipt(event.transactionHash)
|
||||
if (
|
||||
TxReceipt &&
|
||||
TxReceipt.logs &&
|
||||
TxReceipt.logs.length > 1 &&
|
||||
this.waitingForConfirmation.size
|
||||
) {
|
||||
if (TxReceipt && TxReceipt.logs && TxReceipt.logs.length > 1 && this.waitingForConfirmation.size) {
|
||||
this.alertStore.setLoadingStepIndex(3)
|
||||
const urlExplorer = this.getExplorerTxUrl(event.transactionHash)
|
||||
const unitReceived = getUnit(this.rootStore.bridgeMode).unitForeign
|
||||
@ -397,10 +381,7 @@ class ForeignStore {
|
||||
async getValidators() {
|
||||
try {
|
||||
const foreignValidatorsAddress = await getValidatorContract(this.foreignBridge)
|
||||
this.foreignBridgeValidators = new this.foreignWeb3.eth.Contract(
|
||||
BRIDGE_VALIDATORS_ABI,
|
||||
foreignValidatorsAddress
|
||||
)
|
||||
this.foreignBridgeValidators = new this.foreignWeb3.eth.Contract(BRIDGE_VALIDATORS_ABI, foreignValidatorsAddress)
|
||||
|
||||
this.requiredSignatures = await getRequiredSignatures(this.foreignBridgeValidators)
|
||||
this.validatorsCount = await getValidatorCount(this.foreignBridgeValidators)
|
||||
|
@ -193,29 +193,19 @@ class HomeStore {
|
||||
async getTokenInfo() {
|
||||
try {
|
||||
this.tokenAddress = await getErc677TokenAddress(this.homeBridge)
|
||||
this.tokenContract = new this.homeWeb3.eth.Contract(
|
||||
ERC677_BRIDGE_TOKEN_ABI,
|
||||
this.tokenAddress
|
||||
)
|
||||
this.tokenContract = new this.homeWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, this.tokenAddress)
|
||||
this.symbol = await getSymbol(this.tokenContract)
|
||||
this.tokenName = await getName(this.tokenContract)
|
||||
const alternativeContract = new this.homeWeb3.eth.Contract(
|
||||
ERC20_BYTES32_ABI,
|
||||
this.tokenAddress
|
||||
)
|
||||
const alternativeContract = new this.homeWeb3.eth.Contract(ERC20_BYTES32_ABI, this.tokenAddress)
|
||||
try {
|
||||
this.symbol = await getSymbol(this.tokenContract)
|
||||
} catch (e) {
|
||||
this.symbol = this.homeWeb3.utils
|
||||
.hexToAscii(await getSymbol(alternativeContract))
|
||||
.replace(/\u0000*$/, '')
|
||||
this.symbol = this.homeWeb3.utils.hexToAscii(await getSymbol(alternativeContract)).replace(/\u0000*$/, '')
|
||||
}
|
||||
try {
|
||||
this.tokenName = await getName(this.tokenContract)
|
||||
} catch (e) {
|
||||
this.tokenName = this.homeWeb3.utils
|
||||
.hexToAscii(await getName(alternativeContract))
|
||||
.replace(/\u0000*$/, '')
|
||||
this.tokenName = this.homeWeb3.utils.hexToAscii(await getName(alternativeContract)).replace(/\u0000*$/, '')
|
||||
}
|
||||
this.tokenDecimals = await getDecimals(this.tokenContract)
|
||||
} catch (e) {
|
||||
@ -256,17 +246,11 @@ class HomeStore {
|
||||
if (this.rootStore.bridgeMode === BRIDGE_MODES.ERC_TO_ERC) {
|
||||
this.balance = await getTotalSupply(this.tokenContract)
|
||||
this.web3Store.getWeb3Promise.then(async () => {
|
||||
this.userBalance = await getBalanceOf(
|
||||
this.tokenContract,
|
||||
this.web3Store.defaultAccount.address
|
||||
)
|
||||
this.userBalance = await getBalanceOf(this.tokenContract, this.web3Store.defaultAccount.address)
|
||||
balanceLoaded()
|
||||
})
|
||||
} else if (this.rootStore.bridgeMode === BRIDGE_MODES.ERC_TO_NATIVE) {
|
||||
const mintedCoins = await mintedTotallyByBridge(
|
||||
this.blockRewardContract,
|
||||
this.HOME_BRIDGE_ADDRESS
|
||||
)
|
||||
const mintedCoins = await mintedTotallyByBridge(this.blockRewardContract, this.HOME_BRIDGE_ADDRESS)
|
||||
const burntCoins = await totalBurntCoins(this.homeBridge)
|
||||
this.balance = fromDecimals(mintedCoins.minus(burntCoins).toString(10), this.tokenDecimals)
|
||||
} else {
|
||||
@ -388,14 +372,8 @@ class HomeStore {
|
||||
async filterByTxHash(transactionHash) {
|
||||
const events = await this.getEvents(1, 'latest')
|
||||
this.events = events.filter(event => event.transactionHash === transactionHash)
|
||||
if (
|
||||
this.events.length > 0 &&
|
||||
this.events[0].returnValues &&
|
||||
this.events[0].returnValues.transactionHash
|
||||
) {
|
||||
await this.rootStore.foreignStore.filterByTxHashInReturnValues(
|
||||
this.events[0].returnValues.transactionHash
|
||||
)
|
||||
if (this.events.length > 0 && this.events[0].returnValues && this.events[0].returnValues.transactionHash) {
|
||||
await this.rootStore.foreignStore.filterByTxHashInReturnValues(this.events[0].returnValues.transactionHash)
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,10 +410,7 @@ class HomeStore {
|
||||
async getValidators() {
|
||||
try {
|
||||
const homeValidatorsAddress = await getValidatorContract(this.homeBridge)
|
||||
this.homeBridgeValidators = new this.homeWeb3.eth.Contract(
|
||||
BRIDGE_VALIDATORS_ABI,
|
||||
homeValidatorsAddress
|
||||
)
|
||||
this.homeBridgeValidators = new this.homeWeb3.eth.Contract(BRIDGE_VALIDATORS_ABI, homeValidatorsAddress)
|
||||
|
||||
this.requiredSignatures = await getRequiredSignatures(this.homeBridgeValidators)
|
||||
this.validatorsCount = await getValidatorCount(this.homeBridgeValidators)
|
||||
@ -455,9 +430,7 @@ class HomeStore {
|
||||
const events = await getPastEvents(contract, deployedAtBlock, 'latest')
|
||||
processLargeArrayAsync(events, this.processEvent, () => {
|
||||
this.statistics.finished = true
|
||||
this.statistics.totalBridged = this.statistics.depositsValue.plus(
|
||||
this.statistics.withdrawsValue
|
||||
)
|
||||
this.statistics.totalBridged = this.statistics.depositsValue.plus(this.statistics.withdrawsValue)
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
@ -505,10 +478,8 @@ class HomeStore {
|
||||
|
||||
const data = getRewardableData(this.feeManager, this.rootStore.foreignStore.feeManager)
|
||||
|
||||
this.depositFeeCollected.type =
|
||||
data.depositSymbol === 'home' ? this.symbol : this.rootStore.foreignStore.symbol
|
||||
this.withdrawFeeCollected.type =
|
||||
data.withdrawSymbol === 'home' ? this.symbol : this.rootStore.foreignStore.symbol
|
||||
this.depositFeeCollected.type = data.depositSymbol === 'home' ? this.symbol : this.rootStore.foreignStore.symbol
|
||||
this.withdrawFeeCollected.type = data.withdrawSymbol === 'home' ? this.symbol : this.rootStore.foreignStore.symbol
|
||||
this.depositFeeCollected.shouldDisplay = data.displayDeposit
|
||||
this.withdrawFeeCollected.shouldDisplay = data.displayWithdraw
|
||||
|
||||
|
@ -23,10 +23,7 @@ class RootStore {
|
||||
@action
|
||||
async setBridgeMode() {
|
||||
const homeWeb3 = getWeb3Instance(process.env.REACT_APP_HOME_HTTP_PARITY_URL)
|
||||
const homeBridge = new homeWeb3.eth.Contract(
|
||||
HOME_ERC_TO_ERC_ABI,
|
||||
process.env.REACT_APP_HOME_BRIDGE_ADDRESS
|
||||
)
|
||||
const homeBridge = new homeWeb3.eth.Contract(HOME_ERC_TO_ERC_ABI, process.env.REACT_APP_HOME_BRIDGE_ADDRESS)
|
||||
const bridgeModeHash = await homeBridge.methods.getBridgeMode().call()
|
||||
this.bridgeMode = decodeBridgeMode(bridgeModeHash)
|
||||
this.bridgeModeInitialized = true
|
||||
|
@ -112,10 +112,7 @@ class Web3Store {
|
||||
await this.rootStore.homeStore.getBalance()
|
||||
this.alertStore.setLoading(false)
|
||||
}
|
||||
if (
|
||||
this.rootStore.bridgeModeInitialized &&
|
||||
this.rootStore.bridgeMode !== BRIDGE_MODES.ERC_TO_ERC
|
||||
) {
|
||||
if (this.rootStore.bridgeModeInitialized && this.rootStore.bridgeMode !== BRIDGE_MODES.ERC_TO_ERC) {
|
||||
balanceLoaded()
|
||||
}
|
||||
} catch (e) {
|
||||
@ -132,10 +129,7 @@ class Web3Store {
|
||||
}, 1000)
|
||||
return
|
||||
}
|
||||
if (
|
||||
this.metamaskNet.name !== this.homeNet.name &&
|
||||
this.metamaskNet.name !== this.foreignNet.name
|
||||
) {
|
||||
if (this.metamaskNet.name !== this.homeNet.name && this.metamaskNet.name !== this.foreignNet.name) {
|
||||
this.metamaskNotSetted = true
|
||||
this.alertStore.pushError(
|
||||
`You are on an unknown network on your wallet. Please select ${this.homeNet.name} or ${
|
||||
|
@ -24,22 +24,16 @@ describe('HomeStore', () => {
|
||||
|
||||
// Other mocks
|
||||
contract.totalBurntCoins = jest.fn(() => Promise.resolve(new BN(0)))
|
||||
contract.getBlockRewardContract = jest.fn(() =>
|
||||
Promise.resolve('0xCecBE80Ed3548dE11D7d2D922a36576eA40C4c26')
|
||||
)
|
||||
contract.getBlockRewardContract = jest.fn(() => Promise.resolve('0xCecBE80Ed3548dE11D7d2D922a36576eA40C4c26'))
|
||||
contract.getPastEvents = jest.fn(() => Promise.resolve([]))
|
||||
web3StoreUtils.getBlockNumber = jest.fn(() => Promise.resolve(10))
|
||||
contract.getMinPerTxLimit = jest.fn(() => Promise.resolve(100000000))
|
||||
contract.getMaxPerTxLimit = jest.fn(() => Promise.resolve(10000000000))
|
||||
contract.getCurrentLimit = jest.fn(() => Promise.resolve({}))
|
||||
contract.getValidatorContract = jest.fn(() =>
|
||||
Promise.resolve('0xcDF12C376F43A70a07d7Ad2fD3449634717C9235')
|
||||
)
|
||||
contract.getValidatorContract = jest.fn(() => Promise.resolve('0xcDF12C376F43A70a07d7Ad2fD3449634717C9235'))
|
||||
contract.getRequiredSignatures = jest.fn(() => Promise.resolve(1))
|
||||
contract.getValidatorCount = jest.fn(() => Promise.resolve(1))
|
||||
contract.getValidatorList = jest.fn(() =>
|
||||
Promise.resolve(['0x52576e0cCaA0C9157142Fbf1d1c6DbfAc5e4E33e'])
|
||||
)
|
||||
contract.getValidatorList = jest.fn(() => Promise.resolve(['0x52576e0cCaA0C9157142Fbf1d1c6DbfAc5e4E33e']))
|
||||
|
||||
// When
|
||||
new HomeStore(rootStore)
|
||||
|
@ -16,10 +16,7 @@ export const toDecimals = (number, decimals) => {
|
||||
}
|
||||
|
||||
const isBigNumber = object => {
|
||||
return (
|
||||
object &&
|
||||
(object instanceof BN || (object.constructor && object.constructor.name === 'BigNumber'))
|
||||
)
|
||||
return object && (object instanceof BN || (object.constructor && object.constructor.name === 'BigNumber'))
|
||||
}
|
||||
|
||||
const toBigNumber = number => {
|
||||
@ -33,8 +30,5 @@ const toBigNumber = number => {
|
||||
}
|
||||
|
||||
const isString = object => {
|
||||
return (
|
||||
typeof object === 'string' ||
|
||||
(object && object.constructor && object.constructor.name === 'String')
|
||||
)
|
||||
return typeof object === 'string' || (object && object.constructor && object.constructor.name === 'String')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user