Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Fetch collections #2102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Fetch collections
  • Loading branch information
RabbitDoge committed Sep 7, 2021
commit ca936fd82f91a65c38dd3b31dd8e1cb823863d00
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ REACT_APP_NODE_4 = "https://nodes.pancakeswap.com/"
REACT_APP_GRAPH_API_PROFILE = "https://api.thegraph.com/subgraphs/name/pancakeswap/profile"
REACT_APP_GRAPH_API_PREDICTION = "https://api.thegraph.com/subgraphs/name/pancakeswap/prediction-v2"
REACT_APP_GRAPH_API_LOTTERY = "https://api.thegraph.com/subgraphs/name/pancakeswap/lottery"
REACT_APP_GRAPH_API_NFT_MARKET = "https://api.thegraph.com/subgraphs/name/chefnyan/nft-markets"

REACT_APP_SNAPSHOT_BASE_URL = "https://testnet.snapshot.org"
REACT_APP_SNAPSHOT_VOTING_API = "https://xtjyd0liqe.execute-api.ap-northeast-1.amazonaws.com/dev/api"
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ REACT_APP_NODE_4 = "https://nodes.pancakeswap.com/"
REACT_APP_GRAPH_API_PROFILE = "https://api.thegraph.com/subgraphs/name/pancakeswap/profile"
REACT_APP_GRAPH_API_PREDICTION = "https://api.thegraph.com/subgraphs/name/pancakeswap/prediction-v2"
REACT_APP_GRAPH_API_LOTTERY = "https://api.thegraph.com/subgraphs/name/pancakeswap/lottery"
REACT_APP_GRAPH_API_NFT_MARKET = ""

REACT_APP_SNAPSHOT_BASE_URL = "https://hub.snapshot.org"
REACT_APP_SNAPSHOT_VOTING_API = "https://voting-api.pancakeswap.info/api"
1 change: 1 addition & 0 deletions src/config/constants/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export const GRAPH_API_PREDICTION_V1 = 'https://api.thegraph.com/subgraphs/name/

export const INFO_CLIENT = 'https://bsc.streamingfast.io/subgraphs/name/pancakeswap/exchange-v2'
export const BLOCKS_CLIENT = 'https://api.thegraph.com/subgraphs/name/pancakeswap/blocks'
export const GRAPH_API_NFTMARKET = process.env.REACT_APP_GRAPH_API_NFT_MARKET
2 changes: 2 additions & 0 deletions src/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import mint from './mint/reducer'
import lists from './lists/reducer'
import burn from './burn/reducer'
import multicall from './multicall/reducer'
import nftMarketReducer from './nftMarket/reducer'

const PERSISTED_KEYS: string[] = ['user', 'transactions', 'lists', 'profile', 'collectibles']

Expand All @@ -37,6 +38,7 @@ const store = configureStore({
voting: votingReducer,
lottery: lotteryReducer,
info: infoReducer,
nftMarket: nftMarketReducer,

// Exchange
user,
Expand Down
29 changes: 29 additions & 0 deletions src/state/nftMarket/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { request, gql } from 'graphql-request'
import { GRAPH_API_NFTMARKET } from 'config/constants/endpoints'

export const getCollections = async (): Promise<any[]> => {
try {
const res = await request(
GRAPH_API_NFTMARKET,
gql`
{
collections {
id
name
symbol
active
totalVolumeBNB
numberTokensListed
tradingFee
creatorFee
}
}
`,
)
Comment on lines +6 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No default order? By latest, volume, ...?


return res.collections
} catch (error) {
console.error('Failed to fetch NFT collections', error)
return []
}
}
10 changes: 10 additions & 0 deletions src/state/nftMarket/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useEffect } from 'react'
import { useAppDispatch } from 'state'
import { fetchCollections } from './reducer'

export const useFetchCollections = () => {
const dispatch = useAppDispatch()
useEffect(() => {
dispatch(fetchCollections())
RabbitDoge marked this conversation as resolved.
Show resolved Hide resolved
}, [dispatch])
}
15 changes: 0 additions & 15 deletions src/state/nftMarket/index.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/state/nftMarket/reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import { getCollections } from './helpers'
import { State, Collection } from './types'

const initialState: State = {
data: {
collections: [],
users: [],
},
}

export const fetchCollections = createAsyncThunk<Collection[]>('nft/fetchFarmsPublicDataAsync', async () => {
const collections = await getCollections()
return collections
})

export const NftMarket = createSlice({
name: 'NftMarket',
initialState,
reducers: {},
extraReducers: (builder) => {
builder.addCase(fetchCollections.fulfilled, (state, action) => {
state.data.collections = action.payload
})
},
})

export default NftMarket.reducer
13 changes: 6 additions & 7 deletions src/state/nftMarket/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { BigNumberish } from 'ethers'
// Users -> Nft tokens IDs

export interface State {
collections: Collection[]
users: User[]
data: {
collections: Collection[]
users: User[]
}
}

export interface Transaction {
Expand All @@ -30,18 +32,15 @@ export interface NFT {
}

export interface Collection {
address: string
id: string
name: string
symbol: string
active: boolean
totalTrades: BigNumberish
totalVolumeBNB: BigNumberish
numberTokensListed: BigNumberish
nfts: NFT[]
creatorAddress: string
tradingFee: BigNumberish
creatorFee: BigNumberish
whitelistChecker: string
nfts: NFT[]
}

export interface User {
Expand Down
2 changes: 2 additions & 0 deletions src/views/nft/market/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react'
import { useFetchCollections } from 'state/nftMarket/hooks'

const Market = () => {
useFetchCollections()
return <div>Market</div>
}

Expand Down