Skip to content

Commit

Permalink
[FeatFix][Erc721] fix bug token detail nft tranfer tab (#3420)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamvb2391 committed May 23, 2024
1 parent d4f6951 commit 6c1d92b
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 46 deletions.
9 changes: 5 additions & 4 deletions src/app/core/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ export class UserService {
order_by: [{ id: desc }, {height: desc}]
limit: $limit
) {
data,
gas_used: gas
hash
height
Expand All @@ -478,18 +479,18 @@ export class UserService {
content
type
}
cw721_activities: erc721_activities(
erc721_activities(
where: { _or: [{ to: { _eq: $receiver } }, { from: { _eq: $sender } }] }
) {
action
from
to
sender
cw721_token: erc721_token {
erc721_token {
token_id
}
cw721_contract: erc721_contract {
smart_contract: evm_smart_contract {
erc721_contract {
evm_smart_contract {
address
}
}
Expand Down
38 changes: 25 additions & 13 deletions src/app/global/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,31 @@ export function convertDataAccountTransaction(data, coinInfo, modeQuery, coinDec
});
break;
case TabsAccountLink.NftTxs:
arrEvent = _.get(element, 'cw721_activities')?.map((item, index) => {
let { type, action } = getTypeTx(element);
let fromAddress = _.get(item, 'from') || NULL_ADDRESS;
let toAddress = _.get(item, 'to') || _.get(item, 'cw721_contract.smart_contract.address') || NULL_ADDRESS;
if (action === 'burn') {
toAddress = NULL_ADDRESS;
}

let contractAddress = _.get(item, 'cw721_contract.smart_contract.address');
let tokenId = _.get(item, 'cw721_token.token_id');
let eventAttr = element.event_attribute_index;
return { type, fromAddress, toAddress, tokenId, contractAddress, eventAttr };
});
if (element?.cw721_activities) {
arrEvent = _.get(element, 'cw721_activities')?.map((item) => {
let { type, action } = getTypeTx(element);
let fromAddress = _.get(item, 'from') || NULL_ADDRESS;
let toAddress = _.get(item, 'to') || _.get(item, 'cw721_contract.smart_contract.address') || NULL_ADDRESS;
if (action === 'burn') {
toAddress = NULL_ADDRESS;
}

let contractAddress = _.get(item, 'cw721_contract.smart_contract.address');
let tokenId = _.get(item, 'cw721_token.token_id');
let eventAttr = element.event_attribute_index;
return { type, fromAddress, toAddress, tokenId, contractAddress, eventAttr };
});
} else if (element?.erc721_activities) {
arrEvent = _.get(element, 'erc721_activities')?.map((item) => {
let fromAddress = _.get(item, 'from') || NULL_ADDRESS;
let toAddress =
_.get(item, 'to') || _.get(item, 'erc721_contract.evm_smart_contract.address') || NULL_ADDRESS;
type = element?.type;
let contractAddress = _.get(item, 'erc721_contract.evm_smart_contract.address');
let tokenId = _.get(item, 'erc721_token.token_id');
return { type, fromAddress, toAddress, tokenId, contractAddress, eventAttr };
});
}
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,19 @@
<div class="item-show d-flex justify-content-between align-items-center">
<app-name-tag
[value]="item.fromAddress || currentAddress"
[iconContract]="item.fromAddress || currentAddress | isContract"
[linkRouter]="[
(item.fromAddress || currentAddress | isContract) ? '/contracts' : '/address',
item.fromAddress || currentAddress
]"
[iconContract]="isEvmSmartContract(item.fromAddress || currentAddress)"
[linkRouter]="
nonFungibleTokenType === nftType.ERC721
? [
isEvmSmartContract(item.fromAddress || currentAddress)
? '/evm-contracts'
: '/address'
]
: [
(item.fromAddress || currentAddress | isContract) ? '/contracts' : '/address',
item.fromAddress || currentAddress
]
"
[isEnableRouter]="
!(item.fromAddress?.startsWith('Null') || currentAddress?.startsWith('Null')) &&
item.fromAddress !== currentAddress
Expand Down Expand Up @@ -560,11 +568,19 @@
<div [style]="'min-width: 148px'">
<app-name-tag
[value]="item.toAddress || currentAddress"
[linkRouter]="[
(item.toAddress || currentAddress | isContract) ? '/contracts' : '/address',
item.toAddress || currentAddress
]"
[iconContract]="item.toAddress || currentAddress | isContract"
[iconContract]="isEvmSmartContract(item.toAddress || currentAddress)"
[linkRouter]="
nonFungibleTokenType === nftType.ERC721
? [
isEvmSmartContract(item.toAddress || currentAddress)
? '/evm-contracts'
: '/address'
]
: [
(item.toAddress || currentAddress | isContract) ? '/contracts' : '/address',
item.toAddress || currentAddress
]
"
[isEnableRouter]="
!(item.toAddress?.startsWith('Null') || currentAddress?.startsWith('Null')) &&
item.toAddress !== currentAddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { balanceOf } from 'src/app/core/utils/common/parsing';
import local from 'src/app/core/utils/storage/local';
import { convertDataAccountTransaction, mappingMethodName } from 'src/app/global/global';
import { PaginatorComponent } from 'src/app/shared/components/paginator/paginator.component';
import { ContractService } from '../../../../core/services/contract.service';

@Component({
selector: 'app-account-transaction-table',
Expand All @@ -53,6 +54,7 @@ export class AccountTransactionTableComponent implements OnInit, OnDestroy {
displayFilter = false;
EFeature = EFeature;
denom = this.environmentService.chainInfo.currencies[0].coinDenom;
smartContractList: string[] = [];

templatesExecute: Array<TableTemplate> = [
{ matColumnDef: 'tx_hash', headerCellDef: 'Tx Hash', headerWidth: 18, cssClass: 'pt-3' },
Expand Down Expand Up @@ -146,6 +148,7 @@ export class AccountTransactionTableComponent implements OnInit, OnDestroy {
private router: Router,
private layout: BreakpointObserver,
private transactionService: TransactionService,
private contractService: ContractService,
) {}

ngOnInit(): void {
Expand Down Expand Up @@ -602,26 +605,70 @@ export class AccountTransactionTableComponent implements OnInit, OnDestroy {

getListNFTByAddress(payload) {
if (this.nonFungibleTokenType === ETokenNFTTypeBE.ERC721) {
this.userService.getListERC721ByAddress(payload).subscribe({
next: (data) => {
this.handleGetData(data);
},
error: (e) => {
if (e.name === TIMEOUT_ERROR) {
this.errTxt = e.message;
} else {
this.errTxt = e.status + ' ' + e.statusText;
}
this.transactionLoading = false;
},
complete: () => {
this.transactionLoading = false;
},
});
this.userService
.getListERC721ByAddress(payload)
.pipe(
switchMap((res) => {
const listTemp = res?.evm_transaction
?.filter((j) => j?.data?.length > 0)
?.map((k) => k?.data?.substring(0, 8));
const listMethodId = _.uniq(listTemp);
return this.transactionService.getListMappingName(listMethodId).pipe(
map((element) => {
if (res?.evm_transaction?.length > 0) {
return res?.evm_transaction.map((tx) => {
const methodId = _.get(tx, 'data')?.substring(0, 8);
return {
...tx,
type: mappingMethodName(element, methodId),
};
});
}
return [];
}),
);
}),
)
.pipe(
switchMap((res) => {
let listAddr = [];
res.forEach((element) => {
if (element?.erc721_activities?.[0]?.from) {
listAddr.push(element?.erc721_activities?.[0]?.from);
}
if (element?.erc721_activities?.[0]?.to) {
listAddr.push(element?.erc721_activities?.[0]?.to);
}
});
const listAddrUnique = _.uniq(listAddr);
return this.contractService.findEvmContractList(listAddrUnique).pipe(
map((r) => {
this.smartContractList = _.uniq((r?.evm_smart_contract || []).map((i) => i?.address));
return res;
}),
);
}),
)
.subscribe({
next: (data) => {
this.handleGetData({ evm_transaction: data });
},
error: (e) => {
if (e.name === TIMEOUT_ERROR) {
this.errTxt = e.message;
} else {
this.errTxt = e.status + ' ' + e.statusText;
}
this.transactionLoading = false;
},
complete: () => {
this.transactionLoading = false;
},
});
} else {
this.userService.getListCW721ByAddress(payload).subscribe({
next: (data) => {
this.handleGetData(data);
this.handleGetData({ data });
},
error: (e) => {
if (e.name === TIMEOUT_ERROR) {
Expand Down Expand Up @@ -690,6 +737,7 @@ export class AccountTransactionTableComponent implements OnInit, OnDestroy {
transaction_messages: [tx.transaction_messages],
timestamp: tx.transaction.timestamp,
}));

data.transaction = transactions;
}

Expand Down Expand Up @@ -890,4 +938,8 @@ export class AccountTransactionTableComponent implements OnInit, OnDestroy {
this.transactionLoading = true;
this.getTxsAddress();
}

isEvmSmartContract(addr) {
return this.smartContractList.filter((i) => i === addr).length > 0;
}
}
3 changes: 1 addition & 2 deletions src/app/pages/token/token-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ const canMatchFn: CanMatchFn = (route, segments) => {
if (!e) {
return true; // Default, Show No Data screen
}

const tr = router.createUrlTree(['/token', 'evm', e.type.toLowerCase(), address], {
const tr = router.createUrlTree(['/token', 'evm', e.type.toLowerCase(), address.toLowerCase()], {
queryParams: currentQueryParams ? { ...currentQueryParams } : {},
});

Expand Down

0 comments on commit 6c1d92b

Please sign in to comment.