Skip to content

Commit

Permalink
latest
Browse files Browse the repository at this point in the history
  • Loading branch information
crzypatchwork committed Sep 23, 2021
1 parent ed38051 commit e96b5a0
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 37 deletions.
58 changes: 29 additions & 29 deletions src/pages/feeds/feeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ const customFloor = function (value, roundTo) {
return Math.floor(value / roundTo) * roundTo
}

/* const GetUserClaims = async (arr) => {
console.log(JSON.stringify(arr))
return await axios.post('https://indexer.tzprofiles.com/v1/graphql', {
query: `query MyQuery {
tzprofiles(where: {account: {_in: ${JSON.stringify(arr)}}}) {
account
valid_claims
}
}`,
variables: undefined,
operationName: 'MyQuery',
})
} */
const tz_profiles = `
query profiles {
tzprofiles(where: {account: {_in: $arr }}) {
account
contract
}
}
`

const latest_feed = `
query LatestFeed($lastId: bigint = 99999999) {
Expand Down Expand Up @@ -71,9 +66,7 @@ const query_hdao = `query hDAOFeed($offset: Int = 0) {
}`

async function fetchProfiles(arr) {
const { errors, data } = await fetchGraphQLProfiles(
tzprofiles, "MyQuery", {})
console.log(data)
const { errors, data } = await fetchGraphQLProfiles(tz_profiles, "profiles", { "arr": arr })
return data.tzprofiles
}

Expand Down Expand Up @@ -184,10 +177,18 @@ async function fetchRandomObjkts() {
const getRestrictedAddresses = async () =>
await axios
.get(
'https://raw.githubusercontent.com/hicetnunc2000/hicetnunc-reports/main/filters/w.json'
'https://raw.githubusercontent.com/hicetnunc2000/hicetnunc/main/filters/w.json'
)
.then((res) => res.data)

const GetUserClaims = async (arr) => {
return await axios.post('https://indexer.tzprofiles.com/v1/graphql', {
query: `query MyQuery { tzprofiles_by_pk(account: \"${walletAddr}\") { valid_claims } }`,
variables: null,
operationName: 'MyQuery',
})
}

const ONE_MINUTE_MILLIS = 60 * 1000

