diff --git a/src/app/core/services/wallet.service.ts b/src/app/core/services/wallet.service.ts index 286a6beb3..8f86c4082 100644 --- a/src/app/core/services/wallet.service.ts +++ b/src/app/core/services/wallet.service.ts @@ -212,11 +212,10 @@ export class WalletService implements OnDestroy { } restoreEvmAccounts() { - let account = local.getItem(STORAGE_KEY.CURRENT_EVM_WALLET); + const account = local.getItem(STORAGE_KEY.CURRENT_EVM_WALLET); + if (!account) return; - if (account) { - this.connectEvmWallet().then().catch(); - } + this.walletAccount = account; } restoreAccounts() { @@ -249,17 +248,9 @@ export class WalletService implements OnDestroy { } evmChangeEvent() { - const reconnect = () => { - const timeoutId = setTimeout(() => { - clearTimeout(timeoutId); - this.connectToChain(); - }, 1000); - }; - (window as any).ethereum?.on('accountsChanged', () => { this.connectEvmWallet(true).then().catch(); }); - (window as any).ethereum?.on('chainChanged', reconnect); } private async _getSigningCosmWasmClientAuto() { @@ -357,11 +348,11 @@ export class WalletService implements OnDestroy { return this.walletAccount; } - getEvmAccount() { - const account = this.walletAccount; + async getEvmAccount() { + const signer = await this.getWalletSigner(); - if (account?.evmAccount) { - return account; + if (signer) { + return signer; } const repo = this._walletManager.getWalletRepo(this._chain?.chain_name); @@ -424,6 +415,10 @@ export class WalletService implements OnDestroy { ); } + getWalletSigner() { + return getSigner(this.env.etherJsonRpc); + } + async connectEvmWallet(changedWallet = false) { const connected = await this.connectToChain(); if (!changedWallet && !connected) { diff --git a/src/app/pages/evm-contracts/evm-contracts-detail/evm-contract-content/evm-contract/evm-read/evm-read.component.ts b/src/app/pages/evm-contracts/evm-contracts-detail/evm-contract-content/evm-contract/evm-read/evm-read.component.ts index e5c710030..c4f0d0928 100644 --- a/src/app/pages/evm-contracts/evm-contracts-detail/evm-contract-content/evm-contract/evm-read/evm-read.component.ts +++ b/src/app/pages/evm-contracts/evm-contracts-detail/evm-contract-content/evm-contract/evm-read/evm-read.component.ts @@ -140,16 +140,6 @@ export class EvmReadComponent implements OnChanges { return; } - const connected = await this.walletService.connectToChain(); - if (!connected) { - jsonFragment.isLoading = false; - jsonFragment.error = { - code: 'error', - message: `Please switch to ${this.environmentService.evmChainInfo.chain} chain.`, - }; - return; - } - const contract = this.createContract(); if (!contract) { diff --git a/src/app/pages/evm-contracts/evm-contracts-detail/evm-contract-content/evm-contract/evm-write/evm-write.component.ts b/src/app/pages/evm-contracts/evm-contracts-detail/evm-contract-content/evm-contract/evm-write/evm-write.component.ts index 07d31c3fc..b796b01eb 100644 --- a/src/app/pages/evm-contracts/evm-contracts-detail/evm-contract-content/evm-contract/evm-write/evm-write.component.ts +++ b/src/app/pages/evm-contracts/evm-contracts-detail/evm-contract-content/evm-contract/evm-write/evm-write.component.ts @@ -172,7 +172,7 @@ export class EvmWriteComponent implements OnChanges { return; } - const contract = this.createContract(); + const contract = await this.createContract(); if (!contract) { return; @@ -201,15 +201,15 @@ export class EvmWriteComponent implements OnChanges { }); } - createContract() { + async createContract() { try { - const account = this.walletService.getEvmAccount(); + const accountSigner = await this.walletService.getEvmAccount(); - if (!account?.evmAccount) { + if (!accountSigner) { return undefined; } - let contract = new Contract(this.contractAddress, this.abi, account.evmAccount); + let contract = new Contract(this.contractAddress, this.abi, accountSigner); if (contract) { this.contract = contract; diff --git a/src/app/pages/transaction/evm-transaction/evm-internal-transactions/evm-internal-transactions.component.ts b/src/app/pages/transaction/evm-transaction/evm-internal-transactions/evm-internal-transactions.component.ts index f022bdde0..6ed1aff04 100644 --- a/src/app/pages/transaction/evm-transaction/evm-internal-transactions/evm-internal-transactions.component.ts +++ b/src/app/pages/transaction/evm-transaction/evm-internal-transactions/evm-internal-transactions.component.ts @@ -23,7 +23,7 @@ export class EvmInternalTransactionsComponent implements OnInit { displayedColumnsTx: string[] = this.templatesTx.map((dta) => dta.matColumnDef); dataSourceTx: MatTableDataSource = new MatTableDataSource(); denom = this.environmentService.chainInfo.currencies[0].coinDenom; - decimal = this.environmentService.chainInfo.currencies[0].coinDecimals; + decimal = 18; breakpoint$ = this.layout.observe([Breakpoints.Small, Breakpoints.XSmall]); constructor( diff --git a/src/app/pages/validators/staking-info/staking-info.component.html b/src/app/pages/validators/staking-info/staking-info.component.html index 271ebdc55..5bbc5d469 100644 --- a/src/app/pages/validators/staking-info/staking-info.component.html +++ b/src/app/pages/validators/staking-info/staking-info.component.html @@ -24,8 +24,9 @@
@@ -244,4 +246,4 @@
- + \ No newline at end of file diff --git a/src/app/pages/validators/staking-info/staking-info.component.ts b/src/app/pages/validators/staking-info/staking-info.component.ts index 930ef33aa..7ddb8f82c 100644 --- a/src/app/pages/validators/staking-info/staking-info.component.ts +++ b/src/app/pages/validators/staking-info/staking-info.component.ts @@ -1,6 +1,7 @@ import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; import { MatLegacyTableDataSource as MatTableDataSource } from '@angular/material/legacy-table'; import { TableTemplate } from 'src/app/core/models/common.model'; +import { WalletService } from 'src/app/core/services/wallet.service'; @Component({ selector: 'app-staking-info', @@ -30,8 +31,15 @@ export class StakingInfoComponent implements OnChanges { displayedColumnsWallet: string[] = this.templatesWallet.map((dta) => dta.matColumnDef); clicked = false; isDisableClaim = true; + isEvmAccount = false; - constructor() {} + constructor(private walletService: WalletService) { + this.walletService.walletAccount$.subscribe({ + next: (wallet) => { + this.isEvmAccount = !!wallet.evmAccount; + }, + }); + } ngOnChanges(changes: SimpleChanges): void { this.dataSourceWallet = new MatTableDataSource(this.dataUserDelegate?.delegations); diff --git a/src/app/pages/validators/validators-detail/delegate-item/delegate-item.component.ts b/src/app/pages/validators/validators-detail/delegate-item/delegate-item.component.ts index 8336e682f..6e68e6f23 100644 --- a/src/app/pages/validators/validators-detail/delegate-item/delegate-item.component.ts +++ b/src/app/pages/validators/validators-detail/delegate-item/delegate-item.component.ts @@ -164,7 +164,7 @@ export class DelegateItemComponent implements OnInit { this.modalReference.close('Close click'); } } - async createContract(contractAddr, evmAccount) { + async createContract(contractAddr) { try { const connected = await this.walletService.connectToChain(); if (!connected) { @@ -173,7 +173,9 @@ export class DelegateItemComponent implements OnInit { this.toastr.error(`Please switch to ${this.environmentService.evmChainInfo.chain} chain.`); return null; } - let contract = new Contract(contractAddr, stakeAbi, evmAccount); + + const signer = await this.walletService.getWalletSigner(); + let contract = new Contract(contractAddr, stakeAbi, signer); if (contract) { this.contract = contract; @@ -220,7 +222,7 @@ export class DelegateItemComponent implements OnInit { this.checkTxStatusOnchain({ error }); }); } else { - const contract = await this.createContract(this.stakeContractAddr, account.evmAccount); + const contract = await this.createContract(this.stakeContractAddr); if (!contract) { return; diff --git a/src/app/pages/validators/validators.component.html b/src/app/pages/validators/validators.component.html index 7c7dedf96..6d6d1b45f 100644 --- a/src/app/pages/validators/validators.component.html +++ b/src/app/pages/validators/validators.component.html @@ -253,14 +253,16 @@

Validators

- +
+ +
{{ data[template.matColumnDef] }}
@@ -656,4 +658,4 @@
-
+ \ No newline at end of file diff --git a/src/app/pages/validators/validators.component.ts b/src/app/pages/validators/validators.component.ts index def5b9628..01d81287e 100644 --- a/src/app/pages/validators/validators.component.ts +++ b/src/app/pages/validators/validators.component.ts @@ -119,6 +119,7 @@ export class ValidatorsComponent implements OnInit, OnDestroy { coinMinimalDenom = this.chainInfo.currencies[0].coinMinimalDenom; stakeContractAddr = this.environmentService.evmChainInfo.stakeContract; claimContractAddr = this.environmentService.evmChainInfo.claimContract; + isEvmAccount = false; constructor( private validatorService: ValidatorService, @@ -133,7 +134,13 @@ export class ValidatorsComponent implements OnInit, OnDestroy { private environmentService: EnvironmentService, private proposalService: ProposalService, private transactionService: TransactionService, - ) {} + ) { + this.walletService.walletAccount$.subscribe({ + next: (wallet) => { + this.isEvmAccount = !!wallet.evmAccount; + }, + }); + } async ngOnInit() { this.getCountProposal(); @@ -168,9 +175,10 @@ export class ValidatorsComponent implements OnInit, OnDestroy { } } - async createContract(contractAddr, evmAccount) { + async createContract(contractAddr) { try { const connected = await this.walletService.connectToChain(); + if (!connected) { this.isLoading = false; this.isHandleStake = false; @@ -178,7 +186,8 @@ export class ValidatorsComponent implements OnInit, OnDestroy { return null; } - let contract = new Contract(contractAddr, stakeAbi, evmAccount); + const signer = await this.walletService.getWalletSigner(); + let contract = new Contract(contractAddr, stakeAbi, signer); if (contract) { this.contract = contract; @@ -555,7 +564,7 @@ export class ValidatorsComponent implements OnInit, OnDestroy { this.checkTxStatusOnchain({ error }); }); } else { - const contract = await this.createContract(this.stakeContractAddr, account.evmAccount); + const contract = await this.createContract(this.stakeContractAddr); if (!contract) { return; @@ -621,7 +630,7 @@ export class ValidatorsComponent implements OnInit, OnDestroy { this.checkTxStatusOnchain({ error }); }); } else { - const contract = await this.createContract(this.claimContractAddr, account.evmAccount); + const contract = await this.createContract(this.claimContractAddr); if (!contract) { return; @@ -678,7 +687,7 @@ export class ValidatorsComponent implements OnInit, OnDestroy { this.checkTxStatusOnchain({ error }); }); } else { - const contract = await this.createContract(this.stakeContractAddr, account.evmAccount); + const contract = await this.createContract(this.stakeContractAddr); if (!contract) { return; @@ -744,7 +753,7 @@ export class ValidatorsComponent implements OnInit, OnDestroy { this.checkTxStatusOnchain({ error }); }); } else { - const contract = await this.createContract(this.stakeContractAddr, account.evmAccount); + const contract = await this.createContract(this.stakeContractAddr); if (!contract) { return;