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: auction detail #627

Merged
merged 11 commits into from
Nov 7, 2018
10 changes: 10 additions & 0 deletions shared/parcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ export function isParcel(asset) {
)
}

export function getParcelSorter() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought: we could name it as parcelSortAlgorithm or just sortParcel

Copy link
Member

Choose a reason for hiding this comment

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

"sortParcel" would be the return value of this function, since that's the actual function that does the sorting. I think it's fine returning it as a lambda tho, as it is doing now.

return (parcel1, parcel2) => {
if (parcel1.x !== parcel2.x) {
return parcel1.x > parcel2.x ? -1 : 1
} else {
return parcel1.y > parcel2.y ? 1 : -1
}
}
}

export function toParcelObject(parcelArray, prevParcels = {}) {
const parcelObject = {}
for (const parcel of parcelArray) {
Expand Down
1 change: 1 addition & 0 deletions src/Translation/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"your_parcel": "Your parcel"
},
"auction_page": {
"bid": "Bid",
"description": "Select LAND to buy",
"maximum_parcels_message":
"If you try to buy more than {max} parcels in a single transaction it'll fail. You must submit this transaction and then buy more parcels in a subsequent transaction.",
Expand Down
1 change: 1 addition & 0 deletions src/Translation/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"your_parcel": "Tu parcela"
},
"auction_page": {
"bid": "Oferta",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe Ofertar is better

"description": "Seleccione LAND para comprar",
"maximum_parcels_message":
"Si intenta comprar más de {max} parcelas en una sola transacción, fallará. ",
Expand Down
1 change: 1 addition & 0 deletions src/Translation/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"your_parcel": "Votre parcelle"
},
"auction_page": {
"bid": "Offre",
"description": "Sélectionnez LAND à acheter",
"maximum_parcels_message":
"Si vous essayez d'acheter plus de {max} colis en une seule transaction, vous échouerez. ",
Expand Down
1 change: 1 addition & 0 deletions src/Translation/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"your_parcel": "あなたの区画"
},
"auction_page": {
"bid": "入札",
"description": "購入するLANDを選択",
"maximum_parcels_message":
"あなたが単一のトランザクションで{max}パーセル以上を購入しようとすると、それは失敗します。",
Expand Down
1 change: 1 addition & 0 deletions src/Translation/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"your_parcel": "당신의 토지"
},
"auction_page": {
"bid": "매기다",
"description": "구매할 LAND 선택",
"maximum_parcels_message":
"단일 트랜잭션에서 {max} 소포를 초과하여 구매하려고하면 실패합니다. ",
Expand Down
1 change: 1 addition & 0 deletions src/Translation/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"your_parcel": "您的地块"
},
"auction_page": {
"bid": "出价",
"description": "选择LAND购买",
"maximum_parcels_message":
"如果您尝试在单笔交易中购买超过{max}的包裹,那么它将失败。",
Expand Down
38 changes: 35 additions & 3 deletions webapp/src/components/AuctionPage/AuctionPage.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.AuctionPage .subtitle {
color: var(--gray);
margin-bottom: 5px;
}

.AuctionPage .parcel-preview {
height: 400px;
}
Expand All @@ -6,19 +11,46 @@
margin: 30px 0;
}

.AuctionPage .information-blocks {
display: flex;
justify-content: space-between;
}

.AuctionPage .information-block .ui.header {
margin-top: 0;
}

.AuctionPage .parcels-included-description {
width: 100%;
font-size: 18px;
margin: 15px 0 0;
color: var(--gray);
}

.AuctionPage .auction-details .selected-parcels.column {
display: flex;
flex-wrap: wrap;
}

.AuctionPage .parcels-included {
display: flex;
flex-wrap: wrap;
width: 100%;
margin-top: 40px;
}

.AuctionPage .ParcelAttributes {
margin-right: 16px;
margin-top: 20px;
flex-basis: 8%;
}

@media (max-width: 768px) {
.AuctionPage .information-blocks {
display: block;
text-align: center;
}
}

@media (max-width: 992px) {
.AuctionPage .information-block {
margin-top: 20px;
}
}
91 changes: 72 additions & 19 deletions webapp/src/components/AuctionPage/AuctionPage.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Message, Header, Grid, Container } from 'semantic-ui-react'
import { Message, Header, Grid, Container, Button } from 'semantic-ui-react'
import { utils } from 'decentraland-commons'

