Skip to content

Commit

Permalink
fix(validation): allow input negative wallet amount (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev committed Aug 8, 2024
1 parent 8d42129 commit 9af8d78
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions apps/mobile/components/wallet/account-form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useDefaultCurrency } from '@/stores/user-settings/hooks'
import { type AccountFormValues, zAccountFormValues } from '@6pm/validation'
import { type WalletFormValues, zWalletFormValues } from '@6pm/validation'
import { zodResolver } from '@hookform/resolvers/zod'
import { t } from '@lingui/macro'
import { useLingui } from '@lingui/react'
Expand All @@ -14,8 +14,8 @@ import { Text } from '../ui/text'
import { SelectAccountIconField } from './select-account-icon-field'

type AccountFormProps = {
onSubmit: (data: AccountFormValues) => void
defaultValues?: AccountFormValues
onSubmit: (data: WalletFormValues) => void
defaultValues?: WalletFormValues
}

export const AccountForm = ({ onSubmit, defaultValues }: AccountFormProps) => {
Expand All @@ -24,8 +24,8 @@ export const AccountForm = ({ onSubmit, defaultValues }: AccountFormProps) => {
const balanceInputRef = useRef<TextInput>(null)
const defaultCurrency = useDefaultCurrency()

const accountForm = useForm<AccountFormValues>({
resolver: zodResolver(zAccountFormValues),
const accountForm = useForm<WalletFormValues>({
resolver: zodResolver(zWalletFormValues),
defaultValues: {
name: '',
preferredCurrency: defaultCurrency,
Expand Down
6 changes: 3 additions & 3 deletions apps/mobile/mutations/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getHonoClient } from '@/lib/client'
import type { AccountFormValues } from '@6pm/validation'
import type { WalletFormValues } from '@6pm/validation'

export async function createWallet(data: AccountFormValues) {
export async function createWallet(data: WalletFormValues) {
const { balance, ...walletData } = data
const hc = await getHonoClient()
const result = await hc.v1.wallets.wallets.$post({
Expand All @@ -27,7 +27,7 @@ export async function updateWallet({
data,
}: {
id: string
data: AccountFormValues
data: WalletFormValues
}) {
const { balance, ...walletData } = data
const hc = await getHonoClient()
Expand Down
6 changes: 3 additions & 3 deletions packages/validation/src/wallet.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export const zUpdateWallet = z.object({
})
export type UpdateWallet = z.infer<typeof zUpdateWallet>

export const zAccountFormValues = zCreateWallet.extend({
balance: z.number({ coerce: true }).positive().optional(),
export const zWalletFormValues = zCreateWallet.extend({
balance: z.number({ coerce: true }).optional(),
})
export type AccountFormValues = z.infer<typeof zAccountFormValues>
export type WalletFormValues = z.infer<typeof zWalletFormValues>

export const WalletAccountWithBalanceSchema = UserWalletAccountSchema.extend({
balance: z.number({ coerce: true }).optional(),
Expand Down

0 comments on commit 9af8d78

Please sign in to comment.