File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
tests/govtool-frontend/playwright/lib/helpers Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,21 @@ const LOVELACE = 1000000;
22
33export const correctVoteAdaFormat = (
44 lovelace : number | undefined ,
5- locale : string | undefined = undefined
5+ precision = 2
66) => {
77 if ( lovelace ) {
88 const ada = lovelace / LOVELACE ;
9- return ada . toLocaleString ( locale , {
10- maximumFractionDigits : 3 ,
11- } ) ;
9+ if ( ada < 1000 )
10+ return ada . toLocaleString ( "en-us" , {
11+ maximumFractionDigits : precision ,
12+ } ) ;
13+ const suffixes = [ "k" , "M" , "B" , "T" ] ;
14+ const divisors = [ 1000 , 1000000 , 1000000000 , 1000000000000 ] ;
15+ for ( let i = 0 ; i < suffixes . length ; i ++ ) {
16+ if ( ada < divisors [ i ] * 1000 ) {
17+ return ( ada / divisors [ i ] ) . toFixed ( precision ) + suffixes [ i ] ;
18+ }
19+ }
1220 }
1321 return "0" ;
1422} ;
You can’t perform that action at this time.
0 commit comments