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

Support RSK #141

Merged
merged 22 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3528d34
Use polling instead of event logs to check if transaction was processed
fvictorio Oct 5, 2018
e74b4d2
Support RSK success status response
fvictorio Oct 5, 2018
bc80800
Ignore errors when fetching events
fvictorio Oct 5, 2018
2a96208
Merge branch 'add-support-erc20-native' into support-rsk
fvictorio Oct 17, 2018
4a67631
Merge branch 'develop' into support-rsk
fvictorio Oct 22, 2018
5ba8beb
Merge branch 'develop' into support-rsk
patitonar Nov 8, 2018
7f6c628
Fix badges on README
patitonar Nov 8, 2018
65e2daa
Fix transfer success alert
patitonar Nov 12, 2018
7e7ec65
added RSK networks tags
Dec 2, 2018
2824cfb
Merge remote-tracking branch 'upstream/develop' into support-rsk
Dec 2, 2018
de0aee6
unification of chain data retrieval interval
Dec 2, 2018
ff9cd4f
meta tag of the page changed
Dec 3, 2018
f8cc959
Extract meta description as an .env variable
fernandomg Dec 7, 2018
5601f4c
Add support for _WITHOUT_EVENTS
fernandomg Dec 7, 2018
419d93a
Merge branch 'develop' into support-rsk
fernandomg Dec 7, 2018
f76645b
Fix menu styles
fernandomg Dec 7, 2018
305b80b
Update README
fernandomg Dec 10, 2018
26d8b5b
Change `_WITHOUT_EVENTS` constants to be used as boolean values
fernandomg Dec 10, 2018
a6f0ec3
Use `validatorsCount` for 'Authorities' in status page
fernandomg Dec 10, 2018
42513c1
Prevent rendering `events` and `statistic` for non-event based networks
fernandomg Dec 10, 2018
03c3bc0
Prevent from displaying 'Authorities' in `status` page, if the networ…
fernandomg Dec 10, 2018
671f054
Remove dependency incompatible with `react-scripts-v1.1.1`
fernandomg Dec 10, 2018
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# POA Bridge - User Interface (UI) Application

