Skip to content

Commit

Permalink
Use burner-core for token balances
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihal committed Jul 3, 2019
1 parent 4bb8549 commit 8273d41
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 260 deletions.
259 changes: 76 additions & 183 deletions src/App.js

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions src/assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { eth, dai, xdai, ERC20Asset } from '@burner-wallet/assets';
import burnerlogo from './burnerwallet.png';
import bufficorn from './bufficorn.png';

export const assets = [xdai, dai, eth];
export let token = null;
export let WEB3_PROVIDER = 'https://dai.poa.network';
export let ERC20IMAGE;
export let LOADERIMAGE = burnerlogo;
export let XDAI_PROVIDER = 'https://dai.poa.network'


if (window.location.hostname.indexOf("localhost") >= 0 || window.location.hostname.indexOf("10.0.0.107") >= 0) {
XDAI_PROVIDER = "http://localhost:8545"
WEB3_PROVIDER = "http://localhost:8545";
ERC20IMAGE = false
} else if (window.location.hostname.indexOf("wallet.galleass.io") >= 0) {
WEB3_PROVIDER = "http://localhost:8545"
document.domain = 'galleass.io'
} else if (window.location.hostname.indexOf("buffidai") >= 0) {
token = new ERC20Asset({
id: 'buff',
name: 'BUFF',
network: '100',
address: '0x3e50bf6703fc132a94e4baff068db2055655f11b',
usdPrice: 1,
});

ERC20IMAGE = bufficorn
LOADERIMAGE = bufficorn
}
6 changes: 3 additions & 3 deletions src/components/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class Advanced extends React.Component {
changingAllowed[v] = true
this.setState({changingAllowed})
//updateVendor(address wallet, bytes32 name, bool newAllowed)
tx(contracts[this.props.ERC20VENDOR].updateVendor(vendors[v].vendor,web3.utils.utf8ToHex(vendors[v].name),vendors[v].isActive,!vendors[v].isAllowed),120000,0,0,(result)=>{
tx(contracts.ERC20Vendable.updateVendor(vendors[v].vendor,web3.utils.utf8ToHex(vendors[v].name),vendors[v].isActive,!vendors[v].isAllowed),120000,0,0,(result)=>{
console.log("ACTIVE:",result)
setTimeout(()=>{
let {changingAllowed} = this.state
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class Advanced extends React.Component {
changingAllowed[v] = true
this.setState({changingAllowed})
//updateVendor(address wallet, bytes32 name, bool newAllowed)
tx(contracts[this.props.ERC20VENDOR].updateVendor(vendors[v].vendor,web3.utils.utf8ToHex(vendors[v].name),!vendors[v].isActive,vendors[v].isAllowed),120000,0,0,(result)=>{
tx(contracts.ERC20Vendable.updateVendor(vendors[v].vendor,web3.utils.utf8ToHex(vendors[v].name),!vendors[v].isActive,vendors[v].isAllowed),120000,0,0,(result)=>{
console.log("ACTIVE:",result)
setTimeout(()=>{
let {changingAllowed} = this.state
Expand Down Expand Up @@ -191,7 +191,7 @@ export default class Advanced extends React.Component {
<div className="col-4 p-1">
<button className="btn btn-large w-100" style={this.props.buttonStyle.secondary} onClick={()=>{
this.setState({addingVendor:true})
tx(contracts[this.props.ERC20VENDOR].addVendor(this.state.newVendor,web3.utils.utf8ToHex(this.state.newVendorName)),480000,0,0,(result)=>{
tx(contracts.ERC20Vendable.addVendor(this.state.newVendor,web3.utils.utf8ToHex(this.state.newVendorName)),480000,0,0,(result)=>{
console.log("VENDOR ADDED",result)
this.setState({newVendor:"",newVendorName:""})
setTimeout(()=>{
Expand Down
49 changes: 22 additions & 27 deletions src/components/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import xdaiImg from '../images/xdai.jpg';
import InputRange from 'react-input-range';
import 'react-input-range/lib/css/index.css';
import core from '../core';
import { token, ERC20IMAGE } from '../assets';

const MAINNET_CHAIN_ID = '1';
const XDAI_CHAIN_ID = '100';
Expand Down Expand Up @@ -81,11 +82,11 @@ export default class Exchange extends React.Component {
let dendaiContract
let vendorContract
console.log("NETWORK:",this.props.network)
if(props.ERC20TOKEN&&this.props.network=="xDai"){
if(token && token.network == "100"){
try{
console.log("Loading "+props.ERC20TOKEN+" Contract...")
dendaiContract = new this.props.web3.eth.Contract(require("../contracts/"+props.ERC20TOKEN+".abi.js"),require("../contracts/"+props.ERC20TOKEN+".address.js"))
vendorContract = new this.props.web3.eth.Contract(require("../contracts/"+props.ERC20VENDOR+".abi.js"),require("../contracts/"+props.ERC20VENDOR+".address.js"))
console.log("Loading "+token.name+" Contract...")
dendaiContract = new this.props.web3.eth.Contract(require("../contracts/ERC20Vendable.abi.js"),require("../contracts/ERC20Vendable.address.js"))
vendorContract = new this.props.web3.eth.Contract(require("../contracts/VendingMachine.abi.js"),require("../contracts/VendingMachine.address.js"))
console.log("SET vendorContract",vendorContract)
}catch(e){
console.log("ERROR LOADING dendaiContract Contract",e)
Expand Down Expand Up @@ -270,11 +271,8 @@ export default class Exchange extends React.Component {
this.setState({extraGasUpDisplay})
}



if(this.props.ERC20TOKEN&&dendaiContract){
let denDaiBalance = await dendaiContract.methods.balanceOf(this.state.daiAddress).call()
denDaiBalance = core.getWeb3(MAINNET_CHAIN_ID).utils.fromWei(denDaiBalance,"ether")
if(token){
const denDaiBalance = await token.getDisplayBalance(this.state.daiAddress);
if(denDaiBalance!=this.state.denDaiBalance){
this.setState({denDaiBalance})
}
Expand Down Expand Up @@ -811,7 +809,7 @@ export default class Exchange extends React.Component {
let xdaiToDendaiDisplay = i18n.t('loading')

let tokenDisplay = ""
if(this.props.ERC20TOKEN){
if(token){
if(xdaiToDendaiMode=="sending" || xdaiToDendaiMode=="withdrawing" || xdaiToDendaiMode=="depositing"){
xdaiToDendaiDisplay = (
<div className="content ops row" style={{position:"relative"}}>
Expand Down Expand Up @@ -873,7 +871,7 @@ export default class Exchange extends React.Component {
xdaiBalanceAtStart:this.props.xdaiBalance,
xdaiBalanceShouldBe:parseFloat(this.props.xdaiBalance)-parseFloat(this.state.amount),
loaderBarColor:"#3efff8",
loaderBarStatusText:"Depositing xDai into "+this.props.ERC20NAME+"...",
loaderBarStatusText: `Depositing xDai into ${token.name}...`,
loaderBarPercent:0,
loaderBarStartTime: Date.now(),
loaderBarClick:()=>{
Expand Down Expand Up @@ -914,9 +912,9 @@ export default class Exchange extends React.Component {
});

}else{
console.log("Use MetaMask to withdraw "+this.props.ERC20NAME+" to xDai")
console.log(`Use MetaMask to withdraw ${token.name} to xDai`)
this.props.tx(
this.props.contracts[this.props.ERC20VENDOR].deposit()
this.props.contracts.VendingMachine.deposit()
,120000,0,amountOfxDaiToDeposit,(receipt)=>{
if(receipt){
console.log("EXCHANGE COMPLETE?!?",receipt)
Expand Down Expand Up @@ -993,14 +991,14 @@ export default class Exchange extends React.Component {
<button className="btn btn-large w-100" disabled={buttonsDisabled} style={this.props.buttonStyle.primary} onClick={async ()=>{

let amountOfxDaiToWithdraw = core.getWeb3(XDAI_CHAIN_ID).utils.toWei(""+this.state.amount,'ether')
console.log("Using "+this.props.ERC20NAME+" contract to withdraw "+amountOfxDaiToWithdraw+" xDai")
console.log(`Using ${token.name} contract to withdraw ${amountOfxDaiToWithdraw} xDai`);

this.setState({
xdaiToDendaiMode:"withdrawing",
xdaiBalanceAtStart:this.props.xdaiBalance,
xdaiBalanceShouldBe:parseFloat(this.props.xdaiBalance)+parseFloat(this.state.amount),
loaderBarColor:"#3efff8",
loaderBarStatusText:"Withdrawing "+this.props.ERC20NAME+" to xDai...",
loaderBarStatusText: `Withdrawing ${token.name} to xDai...`,
loaderBarPercent:0,
loaderBarStartTime: Date.now(),
loaderBarClick:()=>{
Expand Down Expand Up @@ -1041,9 +1039,9 @@ export default class Exchange extends React.Component {
});

}else{
console.log("Use MetaMask to withdraw "+this.props.ERC20NAME+" to xDai")
console.log(`Use MetaMask to withdraw ${token.name} to xDai`)
this.props.tx(
this.props.contracts[this.props.ERC20VENDOR].withdraw(""+amountOfxDaiToWithdraw)
this.props.contracts.VendingMachine.withdraw(""+amountOfxDaiToWithdraw)
,120000,0,0,(receipt)=>{
if(receipt){
console.log("EXCHANGE COMPLETE?!?",receipt)
Expand Down Expand Up @@ -1077,7 +1075,7 @@ export default class Exchange extends React.Component {
this.setState({xdaiToDendaiMode:"deposit"})
}}>
<Scaler config={{startZoomAt:400,origin:"50% 50%"}}>
<i className="fas fa-arrow-up" /> xDai to {this.props.ERC20NAME}
<i className="fas fa-arrow-up" /> xDai to {token.name}
</Scaler>
</button>
</div>
Expand All @@ -1087,29 +1085,26 @@ export default class Exchange extends React.Component {
this.setState({xdaiToDendaiMode:"withdraw"})
}}>
<Scaler config={{startZoomAt:400,origin:"50% 50%"}}>
<i className="fas fa-arrow-down" /> {this.props.ERC20NAME} to xDai
<i className="fas fa-arrow-down" /> {token.name} to xDai
</Scaler>
</button>
</div>
</div>
)
}

let link = ""
if(this.props.contracts){
link = "https://blockscout.com/poa/dai/address/"+this.props.contracts[this.props.ERC20TOKEN]._address+"/contracts"
}
const link = `https://blockscout.com/poa/dai/address/${token.address}/contracts`;

tokenDisplay = (
<div>
<div className="content ops row" style={{paddingBottom:20}}>
<div className="col-2 p-1">
<a href={link} target="_blank">
<img style={logoStyle} src={this.props.ERC20IMAGE} />
<img style={logoStyle} src={ERC20IMAGE} />
</a>
</div>
<div className="col-3 p-1" style={{marginTop:8}}>
{this.props.ERC20NAME}
{token.name}
</div>
<div className="col-5 p-1" style={{marginTop:8,whiteSpace:"nowrap"}}>
<Scaler config={{startZoomAt:400,origin:"50% 50%"}}>
Expand Down Expand Up @@ -1344,7 +1339,7 @@ export default class Exchange extends React.Component {
}else{

//BECAUSE THIS COULD BE ON A TOKEN, THE SEND FUNCTION IS SENDING TOKENS TO THE BRIDGE HAHAHAHA LETs FIX THAT
if(this.props.ERC20TOKEN){
if(token){
console.log("native sending ",this.state.amount," to ",toDaiBridgeAccount)
this.props.nativeSend(toDaiBridgeAccount, this.state.amount, 120000, (result) => {
console.log("RESUTL!!!!",result)
Expand Down Expand Up @@ -2145,7 +2140,7 @@ export default class Exchange extends React.Component {

let sendXdaiButton

if(this.props.ERC20TOKEN){
if(token){
sendXdaiButton = (
<button className="btn btn-large w-100" disabled={buttonsDisabled} style={this.props.buttonStyle.secondary} onClick={()=>{this.setState({sendXdai:true})}}>
<Scaler config={{startZoomAt:400,origin:"50% 50%"}}>
Expand Down
10 changes: 5 additions & 5 deletions src/components/MainCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'react';
import { Scaler } from "dapparatus";
import {CopyToClipboard} from "react-copy-to-clipboard";
import i18next from 'i18next';
import { token } from '../assets';



export default ({buttonStyle,ERC20TOKEN,address, balance, changeAlert, changeView, dollarDisplay, subBalanceDisplay}) => {


export default ({
buttonStyle, address, balance, changeAlert, changeView, dollarDisplay, subBalanceDisplay
}) => {
var w = window,
d = document,
e = d.documentElement,
Expand Down Expand Up @@ -66,7 +66,7 @@ export default ({buttonStyle,ERC20TOKEN,address, balance, changeAlert, changeVie
</div>
)

if(ERC20TOKEN){
if(token){
sendButtons = (
<div>
<div className="content ops row">
Expand Down
9 changes: 1 addition & 8 deletions src/components/Receipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@ import RecentTransactions from './RecentTransactions';
import { scroller } from 'react-scroll'
import i18n from '../i18n';
import axios from 'axios';
const QRCode = require('qrcode.react');


const BockieSize = 12

export default class Receive extends React.Component {

constructor(props) {
super(props);
let initialState = {
}
}
componentDidMount(){
console.log("RECEIPT LOADED",this.props)
if(this.props.receipt && this.props.receipt.daiposOrderId){
Expand Down Expand Up @@ -50,7 +43,7 @@ export default class Receive extends React.Component {
}
}
render() {
let {receipt,buttonStyle,ERC20TOKEN,address, balance, changeView, dollarDisplay,account} = this.props
const { receipt, dollarDisplay } = this.props

let message = ""

Expand Down
16 changes: 5 additions & 11 deletions src/components/Receive.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ import Blockies from 'react-blockies';
import RecentTransactions from './RecentTransactions';
import { scroller } from 'react-scroll'
import i18n from '../i18n';
const QRCode = require('qrcode.react');
import QRCode from 'qrcode.react';
import { token } from '../assets';

export default class Receive extends React.Component {

constructor(props) {
super(props);
let initialState = {
}
}
render() {
let {dollarDisplay,view,buttonStyle,ERC20TOKEN,address, balance, changeAlert, changeView, subBalanceDisplay,account} = this.props
const {dollarDisplay,view,buttonStyle,address, changeAlert, changeView } = this.props


let qrSize = Math.min(document.documentElement.clientWidth,512)-90
Expand Down Expand Up @@ -49,12 +44,11 @@ export default class Receive extends React.Component {
view={view}
max={5}
buttonStyle={buttonStyle}
ERC20TOKEN={ERC20TOKEN}
transactionsByAddress={ERC20TOKEN?this.props.fullTransactionsByAddress:this.props.transactionsByAddress}
transactionsByAddress={token ? this.props.fullTransactionsByAddress : this.props.transactionsByAddress}
changeView={changeView}
address={address}
block={this.props.block}
recentTxs={ERC20TOKEN?this.props.fullRecentTxs:this.props.recentTxs}
recentTxs={token ? this.props.fullRecentTxs : this.props.recentTxs}
/>
</div>
<div name="theVeryBottom" className="text-center bottom-text">
Expand Down
7 changes: 5 additions & 2 deletions src/components/RecentTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import React from 'react';
import { Blockie } from "dapparatus";
import Ruler from "./Ruler";
import { Scaler } from "dapparatus";
import { token } from '../assets';

export default ({dollarDisplay, view, max, buttonStyle, ERC20TOKEN, vendorName, address, recentTxs, block, changeView}) => {
export default ({
dollarDisplay, view, max, buttonStyle, vendorName, address, recentTxs, block, changeView
}) => {
let txns = []
let count=0
if(!max) max=9999
Expand Down Expand Up @@ -39,7 +42,7 @@ export default ({dollarDisplay, view, max, buttonStyle, ERC20TOKEN, vendorName,
}

let dollarView
if(ERC20TOKEN){
if(token){
if(recentTxs[r].token){
dollarView = (
<span>
Expand Down
2 changes: 0 additions & 2 deletions src/components/SendBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ export default class SendBadge extends React.Component {
}
send = async () => {
let { toAddress, amount } = this.state;
let {ERC20TOKEN} = this.props


if(this.state.canSend){

Expand Down
19 changes: 10 additions & 9 deletions src/components/SendToAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import cookie from 'react-cookies'
import {CopyToClipboard} from "react-copy-to-clipboard";
import Blockies from 'react-blockies';
import { scroller } from 'react-scroll'
import queryString from 'query-string';
import i18n from '../i18n';
const queryString = require('query-string');
import { token } from '../assets';

export default class SendToAddress extends React.Component {

Expand Down Expand Up @@ -159,29 +160,29 @@ export default class SendToAddress extends React.Component {

send = async () => {
let { toAddress, amount } = this.state;
let {ERC20TOKEN, dollarDisplay, convertToDollar} = this.props
let { dollarDisplay, convertToDollar } = this.props

amount = convertToDollar(amount)
console.log("CONVERTED TO DOLLAR AMOUNT",amount)

if(this.state.canSend){
if(ERC20TOKEN){
if(token){
console.log("this is a token")
}else{
console.log("this is not a token")
}
console.log("ERC20TOKEN",ERC20TOKEN,"this.props.balance",parseFloat(this.props.balance),"amount",parseFloat(amount))
console.log("ERC20TOKEN", token.name, "this.props.balance",parseFloat(this.props.balance),"amount",parseFloat(amount))

if(!ERC20TOKEN && parseFloat(this.props.balance) <= 0){
console.log("No funds!?!",ERC20TOKEN,parseFloat(this.props.balance))
if(!token && parseFloat(this.props.balance) <= 0){
console.log("No funds!?!", token.name, parseFloat(this.props.balance))
this.props.changeAlert({type: 'warning', message: "No Funds."})
}else if(!ERC20TOKEN && parseFloat(this.props.balance)-0.0001<=parseFloat(amount)){
}else if(!token && parseFloat(this.props.balance)-0.0001<=parseFloat(amount)){
let extraHint = ""
if(!ERC20TOKEN && parseFloat(amount)-parseFloat(this.props.balance)<=.01){
if(!token && parseFloat(amount)-parseFloat(this.props.balance)<=.01){
extraHint = "(gas costs)"
}
this.props.changeAlert({type: 'warning', message: 'Not enough funds: '+dollarDisplay(Math.floor((parseFloat(this.props.balance)-0.0001)*100)/100)+' '+extraHint})
}else if((ERC20TOKEN && (parseFloat(this.props.balance)<parseFloat(amount)))){
}else if((token && (parseFloat(this.props.balance)<parseFloat(amount)))){
console.log("SO THE BALANCE IS LESS!")
this.props.changeAlert({type: 'warning', message: 'Not enough tokens: $'+parseFloat(this.props.balance)})
}else{
Expand Down
Loading

0 comments on commit 8273d41

Please sign in to comment.