Skip to content

Commit

Permalink
Use new state variables for amount values
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxStalker committed Jul 14, 2019
1 parent 3aca711 commit 5a29c05
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/components/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,11 @@ export default class Exchange extends React.Component {
}

async sendEth(){
const {
const {
ethSendToAddress,
mainnetMetaAccount,
mainnetweb3,
daiAddress
daiAddress
} = this.state;
const {
ethprice,
Expand Down Expand Up @@ -724,14 +724,14 @@ export default class Exchange extends React.Component {
let {daiToXdaiMode,ethToDaiMode } = this.state

let ethCancelButton = <BorderButton className="btn-cancel" onClick={()=>{
this.setState({amount:"",ethToDaiMode:false})
this.setState({ethToDaiAmount:"",ethToDaiMode:false})
}}>
<i className="fas fa-times"/> {i18n.t('cancel')}
</BorderButton>

let daiCancelButton =
<BorderButton className="btn-cancel" onClick={()=>{
this.setState({amount:"",daiToXdaiMode:false})
this.setState({daiToXdaiAmount:"",daiToXdaiMode:false})
}}>
<i className="fas fa-times"/> {i18n.t('cancel')}
</BorderButton>
Expand Down Expand Up @@ -795,23 +795,23 @@ export default class Exchange extends React.Component {
type="number"
step="0.1"
placeholder={this.props.currencyDisplay(0)}
value={this.state.amount}
onChange={event => this.updateState('amount', event.target.value)} />
value={this.state.daiToXdaiAmount}
onChange={event => this.updateState('daiToXdaiAmount', event.target.value)} />
</div>
</div>
{daiCancelButton}
<PrimaryButton
className={"btn-send"}
disabled={buttonsDisabled}
onClick={()=>{
let { amount } = this.state;
let { daiToXdaiAmount } = this.state;
const { convertCurrency } = this.props;
console.log("AMOUNT:", amount,"DAI BALANCE:",this.props.daiBalance)
console.log("AMOUNT:", daiToXdaiAmount,"DAI BALANCE:",this.props.daiBalance)

this.setState({
daiToXdaiMode:"depositing",
xdaiBalanceAtStart:this.props.xdaiBalance,
xdaiBalanceShouldBe:parseFloat(this.props.xdaiBalance)+parseFloat(this.state.amount),
xdaiBalanceShouldBe:parseFloat(this.props.xdaiBalance)+parseFloat(this.state.daiToXdaiAmount),
loaderBarColor:"#3efff8",
loaderBarStatusText: i18n.t('exchange.calculate_gas_price'),
loaderBarPercent:0,
Expand All @@ -822,12 +822,12 @@ export default class Exchange extends React.Component {
})

const displayCurrency = localStorage.getItem("currency");
amount = convertCurrency(amount, `USD/${displayCurrency}`);
let amount = convertCurrency(daiToXdaiAmount, `USD/${displayCurrency}`);
// TODO: depositDai doesn't use the destination parameter anymore
// Remove it.
this.depositDai(null, amount, "Sending funds to bridge...", () => {
this.setState({
amount:"",
daiToXdaiAmount:"",
loaderBarColor:"#4ab3f5",
loaderBarStatusText:"Waiting for bridge...",
loaderBarClick:()=>{
Expand Down Expand Up @@ -866,18 +866,18 @@ export default class Exchange extends React.Component {
type="number"
step="0.1"
placeholder={this.props.currencyDisplay(0)}
value={this.state.amount}
onChange={event => this.updateState('amount', event.target.value)} />
value={this.state.daiToXdaiAmount}
onChange={event => this.updateState('daiToXdaiAmount', event.target.value)} />
</div>
</div>
{daiCancelButton}
<PrimaryButton className={"btn-send"} disabled={buttonsDisabled} onClick={async ()=>{
const { convertCurrency } = this.props;
let { amount } = this.state;
let { daiToXdaiAmount } = this.state;

// First we convert from the current display value and
const displayCurrency = localStorage.getItem("currency");
amount = convertCurrency(amount, `USD/${displayCurrency}`);
let amount = convertCurrency(daiToXdaiAmount, `USD/${displayCurrency}`);

// Then we convert that value to wei
amount = bi(amount * 10 ** 18);
Expand Down Expand Up @@ -932,7 +932,7 @@ export default class Exchange extends React.Component {
// noop
}
})
this.setState({ amount: "", daiToXdaiMode: false });
this.setState({ daiToXdaiAmount: "", daiToXdaiMode: false });
this.props.changeAlert({
type: "success",
message: i18n.t("exchange.fast_exit_patience")
Expand Down Expand Up @@ -965,7 +965,7 @@ export default class Exchange extends React.Component {
message: i18n.t("exchange.fast_exit_patience")
});
this.setState({
amount: "",
daiToXdaiAmount: "",
daiToXdaiMode: false
});
}).catch(err => {
Expand Down Expand Up @@ -1046,15 +1046,15 @@ export default class Exchange extends React.Component {
type="number"
step="0.1"
placeholder={this.props.currencyDisplay(0)}
value={this.state.amount}
onChange={event => this.updateState('amount', event.target.value)} />
value={this.state.ethToDaiAmount}
onChange={event => this.updateState('ethToDaiAmount', event.target.value)} />
</div>
</div>
{ethCancelButton}
<PrimaryButton disabled={buttonsDisabled} onClick={async ()=>{
console.log("Using uniswap exchange to move ETH to DAI")
const { convertCurrency } = this.props;
let { amount } = this.state;
let { ethToDaiAmount } = this.state;

let webToUse = this.props.web3
if(this.state.mainnetMetaAccount){
Expand All @@ -1063,7 +1063,7 @@ export default class Exchange extends React.Component {

// TODO: Error: Returned values aren't valid, did it run Out of Gas?
const displayCurrency = localStorage.getItem("currency");
amount = convertCurrency(amount, `USD/${displayCurrency}`);
let amount = convertCurrency(ethToDaiAmount, `USD/${displayCurrency}`);

console.log("AMOUNT:", amount, "DAI BALANCE:", this.props.daiBalance)

Expand Down Expand Up @@ -1115,7 +1115,7 @@ export default class Exchange extends React.Component {
"Sending funds to 🦄 exchange...",
(receipt)=>{
this.setState({
amount:"",
ethToDaiAmount:"",
loaderBarColor:"#4ab3f5",
loaderBarStatusText:"Waiting for 🦄 exchange...",
loaderBarClick:()=>{
Expand Down Expand Up @@ -1154,23 +1154,23 @@ export default class Exchange extends React.Component {
type="number"
step="0.1"
placeholder={this.props.currencyDisplay(0)}
value={this.state.amount}
onChange={event => this.updateState('amount', event.target.value)} />
value={this.state.ethToDaiAmount}
onChange={event => this.updateState('ethToDaiAmount', event.target.value)} />
</div>
</div>
{ethCancelButton}
<PrimaryButton className="btn-send" disabled={buttonsDisabled} onClick={async ()=>{
console.log("Using uniswap exchange to move DAI to ETH")
const { convertCurrency } = this.props;
let { amount } = this.state;
let { ethToDaiAmount } = this.state;

let webToUse = this.props.web3
if(this.state.mainnetMetaAccount){
webToUse = this.state.mainnetweb3
}

const displayCurrency = localStorage.getItem("currency");
amount = convertCurrency(amount, `USD/${displayCurrency}`);
let amount = convertCurrency(ethToDaiAmount, `USD/${displayCurrency}`);

console.log("AMOUNT:", amount, "ETH BALANCE:", this.props.ethBalance)

Expand Down Expand Up @@ -1277,7 +1277,7 @@ export default class Exchange extends React.Component {
if(receipt&&receipt.transactionHash&&!metaReceiptTracker[receipt.transactionHash]){
metaReceiptTracker[receipt.transactionHash] = true
this.setState({
amount:"",
ethToDaiAmount:"",
})
}
}).on('error', (err)=>{
Expand Down Expand Up @@ -1320,7 +1320,7 @@ export default class Exchange extends React.Component {
if(receipt&&receipt.transactionHash&&!metaReceiptTracker[receipt.transactionHash]){
metaReceiptTracker[receipt.transactionHash] = true
this.setState({
amount:"",
ethToDaiAmount:"",
loaderBarColor:"#4ab3f5",
})
}
Expand All @@ -1342,7 +1342,7 @@ export default class Exchange extends React.Component {

//send funds using metamask (or other injected web3 ... should be checked and on mainnet)
this.setState({
amount:"",
ethToDaiAmount:"",
loaderBarColor:"#42ceb2",
loaderBarStatusText:"Approving 🦄 exchange...",
loaderBarClick:()=>{
Expand All @@ -1358,7 +1358,7 @@ export default class Exchange extends React.Component {
if(receipt){
console.log("APPROVE COMPLETE?!?",receipt)
this.setState({
amount:"",
ethToDaiAmount:"",
ethBalanceAtStart:this.props.ethBalance,
ethBalanceShouldBe:eventualEthBalance,
loaderBarColor:"#4ab3f5",
Expand All @@ -1381,7 +1381,7 @@ export default class Exchange extends React.Component {
})
}else{
this.setState({
amount:"",
ethToDaiAmount:"",
ethBalanceAtStart:this.props.ethBalance,
ethBalanceShouldBe:eventualEthBalance,
loaderBarColor:"#4ab3f5",
Expand Down Expand Up @@ -1614,7 +1614,7 @@ export default class Exchange extends React.Component {
</button>
)
}


let sendXdaiButton = (
<OutlineButton
Expand Down Expand Up @@ -1762,7 +1762,7 @@ export default class Exchange extends React.Component {
</div>

{sendEthRow}

<Ruler />

<div className="content ops row" style={{paddingBottom:20}}>
Expand Down

0 comments on commit 5a29c05

Please sign in to comment.