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-fix][Erc721] - fix show icon contract for tranfers tab, fix con… #3389

Merged
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
21 changes: 21 additions & 0 deletions src/app/core/services/contract.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ export class ContractService extends CommonService {
.pipe(map((res) => (res?.data ? res?.data[this.envDB] : null)));
}

findEvmContractList(listAddr: string[]) {
const operationsDoc = `
query findEvmContractList($listAddress: [String!] = null) {
${this.envDB} {
evm_smart_contract(where: {address: {_in: $listAddress}}, limit: 40, offset: 0) {
address
}
}
}
`;
return this.http
.post<any>(this.graphUrl, {
query: operationsDoc,
variables: {
listAddress: listAddr.map(i=> i?.toLowerCase())
},
operationName: 'findEvmContractList',
})
.pipe(map((res) => (res?.data ? res?.data[this.envDB] : null)));
}

loadContractDetail(contractAddress): Observable<any> {
const contractDoc = `
query queryContractDetail($contractAddress: String = null) {
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/services/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,10 @@ export class TokenService extends CommonService {
.post<any>(this.graphUrl, {
query: operationsDoc,
variables: {
contractAddress: payload.contractAddr,
contractAddress: payload.contractAddr?.toLowerCase(),
actionNotIn: queryActionNotIn,
sender: payload.sender,
receiver: payload.receiver,
sender: payload.sender?.toLowerCase(),
receiver: payload.receiver?.toLowerCase(),
tokenId: payload.tokenId,
idLte: payload.idLte,
txHash: payload.txHash,
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/evm-contracts/evm-contracts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import { PopupProxyContractComponent } from './evm-proxy-contracts-verify/popup-
ContractTableModule,
NgbNavModule,
],
exports: [EvmReadComponent, EvmWriteComponent],
exports: [EvmReadComponent, EvmWriteComponent, EvmContractComponent],
providers: [provideEnvironmentNgxMask(MASK_CONFIG)],
})
export class EvmContractsModule {}
Original file line number Diff line number Diff line change
@@ -1,113 +1,7 @@
<app-loading-sprint class="mt-10" *ngIf="isLoading"></app-loading-sprint>
<div class="box-contract text-white" *ngIf="!isLoading">
<!-- Verify Fail -->
<ng-container *ngIf="contractCode">
<div class="d-flex break-word align-items-center">
<img
[src]="'assets/icons/icons-svg/color/info-circle.svg' | imageS3"
alt=""
width="16"
height="16"
class="mr-2" />
<div>
Are you the contract creator?
<a class="text--primary" [routerLink]="['/evm-contracts', contractAddress, 'verify']"> Verify and Publish </a>
your contract source code today!
</div>
</div>
<div class="d-flex break-word align-items-center mt-2">
<img
[src]="'assets/icons/icons-svg/color/info-circle.svg' | imageS3"
alt=""
width="16"
height="16"
class="mr-2" />
<div>
In case this is proxy contract, verify
<a class="text--primary" [routerLink]="['/evm-contracts', contractAddress, 'proxy-verify']">
Is this a proxy
</a>
or not?
</div>
</div>
<div
class="mt-3 content-info caption fw-normal"
*ngIf="contractCode"
[appExpandable]="contractCode"
[maxCharVisible]="900">
{{ contractCode }}
</div>
</ng-container>

<!-- Verify Successfull -->
<ng-container *ngIf="contractDetail && !contractCode">
<div class="button-tab-group mb-4 mt-lg-3">
<button
class="button-tab"
[class.active]="currentTab === contractType.ReadContract"
(click)="changeTab(contractType.ReadContract)">
<span>Read Contract</span>
</button>
<button
class="button-tab"
[class.active]="currentTab === contractType.WriteContract"
(click)="changeTab(contractType.WriteContract)">
<span>Write Contract</span>
</button>
</div>

<div class="mt-3">
<ng-container>
<app-evm-read
*ngIf="currentTab === contractType.ReadContract"
[abi]="contractDetail.abi"
[contractAddress]="contractAddress">
</app-evm-read>

<app-evm-write
*ngIf="currentTab === contractType.WriteContract"
[abi]="contractDetail.abi"
[contractAddress]="contractAddress">
</app-evm-write>

<ng-container
*ngIf="
isImplementationVerified &&
(currentTab === contractType.ReadProxy || currentTab === contractType.WriteProxy)
">
<div class="mb-6">
<div class="body-02 text--gray-1 fw-semibold mb-2">
ABI for the implementation contract at
<a
[routerLink]="['/evm-contracts', implementationContractAddress]"
class="text--primary body-02 fw-semibold">
{{ implementationContractAddress }}
</a>
</div>
<div class="body-02 text--gray-1" *ngIf="implementationContractDetail.previouslyRecordedContract">
Previously recorded to be on
<a
[routerLink]="['/evm-contracts', implementationContractDetail.previouslyRecordedContract]"
class="text--primary body-02">
{{ implementationContractDetail.previouslyRecordedContract }}
</a>
</div>
</div>
<app-evm-read
*ngIf="currentTab === contractType.ReadProxy"
[abi]="implementationContractDetail.abi"
[contractAddress]="contractAddress"
[isProxyContract]="true">
</app-evm-read>

<app-evm-write
*ngIf="currentTab === contractType.WriteProxy"
[abi]="implementationContractDetail.abi"
[contractAddress]="contractAddress"
[isProxyContract]="true">
</app-evm-write>
</ng-container>
</ng-container>
</div>
</ng-container>
<div class="mt-5">
<app-evm-contract [contractTypeData]="contractDetail?.status || 'UNVERIFIED'" [contractsAddress]="contractAddress">
</app-evm-contract>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { JsonFragment } from 'ethers';
import * as _ from 'lodash';
import { of, switchMap } from 'rxjs';
import { Subject, map, of, switchMap, takeUntil } from 'rxjs';
import { ContractVerifyType } from 'src/app/core/constants/contract.enum';
import { TokenContractType } from 'src/app/core/constants/token.enum';
import { ContractType } from 'src/app/core/constants/token.enum';
import { EnvironmentService } from 'src/app/core/data-services/environment.service';
import { ContractService } from 'src/app/core/services/contract.service';
import { getEthersProvider } from 'src/app/core/utils/ethers';
import { EWalletType } from '../../../../../core/constants/wallet.constant';
import local from '../../../../../core/utils/storage/local';
import { STORAGE_KEYS } from '../../../../../core/constants/common.constant';

@Component({
selector: 'app-evm-token-contract-tab',
Expand All @@ -15,12 +19,13 @@ import { getEthersProvider } from 'src/app/core/utils/ethers';
})
export class EvmTokenContractTabComponent implements OnInit {
@Input() contractAddress: string;
@Input() typeContract: string;
@Input() contractTypeData: string;

contractType = TokenContractType;
currentTab = this.contractType.ReadContract;
contractVerifyType = ContractVerifyType;
ContractType = ContractType;
ContractVerifyType = ContractVerifyType;
currentTab = this.ContractType.ReadContract;
isLoading = true;
isWatchList = false;

contractDetail;
contractCode;
Expand All @@ -33,15 +38,58 @@ export class EvmTokenContractTabComponent implements OnInit {
abi?: JsonFragment[];
};

contract$ = this.route.paramMap.pipe(
map((data) => {
return data.get('contractAddress');
}),
);
destroyed$ = new Subject<void>();

constructor(
private route: ActivatedRoute,
private contractService: ContractService,
private env: EnvironmentService,
) {}
) { }

ngOnInit(): void {
this.getContractDetail();
this.contract$
.pipe(
switchMap((ca) => {
if (!ca) {
return of(null);
}
this.contractAddress = ca;
return this.contractService.queryEvmContractByAddress(ca);
}),
takeUntil(this.destroyed$),
)
.subscribe((res) => {
this.isLoading = false;

if (res) {
const evm_contract_verification = _.get(res, 'evm_contract_verification[0]') || {};
const evm_smart_contract = _.get(res, 'evm_smart_contract[0]') || {};

const contractDetail = {
...evm_smart_contract,
...evm_contract_verification,
};
this.contractService.setContract(contractDetail);
}
});

this.contractService.contractObservable.pipe(takeUntil(this.destroyed$)).subscribe({
next: (res) => {
this.contractDetail = {
...res,
tx_hash: res.created_hash,
contract_hash: res.code_hash,
};
},
});
}


changeTab(tabId): void {
this.currentTab = tabId;
}
Expand All @@ -62,75 +110,5 @@ export class EvmTokenContractTabComponent implements OnInit {
});
}

getContractDetail() {
this.contractService.queryEvmContractByAddress(this.contractAddress).subscribe({
next: (res) => {
if (res) {
const evm_contract_verification = _.get(res, 'evm_contract_verification[0]');
const evm_smart_contract = _.get(res, 'evm_smart_contract[0]') || {};

if (!evm_contract_verification) {
this.getContractCode();
} else {
this.contractDetail = {
...evm_smart_contract,
...evm_contract_verification,
};

this.isLoading = false;
}
}
},
error: () => {
this.isLoading = false;
},
});
}

getProxyContractAbi(address) {
this.contractService
.getProxyContractAbi(address)
.pipe(
switchMap((e) => {
const proxyHistories = _.get(e, 'evm_smart_contract[0].evm_proxy_histories');

if (proxyHistories) {
this.implementationContractDetail = {
proxyContract: proxyHistories[0]?.proxy_contract,
implementationContract: proxyHistories[0]?.implementation_contract,
previouslyRecordedContract: proxyHistories[1]?.implementation_contract,
};

return this.contractService.queryEvmContractByAddress(
this.implementationContractDetail.implementationContract,
);
}

return of(null);
}),
)
.subscribe((res) => {
const abi = _.get(res, 'evm_contract_verification[0].abi');
if (abi) {
this.implementationContractDetail['abi'] = abi as JsonFragment[];
}
});
}

loadProxyContractDetail() {
this.contractService.loadProxyContractDetail(this.contractAddress).subscribe((res) => {
if (res.implementation_contract) {
this.implementationContractAddress = res.implementation_contract;
this.getListContractInfo([res.implementation_contract]);
}
});
}

getListContractInfo(address) {
this.contractService.getListContractInfo(address).subscribe((res) => {
if (res?.evm_contract_verification?.length > 0) {
this.isImplementationVerified = res.evm_contract_verification[0]?.status;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
[value]="data[template.matColumnDef]"
[linkRouter]="['/token', linkAddress]"
[linkParams]="{ a: data[template.matColumnDef] }"
[iconContract]="data[template.matColumnDef] | isContract"
[iconContract]="isEvmSmartContract(data[template.matColumnDef])"
[maxCharacter]="15">
</app-name-tag>
</ng-container>
Expand Down Expand Up @@ -139,7 +139,7 @@
<app-name-tag
*ngIf="data[template.matColumnDef]"
[value]="data[template.matColumnDef]"
[iconContract]="data[template.matColumnDef] | isContract"
[iconContract]="isEvmSmartContract(data[template.matColumnDef])"
[maxCharacter]="15"
[isEnableRouter]="!data[template.matColumnDef]?.startsWith('Null')"
[linkRouter]="['/token', linkAddress]"
Expand Down
Loading