utils#getRandomIPFS JavaScript Examples
The following examples show how to use
utils#getRandomIPFS.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From Artion-Client with GNU General Public License v3.0 | 4 votes |
ExploreCollections = () => {
const dispatch = useDispatch();
const classes = useStyles();
const [filter, setFilter] = useState('');
const { collections: collectionItems, collectionsLoading } = useSelector(
state => state.Collections
);
const { collections } = useSelector(state => state.Filter);
const handleSelectCollection = addr => {
let newCollections = [];
if (collections.includes(addr)) {
newCollections = collections.filter(item => item !== addr);
} else {
newCollections = [...collections, addr];
}
dispatch(FilterActions.updateCollectionsFilter(newCollections));
};
const filteredCollections = () => {
const selected = [];
let unselected = [];
collectionItems.map(item => {
if (collections.includes(item.address)) {
selected.push(item);
} else {
unselected.push(item);
}
});
unselected = unselected.filter(
item =>
(item.name || item.collectionName || '')
.toLowerCase()
.indexOf(filter.toLowerCase()) > -1
);
return [...selected, ...unselected];
};
return (
<FilterWrapper title="Collections" classes={{ body: classes.body }}>
<div className={classes.collectionExpandDiv}>
<SearchIcon className={classes.iconButton} />
<InputBase
className={classes.input}
placeholder="Filter"
inputProps={{ 'aria-label': 'Filter' }}
value={filter}
onChange={e => setFilter(e.target.value)}
/>
</div>
<div className={classes.collectionsList}>
{collectionsLoading &&
collectionItems.length === 0 &&
new Array(8)
.fill(0)
.map((_, idx) => (
<Skeleton
key={idx}
width="100%"
height={40}
className={classes.collection}
/>
))}
{filteredCollections()
.filter(item => item.isVisible)
.map((item, idx) => (
<div
key={idx}
className={classes.collection}
onClick={() => handleSelectCollection(item.address)}
>
{collections.includes(item.address) ? (
<div className={cx(classes.logo, classes.withBorder)}>
<img src={iconCheck} />
</div>
) : (
<img
className={classes.logo}
src={
item.logoImageHash
? `${getRandomIPFS('', true)}${item.logoImageHash}`
: collections.includes(item.address)
? nftActiveIcon
: nftIcon
}
/>
)}
<span className={classes.name}>
{item.name || item.collectionName}
</span>
{item.isVerified && (
<BootstrapTooltip title="Verified Collection" placement="top">
<CheckCircleIcon className={classes.checkIcon} />
</BootstrapTooltip>
)}
</div>
))}
</div>
</FilterWrapper>
);
}
Example #2
Source File: index.js From Artion-Client with GNU General Public License v3.0 | 4 votes |
BaseCard = ({ item, loading, style, create, onCreate, onLike }) => {
const { storageUrl, likeItem, likeBundle } = useApi();
const { getAuction } = useAuctionContract();
const { getTokenByAddress } = useTokens();
const [now, setNow] = useState(new Date());
const [fetching, setFetching] = useState(false);
const [isLiking, setIsLiking] = useState(false);
const [info, setInfo] = useState(null);
const [index, setIndex] = useState(0);
const [isLike, setIsLike] = useState(false);
const [liked, setLiked] = useState(0);
const [auction, setAuction] = useState(null);
const { collections } = useSelector(state => state.Collections);
const { authToken } = useSelector(state => state.ConnectWallet);
const collection = collections.find(
col => col.address === item?.contractAddress
);
const getTokenURI = async tokenURI => {
setFetching(true);
try {
tokenURI = getRandomIPFS(tokenURI);
const { data } = await axios.get(tokenURI);
if (data[Object.keys(data)[0]].image) {
data.image = getRandomIPFS(data[Object.keys(data)[0]].image);
data.name = data[Object.keys(data)[0]].name;
}
if (data.properties && data.properties.image) {
data.image = getRandomIPFS(data.properties.image.description);
}
setInfo(data);
} catch {
setInfo(null);
}
setFetching(false);
};
const getCurrentAuction = async () => {
try {
const _auction = await getAuction(item.contractAddress, item.tokenID);
if (_auction.endTime !== 0) {
const token = getTokenByAddress(_auction.payToken);
_auction.reservePrice = parseFloat(
ethers.utils.formatUnits(_auction.reservePrice, token.decimals)
);
_auction.token = token;
setAuction(_auction);
}
} catch (e) {
console.log(e);
}
};
useEffect(() => {
async function fetchMyAPI() {
if (item && !item.name) {
await getTokenURI(item.tokenURI);
}
if (item) {
if (item.imageURL) {
// eslint-disable-next-line require-atomic-updates
item.imageURL = getRandomIPFS(item.imageURL);
}
setLiked(item.liked);
if (item.items) {
setAuction(null);
} else {
getCurrentAuction();
}
}
}
fetchMyAPI();
}, [item]);
useEffect(() => {
if (item?.isLiked !== undefined) {
setIsLike(item.isLiked);
}
}, [item?.isLiked]);
useEffect(() => {
setInterval(() => {
setNow(new Date());
}, 1000);
}, []);
const auctionStarted = now.getTime() / 1000 >= auction?.startTime;
const auctionEnded = auction?.endTime <= now.getTime() / 1000;
const auctionActive = auctionStarted && !auctionEnded;
const toggleFavorite = async e => {
e.preventDefault();
if (isLiking) return;
setIsLiking(true);
try {
if (item.items) {
const { data } = await likeBundle(item._id, authToken);
setLiked(data);
} else {
const { data } = await likeItem(
item.contractAddress,
item.tokenID,
authToken
);
setLiked(data);
}
} catch (err) {
console.log(err);
}
setIsLike(!isLike);
setIsLiking(false);
onLike && onLike();
};
const formatDiff = diff => {
if (diff >= ONE_MONTH) {
const m = Math.ceil(diff / ONE_MONTH);
return `${m} Month${m > 1 ? 's' : ''}`;
}
if (diff >= ONE_DAY) {
const d = Math.ceil(diff / ONE_DAY);
return `${d} Day${d > 1 ? 's' : ''}`;
}
if (diff >= ONE_HOUR) {
const h = Math.ceil(diff / ONE_HOUR);
return `${h} Hour${h > 1 ? 's' : ''}`;
}
if (diff >= ONE_MIN) {
const h = Math.ceil(diff / ONE_MIN);
return `${h} Min${h > 1 ? 's' : ''}`;
}
return `${diff} Second${diff > 1 ? 's' : ''}`;
};
const formatDuration = endTime => {
const diff = endTime - Math.floor(now.getTime() / 1000);
return formatDiff(diff);
};
const renderSlides = () => {
return item.items.map((v, idx) => (
<div className={styles.imageBox} key={idx}>
{(v.imageURL || v.thumbnailPath?.length > 10) &&
(v.imageURL?.includes('youtube') ? (
<ReactPlayer
className={styles.media}
url={v.imageURL}
controls={true}
width="100%"
height="100%"
/>
) : (
<Suspense
fallback={
<Loader
type="Oval"
color="#007BFF"
height={32}
width={32}
className={styles.loader}
/>
}
>
<SuspenseImg
src={
v.thumbnailPath?.length > 10
? `${storageUrl}/image/${v.thumbnailPath}`
: v.imageURL
}
className={styles.media}
alt={v.name}
/>
</Suspense>
))}
</div>
));
};
const renderDots = () => {
return item.items.map((v, idx) => (
<div className={cx(styles.dot)} key={idx} />
));
};
const renderContent = () => {
return (
<>
<div className={cx(styles.cardHeader, isLike && styles.liking)}>
{!item ? (
<Skeleton width={80} height={20} />
) : (
<>
{isLike ? (
<FavoriteIcon
className={styles.favIcon}
onClick={toggleFavorite}
/>
) : (
<FavoriteBorderIcon
className={styles.favIcon}
onClick={toggleFavorite}
/>
)}
<span className={styles.favLabel}>{liked || 0}</span>
</>
)}
</div>
<div className={styles.mediaBox}>
<div className={styles.mediaPanel}>
{loading || fetching ? (
<Skeleton
width="100%"
height="100%"
className={styles.mediaLoading}
/>
) : item.items ? (
<>
<Carousel
className={styles.carousel}
plugins={['fastSwipe']}
value={index}
onChange={_index =>
setIndex(Math.min(Math.max(_index, 0), 2))
}
slides={renderSlides()}
numberOfInfiniteClones={1}
/>
<Dots
className={styles.dots}
value={index}
onChange={setIndex}
number={Math.min(item.items.length, 18)}
thumbnails={renderDots()}
/>
</>
) : (
<div className={styles.imageBox}>
{(item?.imageURL ||
info?.image ||
item?.thumbnailPath?.length > 10 ||
item?.thumbnailPath === 'embed') &&
(item?.thumbnailPath === 'embed' ? (
<iframe src={item?.imageURL} className={styles.media} />
) : (item?.imageURL || info?.image)?.includes('youtube') ? (
<ReactPlayer
className={styles.media}
url={item?.imageURL || info?.image}
controls={true}
width="100%"
height="100%"
/>
) : (
<Suspense
fallback={
<Loader
type="Oval"
color="#007BFF"
height={32}
width={32}
className={styles.loader}
/>
}
>
<SuspenseImg
src={
item.thumbnailPath?.length > 10
? `${storageUrl}/image/${item.thumbnailPath}`
: item?.imageURL || info?.image
}
className={styles.media}
alt={item.name}
/>
</Suspense>
))}
</div>
)}
</div>
</div>
<div className={styles.content}>
<div className={styles.topLine}>
<div className={styles.itemName}>
{loading || fetching ? (
<Skeleton width={100} height={20} />
) : (
<div className={styles.label}>
{collection?.collectionName || collection?.name}
{collection?.isVerified && (
<BootstrapTooltip
title="Verified Collection"
placement="top"
>
<CheckCircleIcon className={styles.checkIcon} />
</BootstrapTooltip>
)}
</div>
)}
{loading || fetching ? (
<Skeleton width={100} height={20} />
) : (
<div className={styles.name}>{item?.name || info?.name}</div>
)}
</div>
{auction?.reservePrice || item?.price ? (
<div className={styles.alignRight}>
{!loading && (
<div className={styles.label}>
{auctionActive ? 'Auction' : 'Price'}
</div>
)}
{loading || fetching ? (
<Skeleton width={80} height={20} />
) : (
<div className={cx(styles.label, styles.price)}>
<img
src={
auctionActive
? auction?.token?.icon
: getTokenByAddress(item?.paymentToken)?.icon ||
wFTMLogo
}
/>
{formatNumber(
auctionActive
? auction.reservePrice
: item.price.toFixed(2)
)}
</div>
)}
</div>
) : (
''
)}
</div>
<div className={styles.alignBottom}>
<div>
{auctionActive && (
<>
{!loading && <div className={styles.label2}>Time left</div>}
<div className={styles.name2}>
{formatDuration(auction.endTime)}
</div>
</>
)}
</div>
{item?.lastSalePrice > 0 && (
<div className={styles.alignRight}>
{!loading && <div className={styles.label2}>Last Price</div>}
{loading || fetching ? (
<Skeleton width={80} height={20} />
) : (
<div className={cx(styles.label2, styles.price2)}>
<img
src={
getTokenByAddress(item?.lastSalePricePaymentToken)?.icon
}
/>
{formatNumber(item.lastSalePrice)}
</div>
)}
</div>
)}
{/* {loading || fetching ? (
<Skeleton width={80} height={20} />
) : (
<div className={styles.label}>
{item.items
? `${item.items.length} item${
item.items.length !== 1 ? 's' : ''
}`
: `${formatNumber(
item?.holderSupply || item?.supply || 1
)} of ${formatNumber(item?.supply || 1)}`}
</div>
)} */}
</div>
</div>
</>
);
};
return (
<div style={style} className={styles.root} onClick={onCreate}>
<div className={styles.card}>
{create ? (
<div className={styles.createBtn}>
<div className={styles.createIcon}>
<img src={iconPlus} />
</div>
<div className={styles.createLabel}>Create Bundle</div>
</div>
) : item ? (
<Link
to={
item.items
? `/bundle/${item._id}`
: `/explore/${item.contractAddress}/${item.tokenID}`
}
className={styles.link}
>
{renderContent()}
</Link>
) : (
renderContent()
)}
</div>
{item?.tokenType === 1155 && (
<>
<div className={styles.card} />
<div className={styles.card} />
</>
)}
</div>
);
}
Example #3
Source File: index.js From Artion-Client with GNU General Public License v3.0 | 4 votes |
Header = ({ border }) => {
const history = useHistory();
const dispatch = useDispatch();
const {
apiUrl,
storageUrl,
getAuthToken,
getAccountDetails,
getIsModerator,
} = useApi();
const { account, chainId, deactivate } = useWeb3React();
const { user } = useSelector(state => state.Auth);
let isSearchbarShown = useSelector(state => state.HeaderOptions.isShown);
const { isModerator } = useSelector(state => state.ConnectWallet);
const { wftmModalVisible, connectWalletModalVisible } = useSelector(
state => state.Modal
);
const [anchorEl, setAnchorEl] = useState(null);
const [loading, setLoading] = useState(false);
const [searchBarActive, setSearchBarActive] = useState(false);
const [isAdding, setIsAdding] = useState(false);
const [modModalVisible, setModModalVisible] = useState(false);
const [isBan, setIsBan] = useState(false);
const [banCollectionModalVisible, setBanCollectionModalVisible] = useState(
false
);
const [banItemModalVisible, setBanItemModalVisible] = useState(false);
const [banUserModalVisible, setBanUserModalVisible] = useState(false);
const [unbanUserModalVisible, setUnbanUserModalVisible] = useState(false);
const [
boostCollectionModalVisible,
setBoostCollectionModalVisible,
] = useState(false);
const [keyword, setKeyword] = useState('');
const [cancelSource, setCancelSource] = useState(null);
const [accounts, setAccounts] = useState([]);
const [collections, setCollections] = useState([]);
const [tokens, setTokens] = useState([]);
const [bundles, setBundles] = useState([]);
const [tokenDetailsLoading, setTokenDetailsLoading] = useState(false);
const timer = useRef(null);
const isMenuOpen = Boolean(anchorEl);
const login = async () => {
try {
setLoading(true);
const token = await getAuthToken(account);
const isModerator = await getIsModerator(account);
dispatch(WalletConnectActions.connectWallet(token, isModerator));
dispatch(AuthActions.fetchStart());
try {
const { data } = await getAccountDetails(token);
dispatch(AuthActions.fetchSuccess(data));
} catch {
dispatch(AuthActions.fetchFailed());
}
setLoading(false);
} catch {
setLoading(false);
}
};
const init = () => {
login();
};
useEffect(() => {
if (account) {
init();
} else {
handleSignOut();
}
}, [account, chainId]);
const handleConnectWallet = () => {
dispatch(ModalActions.showConnectWalletModal());
};
const resetResults = () => {
setAccounts([]);
setCollections([]);
setTokens([]);
setBundles([]);
};
useEffect(() => {
resetResults();
}, [isSearchbarShown]);
const search = async word => {
setKeyword(word);
if (cancelSource) {
cancelSource.cancel();
}
if (word.length === 0) {
resetResults();
return;
}
try {
const cancelTokenSource = axios.CancelToken.source();
setCancelSource(cancelTokenSource);
const {
data: {
data: { accounts, collections, tokens, bundles },
},
} = await axios({
method: 'post',
url: `${apiUrl}/info/searchNames`,
data: JSON.stringify({ name: word }),
headers: {
'Content-Type': 'application/json',
},
cancelToken: cancelTokenSource.token,
});
Promise.all(
tokens.map(async token => {
if (token.imageURL) {
token.imageURL = getRandomIPFS(token.imageURL);
}
if (token.imageURL === '-') {
const {
data: { image },
} = await axios.get(token.tokenURI);
if (image) {
// eslint-disable-next-line require-atomic-updates
token.imageURL = getRandomIPFS(token.imageURL);
}
}
})
);
setAccounts(accounts);
setCollections(collections);
setTokenDetailsLoading(true);
setTokens(tokens);
setBundles(bundles);
setTokenDetailsLoading(false);
} catch (err) {
console.log(err);
} finally {
setCancelSource(null);
}
};
const handleSelectCollection = addr => {
dispatch(FilterActions.updateCollectionsFilter([addr]));
};
const handleSearch = word => {
if (timer.current) {
clearTimeout(timer.current);
}
timer.current = setTimeout(() => search(word), 500);
};
const handleSignOut = () => {
deactivate();
dispatch(WalletConnectActions.disconnectWallet());
dispatch(AuthActions.signOut());
handleMenuClose();
};
const handleProfileMenuOpen = e => {
setAnchorEl(e.currentTarget);
};
const handleMenuClose = () => {
setAnchorEl(null);
};
const goToMyProfile = () => {
history.push(`/account/${account}`);
handleMenuClose();
};
const goToNotificationSettings = () => {
history.push(`/settings/notification`);
handleMenuClose();
};
// const handleCreateCollection = () => {
// history.push('/collection/create');
// handleMenuClose();
// };
const handleRegisterCollection = () => {
history.push('/collection/register');
handleMenuClose();
};
const openWrapStation = () => {
dispatch(ModalActions.showWFTMModal());
handleMenuClose();
};
const addMod = () => {
setIsAdding(true);
setModModalVisible(true);
handleMenuClose();
};
const removeMod = () => {
setIsAdding(false);
setModModalVisible(true);
handleMenuClose();
};
const reviewCollections = () => {
history.push('/collection/review');
handleMenuClose();
};
const banCollection = () => {
setIsBan(true);
setBanCollectionModalVisible(true);
handleMenuClose();
};
const unbanCollection = () => {
setIsBan(false);
setBanCollectionModalVisible(true);
handleMenuClose();
};
const banItems = () => {
setBanItemModalVisible(true);
handleMenuClose();
};
const banUser = () => {
setBanUserModalVisible(true);
handleMenuClose();
};
const unbanUser = () => {
setUnbanUserModalVisible(true);
handleMenuClose();
};
const boostCollection = () => {
setBoostCollectionModalVisible(true);
handleMenuClose();
};
const renderMenu = (
<Menu
anchorEl={anchorEl}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
keepMounted
transformOrigin={{ vertical: 'top', horizontal: 'right' }}
open={isMenuOpen}
onClose={handleMenuClose}
classes={{
paper: styles.profilemenu,
list: styles.menuList,
}}
>
{account && (
<div
className={cx(styles.menuItem, styles.topItem)}
onClick={goToMyProfile}
>
<img src={iconUser} className={styles.menuIcon} />
My Profile
</div>
)}
<div className={styles.menuItem} onClick={goToNotificationSettings}>
<img src={iconNotification} className={styles.menuIcon} />
Notification Settings
</div>
{/* <div className={styles.menuItem} onClick={handleCreateCollection}>
<img src={iconAdd} className={styles.menuIcon} />
Create New Collection
</div> */}
<div className={styles.menuItem} onClick={handleRegisterCollection}>
<img src={iconEdit} className={styles.menuIcon} />
Register Existing Collection
</div>
<div className={styles.menuItem} onClick={openWrapStation}>
<img src={iconSwap} className={styles.menuIcon} />
FTM / WFTM Station
</div>
<div className={styles.menuSeparator} />
{account?.toLowerCase() === ADMIN_ADDRESS.toLowerCase()
? [
<div key={0} className={styles.menuItem} onClick={addMod}>
Add Mod
</div>,
<div key={1} className={styles.menuItem} onClick={removeMod}>
Remove Mod
</div>,
<div
key={2}
className={styles.menuItem}
onClick={reviewCollections}
>
Review Collections
</div>,
<div key={3} className={styles.menuItem} onClick={banCollection}>
Ban Collection
</div>,
<div key={4} className={styles.menuItem} onClick={unbanCollection}>
Unban Collection
</div>,
<div key={5} className={styles.menuItem} onClick={banItems}>
Ban Items
</div>,
<div key={6} className={styles.menuItem} onClick={banUser}>
Ban a user
</div>,
<div key={6} className={styles.menuItem} onClick={unbanUser}>
Unban a user
</div>,
<div key={7} className={styles.menuItem} onClick={boostCollection}>
Boost Collection
</div>,
<div key={8} className={styles.menuSeparator} />,
]
: isModerator
? [
<div key={1} className={styles.menuItem} onClick={banCollection}>
Ban Collection
</div>,
<div key={2} className={styles.menuItem} onClick={banItems}>
Ban Items
</div>,
<div key={3} className={styles.menuItem} onClick={banUser}>
Ban a user
</div>,
<div key={6} className={styles.menuItem} onClick={unbanUser}>
Unban a user
</div>,
<div key={4} className={styles.menuSeparator} />,
]
: null}
<div className={styles.signOut} onClick={handleSignOut}>
Sign Out
</div>
</Menu>
);
const renderSearchBox = () => (
<div className={cx(styles.searchcont, searchBarActive && styles.active)}>
<div className={styles.searchcontinner}>
<div className={styles.searchbar}>
<SearchIcon className={styles.searchicon} />
<input
placeholder="Search items, collections and accounts"
className={styles.searchinput}
onChange={e => handleSearch(e.target.value)}
onFocus={() => setSearchBarActive(true)}
onBlur={() => setTimeout(() => setSearchBarActive(false), 200)}
/>
</div>
{searchBarActive && (
<div className={styles.resultcont}>
{collections.length > 0 && (
<div className={styles.resultsection}>
<div className={styles.resultsectiontitle}>Collections</div>
<div className={styles.separator} />
<div className={styles.resultlist}>
{collections.map((collection, idx) => (
<div
key={idx}
className={styles.result}
onClick={() =>
handleSelectCollection(collection.erc721Address)
}
>
<img
className={styles.resultimg}
src={`${getRandomIPFS('', true)}${
collection.logoImageHash
}`}
/>
<div className={styles.resulttitle}>
{collection.collectionName}
</div>
</div>
))}
</div>
</div>
)}
{accounts.length > 0 && (
<div className={styles.resultsection}>
<div className={styles.resultsectiontitle}>Accounts</div>
<div className={styles.separator} />
<div className={styles.resultlist}>
{accounts.map((account, idx) => (
<Link
to={`/account/${account.address}`}
key={idx}
className={styles.result}
>
{account.imageHash ? (
<img
className={styles.resultimg}
src={`https://cloudflare-ipfs.com/ipfs/${account.imageHash}`}
/>
) : (
<Identicon
className={styles.resultimg}
account={account.address}
size={40}
/>
)}
<div className={styles.resulttitle}>{account.alias}</div>
</Link>
))}
</div>
</div>
)}
{tokens.length > 0 && (
<div className={styles.resultsection}>
<div className={styles.resultsectiontitle}>Items</div>
<div className={styles.separator} />
<div className={styles.resultlist}>
{tokens.map((tk, idx) => (
<Link
to={`/explore/${tk.contractAddress}/${tk.tokenID}`}
key={idx}
className={styles.result}
>
<div className={styles.resultimg}>
{tokenDetailsLoading ? (
<Skeleton width={40} height={40} />
) : (
tk.thumbnailPath &&
(tk.thumbnailPath.length > 10 ? (
<img
src={`${storageUrl}/image/${tk.thumbnailPath}`}
/>
) : tk.thumbnailPath === '.' ? (
<img src={tk.imageURL} />
) : null)
)}
</div>
<div className={styles.resulttitle}>{tk.name}</div>
</Link>
))}
</div>
</div>
)}
{bundles.length > 0 && (
<div className={styles.resultsection}>
<div className={styles.resultsectiontitle}>Bundles</div>
<div className={styles.separator} />
<div className={styles.resultlist}>
{bundles.map((bundle, idx) => (
<Link
to={`/bundle/${bundle._id}`}
key={idx}
className={styles.result}
>
<div className={styles.resultimg}></div>
<div className={styles.resulttitle}>{bundle.name}</div>
</Link>
))}
</div>
</div>
)}
{keyword.length > 0 &&
collections.length === 0 &&
accounts.length === 0 &&
tokens.length === 0 &&
bundles.length === 0 && (
<div className={styles.noResults}>No Results</div>
)}
</div>
)}
</div>
</div>
);
return (
<div className={cx(styles.header, border && styles.hasBorder)}>
<div className={styles.left}>
<Link to="/" className={styles.logo}>
<img src={logoSmallBlue} alt="logo" />
</Link>
{isSearchbarShown && renderSearchBox()}
<div className={styles.secondmenu}>
<NavLink
to="/explore"
className={cx(styles.menuLink, styles.link)}
activeClassName={styles.active}
>
Explore
</NavLink>
<NavLink
to="/create"
className={cx(styles.menuLink, styles.link)}
activeClassName={styles.active}
>
Create
</NavLink>
</div>
</div>
<div className={styles.menu}>
{isSearchbarShown && renderSearchBox()}
<NavLink
to="/explore"
className={cx(styles.menuLink, styles.link)}
activeClassName={styles.active}
style={{ color: '#fff' }}
>
Explore
</NavLink>
<NavLink
to="/create"
className={cx(styles.menuLink, styles.link)}
activeClassName={styles.active}
style={{ color: '#fff' }}
>
Create
</NavLink>
{account ? (
<div
className={cx(styles.account, styles.menuLink)}
onClick={handleProfileMenuOpen}
>
{loading ? (
<Skeleton className={styles.avatar} />
) : user?.imageHash ? (
<img
src={`https://cloudflare-ipfs.com/ipfs/${user?.imageHash}`}
width="24"
height="24"
className={styles.avatar}
/>
) : (
<Identicon
account={account}
size={36}
className={styles.avatar}
/>
)}
<div className={styles.profile}>
<div className={styles.address}>
{loading ? (
<Skeleton width={120} />
) : (
user?.alias || shortenAddress(account)
)}
</div>
<div className={styles.network}>
{loading ? <Skeleton width={80} /> : NETWORK_LABEL[chainId]}
</div>
</div>
<ExpandMore
className={cx(styles.expand, isMenuOpen && styles.expanded)}
/>
</div>
) : (
<div
className={cx(styles.connect, styles.menuLink)}
onClick={handleConnectWallet}
>
Connect Wallet
</div>
)}
</div>
{renderMenu}
<WFTMModal
visible={wftmModalVisible}
onClose={() => dispatch(ModalActions.hideWFTMModal())}
/>
<ModModal
isAdding={isAdding}
visible={modModalVisible}
onClose={() => setModModalVisible(false)}
/>
<BanCollectionModal
visible={banCollectionModalVisible}
isBan={isBan}
onClose={() => setBanCollectionModalVisible(false)}
/>
<BanItemModal
visible={banItemModalVisible}
onClose={() => setBanItemModalVisible(false)}
/>
<BanUserModal
visible={banUserModalVisible}
onClose={() => setBanUserModalVisible(false)}
isForBanning={true}
/>
<BanUserModal
visible={unbanUserModalVisible}
onClose={() => setUnbanUserModalVisible(false)}
isForBanning={false}
/>
<BoostCollectionModal
visible={boostCollectionModalVisible}
onClose={() => setBoostCollectionModalVisible(false)}
/>
<ConnectWalletModal
visible={connectWalletModalVisible}
onClose={() => dispatch(ModalActions.hideConnectWalletModal())}
/>
</div>
);
}
Example #4
Source File: index.js From Artion-Client with GNU General Public License v3.0 | 4 votes |
ExploreFilterHeader = ({ loading, category }) => {
const dispatch = useDispatch();
const { collections: collectionItems } = useSelector(
state => state.Collections
);
const { count } = useSelector(state => state.Tokens);
const { groupType, sortBy, collections } = useSelector(state => state.Filter);
const selectedCollections = () => {
const res = new Array(collections.length).fill(null);
collectionItems.map(item => {
const index = collections.findIndex(_item => _item === item.address);
if (index > -1) {
res[index] = item;
}
});
return res.filter(item => !!item);
};
const handleGroupTypeChange = e => {
const newGroupType = e.target.value;
dispatch(FilterActions.updateGroupTypeFilter(newGroupType));
};
const handleSortByChange = e => {
const newSortBy = e.target.value;
dispatch(FilterActions.updateSortByFilter(newSortBy));
};
const handleDeselectCollection = addr => {
let newCollections = [];
newCollections = collections.filter(item => item !== addr);
dispatch(FilterActions.updateCollectionsFilter(newCollections));
};
return (
<div className="filterHeaderRoot">
<div className="filterHeaderLeft">
<label className="filterResultLabel">
{loading ? (
<Skeleton width={100} height={24} />
) : (
`${formatNumber(count)} Result${count !== 1 ? 's' : ''}
${
category === null ? '' : `- Category: ${formatCategory(category)}`
}`
)}
</label>
{selectedCollections().map((item, idx) => (
<div key={idx} className="filterCollectionItem">
<img
className="filterCollectionItemLogo"
src={
item.isVerified
? `${getRandomIPFS('', true)}${item.logoImageHash}`
: nftActiveIcon
}
/>
<span className="filterCollectionItemName">
{item.name || item.collectionName}
</span>
<CloseIcon
className="filterCollectionRemoveItem"
onClick={() => handleDeselectCollection(item.address)}
/>
</div>
))}
</div>
<div className="filterSelectGroup">
<FormControl className="filterHeaderFormControl">
<Select
value={groupType}
onChange={handleGroupTypeChange}
className="selectBox"
classes={{
select: 'selectInner',
selectMenu: 'selectMenu',
icon: 'selectIcon',
}}
MenuProps={{
classes: {
paper: 'menuPropsPaper',
list: 'menuItemList',
},
}}
IconComponent={ExpandMoreIcon}
>
{GroupFilters.map((filter, idx) => {
return (
<MenuItem
value={filter.value}
key={idx}
className="menuItem"
classes={{ selected: 'menuItemSelected ' }}
>
{filter.label}
</MenuItem>
);
})}
</Select>
</FormControl>
<FormControl className="filterHeaderFormControl">
<Select
value={sortBy}
onChange={handleSortByChange}
className="selectBox"
classes={{
select: 'selectInner',
selectMenu: 'selectMenu',
icon: 'selectIcon',
}}
MenuProps={{
classes: {
paper: 'menuPropsPaper',
list: 'menuItemList',
},
}}
IconComponent={ExpandMoreIcon}
>
{SortByOptions.map((option, idx) => {
return (
<MenuItem
value={option.id}
key={idx}
className="menuItem"
classes={{ selected: 'menuItemSelected ' }}
>
{option.label}
</MenuItem>
);
})}
</Select>
</FormControl>
</div>
</div>
);
}