Skip to content

Commit

Permalink
Allow bids of 0 value and fix interpretation of bids with 0 value (ky…
Browse files Browse the repository at this point in the history
…okan#170)

* Allow bids of 0 and improve input checking for bid and disguise

* Parse bids with value of 0 as defined in history and bids list
  • Loading branch information
pinheadmz committed Sep 28, 2020
1 parent 76b2696 commit 3f30d21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions app/pages/Auction/BidActionPanel/BidNow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {consensus} from 'hsd/lib/protocol';
import {
AuctionPanel,
AuctionPanelFooter,
Expand Down Expand Up @@ -105,6 +106,15 @@ class BidNow extends Component {
}
}

processValue = (val, field) => {
const value = val.match(/[0-9]*\.?[0-9]{0,6}/g)[0];
if (Number.isNaN(parseFloat(value)))
return;
if (value * consensus.COIN > consensus.MAX_MONEY)
return;
this.setState({[field]: value});
}

render() {
const {domain} = this.props;

Expand Down Expand Up @@ -162,6 +172,7 @@ class BidNow extends Component {
renderBiddingView() {
const {
bidAmount,
disguiseAmount
} = this.state;

const {spendableBalance} = this.props;
Expand All @@ -174,9 +185,8 @@ class BidNow extends Component {
<div className="domains__bid-now__form__row__label">Bid Amount:</div>
<div className="domains__bid-now__form__row__input">
<input
type="number"
placeholder="0.00"
onChange={e => this.setState({bidAmount: e.target.value})}
onChange={e => this.processValue(e.target.value, 'bidAmount')}
value={bidAmount}
/>
</div>
Expand All @@ -186,7 +196,8 @@ class BidNow extends Component {
<button
className="domains__bid-now__action__cta"
onClick={() => this.setState({isReviewing: true})}
disabled={!(bidAmount > 0)}
// bid amount of zero is allowed as long as a disguise is used
disabled={bidAmount > 0 ? false : (disguiseAmount > 0 ? false : true)}
>
Review Bid
</button>
Expand Down Expand Up @@ -225,9 +236,8 @@ class BidNow extends Component {
</div>
<div className="domains__bid-now__form__row__input">
<input
type="number"
placeholder="Optional"
onChange={e => this.setState({disguiseAmount: e.target.value})}
onChange={e => this.processValue(e.target.value, 'disguiseAmount')}
value={disguiseAmount}
/>
</div>
Expand Down Expand Up @@ -408,7 +418,7 @@ function getTotalBids(domain) {
for (const {bid} of domain.bids) {
if (bid.own) {
// This is our bid, but we don't know its value
if (!bid.value)
if (bid.value == null)
return -1;

total += bid.value;
Expand Down
4 changes: 2 additions & 2 deletions app/pages/Auction/BidHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export default class BidHistory extends Component {
const bid = map[fromAddress];
const {month, day, year} = bid.date;
let bidValue = 'Hidden Until Reveal';
if (!bid.bid && bid.own) {
if (bid.bid == null && bid.own) {
bidValue = <RepairBid
bid={bid}
/>;
}
if (bid.bid)
if (bid.bid != null)
bidValue = displayBalance(bid.bid, true);
return (
<tr key={fromAddress}>
Expand Down

0 comments on commit 3f30d21

Please sign in to comment.