export const Feeds = ({ type }) => {
Expand All @@ -201,11 +202,11 @@ export const Feeds = ({ type }) => {
const startTime = customFloor(Date.now(), ONE_MINUTE_MILLIS)

const loadMore = async () => {
if (type === 1) {
/* if (type === 1) {
await getHdaoFeed()
}
if (type === 2) await getRandomFeed()
if (type === 3) await getLatest(Math.min.apply(Math, items.map(e => e.id)))
} */
await getRandomFeed()
//if (type === 3) await getLatest(Math.min.apply(Math, items.map(e => e.id)))
}

useEffect(async () => {
Expand All @@ -214,7 +215,7 @@ export const Feeds = ({ type }) => {
return
}
console.log(type)
if (type === 0) {
/* if (type === 0) {
GetLatestFeed({ counter: count, max_time: startTime })
.then((result) => {
const next = items.concat(result)
Expand All @@ -230,10 +231,10 @@ export const Feeds = ({ type }) => {
})
} else if (type === 1) {
await getHdaoFeed()
} else if (type === 2) {
} else if (type === 2) { */
await getRandomFeed()
} else if (type === 3) {
await getLatest(lastId)
/* } else if (type === 3) {
await getLatest(lastId) */

/* GetFeaturedFeed({ counter: count, max_time: startTime })
.then((result) => {
Expand All @@ -249,7 +250,7 @@ export const Feeds = ({ type }) => {
.catch((e) => {
setError(true)
}) */
}
//}
}, [count, type])

const getLatest = async (id) => {
Expand All @@ -261,8 +262,7 @@ export const Feeds = ({ type }) => {
result = _.uniqBy(result, 'creator_id')
setCreators(creators.concat(result.map(e => e.creator_id)))
result = result.filter(e => !creators.includes(e.creator_id))
let arr = result.map(e => e.creator_id)
//console.log(await GetUserClaims(arr))

let restricted = await getRestrictedAddresses()
result = result.filter(e => !restricted.includes(e.creator_id))
const next = items.concat(result)
Expand Down Expand Up @@ -322,7 +322,7 @@ export const Feeds = ({ type }) => {
</Padding>
</Container>
}
{/* <BottomBanner>
{/* <BottomBanner>
API is down due to heavy server load — We're working to fix the issue — please be patient with us. <a href="https://discord.gg/mNNSpxpDce" target="_blank">Join the discord</a> for updates.
</BottomBanner> */}
</Page>
Expand Down
67 changes: 59 additions & 8 deletions src/pages/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Input } from '../../components/input'
import InfiniteScroll from 'react-infinite-scroll-component'
import { renderMediaType } from '../../components/media-types'
import './style.css'
import { last } from 'lodash'

const axios = require('axios')
const ls = require('local-storage')
Expand Down Expand Up @@ -174,7 +175,7 @@ async function fetchGLB(offset) {
async function fetchInteractive(offset) {
const { errors, data } = await fetchGraphQL(`
query InteractiveObjkts {
hic_et_nunc_token(where: { mime: {_in : [ "application/x-directory" ]}, supply : { _neq : 0 } }, limit : 15, offset : ${offset}, order_by: {id: desc}) {
hic_et_nunc_token(where: { mime: {_in : [ "application/x-directory", "image/svg+xml" ]}, supply : { _neq : 0 } }, limit : 15, offset : ${offset}, order_by: {id: desc}) {
id
artifact_uri
display_uri
Expand Down Expand Up @@ -341,6 +342,7 @@ async function fetchRandomObjkts() {
}

async function fetchDay(day, offset) {
console.log(day)
const { errors, data } = await fetchGraphQL(`query dayTrades {
hic_et_nunc_trade(where: {timestamp: {_gte: "${day}"}}, order_by: {swap: {price: desc}}, limit : 15, offset : ${offset}) {
timestamp
Expand Down Expand Up @@ -370,6 +372,38 @@ async function fetchDay(day, offset) {

}

async function fetchSales(offset) {
console.log(offset)
const { errors, data } = await fetchGraphQL(`
query sales {
hic_et_nunc_trade(order_by: {timestamp: desc}, limit : 15, offset : ${offset}) {
timestamp
swap {
price
}
token {
artifact_uri
display_uri
id
mime
}
}
}`, 'sales', {})

if (errors) {
console.log(errors)
}

let result = []

try {
result = data.hic_et_nunc_trade
} catch (e) { }

return result

}

async function fetchSubjkts(subjkt) {
//console.log(subjkt)
const { errors, data } = await fetchGraphQL(`
Expand Down Expand Up @@ -464,6 +498,8 @@ async function fetchHdao(offset) {
return result
}



export class Search extends Component {
static contextType = HicetnuncContext

Expand All @@ -476,15 +512,17 @@ export class Search extends Component {
prev: '',
reset: false,
flag: false,
lastId: undefined,
tags: [
{ id: 0, value: '○' },
{ id: 1, value: 'random' },
{ id: 2, value: 'glb' },
{ id: 3, value: 'music' },
{ id: 4, value: 'interactive' },
{ id: 5, value: 'gif' },
{ id: 6, value: '1D'},
{ id: 7, value: '1W'},
{ id: 1, value: 'latest sales' },
{ id: 2, value: 'latest mints' },
{ id: 3, value: 'glb' },
{ id: 4, value: 'music' },
{ id: 5, value: 'interactive' },
{ id: 6, value: 'gif' },
{ id: 7, value: '1D'},
{ id: 8, value: '1W'}
/* { id: 4, value: 'illustration' }, */
/* { id: 5, value: 'gif' } */

Expand Down Expand Up @@ -588,6 +626,19 @@ export class Search extends Component {
this.setState({ feed: [...this.state.feed, ...(await fetchTag(this.state.search, this.state.feed[this.state.feed.length - 1].id))] })
}

if (e == 'latest sales') {
let tokens = await fetchSales(this.state.offset + 250)
tokens = tokens.map(e => e.token)
tokens = _.uniqBy(tokens, 'id')

this.setState({ feed: _.uniqBy([...this.state.feed, ...tokens], 'id')})
}

if (e == 'latest mints') {
this.setState({ feed: [...this.state.feed, ...(await fetchFeed(999999 || this.state.lastId))] })
this.setState({ lastId : Math.min.apply(Math, this.state.feed.map(e => e.id))})
}

this.setState({ reset: false })

//this.setState({ feed : this.state.feed })
Expand Down

0 comments on commit e96b5a0

Please sign in to comment.