[![Build Status](https://travis-ci.org/patitonar/bridge-ui.svg?branch=master)](https://travis-ci.org/patitonar/bridge-ui)
[![Build Status](https://travis-ci.org/poanetwork/bridge-ui.svg?branch=master)](https://travis-ci.org/poanetwork/bridge-ui)
[![Gitter](https://badges.gitter.im/poanetwork/poa-bridge.svg)](https://gitter.im/poanetwork/poa-bridge?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Coverage Status](https://coveralls.io/repos/github/patitonar/bridge-ui/badge.svg?branch=master)](https://coveralls.io/github/patitonar/bridge-ui?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/poanetwork/bridge-ui/badge.svg?branch=master)](https://coveralls.io/github/poanetwork/bridge-ui?branch=master)
[![dependencies Status](https://david-dm.org/poanetwork/bridge-ui/status.svg)](https://david-dm.org/poanetwork/bridge-ui)

Welcome to the POA Bridge! Following is an overview of the POA Bridge and Bridge UI Application, as well as [basic instructions for getting started](#getting-started).
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<meta property="og:title" content="POA Bridge UI" />
<meta property="og:description" content="The POA cross-chain bridge serves as a method of transferring POA native tokens from the POA Network to the Ethereum network in a quick and cost-efficient manner. " />
<meta property="og:description" content="The TokenBridge serves as a method of transferring the Bancor Network tokens between the Ethereum network to Rootstock network in a quick and cost-efficient manner." />
fernandomg marked this conversation as resolved.
Show resolved Hide resolved
<meta property="og:url" content="https://poanetwork.github.io/bridge-ui" />
<meta property="og:type" content="website" />
<meta property="og:image" content="/images/bridgeogimage.jpg">
Expand Down
6 changes: 4 additions & 2 deletions src/components/Bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ export class Bridge extends React.Component {
tokenAddress: homeStore.tokenAddress
})
} else {
const value = Web3Utils.toHex(Web3Utils.toWei(amount))
return txStore.doSend({
to: homeStore.HOME_BRIDGE_ADDRESS,
from: web3Store.defaultAccount.address,
value: Web3Utils.toHex(Web3Utils.toWei(amount)),
data: '0x'
value,
data: '0x',
sentValue: value
})
}
} catch (e) {
Expand Down
21 changes: 18 additions & 3 deletions src/stores/ForeignStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getName
} from './utils/contract'
import { balanceLoaded, removePendingTransaction } from './utils/testUtils'
import sleep from './utils/sleep'
import { getBridgeABIs, getUnit, BRIDGE_MODES } from './utils/bridgeMode'
import { abi as BRIDGE_VALIDATORS_ABI } from '../contracts/BridgeValidators'
import ERC20Bytes32Abi from './utils/ERC20Bytes32.abi'
Expand Down Expand Up @@ -148,11 +149,14 @@ class ForeignStore {
fromBlock = fromBlock || this.filteredBlockNumber || this.latestBlockNumber - 50
toBlock = toBlock || this.filteredBlockNumber || "latest"

if(fromBlock < 0) {
if (fromBlock < 0) {
fromBlock = 0
}

let foreignEvents = await getPastEvents(this.foreignBridge, fromBlock, toBlock)
let foreignEvents = await getPastEvents(this.foreignBridge, fromBlock, toBlock).catch(e => {
console.error('Couldn\'t get events', e)
return []
})

if(!this.filter){
this.events = foreignEvents;
Expand Down Expand Up @@ -249,6 +253,18 @@ class ForeignStore {
return this.dailyLimit ? this.totalSpentPerDay / this.dailyLimit * 100 : 0
}

async waitUntilProcessed(txHash) {
const bridge = this.foreignBridge

const processed = await bridge.methods.relayedMessages(txHash).call()

if (processed) {
return Promise.resolve()
} else {
return sleep(5000).then(() => this.waitUntilProcessed(txHash))
}
}

getExplorerTxUrl(txHash) {
return this.explorerTxTemplate.replace('%s', txHash)
}
Expand All @@ -268,7 +284,6 @@ class ForeignStore {
console.error(e)
}
}

}

export default ForeignStore;
28 changes: 23 additions & 5 deletions src/stores/HomeStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getName
} from './utils/contract'
import { balanceLoaded, removePendingTransaction } from './utils/testUtils'
import sleep from './utils/sleep'
import Web3Utils from 'web3-utils'
import BN from 'bignumber.js'
import { getBridgeABIs, getUnit, BRIDGE_MODES } from './utils/bridgeMode'
Expand Down Expand Up @@ -100,10 +101,8 @@ class HomeStore {
this.getEvents()
this.getBalance()
this.getBlockNumber()
}, 5000)
setInterval(() => {
this.getCurrentLimit()
}, 10000)
}, 15000)
}

@action
Expand Down Expand Up @@ -184,11 +183,14 @@ class HomeStore {
fromBlock = fromBlock || this.filteredBlockNumber || this.latestBlockNumber - 50
toBlock = toBlock || this.filteredBlockNumber || "latest"

if(fromBlock < 0) {
if (fromBlock < 0) {
fromBlock = 0
}

let events = await getPastEvents(this.homeBridge, fromBlock, toBlock)
let events = await getPastEvents(this.homeBridge, fromBlock, toBlock).catch(e => {
console.error('Couldn\'t get events', e)
return []
})

let homeEvents = []
await asyncForEach(events, (async (event) => {
Expand Down Expand Up @@ -358,6 +360,22 @@ class HomeStore {
const blockRewardAddress = await this.homeBridge.methods.blockRewardContract().call()
this.blockRewardContract = new this.homeWeb3.eth.Contract(BLOCK_REWARD_ABI, blockRewardAddress)
}

async waitUntilProcessed(txHash, value) {
const web3 = this.rootStore.foreignStore.foreignWeb3
const bridge = this.homeBridge

const tx = await web3.eth.getTransaction(txHash)
const messageHash = web3.utils.soliditySha3(tx.from, web3.utils.toBN(value).toString(), txHash)
const numSigned = await bridge.methods.numAffirmationsSigned(messageHash).call()
const processed = await bridge.methods.isAlreadyProcessed(numSigned).call()

if (processed) {
return Promise.resolve()
} else {
return sleep(5000).then(() => this.waitUntilProcessed(txHash, value))
}
}
}

export default HomeStore;
42 changes: 35 additions & 7 deletions src/stores/TxStore.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { action } from "mobx";
import { action, observable } from "mobx";
import { estimateGas } from './utils/web3'
import { addPendingTransaction } from './utils/testUtils'
import { addPendingTransaction, removePendingTransaction } from './utils/testUtils'
import { getUnit } from './utils/bridgeMode'

class TxStore {
@observable txsValues = {}

constructor(rootStore) {
this.web3Store = rootStore.web3Store
this.gasPriceStore = rootStore.gasPriceStore
this.alertStore = rootStore.alertStore
this.foreignStore = rootStore.foreignStore
this.homeStore = rootStore.homeStore
this.rootStore = rootStore
}

@action
async doSend({to, from, value, data}){
async doSend({to, from, value, data, sentValue}){
return this.web3Store.getWeb3Promise.then(async ()=> {
if(!this.web3Store.defaultAccount){
this.alertStore.pushError("Please unlock wallet")
Expand All @@ -30,6 +34,7 @@ class TxStore {
data
}).on('transactionHash', (hash) => {
console.log('txHash', hash)
this.txsValues[hash] = sentValue
this.alertStore.setLoadingStepIndex(1)
addPendingTransaction()
this.getTxReceipt(hash)
Expand All @@ -53,7 +58,7 @@ class TxStore {
const data = await contract.methods.transferAndCall(
to, value, '0x00'
).encodeABI()
return this.doSend({to: tokenAddress, from, value: '0x00', data})
return this.doSend({to: tokenAddress, from, value: '0x00', data, sentValue: value})
} else {
this.alertStore.pushError('Please unlock wallet');
}
Expand All @@ -71,7 +76,7 @@ class TxStore {
const data = await this.foreignStore.tokenContract.methods.transfer(
to, value
).encodeABI({ from: this.web3Store.defaultAccount.address })
return this.doSend({to: this.foreignStore.tokenAddress, from, value: '0x', data})
return this.doSend({to: this.foreignStore.tokenAddress, from, value: '0x', data, sentValue: value})
} else {
this.alertStore.pushError('Please unlock wallet');
}
Expand Down Expand Up @@ -106,7 +111,18 @@ class TxStore {
if(blockConfirmations >= 8) {
this.alertStore.setBlockConfirmations(8)
this.alertStore.setLoadingStepIndex(2)
this.foreignStore.addWaitingForConfirmation(hash)
this.foreignStore.waitUntilProcessed(hash).then(() => {
this.alertStore.setLoadingStepIndex(3)
const unitReceived = getUnit(this.rootStore.bridgeMode).unitForeign
setTimeout(() => {
this.alertStore.pushSuccess(
`${unitReceived} received on ${this.homeStore.networkName}`,
this.alertStore.FOREIGN_TRANSFER_SUCCESS
)
}
, 2000)
removePendingTransaction()
})
} else {
if(blockConfirmations > 0) {
this.alertStore.setBlockConfirmations(blockConfirmations)
Expand All @@ -119,7 +135,19 @@ class TxStore {
if(blockConfirmations >= 8) {
this.alertStore.setBlockConfirmations(8)
this.alertStore.setLoadingStepIndex(2)
this.homeStore.addWaitingForConfirmation(hash)
this.homeStore.waitUntilProcessed(hash, this.txsValues[hash])
.then(() => {
this.alertStore.setLoadingStepIndex(3)
const unitReceived = getUnit(this.rootStore.bridgeMode).unitHome
setTimeout(() => {
this.alertStore.pushSuccess(
`${unitReceived} received on ${this.foreignStore.networkName}`,
this.alertStore.HOME_TRANSFER_SUCCESS
)
}
, 2000)
removePendingTransaction()
})
} else {
if(blockConfirmations > 0) {
this.alertStore.setBlockConfirmations(blockConfirmations)
Expand Down
3 changes: 3 additions & 0 deletions src/stores/utils/sleep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const sleep = timeout => new Promise(resolve => setTimeout(resolve, timeout))

export default sleep
6 changes: 4 additions & 2 deletions src/stores/utils/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ const networks = {
1: 'ETH Mainnet',
3: 'Ropsten',
4: 'Rinkeby',
42: 'Kovan',
77: 'Sokol',
30: 'RSK Mainnet',
31: 'RSK Testnet',
42:'Kovan',
77:'Sokol',
99: 'POA Network',
100: 'Dai Chain'
}
Expand Down