Skip to content

Commit

Permalink
Merge pull request rairprotocol#115 from rairprotocol/dev
Browse files Browse the repository at this point in the history
Update main branch
  • Loading branch information
sarora180673 authored Jul 16, 2024
2 parents 0f20c43 + c468288 commit 76cf748
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 81 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/MoveToNextIteration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
on:
schedule:
# Runs "at 05:00, only on Tuesday" (see https://crontab.guru)
- cron: '0 5 * * 2'

jobs:
move-to-next-iteration:
name: Move to next iteration
runs-on: ubuntu-latest

steps:
- uses: blombard/move-to-next-iteration@master
with:
owner: rairprotocol
number: 1
token: ${{ secrets.PROJECT_PAT }}
iteration-field: Iteration
iteration: last
new-iteration: current
excluded-statuses: "Done,Won't Fix"
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import ReactPlayer from 'react-player';
import { Provider, useSelector, useStore } from 'react-redux';
import { useNavigate, useParams } from 'react-router-dom';
import axios, { AxiosError } from 'axios';
import { BigNumber, constants, utils } from 'ethers';
import { BigNumber } from 'ethers';
import { formatEther } from 'ethers/lib/utils';

import {
IOffersResponseType,
TUserResponse
} from '../../../axios.responseTypes';
import { IOffersResponseType } from '../../../axios.responseTypes';
import { RootState } from '../../../ducks';
import { ColorStoreType } from '../../../ducks/colors/colorStore.types';
import { ContractsInitialType } from '../../../ducks/contracts/contracts.types';
import { UserType } from '../../../ducks/users/users.types';
import useIPFSImageLink from '../../../hooks/useIPFSImageLink';
import useSwal from '../../../hooks/useSwal';
import useWindowDimensions from '../../../hooks/useWindowDimensions';
Expand Down Expand Up @@ -61,7 +57,6 @@ const NftItemForCollectionViewComponent: React.FC<
const navigate = useNavigate();
const store = useStore();

const [userInfoMinted, setUserInfoMinted] = useState<UserType | null>(null);
const [isFileUrl, setIsFileUrl] = useState<string | undefined>();
const ipfsLink = useIPFSImageLink(metadata?.image);
const [tokenInfo, setTokenInfo] = useState<any>(null);
Expand Down Expand Up @@ -199,20 +194,6 @@ const NftItemForCollectionViewComponent: React.FC<
}
}, [navigate, tokenInfo, contract, blockchain, product, index, item]);

const getInfoFromUser = useCallback(async () => {
// find user
if (
item &&
utils.isAddress(item.ownerAddress) &&
item.ownerAddress !== constants.AddressZero
) {
const result = await axios
.get<TUserResponse>(`/api/users/${item.ownerAddress}`)
.then((res) => res.data);
setUserInfoMinted(result.user);
}
}, [item]);

