Skip to content

Refactor duplicated code into shared utilities - #14

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1784700602-dedupe-shared-utils
Open

Refactor duplicated code into shared utilities#14
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1784700602-dedupe-shared-utils

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jul 22, 2026

Copy link
Copy Markdown

Summary

Extracts repeated boilerplate in the frontend web3 helpers and the Hardhat scripts into shared utilities. No behavior change — public function signatures are preserved and the frontend build + both TS typechecks pass.

frontend/src/helpers/web3.ts

Every callX function repeated the same wrappers. Collapsed into two private helpers:

  • Read calls (callNumTasks, callGetTasks, callNumSubmissions, callGetSubmissions) were each new Promise(async (res,rej)=>{ try{ res(await contract.methods.X().call()) }catch(e){rej(e)} }) → now callContractMethod(contract, "X", [args]).
  • Write calls (callMakeTask, callSubmit, callAssignWinner) each duplicated the Klaytn gas/gasPrice estimation + .send(..., callback) dance → now sendContractMethod(contract, method, args, chainId, { from, value? }):
function sendContractMethod(contract, method, args, chainId, txParams) {
  // klaytn-only gasPrice + estimateGas, then contract.methods[method](...args).send(...)
}

frontend/src/helpers/utilities.ts

convertStringToHex and convertNumberToString were defined identically in both utilities.ts and bignumber.ts. Removed the copies in utilities.ts and re-export them from ./bignumber (keeps existing helpers/utilities importers working).

blockchain/scripts/

Added scripts/utils.ts and routed the scripts through it, removing copy-pasted boilerplate: loadDeployment / saveDeployment (deployment.json), loadArtifactAbi, attachDDALLE (getContractFactory("DDALLE").attach), findEvent(receipt, name) (replaces inline receipt.events?.filter(e=>e.event===name)[0]), and runMain(main) (replaces the repeated main().catch(...) footer). Applied across deploy, makeTask, makeSubmission, listTasks, assignWinner, giveETH.

Link to Devin session: https://app.devin.ai/sessions/98a1211fd774434aa2714c7532d5766a
Requested by: @walnutwaldo


Devin Review

Status Commit
⚪ Not started

Run Devin Review

Open in Devin Review (Staging)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@walnutwaldo walnutwaldo self-assigned this Jul 22, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit d73ae03):

https://decentralized-dall-e--pr14-devin-1784700602-ded-4i0asf72.web.app

(expires Wed, 29 Jul 2026 06:13:07 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 9f3ca659ce42113c1a9d85a3ba19a54f05478557

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant