Skip to content

Commit

Permalink
[FeatFix] fix search non fungible tokens erc721 (#3448)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamvb2391 authored May 30, 2024
1 parent af2e6e0 commit b9e87fb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
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

0 comments on commit b9e87fb

Please sign in to comment.