@@ -288,6 +288,110 @@ describe('Amount formatting', () => {
288288
289289 } ) ;
290290
291+ describe ( 'maxDecimals for ETH and ETH tokens' , ( ) => {
292+
293+ it ( 'ETH limits decimals to maxDecimals' , ( ) => {
294+ const { container } = render (
295+ < Amount amount = "10.123456789012345678" unit = "ETH" maxDecimals = { 6 } />
296+ ) ;
297+
298+ expect ( container . textContent ) . toBe ( '10.123456' ) ;
299+ } ) ;
300+
301+ it ( 'SEPETH limits decimals to maxDecimals' , ( ) => {
302+ const { container } = render (
303+ < Amount amount = "10.123456789012345678" unit = "SEPETH" maxDecimals = { 4 } />
304+ ) ;
305+
306+ expect ( container . textContent ) . toBe ( '10.1234' ) ;
307+ } ) ;
308+
309+ it ( 'ETH keeps decimals when they are below maxDecimals' , ( ) => {
310+ const { container } = render (
311+ < Amount amount = "10.123" unit = "ETH" maxDecimals = { 6 } />
312+ ) ;
313+
314+ expect ( container . textContent ) . toBe ( '10.123' ) ;
315+ } ) ;
316+
317+ it ( 'ETH keeps decimals when they are exactly maxDecimals' , ( ) => {
318+ const { container } = render (
319+ < Amount amount = "10.123456" unit = "ETH" maxDecimals = { 6 } />
320+ ) ;
321+
322+ expect ( container . textContent ) . toBe ( '10.123456' ) ;
323+ } ) ;
324+
325+ it ( 'USDC limits decimals to maxDecimals' , ( ) => {
326+ const { container } = render (
327+ < Amount amount = "1'234.123456789" unit = "USDC" maxDecimals = { 2 } />
328+ ) ;
329+
330+ expect ( container . textContent ) . toBe ( '1’234.12' ) ;
331+ } ) ;
332+
333+ it ( 'USDC keeps decimals when they are below maxDecimals' , ( ) => {
334+ const { container } = render (
335+ < Amount amount = "1'234.1" unit = "USDC" maxDecimals = { 2 } />
336+ ) ;
337+
338+ expect ( container . textContent ) . toBe ( '1’234.1' ) ;
339+ } ) ;
340+
341+ it ( 'DAI limits its 18 decimals to maxDecimals' , ( ) => {
342+ const { container } = render (
343+ < Amount
344+ amount = "1.123456789012345678"
345+ unit = "DAI"
346+ maxDecimals = { 6 }
347+ />
348+ ) ;
349+
350+ expect ( container . textContent ) . toBe ( '1.123456' ) ;
351+ } ) ;
352+
353+ it ( 'DAI limits long decimal values to maxDecimals' , ( ) => {
354+ const { container } = render (
355+ < Amount
356+ amount = "123'456.123456789012345678"
357+ unit = "DAI"
358+ maxDecimals = { 4 }
359+ />
360+ ) ;
361+
362+ expect ( container . textContent ) . toBe ( '123’456.1234' ) ;
363+ } ) ;
364+
365+ } ) ;
366+
367+ describe ( 'maxDecimals does not affect BTC/LTC or fiat amounts' , ( ) => {
368+
369+ it ( 'does not limit BTC decimals' , ( ) => {
370+ const { container } = render (
371+ < Amount amount = "0.12345678" unit = "BTC" maxDecimals = { 2 } />
372+ ) ;
373+
374+ expect ( container . textContent ) . toBe ( '0.12345678' ) ;
375+ } ) ;
376+
377+ it ( 'does not limit LTC decimals' , ( ) => {
378+ const { container } = render (
379+ < Amount amount = "0.12345678" unit = "LTC" maxDecimals = { 2 } />
380+ ) ;
381+
382+ expect ( container . textContent ) . toBe ( '0.12345678' ) ;
383+ } ) ;
384+
385+ it ( 'does not limit fiat decimals' , ( ) => {
386+ const { container } = render (
387+ < Amount amount = "1'340.123456" unit = "CHF" maxDecimals = { 2 } />
388+ ) ;
389+
390+ expect ( container . textContent ) . toBe ( '1’340.123456' ) ;
391+ } ) ;
392+
393+ } ) ;
394+
291395 afterEach ( ( ) => {
292396 vi . clearAllMocks ( ) ;
293397 } ) ;
0 commit comments