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

[FeatFix] fix search non fungible tokens erc721 #3448

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions src/app/core/services/name-tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ export class NameTagService extends CommonService {
return address;
}

findAddressListByNameTag(nameTag: string, findEvmAddr = false) {
if (!nameTag) {
return [];
}

const userEmail = this.userService.getCurrentUser()?.email;
let listAddress: string[] = [];
if (this.listNameTag?.length > 0) {
if (userEmail) {
const tag = this.listNameTag?.find((k) => k.name_tag_private?.trim() === nameTag?.trim());
if (tag) {
listAddress.push(findEvmAddr ? tag?.evm_address : tag?.address);
}
}
const tag = this.listNameTag?.find((k) => k.name_tag?.trim() === nameTag?.trim());
if (tag) {
listAddress.push(findEvmAddr ? tag?.evm_address : tag?.address);
}
}
return listAddress;
}

findUrlByAddress(address: string) {
let result = '';
const nameTag = this.findNameTag(address);
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/services/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ export class TokenService extends CommonService {
.pipe(map((res) => (res?.data ? res?.data[this.envDB] : null)));
}

getListErc721Token(payload, textSearch: string = null): Observable<any> {
getListErc721Token(payload, textSearch: string = null, address: string = null): Observable<any> {
let queryUpdate = '';
if (textSearch?.length > 0) {
queryUpdate = `erc721_contract: { _or: [{name: {_ilike: "%${textSearch}%"}} , {evm_smart_contract: {address: {_eq: "${textSearch}" }}}]}`;
queryUpdate = `erc721_contract: { _or: [{name: {_ilike: "%${textSearch}%"}} , {evm_smart_contract: {address: {_in: ${address} }}}]}`;
}

let querySort = `, order_by: [{${payload.sort_column}: ${payload.sort_order}}, {id: desc}]`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,18 @@ export class NonFungibleTokensComponent implements OnInit {
};

let keySearch = this.textSearch;
const addressNameTag = this.nameTagService.findAddressByNameTag(keySearch, this.filterBy === 'ERC721');

if (addressNameTag?.length > 0) {
keySearch = addressNameTag;
}

if (this.filterBy === 'ERC721') {
this.tokenService.getListErc721Token(payload, keySearch).subscribe({
const listAddress = this.nameTagService.findAddressListByNameTag(keySearch, this.filterBy === 'ERC721');
let tagAddress = '[]';
if (listAddress?.length > 0) {
tagAddress = '';
listAddress.forEach((addr) => {
tagAddress += `"${addr}",`;
});
tagAddress = `[${tagAddress}]`;
}
this.tokenService.getListErc721Token(payload, keySearch, tagAddress).subscribe({
next: (res) => {
this.dataSource = new MatTableDataSource<any>(res.list_token);
this.pageData.length = res.total_token?.aggregate?.count;
Expand All @@ -104,6 +108,11 @@ export class NonFungibleTokensComponent implements OnInit {
},
});
} else if (this.filterBy === 'CW721') {
const addressNameTag = this.nameTagService.findAddressByNameTag(keySearch);

if (addressNameTag?.length > 0) {
keySearch = addressNameTag;
}
this.tokenService.getListCW721Token(payload, keySearch).subscribe({
next: (res) => {
this.dataSource = new MatTableDataSource<any>(res.list_token);
Expand Down