@@ -6,34 +6,26 @@ export const useRefreshDenomination = ({
66} : {
77 sheetEditorRef : React . RefObject < WorkbookInstance | null >
88} ) => {
9- const cryptoPriceRef = useRef < { ETH : number | null , BTC : number | null , SOL : number | null } > ( { BTC : null , ETH : 0 , SOL : 0 } ) ;
9+ const cryptoPriceRef = useRef < { bitcoin : { } , ethereum : object , solana : object } | null > ( null ) ;
1010 const intervalRef = useRef < NodeJS . Timeout | null > ( null ) ;
1111
1212 const fetchPrice = async ( ) => {
1313 // @ts -expect-error later
1414 const cryptoPrices = await fetch ( `${ window . NEXT_PUBLIC_PROXY_BASE_URL } /proxy` , {
1515 headers :
1616 {
17- 'target-url' : 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd' ,
17+ 'target-url' : 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,solana&vs_currencies=usd,aed,ars,aud,bdt,bhd,bmd,brl,cad,chf,clp,cny,czk,dkk,eur,gbp,gel,hkd,huf,idr,ils,inr,jpy,krw,kwd,lkr,mmk,mxn,myr,ngn,nok,nzd,php,pkr,pln,rub,sar,sek,sgd,thb,try,twd,uah,vef,vnd,zar ' ,
1818 method : 'GET' ,
1919 'Content-Type' : 'application/json'
2020 }
2121 } ) ;
2222 const cryptoData = await cryptoPrices . json ( ) ;
23- const ETH = cryptoData . ethereum . usd ;
24- const BTC = cryptoData . bitcoin . usd ;
25- const SOL = cryptoData . solana . usd ;
26- cryptoPriceRef . current = {
27- ETH ,
28- BTC ,
29- SOL
30- }
23+ cryptoPriceRef . current = cryptoData ;
3124 refreshDenomination ( ) ;
3225 }
3326
3427 const refreshDenomination = async ( ) => {
35- const { ETH , BTC , SOL } = cryptoPriceRef . current ;
36- if ( BTC === null || ETH === null || SOL === null ) return ;
28+ if ( cryptoPriceRef . current === null ) return ;
3729 const currentData = sheetEditorRef . current ?. getSheet ( ) ;
3830 const cellData = currentData ?. celldata ;
3931 if ( ! cellData ) return ;
@@ -46,11 +38,14 @@ export const useRefreshDenomination = ({
4638 const value = cell . v ?. m ?. toString ( ) ;
4739 const decemialCount = cell . v ?. m ?. includes ( '.' ) ? cell . v ?. m ?. split ( ' ' ) [ 0 ] ?. split ( '.' ) [ 1 ] ?. length : 0 ;
4840 if ( value ?. includes ( "BTC" ) ) {
49- cell . v . m = value . replace ( / \d + ( \. \d + ) ? / , ( cell . v ?. baseValue / BTC ) . toFixed ( decemialCount ) . toString ( ) ) ;
41+ // @ts -expect-error later
42+ cell . v . m = value . replace ( / \d + ( \. \d + ) ? / , ( cell . v ?. baseValue / cryptoPriceRef . current . bitcoin ?. [ cell . v ?. baseCurrency ] ) . toFixed ( decemialCount ) . toString ( ) ) ;
5043 } else if ( value ?. includes ( "ETH" ) ) {
51- cell . v . m = value . replace ( / \d + ( \. \d + ) ? / , ( cell . v ?. baseValue / ETH ) . toFixed ( decemialCount ) . toString ( ) ) ;
44+ // @ts -expect-error later
45+ cell . v . m = value . replace ( / \d + ( \. \d + ) ? / , ( cell . v ?. baseValue / cryptoPriceRef . current . ethereum ?. [ cell . v ?. baseCurrency ] ) . toFixed ( decemialCount ) . toString ( ) ) ;
5246 } else if ( value ?. includes ( "SOL" ) ) {
53- cell . v . m = value . replace ( / \d + ( \. \d + ) ? / , ( cell . v ?. baseValue / SOL ) . toFixed ( decemialCount ) . toString ( ) ) ;
47+ // @ts -expect-error later
48+ cell . v . m = value . replace ( / \d + ( \. \d + ) ? / , ( cell . v ?. baseValue / cryptoPriceRef . current . solana ?. [ cell . v ?. baseCurrency ] ) . toFixed ( decemialCount ) . toString ( ) ) ;
5449 }
5550 sheetEditorRef . current ?. setCellValue ( cell . r , cell . c , cell . v ) ;
5651 }
0 commit comments