Context
In PR #43, a rejectedDataSchema is introduced inline:
const rejectedDataSchema = z.object({ accepted: z.literal(false) });
This { accepted: false } pattern is already used across multiple response types in packages/hathor-rpc-handler/src/types/prompt.ts:
SendNanoContractTxConfirmationResponse (line 242)
CreateTokenConfirmationResponse (line 252)
PinRequestResponse (line 262)
CreateNanoContractCreateTokenTxConfirmationResponse (line 336)
SendTransactionConfirmationResponse (line 314, uses accepted: boolean — slight variation)
And the rejection check (if (!response.data.accepted)) is repeated across all RPC methods:
sendTransaction.ts
sendNanoContractTx.ts
createToken.ts
createNanoContractCreateTokenTx.ts
signWithAddress.ts
signOracleData.ts
Proposal
Create a shared schema (e.g. in a schemas/ or validators/ file) that can be reused:
-
A shared rejectedDataSchema:
export const rejectedDataSchema = z.object({ accepted: z.literal(false) });
-
Optionally, a discriminated union factory for confirmation responses:
export const confirmationResponseSchema = <T extends z.ZodRawShape>(acceptedFields: T) =>
z.discriminatedUnion('accepted', [
z.object({ accepted: z.literal(true), ...acceptedFields }),
rejectedDataSchema,
]);
This would standardize validation across all confirmation response handlers and reduce duplication.
Context
In PR #43, a
rejectedDataSchemais introduced inline:This
{ accepted: false }pattern is already used across multiple response types inpackages/hathor-rpc-handler/src/types/prompt.ts:SendNanoContractTxConfirmationResponse(line 242)CreateTokenConfirmationResponse(line 252)PinRequestResponse(line 262)CreateNanoContractCreateTokenTxConfirmationResponse(line 336)SendTransactionConfirmationResponse(line 314, usesaccepted: boolean— slight variation)And the rejection check (
if (!response.data.accepted)) is repeated across all RPC methods:sendTransaction.tssendNanoContractTx.tscreateToken.tscreateNanoContractCreateTokenTx.tssignWithAddress.tssignOracleData.tsProposal
Create a shared schema (e.g. in a
schemas/orvalidators/file) that can be reused:A shared
rejectedDataSchema:Optionally, a discriminated union factory for confirmation responses:
This would standardize validation across all confirmation response handlers and reduce duplication.