Skip to content

refactor(solana-wallet-snap): convert enums to as const objects - #217

Merged
ulissesferreira merged 1 commit into
mainfrom
refactor/ban-enums-solana
Aug 28, 2026
Merged

refactor(solana-wallet-snap): convert enums to as const objects#217
ulissesferreira merged 1 commit into
mainfrom
refactor/ban-enums-solana

Conversation

@ulissesferreira

Copy link
Copy Markdown
Contributor

Summary

Convert locally-declared TypeScript enums in solana-wallet-snap to as const objects with derived union types.

Refs: MetaMask/utils#280, MetaMask/eslint-config#417

Enums converted

  • SolMethod, AccountCreationType, TokenFeature, TokenStandard, TransactionScanType, TransactionStatus, TransactionType, AccountType, AccountScope, AccountFeature, Scope, CronjobMethod, ScheduleBackgroundEventMethod, Network, Sep43ErrorCode, Secp256Instruction

Breaking changes

  • Type signatures change: Enum is now a union of string/number literals instead of a nominal enum type
  • Runtime values unchanged: Member access (Enum.Member) works the same way

Validation

  • tsc --noEmit passes (only pre-existing baseline errors)
  • ✅ ESLint clean
  • ✅ Zero enum declarations remaining in solana-wallet-snap

@ulissesferreira ulissesferreira changed the title refactor(solana): convert enums to as const objects refactor(solana): convert enums to as const objects Aug 27, 2026
@ulissesferreira ulissesferreira changed the title refactor(solana): convert enums to as const objects refactor(solana-wallet-snap): convert enums to as const objects Aug 27, 2026
@ulissesferreira
ulissesferreira force-pushed the refactor/ban-enums-solana branch from f72e103 to ce2080e Compare August 27, 2026 09:32
@ulissesferreira
ulissesferreira marked this pull request as ready for review August 27, 2026 09:34
@ulissesferreira
ulissesferreira requested a review from a team as a code owner August 27, 2026 09:34
@ulissesferreira
ulissesferreira force-pushed the refactor/ban-enums-solana branch from ce2080e to 905dda6 Compare August 27, 2026 09:34
@ulissesferreira
ulissesferreira force-pushed the refactor/ban-enums-solana branch from 905dda6 to 456bf09 Compare August 27, 2026 09:54
@ulissesferreira
ulissesferreira requested a review from a team as a code owner August 27, 2026 09:54
@ulissesferreira
ulissesferreira force-pushed the refactor/ban-enums-solana branch from 456bf09 to 3768a50 Compare August 27, 2026 10:11
@ulissesferreira
ulissesferreira force-pushed the refactor/ban-enums-solana branch 6 times, most recently from c50dffd to 2f15938 Compare August 27, 2026 16:55
Comment thread packages/solana-wallet-snap/src/core/handlers/onKeyringRequest/Keyring.test.ts Outdated
@ulissesferreira
ulissesferreira force-pushed the refactor/ban-enums-solana branch 3 times, most recently from fc59fd9 to 36737d5 Compare August 28, 2026 10:18
taran-a
taran-a previously approved these changes Aug 28, 2026

@taran-a taran-a left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I believe we are safe using objects and types with the same names, eslint should catch this?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors packages/solana-wallet-snap to replace locally-declared TypeScript enums with as const objects plus derived union types, aligning with the repo’s preferred typing patterns while keeping runtime member access (X.Member) intact.

Changes:

  • Converted various enum declarations to as const objects with type unions derived from the object’s values.
  • Adjusted call sites where Object.values(...)/type expectations changed due to the enum-to-union refactor.
  • Updated the snap manifest shasum and removed an ESLint suppression entry that is no longer needed.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/solana-wallet-snap/src/index.ts Updates cronjob method validation and error messaging to work with as const-based method definitions.
packages/solana-wallet-snap/src/features/confirmation/views/ConfirmTransactionRequest/events.tsx Converts form-name enum to as const + union type for event handler keys.
packages/solana-wallet-snap/src/features/confirmation/views/ConfirmSignMessage/events.tsx Converts form-name enum to as const + union type for event handler keys.
packages/solana-wallet-snap/src/features/confirmation/views/ConfirmSignIn/events.tsx Converts form-name enum to as const + union type for event handler keys.
packages/solana-wallet-snap/src/entities/instructions/programs/secp256k1-secp256r1.ts Converts instruction enum to as const + union type and updates parsed instruction typing.
packages/solana-wallet-snap/src/core/services/transaction-scan/types.ts Converts scan-related enums to as const objects with derived union types.
packages/solana-wallet-snap/src/core/services/subscriptions/WebSocketConnectionService.test.ts Fixes test helper typing for Network after enum-to-union change.
packages/solana-wallet-snap/src/core/services/send/types.ts Converts send error-code enum to as const + union type.
packages/solana-wallet-snap/src/core/handlers/onRpcRequest/types.ts Converts test-dapp RPC method enum to as const + union type.
packages/solana-wallet-snap/src/core/handlers/onProtocolRequest/structs.ts Converts protocol request method enum to as const + union type used by request structs.
packages/solana-wallet-snap/src/core/handlers/onCronjob/cronjobs/CronjobMethod.ts Replaces empty enum with empty as const object + derived (currently empty) union type.
packages/solana-wallet-snap/src/core/handlers/onCronjob/backgroundEvents/ScheduleBackgroundEventMethod.ts Converts background-event method enum to as const + union type.
packages/solana-wallet-snap/src/core/handlers/onClientRequest/types.ts Converts client request method enum to as const + union type.
packages/solana-wallet-snap/src/core/constants/solana.ts Converts Solana network/token-related enums to as const objects and updates derived template-literal types.
packages/solana-wallet-snap/src/core/clients/token-api-client/TokenApiClient.ts Adjusts supported-network filtering logic to match new Network typing.
packages/solana-wallet-snap/snap.manifest.json Updates bundle shasum after code generation/build output changes.
eslint-suppressions.json Removes a suppression entry related to an issue no longer present after refactor.
Suppressed comments (1)

packages/solana-wallet-snap/src/index.ts:204

  • Avoid disabling @typescript-eslint/no-unnecessary-type-assertion here; the as string[] cast provides no benefit and can be removed along with the suppression.
            // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
            ...(Object.values(CronjobMethod) as string[]),

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/solana-wallet-snap/src/index.ts Outdated
@ulissesferreira

Copy link
Copy Markdown
Contributor Author

LGTM. I believe we are safe using objects and types with the same names, eslint should catch this?

Yes indeed! And I ran tsc even though not part of the CI for safety

@ulissesferreira
ulissesferreira force-pushed the refactor/ban-enums-solana branch 2 times, most recently from eb7b665 to f95b876 Compare August 28, 2026 11:12
@ulissesferreira
ulissesferreira force-pushed the refactor/ban-enums-solana branch from f95b876 to 76625f0 Compare August 28, 2026 11:31
@ulissesferreira
ulissesferreira added this pull request to the merge queue Aug 28, 2026
Merged via the queue into main with commit cfeb073 Aug 28, 2026
53 checks passed
@ulissesferreira
ulissesferreira deleted the refactor/ban-enums-solana branch August 28, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants