Skip to content

Commit

Permalink
View eth balance on gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardonunesp committed Aug 31, 2018
1 parent 8a4ba11 commit 9f8d994
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions transfer_gateway
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ start)
fi

start_and_deploy_truffle_ethereum
# start_dappchain
start_dappchain
deploy_truffle_dappchain
start_webapp
run_mapping
Expand All @@ -260,7 +260,7 @@ stop)
echo

stop_webdapp
# stop_dappchain
stop_dappchain
stop_truffle_ethereum

echo
Expand Down
2 changes: 1 addition & 1 deletion webclient/src/components/dappchain_tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class DAppChainTokens extends React.Component {

async componentWillMount() {
this.props.dcGatewayManager.onTokenWithdrawal(async event => {
alert(`Token ${event.value.toNumber()} ready for withdraw, check Ethereum Gateway`)
alert(`Token ${event.value} ready for withdraw, check Ethereum Gateway`)
await this.updateUI()
})

Expand Down
22 changes: 17 additions & 5 deletions webclient/src/components/gateway_tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class GatewayTokens extends React.Component {
account: '0x',
cardIds: [],
balance: 0,
ethBalance: 0,
mapping: null,
withdrawing: false
}
Expand All @@ -26,12 +27,13 @@ export default class GatewayTokens extends React.Component {
const account = this.props.dcAccountManager.getCurrentAccount()
const data = await this.props.dcGatewayManager.withdrawalReceiptAsync(account)

let ethBalance = 0
let balance = 0
let cardIds = []
if (data) {
switch (data.tokenKind) {
case 0:
balance = +data.value.toString(10)
ethBalance = +data.value.toString(10)
break
case 1:
balance = +data.value.toString(10)
Expand All @@ -42,7 +44,7 @@ export default class GatewayTokens extends React.Component {
}
}

this.setState({ account, mapping, balance, cardIds })
this.setState({ account, mapping, balance, cardIds, ethBalance })
}

async withdrawFromGatewayToken(amount) {
Expand Down Expand Up @@ -75,7 +77,7 @@ export default class GatewayTokens extends React.Component {
const signature = CryptoUtils.bytesToHexAddr(data.oracleSignature)

try {
await this.props.ethAccountManager.withdrawEthAsync(tokenOwner, amount, signature)
await this.props.ethGatewayManager.withdrawEthAsync(tokenOwner, amount, signature)

alert('Token withdraw with success, check Owned Tokens')
} catch (err) {
Expand Down Expand Up @@ -112,6 +114,7 @@ export default class GatewayTokens extends React.Component {
render() {
const wallet = (
<Wallet
title="Game Token"
balance={this.state.balance}
action="Withdraw from gateway"
handleOnClick={() => this.withdrawFromGatewayToken(this.state.balance)}
Expand All @@ -122,9 +125,9 @@ export default class GatewayTokens extends React.Component {
const ethWallet = (
<Wallet
title="Ether"
balance={this.state.balance}
balance={this.state.ethBalance}
action="Withdraw from gateway"
handleOnClick={() => this.withdrawFromGatewayEth(this.state.balance)}
handleOnClick={() => this.withdrawFromGatewayEth(this.state.ethBalance)}
disabled={this.state.sending}
/>
)
Expand All @@ -144,6 +147,14 @@ export default class GatewayTokens extends React.Component {
)
})

const viewEth = !this.state.mapping ? (
<p>Please sign your user first</p>
) : this.state.ethBalance > 0 ? (
ethWallet
) : (
<p>No Ether available</p>
)

const viewTokens = !this.state.mapping ? (
<p>Please sign your user first</p>
) : this.state.balance > 0 ? (
Expand All @@ -164,6 +175,7 @@ export default class GatewayTokens extends React.Component {
<div>
<h2>Ethereum Network Gateway Tokens</h2>
<div className="container">
<div>{ethWallet}</div>
<div>{viewTokens}</div>
<div>{viewCards}</div>
</div>
Expand Down

0 comments on commit 9f8d994

Please sign in to comment.