fix: offer mismatch in offer list (#262)

* fix: display all offers (even if you are an arbitrator)
* fix: disable offers where the user is an arbitrator
This commit is contained in:
Richard Ramos 2019-05-22 11:56:28 -04:00 committed by GitHub
parent 36b31f43bb
commit 0193a25bd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -12,18 +12,24 @@ import {addressCompare} from '../../utils/address';
const Offer = ({offer, offers, withDetail, prices, userAddress}) => {
let user;
let owner;
let arbitrator;
if (!offer) {
if (!offers) {
throw new Error('Component needs either offer or offers');
}
user = offers[0].user;
owner = offers[0].owner;
arbitrator = offers[0].arbitrator;
} else {
user = offer.user;
owner = offer.owner;
arbitrator = offer.arbitrator;
offers = [offer];
}
const isOwner = addressCompare(userAddress, owner);
const isArbitrator = addressCompare(userAddress, arbitrator);
return (<Row className="border bg-white rounded p-3 mr-0 ml-0 mb-2" tag={Link} to={`/profile/${owner}`}>
<Col className="p-0">
<Row className="mb-2">
@ -31,7 +37,8 @@ const Offer = ({offer, offers, withDetail, prices, userAddress}) => {
<Col xs={5}>
<p className={classnames('seller-name', 'm-0', 'font-weight-bold', {
'text-black': !isOwner,
'text-success': isOwner
'text-success': isOwner,
'text-warning': isArbitrator
})}>{user.username}</p>
<p className="text-dark m-0">{user.location}</p>
</Col>
@ -49,6 +56,7 @@ const Offer = ({offer, offers, withDetail, prices, userAddress}) => {
</p>
</Col>
</Row>}
{isArbitrator && <span className="text-warning text-small">You are an arbitrator for this offer</span>}
</Col>
</Row>);
};

View File

@ -86,7 +86,7 @@ class OffersList extends Component {
};
render() {
let filteredOffers = this.props.offers.filter(x => !addressCompare(x.arbitrator, this.props.address));
let filteredOffers = this.props.offers;
if (this.state.locationCoords) {
filteredOffers = filteredOffers.filter((offer) => this.calculateDistance(offer.user.coords) < 0.1);

View File

@ -48,7 +48,7 @@ class Profile extends Component {
<Col xs="12" className="mt-2">
<h3>Offers</h3>
<div>
{profile.offers.map((offer, index) => <Offer disabled={addressCompare(profile.address, address)}
{profile.offers.map((offer, index) => <Offer disabled={addressCompare(profile.address, address) || addressCompare(offer.arbitrator, address)}
key={index}
offer={offer}
prices={prices}