Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Hidelist hotfix (#438)
Browse files Browse the repository at this point in the history
* Reveal listing index in html attibute. Better loading of hidelist.

* Undoing pull/222 in light of kettle bell attack

#222 was a good attempt, but now that we have pages full of kettle bell listings, this hidelist approach results in pages full of empty or single listings.

Per:
>The only awkwardness of this implementation is that on a page with flagged listings, the grid won't be completely filled up. For example:

So until we convert fully to address-based ids on listings, we stick with the old hidelist technicque of using Listing Indexes. (aka listingId)

* Temporary fix to allow admins to see listing index for an address

* Clarify comment and clean up
  • Loading branch information
tyleryasaka authored and micahalcorn committed Aug 27, 2018
1 parent 475a9ed commit b9c69cb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
9 changes: 3 additions & 6 deletions src/actions/Listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export function getListingIds() {

let hideList = []
const { web3, listingsRegistryContract } = origin.contractService
const inProductionEnv =
window.location.hostname === 'demo.originprotocol.com'

try {
let networkId = await web3.eth.net.getId()
Expand All @@ -33,9 +31,9 @@ export function getListingIds() {
return
}

if (inProductionEnv && networkId < 10) {
if (networkId < 10) { // Networks > 9 are local development
let response = await fetch(
`https://raw.githubusercontent.com/OriginProtocol/demo-dapp/hide_list/hidelist_${networkId}.json`
`https://raw.githubusercontent.com/OriginProtocol/origin-dapp/hide_list/hidelist_${networkId}.json`
)
if (response.status === 200) {
hideList = await response.json()
Expand All @@ -47,8 +45,7 @@ export function getListingIds() {

dispatch({
type: ListingConstants.FETCH_IDS_SUCCESS,
ids: showIds.reverse(),
hideList
ids: showIds.reverse()
})
} catch (error) {
dispatch(showAlert(error.message))
Expand Down
18 changes: 8 additions & 10 deletions src/components/listing-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,30 @@ class ListingCard extends Component {
constructor(props) {
super(props)
this.state = {
loading: true,
shouldRender: true
loading: true
}
}

async componentDidMount() {
try {
const listing = await origin.listings.getByIndex(this.props.listingId)

const translatedListing = translateListingCategory(listing)
if (!this.props.hideList.includes(translatedListing.address)) {
const obj = Object.assign({}, translatedListing, { loading: false })

this.setState(obj)
} else {
this.setState({ shouldRender: false })
}
this.setState({ ...translatedListing, loading: false })
} catch (error) {
console.error(`Error fetching contract or IPFS info for listingId: ${this.props.listingId}`)
}
}

render() {
const { address, category, loading, name, pictures, price, unitsAvailable, shouldRender } = this.state
const { address, category, loading, name, pictures, price, unitsAvailable } = this.state
const photo = pictures && pictures.length && (new URL(pictures[0])).protocol === "data:" && pictures[0]

if (!shouldRender) return false
// Temporary fix to allow admins to see listing index for an address
if (address && this.props.listingId) {
console.log(`listing index for address ${address}:`, this.props.listingId)
}

return (
<div className={`col-12 col-md-6 col-lg-4 listing-card${loading ? ' loading' : ''}`}>
Expand Down
5 changes: 2 additions & 3 deletions src/components/listings-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ListingsGrid extends Component {

render() {
const { listingsPerPage } = this.state
const { contractFound, listingIds, hideList } = this.props
const { contractFound, listingIds } = this.props
const pinnedListingIds = [0, 1, 2, 3, 4]
const activePage = this.props.match.params.activePage || 1
const arrangedListingIds = [...pinnedListingIds, ...listingIds.filter(id => !pinnedListingIds.includes(id))]
Expand Down Expand Up @@ -62,7 +62,7 @@ class ListingsGrid extends Component {
}
<div className="row">
{showListingsIds.map(listingId => (
<ListingCard listingId={listingId} key={listingId} hideList={hideList} />
<ListingCard listingId={listingId} key={listingId} />
))}
</div>
<Pagination
Expand All @@ -84,7 +84,6 @@ class ListingsGrid extends Component {

const mapStateToProps = state => ({
listingIds: state.listings.ids,
hideList: state.listings.hideList,
contractFound: state.listings.contractFound
})

Expand Down
3 changes: 1 addition & 2 deletions src/reducers/Listings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ListingConstants } from 'actions/Listing'

const initialState = {
ids: [],
hideList: [],
contractFound: true
}

Expand All @@ -13,7 +12,7 @@ export default function Listings(state = initialState, action = {}) {
return { ...state, ids: [], contractFound: action.contractFound }

case ListingConstants.FETCH_IDS_SUCCESS:
return { ...state, ids: action.ids, hideList: action.hideList }
return { ...state, ids: action.ids }

default:
return state
Expand Down

0 comments on commit b9c69cb

Please sign in to comment.