const initialTokenData = useCallback(() => {
if (item && resaleFlag) {
if (item.contract?.diamond) {
Expand Down Expand Up @@ -313,10 +294,6 @@ const NftItemForCollectionViewComponent: React.FC<
getParticularOffer();
}, [getParticularOffer]);

useEffect(() => {
getInfoFromUser();
}, [getInfoFromUser]);

useEffect(() => {
checkUrl();
}, [checkUrl]);
Expand Down Expand Up @@ -517,25 +494,25 @@ const NftItemForCollectionViewComponent: React.FC<
maxHeight: '40px'
}}>
<div>
{item?.isMinted && userInfoMinted ? (
{item?.isMinted && item.ownerData ? (
<div className="collection-block-user-creator">
<img
src={
userInfoMinted.avatar
? userInfoMinted.avatar
item.ownerData?.avatar
? item.ownerData?.avatar
: defaultImage
}
alt="User Avatar"
/>
<h5 style={{ wordBreak: 'break-all' }}>
{userInfoMinted.nickName
? userInfoMinted.nickName.length > 16
? userInfoMinted.nickName.slice(0, 5) +
{item.ownerData?.nickName
? item.ownerData?.nickName.length > 16
? item.ownerData?.nickName.slice(0, 5) +
'...' +
userInfoMinted.nickName.slice(
userInfoMinted.nickName.length - 4
item.ownerData?.nickName.slice(
item.ownerData?.nickName.length - 4
)
: userInfoMinted.nickName
: item.ownerData?.nickName
: userName?.slice(0, 5) +
'....' +
userName?.slice(userName.length - 4)}
Expand Down Expand Up @@ -578,10 +555,10 @@ const NftItemForCollectionViewComponent: React.FC<
)}
</div>
{item && !resaleFlag && item.isMinted && !resalePrice && (
<div className="nft-item-collection-sold-out">
<div className="sold-out-box">Sold out</div>
</div>
)}
<div className="nft-item-collection-sold-out">
<div className="sold-out-box">Sold out</div>
</div>
)}
<div
className="collection-block-price"
style={{ alignItems: 'flex-end' }}>
Expand Down
12 changes: 9 additions & 3 deletions rair-node/bin/api/nft/nft.Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ router.post(
router.get(
'/network/:networkId/:contract/:product',
validation(['nftContract', 'nftProduct'], 'params'),
findContractMiddleware,
findProductMiddleware,
validation(['getTokensByContractProduct', 'resaleFlag', 'metadataSearch'], 'query'),
findContractAndProductMiddleware,
validation(['getTokensByContractProduct', 'resaleFlag', 'metadataSearch', 'tokenLimits'], 'query'),
getTokensForProduct,
);
router.get(
'/network/:networkId/:contract/:product/numbers',
validation(['nftContract', 'nftProduct'], 'params'),
validation(['tokenLimits'], 'query'),
findContractAndProductMiddleware,
getTokenNumbers,
);
router.get(
'/network/:networkId/:contract/:product/attributes',
validation(['nftContract', 'nftProduct'], 'params'),
Expand Down
138 changes: 109 additions & 29 deletions rair-node/bin/api/nft/nft.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,23 +347,89 @@ module.exports = {
next(err);
}
},
findProductMiddleware: async (req, res, next) => {
try {
const product = await Product.findOne({
contract: req.contract._id,
collectionIndexInContract: req.params.product,
});

if (!product) {
return next(new AppError('Product not found.', 404));
}

req.product = product;

return next();
} catch (e) {
return next(e);
getTokenNumbers: async (req, res, next) => {
try {
const { contract, product } = req;
const { fromToken, toToken } = req.query;
const tokenLimitFilter = [];
if (fromToken) {
tokenLimitFilter.push(
{
$gte: ['$token', fromToken],
},
);
}
if (toToken) {
tokenLimitFilter.push(
{
$lte: ['$token', toToken],
},
);
}
const offerData = await Offer.aggregate([
{
$match: {
$expr: {
$eq: [contract._id, '$contract'],
},
product: product.collectionIndexInContract,
},
},
{
$lookup: {
from: 'MintedToken',
let: { offerIndex: '$diamondRangeIndex' },
as: 'tokens',
pipeline: [{
$match: {
$expr: {
$and: [
{
$eq: ['$offer', '$$offerIndex'],
},
...tokenLimitFilter,
],
},
contract: contract._id,
},
},
{
$sort: { uniqueIndexInContract: 1 },
},
{
$addFields: {
sold: {
$cond: {
if: { $eq: ['$ownerAddress', ZeroAddress] },
then: false,
else: true,
},
},
},
},
{
$project: {
_id: 0,
token: 1,
sold: 1,
},
},
],
},
},
{
$project: {
tokens: 1,
},
},
]).collation({ locale: 'en_US', numericOrdering: true });
return res.json({
success: true,
tokens: offerData.reduce((total, offer) => total.concat(offer.tokens), []),
});
} catch (err) {
return next(err);
}
},
getProductAttributes: async (req, res, next) => {
try {
Expand Down Expand Up @@ -499,20 +565,34 @@ module.exports = {
},
},
{
$lookup: {
from: 'Offer',
let: populateOptions.let,
pipeline: [
{
$match: {
$expr: {
$and: populateOptions.and,
},
},
},
],
as: 'offer',
$lookup: {
from: 'Offer',
let: populateOptions.let,
pipeline: [
{
$match: {
$expr: {
$and: populateOptions.and,
},
},
},
],
as: 'offer',
},
},
{
$lookup: {
from: 'User',
localField: 'ownerAddress',
foreignField: 'publicAddress',
as: 'ownerData',
},
},
{
$unwind: {
path: '$ownerData',
preserveNullAndEmptyArrays: true,
},
},
{ $unwind: '$offer' },
{ $match: filterOptions },
Expand Down
7 changes: 6 additions & 1 deletion rair-node/bin/api/notifications/notifications.Controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const express = require('express');
const { requireUserSession, validation } = require('../../middleware');
const { markNotificationAsRead, getSingleNotification, listNotifications, deleteNotification } = require('./notifications.Service');
const {
markNotificationAsRead,
getSingleNotification,
listNotifications,
deleteNotification,
} = require('./notifications.Service');

const router = express.Router();

Expand Down
27 changes: 19 additions & 8 deletions rair-node/bin/api/notifications/notifications.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,18 @@ module.exports = {
},
markNotificationAsRead: async (req, res, next) => {
try {
const { id } = req.params;
const notification = await Notification.findByIdAndUpdate(id, { $set: { read: true } });
if (!notification) {
return next(new AppError('Notification not found', 404));
const { publicAddress } = req.user;
const { ids = [] } = req.body;
const filter = {
user: publicAddress,
};
if (ids?.length) {
filter._id = { $in: ids };
}
const result = await Notification.updateMany(
filter,
{ $set: { read: true } },
);
return res.json({
success: true,
notification,
Expand All @@ -75,11 +82,15 @@ module.exports = {
},
deleteNotification: async (req, res, next) => {
try {
const { id } = req.params;
const notification = await Notification.findByIdAndDelete(id);
if (!notification) {
return next(new AppError('Notification not found', 404));
const { publicAddress } = req.user;
const { ids = [] } = req.body;
const filter = {
user: publicAddress,
};
if (ids?.length) {
filter._id = { $in: ids };
}
const result = await Notification.deleteMany(filter);
return res.json({
success: true,
notification,
Expand Down
4 changes: 4 additions & 0 deletions rair-node/bin/schemas/commonApiSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ module.exports = {
metadataSearch: () => ({
metadataFilters: Joi.string(),
}),
tokenLimits: () => ({
fromToken: Joi.string(),
toToken: Joi.string(),
}),
};
2 changes: 0 additions & 2 deletions rair-node/bin/schemas/getTokensByContractProduct.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const Joi = require('joi');

module.exports = () => ({
fromToken: Joi.string(),
toToken: Joi.string(),
limit: Joi.number(),
forSale: Joi.any()
.valid('true', 'false'),
Expand Down
2 changes: 2 additions & 0 deletions rair-node/bin/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const {
userAddress,
resaleFlag,
metadataSearch,
tokenLimits,
} = require('./commonApiSchemas');
const {
fullContracts,
Expand Down Expand Up @@ -137,6 +138,7 @@ module.exports = {
userAddress,
resaleFlag,
metadataSearch,
tokenLimits,

// Contract schemas
fullContracts,
Expand Down

0 comments on commit 76cf748

Please sign in to comment.