refactor(solana-wallet-snap): convert enums to as const objects - #217
Conversation
as const objects
as const objectsas const objects
f72e103 to
ce2080e
Compare
ce2080e to
905dda6
Compare
905dda6 to
456bf09
Compare
456bf09 to
3768a50
Compare
c50dffd to
2f15938
Compare
fc59fd9 to
36737d5
Compare
taran-a
left a comment
There was a problem hiding this comment.
LGTM. I believe we are safe using objects and types with the same names, eslint should catch this?
There was a problem hiding this comment.
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
enumdeclarations toas constobjects withtypeunions 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
shasumand 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-assertionhere; theas 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.
Yes indeed! And I ran |
eb7b665 to
f95b876
Compare
f95b876 to
76625f0
Compare
Summary
Convert locally-declared TypeScript enums in solana-wallet-snap to
as constobjects 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,Secp256InstructionBreaking changes
Enumis now a union of string/number literals instead of a nominal enum typeEnum.Member) works the same wayValidation
tsc --noEmitpasses (only pre-existing baseline errors)enumdeclarations remaining in solana-wallet-snap