Skip to content

Commit

Permalink
Release/euphoria 20240827 (#3682)
Browse files Browse the repository at this point in the history
* [feat][704] remove request chain id while opening multiple tabs (#3678)

* feat: remove request chain id while opening multple tab

* fix: signer empty when sign transaction (#3677)

* update: disabled delegate for evm-account

* fix: wrong decimal for evm
  • Loading branch information
TranTrungTien authored Aug 27, 2024
1 parent f3615cb commit 37a69dc
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 56 deletions.
27 changes: 11 additions & 16 deletions src/app/core/services/wallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class EvmWriteComponent implements OnChanges {
return;
}

const contract = this.createContract();
const contract = await this.createContract();

if (!contract) {
return;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class EvmInternalTransactionsComponent implements OnInit {
displayedColumnsTx: string[] = this.templatesTx.map((dta) => dta.matColumnDef);
dataSourceTx: MatTableDataSource<any> = 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ <h6 class="mb-0">
<button
class="button button-outline button--sm button-pill button-flat d-flex text--black"
type="button"
[disabled]="isDisableClaim || isLoading"
(click)="viewDialog(true)">
(click)="viewDialog(true)"
[appTooltip]="isEvmAccount ? 'Using cosmos account. Please!': ''"
[disabled]="isEvmAccount || isDisableClaim || isLoading">
<img
[src]="'assets/icons/icons-svg/color/spinner.svg' | imageS3"
alt=""
Expand Down Expand Up @@ -85,8 +86,9 @@ <h6 class="mb-0">
<div *ngSwitchCase="'action'" class="py-4">
<button
type="button"
[appTooltip]="isEvmAccount ? 'Using cosmos account. Please!': ''"
class="button button--sm button-pill button-outline button-outline__in-card ml-auto"
[disabled]="clicked"
[disabled]="isEvmAccount || clicked"
(click)="clicked = true; viewDialog(false, modalManage, data['validator_address'])">
<span class="body-02 text--gray-1">Manage</span>
</button>
Expand Down Expand Up @@ -244,4 +246,4 @@ <h6 class="mb-0">
</div>
</div>
</div>
</ng-container>
</ng-container>
10 changes: 9 additions & 1 deletion src/app/pages/validators/staking-info/staking-info.component.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 11 additions & 9 deletions src/app/pages/validators/validators.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,16 @@ <h2 class="h3-mob mb-0 text--white">Validators</h2>
</div>
</div>
<div *ngSwitchCase="'action'">
<button
type="button"
class="button button--sm button-pill button-outline button-outline__in-card ml-auto"
[disabled]="clicked"
*ngIf="!data['jailed']"
(click)="viewPopupDetail(modalManage, data.operator_address, dialogMode.Delegate, true)">
<span class="body-02 text--gray-1">Delegate</span>
</button>
<div *ngSwitchCase="'action'">
<button
type="button"
[appTooltip]="isEvmAccount ? 'Using cosmos account. Please!': ''"
class="button button--sm button-pill button-outline button-outline__in-card ml-auto"
[disabled]="clicked || isEvmAccount" *ngIf="!data['jailed']"
(click)="viewPopupDetail(modalManage, data.operator_address, dialogMode.Delegate, true)">
<span class="body-02 text--gray-1">Delegate</span>
</button>
</div>
</div>
<div *ngSwitchDefault class="text-center">{{ data[template.matColumnDef] }}</div>
</ng-container>
Expand Down Expand Up @@ -656,4 +658,4 @@ <h5 class="mb-1 text--gray-1">

<div *ngIf="loadingData" class="mt-20">
<app-loading-sprint></app-loading-sprint>
</div>
</div>
23 changes: 16 additions & 7 deletions src/app/pages/validators/validators.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -168,17 +175,19 @@ 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;
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 37a69dc

Please sign in to comment.