From e96b5a020808620e0413e5a5581262a9f0c9f773 Mon Sep 17 00:00:00 2001 From: crzypatchwork <180111973@aluno.unb.br> Date: Thu, 23 Sep 2021 05:19:24 -0300 Subject: [PATCH] latest --- src/pages/feeds/feeds.js | 58 ++++++++++++++++----------------- src/pages/search/index.js | 67 ++++++++++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 37 deletions(-) diff --git a/src/pages/feeds/feeds.js b/src/pages/feeds/feeds.js index e28920230..19e619d06 100644 --- a/src/pages/feeds/feeds.js +++ b/src/pages/feeds/feeds.js @@ -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) { @@ -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 } @@ -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 }) => { @@ -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 () => { @@ -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) @@ -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) => { @@ -249,7 +250,7 @@ export const Feeds = ({ type }) => { .catch((e) => { setError(true) }) */ - } + //} }, [count, type]) const getLatest = async (id) => { @@ -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) @@ -322,7 +322,7 @@ export const Feeds = ({ type }) => { } -{/* + {/* API is down due to heavy server load — We're working to fix the issue — please be patient with us. Join the discord for updates. */} diff --git a/src/pages/search/index.js b/src/pages/search/index.js index 8453e7e2a..62752dc54 100644 --- a/src/pages/search/index.js +++ b/src/pages/search/index.js @@ -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') @@ -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 @@ -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 @@ -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(` @@ -464,6 +498,8 @@ async function fetchHdao(offset) { return result } + + export class Search extends Component { static contextType = HicetnuncContext @@ -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' } */ @@ -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 })