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 api new #45

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
2e0ea11
:zap: Update: Updated the feature of getting the listed nft
cryptodev0115 Nov 9, 2022
3b33b41
:zap: Update: Updated the assist url for getting the owned list nft
cryptodev0115 Nov 9, 2022
0be2e41
:zap: Update: Updated the package on npmjs
cryptodev0115 Nov 9, 2022
2a2a0d3
:zap: Update: Updated the apis for new assist service
cryptodev0115 Nov 10, 2022
4bad397
:bug: Fix: Fixed the issue of getting the buyoutPrice and reservePrice
cryptodev0115 Nov 10, 2022
67483e1
:bug: Fix: Fixed an issue of elastos sdk on sample project
cryptodev0115 Nov 10, 2022
d471969
:bug: Fix: Fixed an issue of parsing the nft information
cryptodev0115 Nov 10, 2022
2b99f86
:zap: Update: Updated the feature of getting item information
cryptodev0115 Nov 14, 2022
9c6a07b
:zap: Update: Updated the feature of parsing the nft information
cryptodev0115 Nov 14, 2022
3b3f2f3
:zap: Update: Updated the feature of parsing the collection information
cryptodev0115 Nov 14, 2022
e555603
:sparkles: Implement: Implemented the function of parsing the collection
cryptodev0115 Nov 14, 2022
5457a8d
:zap: Update: Updated the feature of getting the collection information
cryptodev0115 Nov 14, 2022
d687308
:sparkles: Implement: Implemented the some features on collection
cryptodev0115 Nov 14, 2022
8f1f731
:zap: Update: Updated the feature of parsing the collection information
cryptodev0115 Nov 15, 2022
702e136
Merge branch 'main' into feat-api-new
cryptodev0115 Nov 15, 2022
7db72ba
:zap: Update: Updated the package version
cryptodev0115 Nov 15, 2022
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crypto-dev/pasar-sdk-development",
"version": "0.0.16",
"version": "0.0.21",
"description": "PasarProtocol NFT Marketplace SDK",
"exports": {
"node": "./dist/pasar-sdk.browser.js",
Expand Down
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@crypto-dev/pasar-sdk-development": "0.0.16",
"@crypto-dev/pasar-sdk-development": "0.0.20",
"@elastosfoundation/elastos-connectivity-sdk-js": "^1.0.23",
"@ethersproject/providers": "^5.5.2",
"@testing-library/react": "^13.3.0",
Expand Down
71 changes: 33 additions & 38 deletions src/assistservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,16 @@ const getAllListedItems = async (assistUrl: string, earilerThan:number, pageNum

const getCollectionInfo = async (assistUrl: string, collectionAddr:string, chainType: ChainType): Promise<CollectionInfo> => {
try {
let response = await fetch(`${assistUrl}/api/v1/getCollectionsByWalletAddr?chain=all&walletAddr=${collectionAddr}`);
let response = await fetch(`${assistUrl}/api/v1/getCollectionInfo?chain=${chainType}&collection=${collectionAddr}`);
let json = await response.json();
if (json['status'] != 200) {
throw new Error("Call API to fetch collection info failed");
}

let body = json['data'];
let data = body['tokenJson']['data'];

let info = new CollectionInfo(
body['token'],
chainType,
body['creatorDid'],
body['owner'],
body['name'],
body['symbol']
);

return info.setSocialLinks(data['socials'])
.setDescription(data['description'])
.setAvatar(data['avatar'])
.setDescription(data['description'])
.setCategory(data['category'])
.setErcType(body['is721'] ? ERCType.ERC721 : ERCType.ERC1155)

let collectionInfo = parseCollectionInfo(body);
return collectionInfo;
}catch (error) {
throw new Error(`Failed to get Collection Info (erro: ${error}`);
}
Expand Down Expand Up @@ -86,26 +72,7 @@ const getOwnedCollections = async (assistUrl: string, walletAddress: string): Pr
let body = data['data'];

for (var i = 0; i < body.length; i++) {
let item = body[i];
let creator = item['creator'];
let data = item['data'];

let info = new CollectionInfo(
item['token'],
item['chain'],
creator && creator['did'] ? creator['did'] : null,
item['owner'],
item['name'],
item['symbol']
);

info.setSocialLinks(data && data['socials'] ? data['socials'] : null)
.setDescription(data && data['description'] ? data['description'] : null)
.setAvatar(data && data['avatar'] ? data['avatar'] : null)
.setBanner(data && data['background'] ? data['background'] : null)
.setCategory(data && data['category'] ? data['category'] : null)
.setErcType(item['is721'] ? ERCType.ERC721 : ERCType.ERC1155)

let info = parseCollectionInfo(body[i]);
collections.push(info);
}

Expand All @@ -115,6 +82,34 @@ const getOwnedCollections = async (assistUrl: string, walletAddress: string): Pr
}
}

const parseCollectionInfo = (itemInfo: any): CollectionInfo => {
let creator = itemInfo['creator'];
let data = itemInfo['data'];

let collectionInfo = new CollectionInfo(
itemInfo['token'],
itemInfo['chain'],
creator && creator['did'] ? creator['did'] : null,
itemInfo['owner'],
itemInfo['name'],
itemInfo['symbol']
);

collectionInfo.setSocialLinks(data && data['socials'] ? data['socials'] : null)
.setDescription(data && data['description'] ? data['description'] : null)
.setAvatar(data && data['avatar'] ? data['avatar'] : null)
.setBanner(data && data['background'] ? data['background'] : null)
.setCategory(data && data['category'] ? data['category'] : null)
.setErcType(itemInfo['is721'] ? ERCType.ERC721 : ERCType.ERC1155)
.setUri(itemInfo['uri'])
.setItems(itemInfo['items'])
.setOwners(itemInfo['owners'])
.setLowestPrice(itemInfo['lowestPrice'])
.setTradingVolume(itemInfo['tradeVolume'])

return collectionInfo;
}

const getItemInfo = (itemInfo:any):ItemInfo => {
let tokenData = itemInfo['token'] ? itemInfo['token'] : itemInfo;
let image = tokenData['image'] ? tokenData['image'] : tokenData['data'] && tokenData['data']['image'] ? tokenData['data']['image'] : null;
Expand Down
50 changes: 50 additions & 0 deletions src/collection/collectioninfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class CollectionInfo {
private description: string;
private ercType: ERCType;
private category: Category;
private uri: string;
private items: number;
private owners: number;
private lowestPrice: bigint;
private tradingVolume: bigint;

constructor(contractAddr: string,
network: ChainType,
Expand Down Expand Up @@ -63,6 +68,31 @@ class CollectionInfo {
return this;
}

public setUri(uri: string): CollectionInfo {
this.uri = uri;
return this;
}

public setItems(items: number): CollectionInfo {
this.items = items;
return this;
}

public setOwners(owners: number): CollectionInfo {
this.owners = owners;
return this;
}

public setLowestPrice(price: bigint): CollectionInfo {
this.lowestPrice = price;
return this;
}

public setTradingVolume(value: bigint): CollectionInfo {
this.tradingVolume = value;
return this;
}

public getContractAddress(): string {
return this.constractAddr;
}
Expand Down Expand Up @@ -110,6 +140,26 @@ class CollectionInfo {
public getCategory(): string {
return this.category;
}

public getUri(): string {
return this.uri;
}

public getOwners(): number {
return this.owners;
}

public getItems(): number {
return this.items;
}

public getLowestPrice(): bigint {
return this.lowestPrice;
}

public getTradingVolume(): bigint {
return this.tradingVolume;
}
}

export {
Expand Down