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][573] fix query search non-fungible-tokens list #3518

Merged
merged 1 commit into from
Jun 13, 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
36 changes: 18 additions & 18 deletions src/app/core/services/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,27 @@ export class TokenService extends CommonService {
.pipe(map((res) => (res?.data ? res?.data[this.envDB] : null)));
}

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: {_in: ${address} }}}]}`;
}

let querySort = `, order_by: [{${payload.sort_column}: ${payload.sort_order}}, {id: desc}]`;
getListErc721Token(payload, textSearch: string = null, addressIn: string[] = []): Observable<any> {
let querySort = `order_by: [{erc721_stat: {${payload.sort_column}: ${payload.sort_order}_nulls_last}}, {id: desc}]`;
let queryWhere = `where: {_or: [{address: {_in: $addressIn}}, {name: {_ilike: "%${textSearch}%"}}]}`;
const operationsDoc = `
query queryListErc721($limit: Int = 10, $offset: Int = 0) {
query queryListErc721($limit: Int = 10, $offset: Int = 0, $addressIn: [String!] = null) {
${this.envDB} {
list_token: erc721_stats(limit: $limit, offset: $offset ${querySort}, where: { ${queryUpdate} }) {
transfer_24h
total_activity
erc721_contract {
name
symbol
evm_smart_contract {
address
}
list_token: erc721_contract(
limit: $limit
offset: $offset
${querySort}
${queryWhere}
) {
address
name
symbol
erc721_stat {
total_activity
transfer_24h
}
}
total_token: erc721_stats_aggregate (where: { ${queryUpdate} }) {
total_token: erc721_contract_aggregate (${queryWhere}) {
aggregate {
count
}
Expand All @@ -176,6 +175,7 @@ export class TokenService extends CommonService {
variables: {
limit: payload.limit || 20,
offset: payload.offset || 0,
addressIn: addressIn,
},
operationName: 'queryListErc721',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,11 @@ <h1 class="mb-0 text--white">Non-Fungible Tokens (NFT)</h1>
<div class="d-flex">
<div>
<a
[routerLink]="[
'/token',
element.cw721_contract?.smart_contract?.address ||
element?.erc721_contract?.evm_smart_contract?.address
]"
[routerLink]="['/token', element.cw721_contract?.smart_contract?.address || element?.address]"
class="text--primary text-nowrap">
{{ element.cw721_contract?.name || element.erc721_contract?.name | ellipsis: 30 }}
<span *ngIf="element.cw721_contract?.symbol || element.erc721_contract?.symbol"
>({{ element.cw721_contract?.symbol || element.erc721_contract?.symbol | ellipsis: 10 }})</span
{{ element.cw721_contract?.name || element?.name | ellipsis: 30 }}
<span *ngIf="element.cw721_contract?.symbol || element?.symbol"
>({{ element.cw721_contract?.symbol || element?.symbol | ellipsis: 10 }})</span
>
</a>
<div class="body-02 fw-normal caption-mob mb-0 text--gray-6 pr-5 desc">
Expand All @@ -114,33 +110,28 @@ <h1 class="mb-0 text--white">Non-Fungible Tokens (NFT)</h1>
<th mat-header-cell *matHeaderCellDef>Contract</th>
<td mat-cell *matCellDef="let element" class="vertical-align-top py-4">
<app-name-tag
[value]="
element.cw721_contract?.smart_contract?.address ||
element.erc721_contract?.evm_smart_contract?.address | beautyAddress
"
[iconContract]="
element.cw721_contract?.smart_contract?.address ||
element.erc721_contract?.evm_smart_contract?.address
"
[value]="element.cw721_contract?.smart_contract?.address || element.address | beautyAddress"
[iconContract]="element.cw721_contract?.smart_contract?.address || element?.address"
[linkRouter]="[
element.cw721_contract ? '/contracts' : '/evm-contracts',
element.cw721_contract?.smart_contract?.address ||
element.erc721_contract?.evm_smart_contract?.address
element.cw721_contract?.smart_contract?.address || element?.address
]">
</app-name-tag>
</td>
</ng-container>
<ng-container matColumnDef="total_activity">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Total Activities</th>
<td mat-cell *matCellDef="let element" class="vertical-align-top py-4">
{{ element.total_activity | number }}
<ng-container *ngIf="element.total_activity || element?.erc721_stat?.total_activity; else noData">
{{ element.total_activity || element?.erc721_stat?.total_activity | number }}
</ng-container>
</td>
</ng-container>
<ng-container matColumnDef="transfer_24h">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Transfers (24H)</th>
<td mat-cell *matCellDef="let element" class="vertical-align-top py-4">
<ng-container *ngIf="element.transfer_24h; else noData">
{{ element.transfer_24h | number }}
<ng-container *ngIf="element.transfer_24h || element?.erc721_stat?.transfer_24h; else noData">
{{ element.transfer_24h || element?.erc721_stat?.transfer_24h | number }}
</ng-container>
</td>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ export class NonFungibleTokensComponent implements OnInit {

if (this.filterBy === 'ERC721') {
const listAddress = this.nameTagService.findAddressListByNameTag(keySearch, this.filterBy === 'ERC721');
let tagAddress = `["${keySearch}"]`;
let addressIn = [];
if (keySearch.length > 0) {
addressIn.push(keySearch);
}
if (listAddress?.length > 0) {
tagAddress = '';
listAddress.forEach((addr) => {
tagAddress += `"${addr}",`;
addressIn.push(addr);
});
tagAddress = `[${tagAddress}"${keySearch}"]`;
}
this.tokenService.getListErc721Token(payload, keySearch, tagAddress).subscribe({
this.tokenService.getListErc721Token(payload, keySearch, addressIn).subscribe({
next: (res) => {
this.dataSource = new MatTableDataSource<any>(res.list_token);
this.pageData.length = res.total_token?.aggregate?.count;
Expand Down