@@ -3,17 +3,39 @@ import type { FeeConfig } from '../contracts'
33import { formatBps , formatTrust } from '../lib/format'
44
55export type FeeFields = {
6- depositBps : string
7- creationBps : string
6+ /** Percentage fees entered as a human percent (e.g. "1.5" = 1.5%). */
7+ depositPct : string
8+ creationPct : string
89 /** Fixed fees entered as a decimal TRUST amount (converted to wei). */
910 depositFixedFee : string
1011 creationFixedFee : string
1112}
1213
14+ /**
15+ * Convert a human percentage string to on-chain bps (basis points, base 10000).
16+ * "1" → 100, "2.5" → 250, "0.05" → 5. Max 2 decimals (1 bps = 0.01%).
17+ */
18+ function pctToBps ( pct : string ) : bigint {
19+ const t = ( pct || '0' ) . trim ( )
20+ if ( ! / ^ \d + ( \. \d { 1 , 2 } ) ? $ / . test ( t ) ) {
21+ throw new Error ( `Invalid percentage "${ pct } " — use up to 2 decimals (e.g. 1.5)` )
22+ }
23+ return BigInt ( Math . round ( parseFloat ( t ) * 100 ) )
24+ }
25+
26+ /** Convert on-chain bps to a clean percentage string. 250 → "2.5", 5 → "0.05". */
27+ function bpsToPct ( bps : bigint ) : string {
28+ const whole = bps / 100n
29+ const frac = bps % 100n
30+ if ( frac === 0n ) return whole . toString ( )
31+ const fracStr = frac . toString ( ) . padStart ( 2 , '0' ) . replace ( / 0 $ / , '' )
32+ return `${ whole } .${ fracStr } `
33+ }
34+
1335/** Parse the string form fields into an on-chain `FeeConfig` (bigints). */
1436export function parseFeeFields ( f : FeeFields ) : FeeConfig {
15- const depositBps = BigInt ( f . depositBps || '0' )
16- const creationBps = BigInt ( f . creationBps || '0' )
37+ const depositBps = pctToBps ( f . depositPct )
38+ const creationBps = pctToBps ( f . creationPct )
1739 const depositFixedFee = parseEther ( ( f . depositFixedFee || '0' ) . trim ( ) )
1840 const creationFixedFee = parseEther ( ( f . creationFixedFee || '0' ) . trim ( ) )
1941 return { depositBps, creationBps, depositFixedFee, creationFixedFee }
@@ -22,8 +44,8 @@ export function parseFeeFields(f: FeeFields): FeeConfig {
2244/** Build editable string fields from an on-chain `FeeConfig`. */
2345export function feeFieldsFrom ( fees : FeeConfig ) : FeeFields {
2446 return {
25- depositBps : fees . depositBps . toString ( ) ,
26- creationBps : fees . creationBps . toString ( ) ,
47+ depositPct : bpsToPct ( fees . depositBps ) ,
48+ creationPct : bpsToPct ( fees . creationBps ) ,
2749 depositFixedFee : formatTrust ( fees . depositFixedFee ) ,
2850 creationFixedFee : formatTrust ( fees . creationFixedFee ) ,
2951 }
@@ -38,15 +60,16 @@ interface Props {
3860
3961/**
4062 * Shared fee-schedule editor used by registration and fee-update flows.
41- * bps are integers (base 10000); fixed fees are entered in TRUST.
63+ * Percentages are entered as human percents and converted to bps on submit;
64+ * fixed fees are entered in TRUST.
4265 */
4366export function FeeConfigFields ( { fields, onChange, maxBps, maxFixedFee } : Props ) {
4467 const set = ( key : keyof FeeFields ) => ( e : React . ChangeEvent < HTMLInputElement > ) =>
4568 onChange ( { ...fields , [ key ] : e . target . value } )
4669
4770 const capHint =
4871 maxBps !== undefined
49- ? `Caps: max ${ maxBps . toString ( ) } bps ( ${ formatBps ( maxBps ) } ) ${
72+ ? `Caps: max ${ formatBps ( maxBps ) } ${
5073 maxFixedFee !== undefined ? `, max ${ formatTrust ( maxFixedFee ) } TRUST fixed` : ''
5174 } `
5275 : null
@@ -56,17 +79,17 @@ export function FeeConfigFields({ fields, onChange, maxBps, maxFixedFee }: Props
5679 < div className = "text-xs text-subtle" > Fee schedule{ capHint ? ` — ${ capHint } ` : '' } </ div >
5780 < div className = "grid gap-4 sm:grid-cols-2" >
5881 < Field
59- label = "Deposit bps "
60- hint = "base 10000 "
61- value = { fields . depositBps }
62- onChange = { set ( 'depositBps ' ) }
82+ label = "Deposit fee (%) "
83+ hint = "e.g. 1.5 for 1.5% "
84+ value = { fields . depositPct }
85+ onChange = { set ( 'depositPct ' ) }
6386 mono
6487 />
6588 < Field
66- label = "Creation bps "
67- hint = "base 10000 "
68- value = { fields . creationBps }
69- onChange = { set ( 'creationBps ' ) }
89+ label = "Creation fee (%) "
90+ hint = "e.g. 1.5 for 1.5% "
91+ value = { fields . creationPct }
92+ onChange = { set ( 'creationPct ' ) }
7093 mono
7194 />
7295 < Field
0 commit comments