This repository was archived by the owner on Feb 23, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,11 @@ export const toAmount = (satoshis, unit) => {
8282 if ( ! Number . isInteger ( satoshis ) || ! UNITS [ unit ] ) {
8383 throw new Error ( 'Invalid input!' ) ;
8484 }
85- return ( satoshis / UNITS [ unit ] . denominator ) . toString ( ) ;
85+ const num = satoshis / UNITS [ unit ] . denominator ;
86+ return num . toLocaleString ( 'en-US' , {
87+ useGrouping : false ,
88+ maximumFractionDigits : 8 ,
89+ } ) ;
8690} ;
8791
8892/**
Original file line number Diff line number Diff line change @@ -275,6 +275,26 @@ describe('Helpers Unit Tests', () => {
275275 const num = helpers . toAmount ( 0 , 'btc' ) ;
276276 expect ( num , 'to equal' , '0' ) ;
277277 } ) ;
278+
279+ it ( 'should work for 1' , ( ) => {
280+ const num = helpers . toAmount ( 1 , 'btc' ) ;
281+ expect ( num , 'to equal' , '0.00000001' ) ;
282+ } ) ;
283+
284+ it ( 'should work for 10' , ( ) => {
285+ const num = helpers . toAmount ( 10 , 'btc' ) ;
286+ expect ( num , 'to equal' , '0.0000001' ) ;
287+ } ) ;
288+
289+ it ( 'should work for 100' , ( ) => {
290+ const num = helpers . toAmount ( 100 , 'btc' ) ;
291+ expect ( num , 'to equal' , '0.000001' ) ;
292+ } ) ;
293+
294+ it ( 'should work for 1000' , ( ) => {
295+ const num = helpers . toAmount ( 1000 , 'btc' ) ;
296+ expect ( num , 'to equal' , '0.00001' ) ;
297+ } ) ;
278298 } ) ;
279299
280300 describe ( 'calculateExchangeRate()' , ( ) => {
You can’t perform that action at this time.
0 commit comments