Skip to content

Commit

Permalink
Revert "[feat][704] remove request change chain id while opening mult…
Browse files Browse the repository at this point in the history
…iple tabs" (#3667)
  • Loading branch information
TranTrungTien authored Aug 1, 2024
1 parent 2e08207 commit 016ebac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/app/core/services/wallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ export class WalletService implements OnDestroy {
}

restoreEvmAccounts() {
const account = local.getItem(STORAGE_KEY.CURRENT_EVM_WALLET);
if (!account) return;
let account = local.getItem(STORAGE_KEY.CURRENT_EVM_WALLET);

this.walletAccount = account
if (account) {
this.connectEvmWallet().then().catch();
}
}

restoreAccounts() {
Expand Down Expand Up @@ -248,9 +249,17 @@ 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, Inject } from '@angular/core';
import {
MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA,
MatLegacyDialogRef as MatDialogRef,
MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA,
} from '@angular/material/legacy-dialog';
import { MsgVote } from 'cosmjs-types/cosmos/gov/v1beta1/tx';
import { TIME_OUT_CALL_API } from 'src/app/core/constants/common.constant';
import { TRANSACTION_TYPE_ENUM } from 'src/app/core/constants/transaction.enum';
import { EnvironmentService } from 'src/app/core/data-services/environment.service';
Expand Down Expand Up @@ -41,7 +42,7 @@ export class ProposalVoteComponent {
this.keyVote = data.voteValue ?? null;
}

async vote() {
async vote() {
const account = this.walletService.getAccount();

if (!account) {
Expand Down

0 comments on commit 016ebac

Please sign in to comment.