Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
chore: added firebase config
Browse files Browse the repository at this point in the history
  • Loading branch information
meenu-deriv committed Nov 13, 2023
1 parent 4411d52 commit 150565b
Show file tree
Hide file tree
Showing 5 changed files with 25,095 additions and 1,510 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useState, useEffect } from 'react';
import { initializeApp } from 'firebase/app';
import { getDatabase, ref, onValue } from 'firebase/database';
import { firebaseConfig } from '@deriv-com/utils';

const usePricingFeed = () => {
const [data, setData] = useState(null);
const [error, setError] = useState(null);

useEffect(() => {
const app = initializeApp(firebaseConfig);
const db = getDatabase(app);

const commoditiesRef = ref(db);
const unsubscribe = onValue(
commoditiesRef,
(snapshot) => {
setData(snapshot.val());
},
(err) => {
setError(err);
},
);

return unsubscribe;
}, []);

return [error, data];
};

export default usePricingFeed;
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
MarketForexUsdcadIcon,
StandaloneLocationCrosshairsBoldIcon,
} from '@deriv/quill-icons';
import usePricingFeed from './hooks/use-pricing-feed';

const LiveMarketSection = () => {
const [LivePriceData, setLivePriceData] = useState<LiveMarketContent[]>([]);
const [error, liveMarketsData] = usePricingFeed();

const forexIcons: { [key: string]: ReactNode } = {
'AUD/USD': <MarketForexAudusdIcon />,
Expand All @@ -21,14 +23,15 @@ const LiveMarketSection = () => {
'GBP/USD': <MarketForexGbpusdIcon />,
'USD/CAD': <MarketForexUsdcadIcon />,
};

const handleLiveMarketData = (data: any) => {
if (data) {
const markets = data?.row?.mkt;

if (markets) {
const { fx } = markets;

const newLivePriceData = [...LivePriceData];
console.log('fnewLivePriceDatax', newLivePriceData);

Object.keys(fx).forEach((marketKey) => {
const { sym, ask, bid, chng, sprd } = fx[marketKey];
Expand All @@ -53,17 +56,13 @@ const LiveMarketSection = () => {
});

setLivePriceData(newLivePriceData);
}
} else return error;
}
};

useEffect(() => {
setInterval(() => {
fetch('https://deriv-static-pricingfeedv2.firebaseio.com/.json')
.then((response) => response.json())
.then((data) => handleLiveMarketData(data));
}, 900);
}, []);
handleLiveMarketData(liveMarketsData);
}, [liveMarketsData]);

return (
<LiveMarket
Expand Down
4 changes: 4 additions & 0 deletions libs/utils/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ export const searchString = (

return [];
};

export const firebaseConfig = {
databaseURL: 'https://deriv-static-pricingfeedv2.firebaseio.com/',
};
Loading

0 comments on commit 150565b

Please sign in to comment.