Skip to content

Commit

Permalink
Integrate burner-core for reading balances
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihal committed Jun 14, 2019
1 parent 1e3a2b5 commit e184049
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 44 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@burner-wallet/assets": "0.0.4",
"@burner-wallet/core": "0.0.6",
"autolinker": "^2.2.1",
"axios": "^0.18.0",
"base64url": "^3.0.1",
Expand Down
88 changes: 49 additions & 39 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { ContractLoader, Dapparatus, Transactions, Gas, Address, Events } from "
import Web3 from 'web3';
import axios from 'axios';
import { I18nextProvider } from 'react-i18next';
import i18n from './i18n';
import gasless from 'tabookey-gasless';
import { eth, dai, xdai } from '@burner-wallet/assets';

import i18n from './i18n';
import './App.scss';
import Header from './components/Header';
import NavCard from './components/NavCard';
Expand Down Expand Up @@ -47,9 +49,9 @@ import RNMessageChannel from 'react-native-webview-messaging';

import bufficorn from './bufficorn.png';
import cypherpunk from './cypherpunk.png';
import eth from './ethereum.png';
import dai from './dai.jpg';
import xdai from './xdai.jpg';
import ethImg from './images/ethereum.png';
import daiImg from './images/dai.jpg';
import xdaiImg from './images/xdai.jpg';
import Wyre from './services/wyre';

