From b8c31df54f4edaab892d3de20a02097ee140f979 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Mon, 28 Oct 2024 12:22:13 +0530 Subject: [PATCH] Refactor out method to get account from private key --- packages/backend/src/registry.ts | 7 +++---- packages/backend/src/service.ts | 10 ++++++---- packages/frontend/src/components/StopWatch.tsx | 6 +----- .../src/components/projects/create/ConnectWallet.tsx | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index a7f5441f..9f3b314c 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -499,16 +499,15 @@ export class Registry { ); } - async getAddress(): Promise { + async getAccount(): Promise { const account = new Account(Buffer.from(this.registryConfig.privateKey, 'hex')); await account.init(); - return account.address; + return account; } async getTxResponse(txHash: string): Promise { - const account = new Account(Buffer.from(this.registryConfig.privateKey, 'hex')); - await account.init(); + const account = await this.getAccount(); const laconicClient = await this.registry.getLaconicClient(account); const txResponse: IndexedTx | null = await laconicClient.getTx(txHash); diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 417e3cfb..e697b663 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -213,7 +213,7 @@ export class Service { const fundsReleased = await this.releaseDeployerFundsByProjectId(deployment.projectId); // Return remaining amount to owner - await this.returnCreatorFundsByProjectId(deployment.projectId, true); + await this.returnUserFundsByProjectId(deployment.projectId, true); await this.db.updateProjectById(deployment.projectId, { fundsReleased, @@ -314,7 +314,7 @@ export class Service { log(`No winning deployer for auction ${project!.auctionId}`); // Return all funds to the owner - await this.returnCreatorFundsByProjectId(project.id, false) + await this.returnUserFundsByProjectId(project.id, false) } else { const deployers = await this.saveDeployersByDeployerRecords(deployerRecords); for (const deployer of deployers) { @@ -1332,7 +1332,7 @@ export class Service { return false; } - async returnCreatorFundsByProjectId(projectId: string, winningDeployersPresent: boolean) { + async returnUserFundsByProjectId(projectId: string, winningDeployersPresent: boolean) { const project = await this.db.getProjectById(projectId); if (!project || !project.auctionId) { @@ -1405,7 +1405,9 @@ export class Service { } async getAddress(): Promise { - return this.laconicRegistry.getAddress(); + const account = await this.laconicRegistry.getAccount(); + + return account.address; } async verifyTx(txHash: string, amountSent: string, senderAddress: string): Promise { diff --git a/packages/frontend/src/components/StopWatch.tsx b/packages/frontend/src/components/StopWatch.tsx index d5c7d63d..34e7d97b 100644 --- a/packages/frontend/src/components/StopWatch.tsx +++ b/packages/frontend/src/components/StopWatch.tsx @@ -23,11 +23,7 @@ const Stopwatch = ({ offsetTimestamp, isPaused, ...props }: StopwatchProps) => { }); useEffect(() => { - if (isPaused) { - pause(); - } else { - start(); - } + isPaused ? pause() : start(); }, [isPaused]); return ; diff --git a/packages/frontend/src/components/projects/create/ConnectWallet.tsx b/packages/frontend/src/components/projects/create/ConnectWallet.tsx index fffa82eb..40dc2d81 100644 --- a/packages/frontend/src/components/projects/create/ConnectWallet.tsx +++ b/packages/frontend/src/components/projects/create/ConnectWallet.tsx @@ -32,7 +32,7 @@ const ConnectWallet = ({ > {accounts.map((account, index) => ( ))}