@@ -26,6 +26,13 @@ export default function NewInvoicePage() {
2626 ) ;
2727 const [ submitting , setSubmitting ] = useState ( false ) ;
2828 const [ error , setError ] = useState < string | null > ( null ) ;
29+ const [ equalSplit , setEqualSplit ] = useState ( false ) ;
30+ const [ totalAmount , setTotalAmount ] = useState ( "" ) ;
31+
32+ const perRecipientAmount =
33+ equalSplit && totalAmount && recipients . length > 0
34+ ? ( parseFloat ( totalAmount ) / recipients . length ) . toFixed ( 7 )
35+ : undefined ;
2936
3037 const handleSubmit = async ( e : React . FormEvent ) => {
3138 e . preventDefault ( ) ;
@@ -39,7 +46,7 @@ export default function NewInvoicePage() {
3946 creator,
4047 recipients : recipients . map ( ( r ) => ( {
4148 address : r . address ,
42- amount : parseAmount ( r . amount ) ,
49+ amount : parseAmount ( equalSplit ? ( perRecipientAmount ?? "0" ) : r . amount ) ,
4350 } ) ) ,
4451 token,
4552 deadline : deadlineFromDays ( deadlineDays ) ,
@@ -58,12 +65,61 @@ export default function NewInvoicePage() {
5865 < h1 className = "text-3xl font-bold mb-8" > Create Invoice</ h1 >
5966
6067 < form onSubmit = { handleSubmit } className = "flex flex-col gap-6" >
68+ { /* Equal Split toggle */ }
69+ < div className = "flex items-center justify-between rounded-lg bg-gray-800 border border-gray-700 px-4 py-3" >
70+ < span className = "text-sm font-medium text-gray-300" > Equal Split</ span >
71+ < button
72+ type = "button"
73+ role = "switch"
74+ aria-checked = { equalSplit }
75+ onClick = { ( ) => setEqualSplit ( ( v ) => ! v ) }
76+ className = { `relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-indigo-500 ${
77+ equalSplit ? "bg-indigo-600" : "bg-gray-600"
78+ } `}
79+ >
80+ < span
81+ className = { `inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${
82+ equalSplit ? "translate-x-6" : "translate-x-1"
83+ } `}
84+ />
85+ </ button >
86+ </ div >
87+
88+ { /* Total amount input (equal split mode) */ }
89+ { equalSplit && (
90+ < div >
91+ < label className = "block text-sm font-medium text-gray-300 mb-1" >
92+ Total Amount (USDC)
93+ </ label >
94+ < input
95+ type = "number"
96+ placeholder = "0.00"
97+ step = "0.0000001"
98+ min = "0.0000001"
99+ value = { totalAmount }
100+ onChange = { ( e ) => setTotalAmount ( e . target . value ) }
101+ required
102+ className = "w-full bg-gray-800 border border-gray-700 rounded-lg px-4 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500"
103+ />
104+ { perRecipientAmount && (
105+ < p className = "mt-1 text-xs text-gray-400" >
106+ { perRecipientAmount } USDC per recipient
107+ </ p >
108+ ) }
109+ </ div >
110+ ) }
111+
61112 { /* Recipients */ }
62113 < div >
63114 < label className = "block text-sm font-medium text-gray-300 mb-2" >
64- Recipients & Amounts (USDC)
115+ Recipients { equalSplit ? "" : "& Amounts (USDC)" }
65116 </ label >
66- < RecipientForm recipients = { recipients } onChange = { setRecipients } />
117+ < RecipientForm
118+ recipients = { recipients }
119+ onChange = { setRecipients }
120+ equalSplit = { equalSplit }
121+ amountOverride = { perRecipientAmount }
122+ />
67123 </ div >
68124
69125 { /* Token address */ }
0 commit comments