Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: make bids public #884

Merged
merged 3 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions shared/bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export function isActive(bid) {
export function shouldShowBid(bid, isOwner) {
return (isOwner && isOpen(bid)) || (!isOwner && isActive(bid))
}

export function hasBid(bids, bidder) {
return bids.some(bid => bid.bidder === bidder)
}
6 changes: 5 additions & 1 deletion webapp/src/components/Bid/Bid.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import { splitCoordinate } from 'shared/coordinates'
import { archiveBid, unarchiveBid } from 'modules/archivedBid/actions'
import { getEstates } from 'modules/estates/selectors'
import { getData as getArchivedBids } from 'modules/archivedBid/selectors'
import { getWallet } from 'modules/wallet/selectors'
import Bid from './Bid'

const mapState = (state, ownProps) => {
const wallet = getWallet(state)

const archivedBids = getArchivedBids(state)

return {
estates: getEstates(state),
isBidArchived: !!archivedBids[ownProps.bid.id]
isBidArchived: !!archivedBids[ownProps.bid.id],
address: wallet ? wallet.address : null
}
}

Expand Down
75 changes: 40 additions & 35 deletions webapp/src/components/Bid/Bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class Bid extends React.PureComponent {
bid: bidType.isRequired,
estates: PropTypes.objectOf(estateType),
className: PropTypes.string,
address: PropTypes.string,
onConfirm: PropTypes.func.isRequired,
onUpdate: PropTypes.func.isRequired,
onArchive: PropTypes.func.isRequired,
Expand Down Expand Up @@ -156,9 +157,11 @@ export default class Bid extends React.PureComponent {
onConfirm,
onUpdate,
showAssetDetail,
isBidArchived
isBidArchived,
address
} = this.props

const isBidderOrSeller = address === bid.seller || address === bid.bidder
const hasSameSellerAndBidder = bid.seller === bid.bidder
const fingerprintChanged = hasFingerprintChanged(bid)
const assetDetailLink = this.getDetailLink()
Expand Down Expand Up @@ -223,41 +226,43 @@ export default class Bid extends React.PureComponent {
<h3>{t('global.time_left')}</h3>
<p>{distanceInWordStrict(parseInt(bid.expires_at, 10))}</p>
</Grid.Column>
<Grid.Column
computer={showAssetDetail ? 16 : 7}
tablet={showAssetDetail ? 16 : 7}
mobile={16}
className={'actions'}
>
<Button
className={`${isOwner ? 'primary' : ''}`}
onClick={preventDefault(onConfirm)}
{isBidderOrSeller && (
<Grid.Column
computer={showAssetDetail ? 16 : 7}
tablet={showAssetDetail ? 16 : 7}
mobile={16}
className={'actions'}
>
{!isOwner || hasSameSellerAndBidder
? t('global.cancel')
: t('global.accept')}
</Button>
{!isOwner &&
!hasSameSellerAndBidder && (
<Button
className="primary"
onClick={preventDefault(onUpdate)}
>
{t('global.update')}
</Button>
)}
{isOwner ? (
isBidArchived ? (
<Button onClick={preventDefault(this.handleUnarchiveBid)}>
{t('global.unarchive')}
</Button>
) : (
<Button onClick={preventDefault(this.handleArchiveBid)}>
{t('global.archive')}
</Button>
)
) : null}
</Grid.Column>
<Button
className={`${isOwner ? 'primary' : ''}`}
onClick={preventDefault(onConfirm)}
>
{!isOwner || hasSameSellerAndBidder
? t('global.cancel')
: t('global.accept')}
</Button>
{!isOwner &&
!hasSameSellerAndBidder && (
<Button
className="primary"
onClick={preventDefault(onUpdate)}
>
{t('global.update')}
</Button>
)}
{isOwner ? (
isBidArchived ? (
<Button onClick={preventDefault(this.handleUnarchiveBid)}>
{t('global.unarchive')}
</Button>
) : (
<Button onClick={preventDefault(this.handleArchiveBid)}>
{t('global.archive')}
</Button>
)
) : null}
</Grid.Column>
)}
</Grid>
</Grid.Column>
</Grid.Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import { Button, Icon } from 'semantic-ui-react'
import { locations } from 'locations'
import { isOnSale } from 'shared/asset'
import { isListable } from 'shared/listing'
import { hasBid } from 'shared/bid'
import { isFeatureEnabled } from 'lib/featureUtils'
import { t } from '@dapps/modules/translation/utils'
import { publicationType, estateType, bidType } from 'components/types'
import {
publicationType,
estateType,
bidType,
walletType
} from 'components/types'

import './EstateActions.css'

Expand All @@ -17,20 +23,20 @@ export default class EstateActions extends React.PureComponent {
estate: estateType.isRequired,
isOwner: PropTypes.bool.isRequired,
publications: PropTypes.objectOf(publicationType).isRequired,
bids: PropTypes.arrayOf(bidType)
bids: PropTypes.arrayOf(bidType),
wallet: walletType
}

render() {
const { estate, publications, isOwner, bids } = this.props
const { estate, publications, isOwner, bids, wallet } = this.props
const { id } = estate
const isListed = isOnSale(estate, publications)

return (
<div className="EstateActions">
{!isOwner &&
isFeatureEnabled('BIDS') &&
isListable(estate) &&
bids.length === 0 && (
!hasBid(bids, wallet.address) && (
<Link to={locations.bidEstate(id)}>
<Button size="large">{t('asset_detail.bid.place')}</Button>
</Link>
Expand Down
29 changes: 18 additions & 11 deletions webapp/src/components/EstateDetailPage/EstateDetailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import { calculateMapProps } from 'shared/estate'
import { buildCoordinate } from 'shared/coordinates'
import { isDistrict } from 'shared/district'
import { shouldShowBid } from 'shared/bid'
import { estateType, publicationType, bidType } from 'components/types'
import {
estateType,
publicationType,
bidType,
walletType
} from 'components/types'
import EstateActions from './EstateActions'
import ParcelTags from 'components/ParcelTags'
import ParcelCoords from 'components/ParcelCoords'
Expand All @@ -37,7 +42,8 @@ export default class EstateDetailPage extends React.PureComponent {
onEditMetadata: PropTypes.func.isRequired,
onManageEstate: PropTypes.func.isRequired,
onParcelClick: PropTypes.func.isRequired,
bids: PropTypes.arrayOf(bidType)
bids: PropTypes.arrayOf(bidType),
wallet: walletType
}

getEstateParcels() {
Expand Down Expand Up @@ -75,7 +81,8 @@ export default class EstateDetailPage extends React.PureComponent {
onEditMetadata,
onManageEstate,
onParcelClick,
bids
bids,
wallet
} = this.props

if (estate.data.parcels.length === 0) {
Expand All @@ -84,6 +91,7 @@ export default class EstateDetailPage extends React.PureComponent {

const publication = getOpenPublication(estate, publications)
const { center } = calculateMapProps(estate.data.parcels)
const bidsToShow = bids.filter(bid => shouldShowBid(bid, isOwner))

return (
<div className="EstateDetailPage">
Expand Down Expand Up @@ -187,24 +195,23 @@ export default class EstateDetailPage extends React.PureComponent {
}
>
<EstateActions
wallet={wallet}
isOwner={isOwner}
publications={publications}
estate={estate}
bids={bids}
bids={bidsToShow}
/>
</Grid.Column>
</Grid.Row>

{bids &&
bids.length > 0 && (
{bidsToShow &&
bidsToShow.length > 0 && (
<Grid.Row>
<Grid.Column>
<h3>{t('asset_detail.bid.title')}</h3>
{bids
.filter(bid => shouldShowBid(bid, isOwner))
.map(bid => (
<Bid key={bid.id} bid={bid} isOwner={isOwner} />
))}
{bidsToShow.map(bid => (
<Bid key={bid.id} bid={bid} isOwner={isOwner} />
))}
</Grid.Column>
</Grid.Row>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import {
parcelType,
publicationType,
mortgageType,
bidType
bidType,
walletType
} from 'components/types'
import { isLegacyPublication } from 'modules/publication/utils'
import { getOpenPublication } from 'shared/asset'
import { hasParcelsConnected } from 'shared/parcel'
import { isParcelListable } from 'shared/listing'
import { hasBid } from 'shared/bid'

import './ParcelActions.css'

Expand All @@ -26,7 +28,8 @@ export default class ParcelActions extends React.PureComponent {
mortgage: mortgageType,
bids: PropTypes.arrayOf(bidType),
publications: PropTypes.objectOf(publicationType).isRequired,
isLoading: PropTypes.bool.isRequired
isLoading: PropTypes.bool.isRequired,
wallet: walletType
}

canCreateEstate = isOnSale => {
Expand Down Expand Up @@ -99,7 +102,7 @@ export default class ParcelActions extends React.PureComponent {
</Link>
)}
{isFeatureEnabled('BIDS') &&
!bids.length &&
!hasBid(bids, wallet.address) &&
isParcelListable(parcel) && (
<Link to={locations.bidParcel(x, y)}>
<Button size="large">{t('asset_detail.bid.place')}</Button>
Expand Down
14 changes: 7 additions & 7 deletions webapp/src/components/ParcelDetailPage/ParcelDetailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export default class ParcelDetailPage extends React.PureComponent {

const description = this.getDescription()
const publication = getOpenPublication(parcel, publications)
const bidsToShow = bids.filter(bid => shouldShowBid(bid, isOwner))

return (
<div className="ParcelDetailPage">
<Grid columns={2} stackable>
Expand Down Expand Up @@ -130,17 +132,15 @@ export default class ParcelDetailPage extends React.PureComponent {
</Grid.Row>
</Grid>

{bids &&
bids.length > 0 && (
{bidsToShow &&
bidsToShow.length > 0 && (
<Grid stackable className="parcel-detail-row">
<Grid.Row>
<Grid.Column>
<h3>{t('asset_detail.bid.title')}</h3>
{bids
.filter(bid => shouldShowBid(bid, isOwner))
.map(bid => (
<Bid key={bid.id} bid={bid} isOwner={isOwner} />
))}
{bidsToShow.map(bid => (
<Bid key={bid.id} bid={bid} isOwner={isOwner} />
))}
</Grid.Column>
</Grid.Row>
</Grid>
Expand Down
20 changes: 10 additions & 10 deletions webapp/src/components/ProfilePage/ProfilePage.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { fetchAddress } from 'modules/address/actions'
import { getLoading } from 'modules/address/selectors'
import { getWallet, isConnecting } from 'modules/wallet/selectors'
import { getAddresses } from 'modules/address/selectors'
import { getData as getArchivedBids } from 'modules/archivedBid/selectors'
import {
getWalletArchivedBids,
getWalletUnarchivedBids
} from 'modules/archivedBid/selectors'
import { orderBids } from 'modules/bid/utils'
import ProfilePage from './ProfilePage'

Expand All @@ -28,13 +31,18 @@ const mapState = (state, { location, match }) => {
let mortgagedParcels = []
let publishedEstates = []
let bids = []
let allBidsCount = 0
if (address in addresses) {
parcels = addresses[address].parcels
contributions = addresses[address].contributions
publishedParcels = addresses[address].publishedParcels
publishedEstates = addresses[address].publishedEstates
estates = addresses[address].estates
bids = addresses[address].bids
allBidsCount = addresses[address].bids.length
bids =
tab === PROFILE_PAGE_TABS.archivebids
? getWalletArchivedBids(state, addresses[address].bids)
: getWalletUnarchivedBids(state, addresses[address].bids)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

mortgagedParcels = addresses[address].mortgagedParcels
}

Expand All @@ -43,14 +51,6 @@ const mapState = (state, { location, match }) => {
}

const publishedAssets = publishedParcels.concat(publishedEstates)
const archivedBids = getArchivedBids(state)
const allBidsCount = bids.length

if (tab === PROFILE_PAGE_TABS.archivebids) {
bids = bids.filter(bid => archivedBids[bid.id])
} else {
bids = bids.filter(bid => !archivedBids[bid.id])
}

let pagination
switch (tab) {
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/modules/archivedBid/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ export const getWalletUnarchivedBidsByAsset = (state, asset, asseyType) => {
const archivedBids = getData(state)
return bids.filter(bid => !archivedBids[bid.id])
}

export const getWalletArchivedBids = (state, bids) => {
const archivedBids = getData(state)
return bids.filter(bid => archivedBids[bid.id])
}

export const getWalletUnarchivedBids = (state, bids) => {
const archivedBids = getData(state)
return bids.filter(bid => !archivedBids[bid.id])
}
Loading