Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Commit

Permalink
Added UserTradesGraph in CoinPage
Browse files Browse the repository at this point in the history
  • Loading branch information
superRaptor911 committed Feb 18, 2022
1 parent e6c454a commit d1d507e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
33 changes: 21 additions & 12 deletions src/pages/Coin.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useState} from 'react';
import React, {Fragment, useEffect, useState} from 'react';
import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';
import {useParams} from 'react-router-dom';
Expand All @@ -16,13 +16,14 @@ import {
getCoinPrice,
getWazirxUser,
} from '../components/helper';
import {Coin} from '../types';
import {Coin, Transaction} from '../types';
import CoinGraph from '../components/coin/CoinGraph';
import Loading from '../components/Loading';
import UserTransaction from '../components/user/UserTransactions';
import StopLossBot4Coin from '../components/coin/StopLossBot4Coin';
import CoinBuyMenu from '../components/coin/CoinBuyMenu';
import useTimer from '../components/hooks/useTimer';
import UserTradesGraph from '../components/user/UserTradesGraph';

interface CoinDetailsProp {
coin: Coin;
Expand Down Expand Up @@ -77,6 +78,7 @@ const CoinDetails = ({coin}: CoinDetailsProp) => {
const CoinPage = () => {
const {coinName}: {coinName: string} = useParams();
const [coin, setCoin] = useState<Coin | null>();
const [userTransactions, setUserTransactions] = useState<Transaction[]>([]);

const coins = useStore(state => state.coins);
const loadCoinPrices = useStore(state => state.loadCoinPrices);
Expand All @@ -88,11 +90,12 @@ const CoinPage = () => {
setCoin(getCoin(coins, coinName));
}, [coinName]);

// Load coin price and transaction list on load
// useEffect(() => {
// loadCoinPrices();
// loadTransactions();
// }, []);
useEffect(() => {
if (user) {
const list = transactions.filter(item => item.username == user.name);
setUserTransactions(list);
}
}, [transactions]);

// Load coin price and transaction list every 2000 ms
useTimer(2000, () => {
Expand Down Expand Up @@ -130,11 +133,17 @@ const CoinPage = () => {
<CoinBuyMenu coinId={coin.id} />
<CoinDetails coin={coin} />
{user && (
<UserTransaction
allTransactions={transactions}
user={user}
coinId={coin.id}
/>
<Fragment>
<UserTransaction
allTransactions={transactions}
user={user}
coinId={coin.id}
/>
<UserTradesGraph
userTransactions={userTransactions}
coinId={coin.id}
/>
</Fragment>
)}
<StopLossBot4Coin coinId={coin.id} />
</div>
Expand Down
8 changes: 1 addition & 7 deletions src/pages/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ const UserPage = () => {

useEffect(() => {
if (transactions) {
let list: Transaction[] = [];
transactions.forEach(item => {
if (item.username === username) {
list.push(item);
}
});

const list = transactions.filter(item => item.username == username);
setUserTransactions(list);
}
}, [transactions, username]);
Expand Down

0 comments on commit d1d507e

Please sign in to comment.