diff --git a/src/shared/rpc/methods/send-transfer.ts b/src/shared/rpc/methods/send-transfer.ts index 63d2ed93ea..04cf9237db 100644 --- a/src/shared/rpc/methods/send-transfer.ts +++ b/src/shared/rpc/methods/send-transfer.ts @@ -1,7 +1,7 @@ import type { SendTransferRequestParams } from '@btckit/types'; import { z } from 'zod'; -import { type BitcoinNetworkModes, WalletDefaultNetworkConfigurationIds } from '@leather.io/models'; +import { type BitcoinNetworkModes } from '@leather.io/models'; import { uniqueArray } from '@leather.io/utils'; import { FormErrorMessages } from '@shared/error-messages'; @@ -11,6 +11,7 @@ import { } from '@shared/forms/address-validators'; import { checkIfDigitsOnly } from '@shared/forms/amount-validators'; +import { defaultNetworksSchema } from '../rpc-schemas'; import { accountSchema, formatValidationErrors, @@ -24,17 +25,13 @@ export const rpcSendTransferParamsSchemaLegacy = z.object({ account: accountSchema.optional(), address: z.string(), amount: z.string(), - network: z - .enum(Object.values(WalletDefaultNetworkConfigurationIds) as [string, ...string[]]) - .optional(), + network: defaultNetworksSchema.optional(), }); export const rpcSendTransferParamsSchema = z .object({ account: accountSchema.optional(), - network: z - .enum(Object.values(WalletDefaultNetworkConfigurationIds) as [string, ...string[]]) - .optional(), + network: defaultNetworksSchema.optional(), recipients: z .array( z.object({ diff --git a/src/shared/rpc/methods/sign-message.ts b/src/shared/rpc/methods/sign-message.ts index 4328e239ac..1c23a6094a 100644 --- a/src/shared/rpc/methods/sign-message.ts +++ b/src/shared/rpc/methods/sign-message.ts @@ -1,8 +1,8 @@ import { z } from 'zod'; -import { WalletDefaultNetworkConfigurationIds } from '@leather.io/models'; import type { PaymentTypes } from '@leather.io/rpc'; +import { defaultNetworksSchema } from '../rpc-schemas'; import { accountSchema, formatValidationErrors, @@ -14,9 +14,7 @@ const rpcSignMessageParamsSchema = z.object({ type: z.enum(['bip322']).optional(), account: accountSchema.optional(), message: z.string(), - network: z - .enum(Object.values(WalletDefaultNetworkConfigurationIds) as [string, ...string[]]) - .optional(), + network: defaultNetworksSchema.optional(), paymentType: z.enum(['p2tr', 'p2wpkh'] as [PaymentTypes, PaymentTypes]).optional(), }); diff --git a/src/shared/rpc/methods/sign-psbt.ts b/src/shared/rpc/methods/sign-psbt.ts index 587816fec0..a5e37d565f 100644 --- a/src/shared/rpc/methods/sign-psbt.ts +++ b/src/shared/rpc/methods/sign-psbt.ts @@ -9,6 +9,7 @@ import { RpcResponse, } from '@leather.io/rpc'; +import { defaultNetworksSchema } from '../rpc-schemas'; import { accountSchema, formatValidationErrors, @@ -36,9 +37,7 @@ const rpcSignPsbtParamsSchema = z.object({ allowedSighash: z.array(z.any()).optional(), broadcast: z.boolean().optional(), hex: z.string(), - network: z - .enum(Object.values(WalletDefaultNetworkConfigurationIds) as [string, ...string[]]) - .optional(), + network: defaultNetworksSchema.optional(), signAtIndex: z .union([z.number(), z.array(z.number())]) .optional() diff --git a/src/shared/rpc/rpc-schemas.ts b/src/shared/rpc/rpc-schemas.ts new file mode 100644 index 0000000000..29554a9e3b --- /dev/null +++ b/src/shared/rpc/rpc-schemas.ts @@ -0,0 +1,12 @@ +import { z } from 'zod'; + +import { + type DefaultNetworkConfigurations, + WalletDefaultNetworkConfigurationIds, +} from '@leather.io/models'; + +type NonEmptyNetworkList = [DefaultNetworkConfigurations, ...DefaultNetworkConfigurations[]]; + +export const defaultNetworksSchema = z.enum( + Object.values(WalletDefaultNetworkConfigurationIds) as NonEmptyNetworkList +);