Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
/* eslint-env jest */
import '@testing-library/jest-dom';
import React from 'react';

// Ensure React is available for hooks in test environment
if (typeof globalThis !== 'undefined') {
(globalThis as unknown as { React: typeof React }).React = React;
}
9 changes: 8 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ const config: Config = {
'^@/(.*)$': '<rootDir>/src/$1',
},
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: {
jsx: 'react-jsx',
},
},
],
},
};

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
"luxon": "^3.5.0",
"match-sorter": "^6.3.1",
"motion": "^11.15.0",
"numora": "^3.0.2",
"numora-react": "^3.0.2",
"qrcode.react": "^3.1.0",
"react": "^19.0.0",
"react-daisyui": "^5.0.5",
Expand Down
17 changes: 10 additions & 7 deletions src/components/Form/Amount/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { UseFormRegisterReturn } from 'react-hook-form';
import { Control, FieldPath, FieldValues } from 'react-hook-form';
import { roundNumber } from '../../../shared/parseNumbers/metric';
import { NumericInput } from '../From/NumericInput';

export interface AmountProps {
export interface AmountProps<FormFieldValues extends FieldValues = FieldValues> {
className?: string;
max?: number;
min?: number;
register: UseFormRegisterReturn;
control: Control<FormFieldValues>;
name: FieldPath<FormFieldValues>;
setValue: (n: number) => void;
assetSuffix?: string;
error?: string;
Expand All @@ -25,9 +26,10 @@ function calculateMaxAmount(max: number, fullMax: boolean) {
return Math.max(0, maxAmount);
}

const Amount = ({
const Amount = <FormFieldValues extends FieldValues = FieldValues>({
className,
register,
control,
name,
max,
setValue,
error,
Expand All @@ -36,7 +38,7 @@ const Amount = ({
hideMaxButton = false,
readOnly = false,
defaultValue,
}: AmountProps): JSX.Element | null => (
}: AmountProps<FormFieldValues>): JSX.Element | null => (
<>
<div
className={`rounded-lg bg-base-300 px-4 py-3 ${className || ''} ${
Expand All @@ -46,7 +48,8 @@ const Amount = ({
<div className="flex w-full justify-between">
<div className="font-outfit flex-grow text-4xl text-accent-content">
<NumericInput
register={register}
control={control}
name={name}
readOnly={readOnly}
additionalStyle="input-ghost w-full text-4xl font-outfit pl-0 focus:outline-none"
defaultValue={defaultValue}
Expand Down
Loading
Loading