refactor: convert shared/lib/transactions-controller-utils to TypeScript (level 29)#41333
Conversation
Agent-Logs-Url: https://github.com/MetaMask/metamask-extension/sessions/bda8384d-d827-4f0e-a207-e6abddb13981 Co-authored-by: DDDDDanica <12678455+DDDDDanica@users.noreply.github.com>
Builds ready [8fcd6f5]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Builds ready [5e8ac6f]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
Builds ready [83a3186]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
…actions-controller-utils-to-typescrip
Builds ready [2c01f08]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 0 warn · 🔴 0 fail)
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs
|
|
Builds ready [170fb34]
⚡ Performance Benchmarks (Total: 🟢 16 pass · 🟡 2 warn · 🔴 0 fail)
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚀 Bundle size reduced!]
|



[skip-e2e]
Converts
shared/lib/transactions-controller-utils.jsand its test file to TypeScript, removing both fromfiles-to-convert.json.Changes
transactions-controller-utils.ts— typed all exports:calcGasTotal:string | numberparams (was JS untyped, callers pass numbers)toPrecisionWithoutTrailingZeros:string | number | BigNumber→stringcalcTokenAmount:string | number | BigNumber→BigNumbergetSwapsTokensReceivedFromTxMeta: all params optional to match existing JS call-site patterns;chainId: string | number;precision: number | null = 6txReceiptto{ type?: string }to access MetaMask's internal envelope-type field (absent from@metamask/transaction-controller'sTransactionReceipt)Log[]to a localLogWithTopicsArray[]type sinceLog.topicsis incorrectly typed asstringinstead ofstring[]in the upstream packagetransactions-controller-utils.test.ts(renamed fromtransaction-controller-utils.test.js):as unknown as TransactionMeta/* eslint-disable @typescript-eslint/naming-convention */fortoken_to_amount(external API snake_case property).toBe()call (silently ignored in JS, TypeScript surfaced it)transaction-breakdown-utils.ts: removed now-unnecessary@ts-expect-erroronprecision: nullcall (previously required because the JS version had no type for this parameter)✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Note
Medium Risk
Mostly a type-migration, but it touches
getSwapsTokensReceivedFromTxMetalogic (default-token detection, receipt typing, and output formatting), which could subtly affect swaps amount display in the UI.Overview
Migrates
shared/lib/transactions-controller-utilsand its tests from JS to TS. Exports are now explicitly typed (including optional params forgetSwapsTokensReceivedFromTxMeta) and tests use typedTransactionMetafixtures.getSwapsTokensReceivedFromTxMetaadds stricter handling aroundtxReceipt.type,chainId(supportsnumberby converting to hex), optionalgasPriceaccess, and log topic typing, and slightly changes formatting behavior (e.g., removes an ignored extra arg in a.toBe()assertion). The transaction breakdown caller drops an unnecessary@ts-expect-errorfor passingprecision: null.Also removes the converted files from
development/ts-migration-dashboard/files-to-convert.json.Written by Cursor Bugbot for commit 170fb34. This will update automatically on new commits. Configure here.