import { parcelType } from 'components/types'
import ParcelPreview from 'components/ParcelPreview'
import ParcelAttributes from 'components/ParcelAttributes'
import { t } from '@dapps/modules/translation/utils'
import { getParcelSorter } from 'shared/parcel'

import './AuctionPage.css'

// TODO: Real number here
const MAX_PARCELS_PER_TX = Infinity
const MAX_PARCELS_PER_TX = 20

export default class AuctionPage extends React.PureComponent {
static propTypes = {
Expand All @@ -20,6 +21,8 @@ export default class AuctionPage extends React.PureComponent {

constructor(props) {
super(props)

this.parcelPrice = 3000 // TODO: use the contract to get this value
this.state = {
selectedCoordsById: {}
}
Expand All @@ -29,7 +32,7 @@ export default class AuctionPage extends React.PureComponent {
const { selectedCoordsById } = this.state

// TODO: Check ownership with contract
if (asset.owner != null) return
if (asset.owner != null || asset.district_id != null) return

let newSelectedCoordsById = {}

Expand All @@ -54,11 +57,28 @@ export default class AuctionPage extends React.PureComponent {

handleSubmit = () => {}

render() {
getParcels() {
const { allParcels } = this.props
const { selectedCoordsById } = this.state

if (!allParcels) return []

const parcelIds = Object.keys(selectedCoordsById)
const parcels = []

for (const parcelId of parcelIds) {
const parcel = allParcels[parcelId]
if (parcel) {
parcels.push(parcel)
}
}

return parcels.sort(getParcelSorter())
}

render() {
const { selectedCoordsById } = this.state

const selected = Object.values(selectedCoordsById)

return (
Expand Down Expand Up @@ -95,24 +115,57 @@ export default class AuctionPage extends React.PureComponent {
) : null}

<Grid.Row>
<Grid.Column width={16}>
<Grid.Column mobile={16} computer={6}>
<Header size="large">{t('auction_page.title')}</Header>
</Grid.Column>
<Grid.Column width={16} className="selected-parcels">
<p className="parcels-included-description">
<p className="subtitle parcels-included-description">
{t('auction_page.description')}
</p>
{allParcels &&
parcelIds.map(parcelId => {
const parcel = allParcels[parcelId]
return parcel ? (
<ParcelAttributes
key={parcel.id}
parcel={parcel}
withLink={false}
/>
) : null
})}
</Grid.Column>
<Grid.Column mobile={16} computer={10}>
<div className="information-blocks">
<div className="information-block">
<p className="subtitle">GAS PRICE</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth to have this on translations?

<Header size="large">300wei</Header>
</div>
<div className="information-block">
<p className="subtitle">PARCEL PRICE</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe LAND PRICE and also I would add it to the translations

<Header size="large">{this.parcelPrice}</Header>
</div>
<div className="information-block">
<p className="subtitle">PARCELS</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Same about translations

<Header size="large">
{selected.length}/{MAX_PARCELS_PER_TX}
</Header>
</div>
<div className="information-block">
<p className="subtitle">TOTAL PRICE</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Same about translations

<Header size="large">
{this.parcelPrice * selected.length}
</Header>
</div>
<div className="information-block">
<Button
type="submit"
primary={true}
disabled={selected.length === 0}
>
{t('auction_page.bid')}
</Button>
</div>
</div>
</Grid.Column>

<Grid.Column width={16} className="selected-parcels">
<div className="parcels-included">
{this.getParcels().map(parcel => (
<ParcelAttributes
key={parcel.id}
parcel={parcel}
withLink={false}
withTags={false}
/>
))}
</div>
</Grid.Column>
</Grid.Row>
</Grid>
Expand Down