Skip to content

Commit

Permalink
fix: signer empty when sign transaction (#3677)
Browse files Browse the repository at this point in the history
  • Loading branch information
TranTrungTien authored Aug 19, 2024
1 parent a5750ba commit 6ea27a7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
14 changes: 9 additions & 5 deletions src/app/core/services/wallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class WalletService implements OnDestroy {
const account = local.getItem(STORAGE_KEY.CURRENT_EVM_WALLET);
if (!account) return;

this.walletAccount = account
this.walletAccount = account;
}

restoreAccounts() {
Expand Down Expand Up @@ -348,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 @@ -415,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 @@ -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 @@ -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
14 changes: 8 additions & 6 deletions src/app/pages/validators/validators.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,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 +557,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 +623,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 +680,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 +746,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 6ea27a7

Please sign in to comment.