Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #258 from capsule-corp-ternoa/testnet
Browse files Browse the repository at this point in the history
Testnet
  • Loading branch information
Leouarz authored Dec 6, 2021
2 parents 82a990a + 7d06019 commit 70d356a
Show file tree
Hide file tree
Showing 157 changed files with 9,614 additions and 4,478 deletions.
13 changes: 13 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": ["next/babel"],
"plugins": [
[
"styled-components",
{
"ssr": true,
"displayName": true,
"preprocess": false
}
]
]
}
17 changes: 0 additions & 17 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,3 @@

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

# Type of change

- [ ] Bug fix
- [ ] Design fix
- [ ] New feature
- [ ] Existing feature update
- [ ] Enhancement

# Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings (`npm run eslint`)
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes (`npm run test`)
11 changes: 11 additions & 0 deletions actions/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { CategoryType } from "interfaces";
import { NODE_API_URL } from "utils/constant";

export const getCategories = async (codes?: string[]) => {
const filter: any = {}
if (codes) filter.codes = codes
const res = await fetch(`${NODE_API_URL}/api/categories/?filter=${JSON.stringify(filter)}`);
if (!res.ok) throw new Error();
let result = await res.json() as CategoryType[];
return result;
};
62 changes: 34 additions & 28 deletions actions/follower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,50 @@ import { NODE_API_URL } from "utils/constant";
import { DEFAULT_LIMIT_PAGINATION } from "../utils/constant";
import Cookies from 'js-cookie';

