@mojito-inc/secondary-market
Version:
Mojito secondary market is the platform to purchase NFT.
2 lines (1 loc) • 2.9 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import{createContext as l,useMemo as t,useState as o,useCallback as i,useEffect as r,useContext as s}from"react";import{useCollections as a}from"../hooks/useCollections.js";import{SessionVariable as c}from"../constant/index.js";import{session as n}from"../utils/sessionStorage.utils.js";import{Currency as d}from"../interface/index.js";import u from"../hooks/useCollectionsList.js";const f=[{label:"Price: Low to High",value:"price_low_to_high"},{label:"Price: High to Low",value:"price_high_to_low"},{label:"Recently Listed",value:"recently_listed"},{label:"Newest",value:"recently_minted"},{label:"Oldest",value:"initially_minted"}],m=l({}),v=()=>s(m),p=({isShowFilters:l,walletType:s,children:v,filterConfig:p,walletDetails:h})=>{var C;const D=t((()=>20),[]),[g,w]=o([]),[y,F]=o(""),[L,T]=o(0),[b,I]=o([]),[_,j]=o(!1),[k,S]=o("All"),[x,A]=o(d.USD),[O,P]=o(null!==(C=n(c.CollectionFilter,!0))&&void 0!==C?C:f[0].label),H=i((()=>{var e,l;const t=f.filter((e=>e.label===O));return n(c.CollectionFilter,!1,null===(e=null==t?void 0:t[0])||void 0===e?void 0:e.label),null===(l=null==t?void 0:t[0])||void 0===l?void 0:l.value}),[O]),R=t((()=>({orgID:p.orgID,marketplaceID:null==p?void 0:p.marketplaceID,limit:D,offset:L*D,walletAddress:h.walletAddress,search:y,filters:H(),walletType:s,selectedCollection:"all"===(null==k?void 0:k.toLowerCase())?void 0:k,currencyType:x})),[p.orgID,null==p?void 0:p.marketplaceID,D,L,h.walletAddress,y,s,H,x,k]),M=t((()=>{if((null==b?void 0:b.length)>0)return null==b?void 0:b.map((e=>({traitType:e.field,traitValue:e.value})))}),[b]),{collectionsData:N,collectionsLoading:U,totalCollections:V,traitsData:q,traitsLoading:z,fetchCollection:B,fetchMetaDataDetails:E}=a(Object.assign(Object.assign({},R),{metaDataFilters:M})),{collectionsOptions:G,fetchCollectionsList:J,collectionsListLoading:K}=u({orgID:R.orgID,marketplaceID:R.marketplaceID}),Q=i((()=>{I([]),j(!0)}),[]),W=t((()=>U||z||K),[U,z,K]);r((()=>{const e=n(c.CollectionFilter,!0);e?P(e):n(c.CollectionFilter,!1,f[2].label)}),[]),r((()=>{if(y||L||O||(null==h?void 0:h.walletAddress)){const e=setTimeout((async()=>{B()}),200);return()=>clearTimeout(e)}return()=>{}}),[y,O,L,null==h?void 0:h.walletAddress,B]),r((()=>{_&&(j(!1),B())}),[B,_]),r((()=>{l&&E()}),[l,E,R.selectedCollection]);const X=t((()=>({search:g,selectedFilter:b,refetchFilter:_,filteredCollectionData:N,filteredCollectionsLoading:W,searchText:y,offset:L,totalCollections:V,traitsData:q,filter:O,walletType:s,selectedCollection:k,collectionsOptions:G,setSelectedFilter:I,setSearch:w,setRefetchFilter:j,setSearchText:F,setOffset:T,fetchCollection:B,setFilter:P,setSelectedCollection:S,fetchCollectionsList:J,clearTraitsFilter:Q,currencyType:x,setCurrencyType:A})),[g,b,_,N,W,y,L,V,q,O,s,k,G,B,S,J,Q,x,A]);return e(m.Provider,{value:X,children:v})};export{p as default,f as tokensFilterOptions,v as useFilterData};