Skip to content

Commit 3b6d902

Browse files
authored
add all other fiat support for crypto denomination (#139)
* add all other fiat support for cryptodenomination * minor changes * minor changes
1 parent 52ae73f commit 3b6d902

4 files changed

Lines changed: 33 additions & 38 deletions

File tree

demo/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function App() {
1818
const sheetEditorRef = useRef<WorkbookInstance>(null);
1919

2020
// Use a stable dsheetId
21-
const dsheetId = 'demo-dsheet-3';
21+
const dsheetId = 'demo-dsheet-4';
2222
// @ts-expect-error later
2323
window.NEXT_PUBLIC_PROXY_BASE_URL = 'https://staging-api-proxy-ca4268d7d581.herokuapp.com';
2424

package-lock.json

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@fileverse-dev/dsheet",
33
"private": false,
44
"description": "DSheet",
5-
"version": "1.0.63",
5+
"version": "1.0.67",
66
"main": "dist/index.es.js",
77
"module": "dist/index.es.js",
88
"exports": {
@@ -36,8 +36,8 @@
3636
"@fileverse-dev/dsheets-templates": "^0.0.17",
3737
"@fileverse-dev/formula-parser": "^0.2.37",
3838
"@fileverse-dev/formulajs": "^4.4.11-mod-83",
39-
"@fileverse-dev/fortune-core": "^1.0.51",
40-
"@fileverse-dev/fortune-react": "^1.0.51",
39+
"@fileverse-dev/fortune-core": "^1.0.59",
40+
"@fileverse-dev/fortune-react": "^1.0.59",
4141
"@fileverse/ui": "^4.1.7-patch-18",
4242
"classnames": "^2.5.1",
4343
"exceljs": "^4.4.0",

package/hooks/useRefreshDenomination.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)