export const getFollowers = async (walletId: string, page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, searchText?: string, certifiedOnly?: string) => {
const query = `${searchText ? `&nameOrAddressSearch=${searchText}`: ""}${certifiedOnly ? `&certifiedOnly=${certifiedOnly}` : ""}`
const res = await fetch(`${NODE_API_URL}/api/follow/followers/${walletId}?page=${page}&limit=${limit}${query}`);
export const getFollowers = async (walletId: string, page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, searchText?: string, verified?: boolean) => {
const pagination = {page, limit}
const filter: any = {}
if (searchText) filter.searchText = searchText
if (verified !== undefined) filter.verified = verified
const res = await fetch(`${NODE_API_URL}/api/follow/followers/${walletId}?pagination=${JSON.stringify(pagination)}&filter=${JSON.stringify(filter)}`);
if (!res.ok) throw new Error();
let result = await res.json() as CustomResponse<UserType>;
return result;
};

export const getFollowed = async (walletId: string, page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, searchText?: string, certifiedOnly?: string) => {
const query = `${searchText ? `&nameOrAddressSearch=${searchText}`: ""}${certifiedOnly ? `&certifiedOnly=${certifiedOnly}` : ""}`
const res = await fetch(`${NODE_API_URL}/api/follow/followed/${walletId}?page=${page}&limit=${limit}${query}`);
export const getFollowed = async (walletId: string, page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, searchText?: string, verified?: boolean) => {
const pagination = {page, limit}
const filter: any = {}
if (searchText) filter.searchText = searchText
if (verified !== undefined) filter.verified = verified
const res = await fetch(`${NODE_API_URL}/api/follow/followed/${walletId}?pagination=${JSON.stringify(pagination)}&filter=${JSON.stringify(filter)}`);
if (!res.ok) throw new Error();
let result = await res.json() as CustomResponse<UserType>;
return result;
};

export const getFollowersCount = async (walletId: string) => {
const res = await fetch(`${NODE_API_URL}/api/follow/countFollowers/${walletId}`);
if (!res.ok) throw new Error();
let result = await res.json() as number;
return result;
};

export const getFollowedCount = async (walletId: string) => {
const res = await fetch(`${NODE_API_URL}/api/follow/countFollowed/${walletId}`);
if (!res.ok) throw new Error();
let result = await res.json() as number;
return result;
};

export const isUserFollowing = async (walletIdFollowed: string, walletIdFollower: string) => {
const queryString = `?walletIdFollowed=${walletIdFollowed}&walletIdFollower=${walletIdFollower}`
const res = await fetch(`${NODE_API_URL}/api/follow/isUserFollowing/${queryString}`);
if (!res.ok) throw new Error();
let data: {isFollowing: boolean} = await res.json();
return data;
};

export const follow = async (walletIdFollowed: string, walletIdFollower: string) => {
const cookie = Cookies.get("token")
const queryString = `?walletIdFollowed=${walletIdFollowed}&walletIdFollower=${walletIdFollower}`
Expand Down Expand Up @@ -49,26 +77,4 @@ export const unfollow = async (walletIdFollowed: string, walletIdFollower: strin
}else{
throw new Error("Unvalid authentication");
}
};

export const isUserFollowing = async (walletIdFollowed: string, walletIdFollower: string) => {
const queryString = `?walletIdFollowed=${walletIdFollowed}&walletIdFollower=${walletIdFollower}`
const res = await fetch(`${NODE_API_URL}/api/follow/isUserFollowing/${queryString}`);
if (!res.ok) throw new Error();
let data: {isFollowing: boolean} = await res.json();
return data;
};

export const getFollowersCount = async (walletId: string) => {
const res = await fetch(`${NODE_API_URL}/api/follow/countFollowers/${walletId}`);
if (!res.ok) throw new Error();
let result = await res.json() as number;
return result;
};

export const getFollowedCount = async (walletId: string) => {
const res = await fetch(`${NODE_API_URL}/api/follow/countFollowed/${walletId}`);
if (!res.ok) throw new Error();
let result = await res.json() as number;
return result;
};
90 changes: 78 additions & 12 deletions actions/nft.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
import { CustomResponse, NftType } from 'interfaces/index';
import { MARKETPLACE_ID, NODE_API_URL } from 'utils/constant';
import { envStringToCondition } from '../utils/strings'
import { encryptCookie } from 'utils/cookie';
import { DEFAULT_LIMIT_PAGINATION } from "../utils/constant";

export const filterNFTs = (data: NftType[]) => data.filter((item) => item.creatorData && item.ownerData && item.media && envStringToCondition(Number(item.id)))
export const filterNFTs = (data: NftType[]) => data.filter((item) => item.properties?.preview.ipfs)

export const getOwnedNFTS = async (id: string, onlyFromMpId: boolean, listed? :number, page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, noSeriesData: boolean = false) => {
const res = await fetch(`${NODE_API_URL}/api/NFTs/owner/${id}?page=${page}&limit=${limit}${listed!==undefined ? `&listed=${listed}` : ""}${onlyFromMpId ? `&marketplaceId=${MARKETPLACE_ID}` : ""}&noSeriesData=${noSeriesData}`);
export const getOwnedNFTS = async (id: string, onlyFromMpId: boolean, listed? :boolean, page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, noSeriesData: boolean = false, nftIdsFilter: string[] = []) => {
const paginationOptions = {page, limit}
const filterOptions: any = {owner: id, noSeriesData}
if (listed !== undefined) filterOptions.listed = listed
if (onlyFromMpId) filterOptions.marketplaceId = MARKETPLACE_ID
if (nftIdsFilter.length > 0) filterOptions.ids = nftIdsFilter
const sortOptions = "created_at:desc"
const res = await fetch(`${NODE_API_URL}/api/NFTs/?pagination=${JSON.stringify(paginationOptions)}&filter=${JSON.stringify(filterOptions)}&sort=${sortOptions}`);
if (!res.ok) throw new Error('error fetching owned NFTs');
let result: CustomResponse<NftType> = await res.json();
result.data = filterNFTs(result.data)
return result;
};

export const getCreatorNFTS = async (id: string, page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, noSeriesData: boolean = false) => {
const paginationOptions = {page, limit}
const filterOptions: any = {creator: id, noSeriesData}
const res = await fetch(
`${NODE_API_URL}/api/NFTs/creator/${id}?page=${page}&limit=${limit}&noSeriesData=${noSeriesData}`
`${NODE_API_URL}/api/NFTs/?pagination=${JSON.stringify(paginationOptions)}&filter=${JSON.stringify(filterOptions)}`
);
if (!res.ok) throw new Error('error fetching created NFTs');
let result: CustomResponse<NftType> = await res.json();
result.data = filterNFTs(result.data)
return result;
};

export const getCategoryNFTs = async (codes?: string | string[], page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, noSeriesData: boolean = false) => {
const queryString = !codes ? "" : (typeof codes==='string' ? `&codes=${codes}` : `&codes=${codes.join("&codes=")}`)
export const getNFTs = async (codes?: string[], page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, noSeriesData: boolean = false, listed? :Boolean) => {
const paginationOptions = {page, limit}
const filterOptions: any = {noSeriesData, marketplaceId: MARKETPLACE_ID}
if (codes) filterOptions.categories = codes
if (listed !== undefined) filterOptions.listed = listed
const res = await fetch(
`${NODE_API_URL}/api/NFTs/category/?marketplaceId=${MARKETPLACE_ID}&listed=1&page=${page}&limit=${limit}&noSeriesData=${noSeriesData}${queryString}`
`${NODE_API_URL}/api/NFTs/?pagination=${JSON.stringify(paginationOptions)}&filter=${JSON.stringify(filterOptions)}`
);
if (!res.ok) throw new Error('error fetching NFTs by categories');
let result: CustomResponse<NftType> = await res.json();
Expand All @@ -35,13 +46,39 @@ export const getCategoryNFTs = async (codes?: string | string[], page: string="1
};

export const getNFT = async (id: string, incViews: boolean = false, viewerWalletId: string | null = null, ip?: string, noSeriesData: boolean = false, marketplaceId?: string) => {
const res = await fetch(`${NODE_API_URL}/api/NFTs/${id}?incViews=${incViews}&viewerWalletId=${viewerWalletId}&viewerIp=${ip}&noSeriesData=${noSeriesData}${marketplaceId ? `&marketplaceId=${marketplaceId}` : ""}`);
const filterOptions: any = {noSeriesData, marketplaceId}
const res = await fetch(`${NODE_API_URL}/api/NFTs/${id}?filter=${JSON.stringify(filterOptions)}&incViews=${incViews}&viewerWalletId=${viewerWalletId}&viewerIp=${ip}`);
if (!res.ok) throw new Error('error fetching NFT');
let data: NftType = await res.json();
if (!data.creatorData || !data.ownerData || !data.media) throw new Error();
if (!data.properties?.preview.ipfs) throw new Error();
return data;
};

export const getLikedNFTs = async (walletId: string, page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, noSeriesData: boolean = false) => {
const paginationOptions = {page, limit}
const filterOptions: any = {liked: walletId, noSeriesData}
const res = await fetch(
`${NODE_API_URL}/api/NFTs/?pagination=${JSON.stringify(paginationOptions)}&filter=${JSON.stringify(filterOptions)}`
);
if (!res.ok) throw new Error();
let result: CustomResponse<NftType> = await res.json();
result.data = filterNFTs(result.data)
return result;
}

export const getByTheSameArtistNFTs = async (walletId: string, page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, noSeriesData: boolean = false) => {
const paginationOptions = {page, limit}
const filterOptions: any = {creator: walletId, noSeriesData}
const sortOptions: string = "created_at:desc"
const res = await fetch(
`${NODE_API_URL}/api/NFTs/?pagination=${JSON.stringify(paginationOptions)}&filter=${JSON.stringify(filterOptions)}&sort=${sortOptions}`
);
if (!res.ok) throw new Error();
let result: CustomResponse<NftType> = await res.json();
result.data = filterNFTs(result.data)
return result;
}

export const getUserNFTsStat = async (id: string, onlyFromMpId: boolean): Promise<{
countOwned: number,
countOwnedListed: number,
Expand All @@ -50,8 +87,37 @@ export const getUserNFTsStat = async (id: string, onlyFromMpId: boolean): Promis
countFollowers: number,
countFollowed: number
}> => {
const res = await fetch(`${NODE_API_URL}/api/NFTs/stat/${id}${onlyFromMpId ? `?marketplaceId=${MARKETPLACE_ID}` : ""}`);
const filterOptions: any = {}
if (onlyFromMpId) filterOptions.marketplaceId = MARKETPLACE_ID
const res = await fetch(`${NODE_API_URL}/api/NFTs/stat/${id}?filter=${JSON.stringify(filterOptions)}`);
if (!res.ok) throw new Error('error fetching user NFTs stat');
let result = await res.json()
return result;
};
};

export const getHistory = async (nftId: string, seriesId: string, grouped: boolean=false) => {
const sortOptions: string = "timestamp:desc"
const filterOptions: any = {grouped: grouped}
const res = await fetch(`${NODE_API_URL}/api/nfts/history/${seriesId}/${nftId}?sort=${sortOptions}&filter=${JSON.stringify(filterOptions)}`);
if (!res.ok) throw new Error('error fetching NFT history');
let result = await res.json()
return result;
}

export const canAddToSeries = async (seriesId: string, walletId: string) => {
const res = await fetch(`${NODE_API_URL}/api/nfts/series/can-add?seriesId=${seriesId}&walletId=${walletId}`)
if (!res.ok) throw new Error('error getting information about this series for this user');
let result = await res.json()
return result as boolean
}

export const addNFTsToCategories = async (creator: string, chainIds: string[], categories: string[]) => {
const nftsAuthToken = encryptCookie(`${creator},${chainIds.join('-')},${categories.join('-')}`)
const res = await fetch(`${NODE_API_URL}/api/nfts/add-nfts-categories`, {
method: 'POST',
body:JSON.stringify({creator, chainIds, categories, nftsAuthToken}),
});
if (!res.ok) throw new Error();
let success: boolean = await res.json();
return success
}
33 changes: 10 additions & 23 deletions actions/user.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { CustomResponse, NftType, UserType } from 'interfaces/index';
import { filterNFTs } from "./nft";
import { CustomResponse, UserType } from 'interfaces/index';
import { DEFAULT_LIMIT_PAGINATION, NODE_API_URL } from "../utils/constant";
import Cookies from 'js-cookie';

export const getUser = async (token: string) => {
export const getUser = async (token: string, ignoreCache=false) => {
const res = await fetch(
`${NODE_API_URL}/api/users/${token}`
`${NODE_API_URL}/api/users/${token}?ignoreCache=${ignoreCache}`
);

if (!res.ok) throw new Error();
Expand Down Expand Up @@ -43,17 +42,13 @@ export const getAccountBalance = async (id: string) => {
return data.capsAmout;
};

export const getUsers = async () => {
const res = await fetch(`${NODE_API_URL}/api/users`);
if (!res.ok) throw new Error();
const response: CustomResponse<UserType> = await res.json();
return response;
};

export const getUsersByWalletIds = async (walletIds: string[]) => {
if (walletIds.length === 0) return {totalCount:0, data:[]}
const query = `?walletIds=${walletIds.join("&walletIds=")}`
const res = await fetch(`${NODE_API_URL}/api/users/getUsers${query}`);
export const getUsers = async (walletIds?: string[], artist?: boolean, verified?: boolean, page: string = "1", limit: string = DEFAULT_LIMIT_PAGINATION) => {
const paginationOptions = {page, limit}
const filter:any = {}
if (walletIds) filter.walletIds = walletIds
if (artist !== undefined) filter.artist = artist
if (verified !== undefined) filter.verified = verified
const res = await fetch(`${NODE_API_URL}/api/users/?filter=${JSON.stringify(filter)}&pagination=${JSON.stringify(paginationOptions)}`);
if (!res.ok) throw new Error();
const response: CustomResponse<UserType> = await res.json();
return response;
Expand Down Expand Up @@ -103,11 +98,3 @@ export const unlikeNFT = async (walletId: string, nftId: string, serieId: string
throw new Error("Unvalid authentication");
}
}

export const getLikedNFTs = async (walletId: string, page: string="1", limit: string=DEFAULT_LIMIT_PAGINATION, noSeriesData: boolean = false) => {
const res = await fetch(`${NODE_API_URL}/api/users/${walletId}/liked?page=${page}&limit=${limit}&noSeriesData=${noSeriesData}`)
if (!res.ok) throw new Error();
let result: CustomResponse<NftType> = await res.json();
result.data = filterNFTs(result.data)
return result;
}
Loading

1 comment on commit 70d356a

@vercel
Copy link

@vercel vercel bot commented on 70d356a Dec 6, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.