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

Commit b9c69cb

Browse files
tyleryasakamicahalcorn
authored andcommitted
Hidelist hotfix (#438)
* 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
1 parent 475a9ed commit b9c69cb

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

src/actions/Listing.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export function getListingIds() {
1919

2020
let hideList = []
2121
const { web3, listingsRegistryContract } = origin.contractService
22-
const inProductionEnv =
23-
window.location.hostname === 'demo.originprotocol.com'
2422

2523
try {
2624
let networkId = await web3.eth.net.getId()
@@ -33,9 +31,9 @@ export function getListingIds() {
3331
return
3432
}
3533

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

4846
dispatch({
4947
type: ListingConstants.FETCH_IDS_SUCCESS,
50-
ids: showIds.reverse(),
51-
hideList
48+
ids: showIds.reverse()
5249
})
5350
} catch (error) {
5451
dispatch(showAlert(error.message))

src/components/listing-card.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,30 @@ class ListingCard extends Component {
1313
constructor(props) {
1414
super(props)
1515
this.state = {
16-
loading: true,
17-
shouldRender: true
16+
loading: true
1817
}
1918
}
2019

2120
async componentDidMount() {
2221
try {
2322
const listing = await origin.listings.getByIndex(this.props.listingId)
23+
2424
const translatedListing = translateListingCategory(listing)
25-
if (!this.props.hideList.includes(translatedListing.address)) {
26-
const obj = Object.assign({}, translatedListing, { loading: false })
2725

28-
this.setState(obj)
29-
} else {
30-
this.setState({ shouldRender: false })
31-
}
26+
this.setState({ ...translatedListing, loading: false })
3227
} catch (error) {
3328
console.error(`Error fetching contract or IPFS info for listingId: ${this.props.listingId}`)
3429
}
3530
}
3631

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

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

4341
return (
4442
<div className={`col-12 col-md-6 col-lg-4 listing-card${loading ? ' loading' : ''}`}>

src/components/listings-grid.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ListingsGrid extends Component {
2222

2323
render() {
2424
const { listingsPerPage } = this.state
25-
const { contractFound, listingIds, hideList } = this.props
25+
const { contractFound, listingIds } = this.props
2626
const pinnedListingIds = [0, 1, 2, 3, 4]
2727
const activePage = this.props.match.params.activePage || 1
2828
const arrangedListingIds = [...pinnedListingIds, ...listingIds.filter(id => !pinnedListingIds.includes(id))]
@@ -62,7 +62,7 @@ class ListingsGrid extends Component {
6262
}
6363
<div className="row">
6464
{showListingsIds.map(listingId => (
65-
<ListingCard listingId={listingId} key={listingId} hideList={hideList} />
65+
<ListingCard listingId={listingId} key={listingId} />
6666
))}
6767
</div>
6868
<Pagination
@@ -84,7 +84,6 @@ class ListingsGrid extends Component {
8484

8585
const mapStateToProps = state => ({
8686
listingIds: state.listings.ids,
87-
hideList: state.listings.hideList,
8887
contractFound: state.listings.contractFound
8988
})
9089

src/reducers/Listings.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ListingConstants } from 'actions/Listing'
22

33
const initialState = {
44
ids: [],
5-
hideList: [],
65
contractFound: true
76
}
87

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

1514
case ListingConstants.FETCH_IDS_SUCCESS:
16-
return { ...state, ids: action.ids, hideList: action.hideList }
15+
return { ...state, ids: action.ids }
1716

1817
default:
1918
return state

0 commit comments

Comments
 (0)