let base64url = require('base64url')
Expand Down Expand Up @@ -537,34 +539,17 @@ class App extends Component {


if(this.state.account){
let ethBalance = 0.00
let daiBalance = 0.00
let xdaiBalance = 0.00

if(this.state.mainnetweb3){

try{
ethBalance = await this.state.mainnetweb3.eth.getBalance(this.state.account)
ethBalance = this.state.mainnetweb3.utils.fromWei(""+ethBalance,'ether')

if(this.state.daiContract){
daiBalance = await this.state.daiContract.methods.balanceOf(this.state.account).call()
daiBalance = this.state.mainnetweb3.utils.fromWei(""+daiBalance,'ether')
}
}catch(e){
console.log(e)
this.connectToRPC()
}



}
if(this.state.xdaiweb3){
xdaiBalance = await this.state.xdaiweb3.eth.getBalance(this.state.account)
xdaiBalance = this.state.xdaiweb3.utils.fromWei(""+xdaiBalance,'ether')
}

this.setState({ethBalance,daiBalance,xdaiBalance,badgeBalance,hasUpdateOnce:true})
const ethBalance = await eth.getDisplayBalance(this.state.account, 20);
const daiBalance = await dai.getDisplayBalance(this.state.account, 20);
const xdaiBalance = await xdai.getDisplayBalance(this.state.account, 20);

this.setState({
ethBalance,
daiBalance,
xdaiBalance,
badgeBalance,
hasUpdateOnce:true
});

if(xdaiBalance < 0.01 && singleBadgeId && !this.state.switchedToSingleBadge){
this.setState({switchedToSingleBadge:true})
Expand Down Expand Up @@ -1352,7 +1337,14 @@ render() {

let defaultBalanceDisplay = (
<div>
<Balance icon={xdai} selected={false} text={"xdai"} amount={this.state.xdaiBalance} address={account} dollarDisplay={dollarDisplay} />
<Balance
icon={xdaiImg}
selected={false}
text="xdai"
amount={this.state.xdaiBalance}
address={account}
dollarDisplay={dollarDisplay}
/>
<Ruler/>
</div>
)
Expand Down Expand Up @@ -1391,11 +1383,32 @@ render() {

{extraTokens}

<Balance icon={xdai} selected={selected} text={"xDai"} amount={this.state.xdaiBalance} address={account} dollarDisplay={dollarDisplay}/>
<Balance
icon={xdaiImg}
selected={selected}
text="xDai"
amount={this.state.xdaiBalance}
address={account}
dollarDisplay={dollarDisplay}
/>
<Ruler/>
<Balance icon={dai} selected={selected} text={"DAI"} amount={this.state.daiBalance} address={account} dollarDisplay={dollarDisplay}/>
<Balance
icon={daiImg}
selected={selected}
text="DAI"
amount={this.state.daiBalance}
address={account}
dollarDisplay={dollarDisplay}
/>
<Ruler/>
<Balance icon={eth} selected={selected} text={"ETH"} amount={parseFloat(this.state.ethBalance) * parseFloat(this.state.ethprice)} address={account} dollarDisplay={dollarDisplay}/>
<Balance
icon={ethImg}
selected={selected}
text="ETH"
amount={parseFloat(this.state.ethBalance) * parseFloat(this.state.ethprice)}
address={account}
dollarDisplay={dollarDisplay}
/>
<Ruler/>
{badgeDisplay}

Expand Down Expand Up @@ -1835,9 +1848,6 @@ render() {

<NavCard title={i18n.t('exchange_title')} goBack={this.goBack.bind(this)}/>
<Exchange
eth={eth}
dai={dai}
xdai={xdai}
ERC20NAME={ERC20NAME}
ERC20IMAGE={ERC20IMAGE}
ERC20TOKEN={ERC20TOKEN}
Expand Down
4 changes: 2 additions & 2 deletions src/components/BalanceDisplay.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import axios from 'axios';

import eth from '../ethereum.png';
import ethImg from '../images/ethereum.png';
import i18n from '../i18n';

export default class BalanceDisplay extends React.Component {
Expand Down Expand Up @@ -79,7 +79,7 @@ export default class BalanceDisplay extends React.Component {
}

let moneytype = (
<img style={{maxHeight:30,verticalAlign:"middle"}} src={eth}/>
<img style={{maxHeight:30,verticalAlign:"middle"}} src={ethImg}/>
)
if(window.location.hostname.indexOf("xdai") >= 0 || window.location.hostname.indexOf("localhost") >= 0){
moneytype="$"
Expand Down
9 changes: 6 additions & 3 deletions src/components/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import i18n from '../i18n';

import Wyre from '../services/wyre';
import wyrelogo from '../wyre.png';
import ethImg from '../images/ethereum.png';
import daiImg from '../images/dai.jpg';
import xdaiImg from '../images/xdai.jpg';

import InputRange from 'react-input-range';
import 'react-input-range/lib/css/index.css';
Expand Down Expand Up @@ -2224,7 +2227,7 @@ export default class Exchange extends React.Component {

<div className="content ops row" style={{paddingBottom:20}}>
<div className="col-2 p-1">
<img style={logoStyle} src={this.props.xdai} />
<img style={logoStyle} src={xdaiImg} />
</div>
<div className="col-3 p-1" style={{marginTop:8}}>
xDai
Expand All @@ -2249,7 +2252,7 @@ export default class Exchange extends React.Component {

<div className="content ops row" style={{paddingBottom:20}}>
<div className="col-2 p-1">
<img style={logoStyle} src={this.props.dai} />
<img style={logoStyle} src={daiImg} />
</div>
<div className="col-3 p-1" style={{marginTop:9}}>
DAI
Expand All @@ -2273,7 +2276,7 @@ export default class Exchange extends React.Component {

<div className="content ops row" style={{paddingBottom:20}}>
<div className="col-2 p-1">
<img style={logoStyle} src={this.props.eth} />
<img style={logoStyle} src={ethImg} />
</div>
<div className="col-3 p-1" style={{marginTop:10}}>
ETH
Expand Down
19 changes: 19 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import BurnerCore from '@burner-wallet/core';
import { InjectedSigner, LocalSigner } from '@burner-wallet/core/src/signers';
import { InfuraGateway, InjectedGateway, XDaiGateway } from '@burner-wallet/core/src/gateways';
import { eth, dai, xdai } from '@burner-wallet/assets';

// TODO: Move all keys to env variable
const infuraKey = 'e0ea6e73570246bbb3d4bd042c4b5dac';

const core = new BurnerCore({
signers: [new InjectedSigner(), new LocalSigner()],
gateways: [
new InjectedGateway(),
new InfuraGateway(infuraKey),
new XDaiGateway(),
],
assets: [xdai, dai, eth],
});

export default core;
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import './index.scss';
import './core';
import App from './App';


Expand Down

0 comments on commit e184049

Please sign in to comment.