Skip to content

Commit

Permalink
feat: add distict_id to estates and filter bids for distrincts (#849)
Browse files Browse the repository at this point in the history
- Add `distrinct_id` to `Estate` column 
- Set Estate `district_ids` once monitor finished
- Do not index bids for districts
- Do not show bid button on a district details
- Hide `owner of` from Estate details if it is a district

## Note:

`npm run migrate up`
  • Loading branch information
nachomazzara authored and nicosantangelo committed Feb 21, 2019
1 parent e36f299 commit 166e402
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 51 deletions.
9 changes: 9 additions & 0 deletions migrations/1550588222674_estates-add-district-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Estate } from '../src/Asset'

exports.up = pgm => {
const tableName = Estate.tableName

pgm.addColumns(tableName, {
district_id: 'TEXT'
})
}
12 changes: 11 additions & 1 deletion monitor/consolidateProccesedEvents.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { Log } from 'decentraland-commons'

import { Estate } from '../src/Asset'
import { Publication } from '../src/Listing'
import { Tile } from '../src/Tile'
import { asyncBatch } from '../src/lib'

const log = new Log('consolidateProccesedEvents')

export async function consolidateProccesedEvents() {
await Promise.all([cancelInactivePublications(), updateEstateDistrinctIds()])
}

async function cancelInactivePublications() {
log.info('Cancelling inactive publications')
const inactivePublications = await Publication.findInactive()
await Publication.cancelInactive()

log.info('Updating tiles')
await asyncBatch({
return asyncBatch({
elements: inactivePublications,
callback: async publications => {
const upserts = publications.map(publication =>
Expand All @@ -23,3 +28,8 @@ export async function consolidateProccesedEvents() {
batchSize: 20
})
}

async function updateEstateDistrinctIds() {
log.info('Updating estate district ids')
return Estate.updateDistrictIds()
}
14 changes: 10 additions & 4 deletions monitor/reducers/bidReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { isDuplicatedConstraintError } from '../../src/database'
import { Asset } from '../../src/Asset'
import { Bid } from '../../src/Listing'
import { LISTING_STATUS } from '../../shared/listing'
import { isDistrict } from '../../shared/district'

const log = new Log('bidReducer')

Expand Down Expand Up @@ -56,16 +57,21 @@ async function reduceBid(event) {
return log.info(`[${name}] Bid ${_id} already exist`)
}

log.info(
`[${name}] Creating bid ${_id} for token with address: ${_tokenAddress} and id: ${_tokenId}`
)

await Bid.deleteBid(_tokenAddress, _tokenId, _bidder.toLowerCase(), [
LISTING_STATUS.open,
LISTING_STATUS.fingerprintChanged
])

const asset = await Asset.getNew(assetType).findById(assetId)
if (isDistrict(asset)) {
return log.info(
`[${name}] Token with address: ${_tokenAddress} and id: ${_tokenId} is part of a district and won't be indexed`
)
}

log.info(
`[${name}] Creating bid ${_id} for token with address: ${_tokenAddress} and id: ${_tokenId}`
)

try {
await Bid.insert({
Expand Down
8 changes: 4 additions & 4 deletions shared/district.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export function isPlaza(district_id) {
return district_id === PLAZA_ID
}

export function isDistrict(parcel) {
return !!parcel.district_id
export function isDistrict(asset) {
return !!asset.district_id
}

export function getDistrict(parcel, districts = {}) {
return parcel && districts[parcel.district_id]
export function getDistrict(asset, districts = {}) {
return asset && districts[asset.district_id]
}
11 changes: 11 additions & 0 deletions shared/listing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isDistrict } from './district'

export const LISTING_STATUS = Object.freeze({
open: 'open',
sold: 'sold',
Expand Down Expand Up @@ -77,3 +79,12 @@ export function sortListings(listings, key) {
(a, b) => (parseInt(a[key], 10) > parseInt(b[key], 10) ? -1 : 1)
)
}

/**
* Check if asset is listable or not
* @param asset
* @return boolean - whether is listable or not
*/
export function isListable(asset) {
return !isDistrict(asset) && asset.owner
}
10 changes: 0 additions & 10 deletions shared/parcel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { utils } from 'decentraland-commons'
import { Bounds } from './map'
import { buildCoordinate } from './coordinates'
import { isDistrict } from './district'

export const FIRST_AUCTION_DATE = new Date('2018-01-31T00:00:00Z')

Expand Down Expand Up @@ -97,12 +96,3 @@ export function getParcelsNotIncluded(newParcels, allParcels) {
export function hasTags(parcel) {
return parcel && !utils.isEmptyObject(parcel.tags)
}

/**
* Check if parcel is listable or not
* @param parcel
* @return boolean - whether is listable or not
*/
export function isListable(parcel) {
return !isDistrict(parcel) && parcel.owner
}
12 changes: 12 additions & 0 deletions src/Asset/Estate/Estate.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class Estate extends Model {
'id',
'tx_hash',
'token_id',
'district_id',
'owner',
'update_operator',
'data',
Expand Down Expand Up @@ -63,4 +64,15 @@ export class Estate extends Model {
WHERE ${BlockchainEventQueries.byArgs('_estateId', estateId)}
OR (${BlockchainEventQueries.byArgs('_tokenId', estateId)} AND address = ${address})`)
}

static async updateDistrictIds() {
return this.db.query(
SQL`UPDATE ${SQL.raw(this.tableName)}
SET district_id = P.district_id
FROM parcels as P
WHERE ${SQL.raw(this.tableName)}.id = P.estate_id AND
P.estate_id IS NOT NULL AND
P.district_id IS NOT NULL;`
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const mapState = (state, ownProps) => {
allParcels: getParcels(state),
pristineEstate: estate,
isTxIdle: isEstateTransactionIdle(state),
bids: getWalletBidsByAsset(state, estate, ASSET_TYPES.estate)
bids: estate ? getWalletBidsByAsset(state, estate, ASSET_TYPES.estate) : []
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { Button, Icon } from 'semantic-ui-react'

import { locations } from 'locations'
import { isOnSale } from 'shared/asset'
import { isListable } from 'shared/listing'
import { isFeatureEnabled } from 'lib/featureUtils'
import { t } from '@dapps/modules/translation/utils'
import { publicationType, estateType, bidType } from 'components/types'

import './EstateActions.css'

export default class EstateActions extends React.PureComponent {
Expand Down Expand Up @@ -60,6 +62,7 @@ export default class EstateActions extends React.PureComponent {
</Link>
)}
{isFeatureEnabled('BIDS') &&
isListable(estate) &&
bids.length === 0 && (
<Link to={locations.bidEstate(id)}>
<Button primary size="large">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { getWalletBidsByAsset } from 'modules/bid/selectors'
import EstateDetailPage from './EstateDetailPage'

const mapState = (state, ownProps) => {
const estate = ownProps.asset
return {
estate: ownProps.asset,
publications: getPublications(state),
tiles: getTiles(state),
bids: getWalletBidsByAsset(state, ownProps.asset, ASSET_TYPES.estate)
bids: getWalletBidsByAsset(state, estate, ASSET_TYPES.estate),
estate
}
}

Expand Down
61 changes: 34 additions & 27 deletions webapp/src/components/EstateDetailPage/EstateDetailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getOpenPublication, ASSET_TYPES } from 'shared/asset'
import { hasTags } from 'shared/parcel'
import { calculateMapProps } from 'shared/estate'
import { buildCoordinate } from 'shared/coordinates'
import { isDistrict } from 'shared/district'
import { estateType, publicationType, bidType } from 'components/types'
import EstateActions from './EstateActions'
import ParcelTags from 'components/ParcelTags'
Expand Down Expand Up @@ -112,33 +113,39 @@ export default class EstateDetailPage extends React.PureComponent {
)}
</Header>
</Grid.Column>
<Grid.Column
computer={WITH_ACTION_BUTTONS_WIDTH}
mobile={WITHOUT_ACTION_BUTTONS_WIDTH}
className="estate-owner-container"
>
{isOwner ? (
<div>
<Button size="tiny" className="link" onClick={onEditMetadata}>
<Icon name="pencil" />
{t('global.edit')}
</Button>
<Button
size="tiny"
className="link manage-button"
onClick={onManageEstate}
>
<Icon name="add user" />
{t('asset_detail.actions.permissions')}
</Button>
</div>
) : (
<span className="owned-by">
<span>{t('global.owned_by')}</span>
<AddressBlock address={estate.owner} scale={4} />
</span>
)}
</Grid.Column>
{!isDistrict(estate) && (
<Grid.Column
computer={WITH_ACTION_BUTTONS_WIDTH}
mobile={WITHOUT_ACTION_BUTTONS_WIDTH}
className="estate-owner-container"
>
{isOwner ? (
<div>
<Button
size="tiny"
className="link"
onClick={onEditMetadata}
>
<Icon name="pencil" />
{t('global.edit')}
</Button>
<Button
size="tiny"
className="link manage-button"
onClick={onManageEstate}
>
<Icon name="add user" />
{t('asset_detail.actions.permissions')}
</Button>
</div>
) : (
<span className="owned-by">
<span>{t('global.owned_by')}</span>
<AddressBlock address={estate.owner} scale={4} />
</span>
)}
</Grid.Column>
)}
</Grid.Row>
<Grid.Row>
{publication && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import { t } from '@dapps/modules/translation/utils'

import { locations } from 'locations'
import { isFeatureEnabled } from 'lib/featureUtils'
import { getOpenPublication } from 'shared/asset'
import { hasParcelsConnected } from 'shared/parcel'
import { isListable } from 'shared/listing'
import {
parcelType,
publicationType,
mortgageType,
bidType
} from 'components/types'
import { isLegacyPublication } from 'modules/publication/utils'
import { getOpenPublication } from 'shared/asset'
import { hasParcelsConnected, isListable } from 'shared/parcel'

import './ParcelActions.css'

Expand Down

0 comments on commit 166e402

Please sign in to comment.