Skip to content

Commit

Permalink
Merge pull request #4 from near-daos/develop
Browse files Browse the repository at this point in the history
sync main with develop branch
  • Loading branch information
okalenyk authored Jan 21, 2022
2 parents a91659c + 65c0f44 commit 1b6ded0
Show file tree
Hide file tree
Showing 90 changed files with 1,278 additions and 989 deletions.
4 changes: 2 additions & 2 deletions src/api/currency/currency.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AxiosResponse } from 'axios';
import { HttpService } from '../http-service';
import { Currency } from './types';
import { CurrentCurrency } from './types';

export class CurrencyService extends HttpService {
async getCurrency(): Promise<AxiosResponse<Currency>> {
async getCurrency(): Promise<AxiosResponse<CurrentCurrency>> {
return this.get('/api/v3/simple/price?ids=near&vs_currencies=usd', {
baseURL: 'https://api.coingecko.com',
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/currency/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export type Usd = {
usd: number;
};

export type Currency = {
export type CurrentCurrency = {
near: Usd;
};
3 changes: 2 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './types';
export * from './general';
export * from './governance';
export * from './users';
Expand All @@ -8,3 +7,5 @@ export * from './flow';
export * from './tokens';
export * from './currency';
export * from './tvl';
export * from './market';
export * from './types';
2 changes: 2 additions & 0 deletions src/api/market/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './market';
export * from './types';
20 changes: 20 additions & 0 deletions src/api/market/market.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { AxiosResponse } from 'axios';
import queryString from 'query-string';

import { HttpService } from '../http-service';
import { PriceParamsHistory } from '../types';
import { Price } from './types';

export class MarketService extends HttpService {
async getPrice(params: PriceParamsHistory): Promise<AxiosResponse<Price[]>> {
const query = queryString.stringify({
from: params.from,
to: params.to,
currency: params.currency,
});

return this.get(`/market/${params.coin}/price?${query}`);
}
}

export const marketService = new MarketService();
8 changes: 8 additions & 0 deletions src/api/market/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Coin, Currency } from 'src/api/types';

export type Price = {
date: number;
coin: Coin;
currency: Currency;
price: string;
};
6 changes: 0 additions & 6 deletions src/api/tvl/tvl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export class TvlService extends HttpService {
return this.get(`${params.contract}/tvl/tvl/leaderboard`);
}

async getTvlAvgTvl(params: HistoryParams): Promise<AxiosResponse<Metrics>> {
const query = queryString.stringify({ from: params.from, to: params.to });

return this.get(`${params.contract}/tvl/avg-tvl?${query}`);
}

async getTvlBountiesAndGrantsVl(
params: HistoryParams,
): Promise<AxiosResponse<Metrics>> {
Expand Down
12 changes: 12 additions & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,15 @@ export type MetricsEntity = Metrics & {
export type FlowMetricsEntity = FlowMetrics & {
id: string;
};

export enum Currency {
USD = 'USD',
}

export enum Coin {
NEAR = 'NEAR',
}

export type PriceParams = { currency: Currency; coin: Coin };

export type PriceParamsHistory = PriceParams & History;
4 changes: 2 additions & 2 deletions src/app/flow-dao/flow-dao.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from 'src/components';
import { useRoutes } from 'src/hooks';
import { useAppDispatch, useAppSelector } from 'src/store';
import { ROUTES } from 'src/constants';
import { UrlParams, ROUTES } from 'src/constants';
import styles from 'src/styles/page.module.scss';

import { IncomingFunds } from './funds/incoming';
Expand All @@ -31,7 +31,7 @@ import { OutgoingTransactions } from './transactions/outgoing';
export const FlowDao: FC = () => {
const location = useLocation();
const history = useHistory();
const { contract, dao } = useParams<{ dao: string; contract: string }>();
const { contract, dao } = useParams<UrlParams>();
const routes = useRoutes();

const dispatch = useAppDispatch();
Expand Down
29 changes: 18 additions & 11 deletions src/app/flow-dao/funds/incoming/incoming-funds.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import React, { FC, useState } from 'react';
import { useParams } from 'react-router';
import { useMount } from 'react-use';
import { useMount, useUnmount } from 'react-use';

import { ChartLine, LoadingContainer } from 'src/components';
import { useFilterMetrics, usePeriods } from 'src/hooks';
import { useAppDispatch, useAppSelector } from 'src/store';
import { selectFlowDaoFundsById } from 'src/app/shared/flow/selectors';
import { getFlowDaoFunds } from 'src/app/shared/flow/slice';
import {
selectFlowDaoFundsById,
selectFlowError,
} from 'src/app/shared/flow/selectors';
import { clearFlowError, getFlowDaoFunds } from 'src/app/shared/flow/slice';
import { selectActionLoading } from 'src/store/loading';
import { isSuccess, isFailed } from 'src/utils';
import { UrlParams } from 'src/constants';

import styles from 'src/styles/page.module.scss';

export const IncomingFunds: FC = () => {
const [period, setPeriod] = useState('All');
const { contract, dao } = useParams<{ dao: string; contract: string }>();
const { contract, dao } = useParams<UrlParams>();
const dispatch = useAppDispatch();
const funds = useAppSelector(selectFlowDaoFundsById(dao));
const error = useAppSelector(selectFlowError);
const getFlowDaoFundsLoading = useAppSelector(
selectActionLoading(getFlowDaoFunds.typePrefix),
);
Expand All @@ -28,12 +33,14 @@ export const IncomingFunds: FC = () => {
contract,
dao,
}),
).catch((error: unknown) => {
console.error(error);
});
).catch((err: unknown) => console.error(err));
}
});

useUnmount(() => {
dispatch(clearFlowError());
});

const fundsData = useFilterMetrics(period, funds);
const periods = usePeriods(fundsData?.metrics);

Expand All @@ -44,12 +51,12 @@ export const IncomingFunds: FC = () => {
isSuccess(getFlowDaoFundsLoading) || isFailed(getFlowDaoFundsLoading)
}
/>

{fundsData?.metrics?.length === 0 ? 'Not enough data' : null}
{error ? <p className={styles.error}>{error}</p> : null}
<div className={styles.metricsContainer}>
{fundsData?.metrics?.length === 0 ? 'Not enough data' : null}
{fundsData && fundsData?.metrics?.length ? (
{fundsData?.metrics?.length ? (
<ChartLine
isCurrency
isNear
data={fundsData}
period={period}
setPeriod={setPeriod}
Expand Down
27 changes: 17 additions & 10 deletions src/app/flow-dao/funds/outgoing/outgoing-funds.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import React, { FC, useState } from 'react';
import { useParams } from 'react-router';
import { useMount } from 'react-use';
import { useMount, useUnmount } from 'react-use';

import { ChartLine, LoadingContainer } from 'src/components';
import { useFilterMetrics, usePeriods } from 'src/hooks';
import { useAppDispatch, useAppSelector } from 'src/store';
import { selectFlowDaoFundsById } from 'src/app/shared/flow/selectors';
import { getFlowDaoFunds } from 'src/app/shared/flow/slice';
import {
selectFlowDaoFundsById,
selectFlowError,
} from 'src/app/shared/flow/selectors';
import { clearFlowError, getFlowDaoFunds } from 'src/app/shared/flow/slice';
import { selectActionLoading } from 'src/store/loading';
import { isSuccess, isFailed } from 'src/utils';
import { UrlParams } from 'src/constants';

import styles from 'src/styles/page.module.scss';

export const OutgoingFunds: FC = () => {
const [period, setPeriod] = useState('All');
const { contract, dao } = useParams<{ dao: string; contract: string }>();
const { contract, dao } = useParams<UrlParams>();
const dispatch = useAppDispatch();
const funds = useAppSelector(selectFlowDaoFundsById(dao));
const error = useAppSelector(selectFlowError);
const getFlowDaoFundsLoading = useAppSelector(
selectActionLoading(getFlowDaoFunds.typePrefix),
);
Expand All @@ -28,12 +33,14 @@ export const OutgoingFunds: FC = () => {
contract,
dao,
}),
).catch((error: unknown) => {
console.error(error);
});
).catch((err: unknown) => console.error(err));
}
});

useUnmount(() => {
dispatch(clearFlowError());
});

const fundsData = useFilterMetrics(period, funds);
const periods = usePeriods(funds?.metrics);

Expand All @@ -44,12 +51,12 @@ export const OutgoingFunds: FC = () => {
isSuccess(getFlowDaoFundsLoading) || isFailed(getFlowDaoFundsLoading)
}
/>

{fundsData?.metrics?.length === 0 ? 'Not enough data' : null}
{error ? <p className={styles.error}>{error}</p> : null}
<div className={styles.metricsContainer}>
{fundsData?.metrics?.length === 0 ? 'Not enough data' : null}
{fundsData && fundsData?.metrics?.length ? (
<ChartLine
isCurrency
isNear
data={fundsData}
period={period}
setPeriod={setPeriod}
Expand Down
30 changes: 20 additions & 10 deletions src/app/flow-dao/transactions/incoming/incoming-transactions.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import React, { FC, useState } from 'react';
import { useParams } from 'react-router';
import { useMount } from 'react-use';
import { useMount, useUnmount } from 'react-use';

import { ChartLine, LoadingContainer } from 'src/components';
import { useFilterMetrics, usePeriods } from 'src/hooks';
import { useAppDispatch, useAppSelector } from 'src/store';
import { selectFlowDaoTransactionsById } from 'src/app/shared/flow/selectors';
import { getFlowDaoTransactions } from 'src/app/shared/flow/slice';
import {
selectFlowDaoTransactionsById,
selectFlowError,
} from 'src/app/shared/flow/selectors';
import {
clearFlowError,
getFlowDaoTransactions,
} from 'src/app/shared/flow/slice';
import { selectActionLoading } from 'src/store/loading';
import { isFailed, isSuccess } from 'src/utils';
import { UrlParams } from 'src/constants';

import styles from 'src/styles/page.module.scss';

export const IncomingTransactions: FC = () => {
const [period, setPeriod] = useState('All');
const { contract, dao } = useParams<{ dao: string; contract: string }>();
const { contract, dao } = useParams<UrlParams>();
const dispatch = useAppDispatch();
const error = useAppSelector(selectFlowError);
const transactions = useAppSelector(selectFlowDaoTransactionsById(dao));
const getFlowDaoTransactionLoading = useAppSelector(
selectActionLoading(getFlowDaoTransactions.typePrefix),
Expand All @@ -28,12 +36,14 @@ export const IncomingTransactions: FC = () => {
contract,
dao,
}),
).catch((error: unknown) => {
console.error(error);
});
).catch((err: unknown) => console.error(err));
}
});

useUnmount(() => {
dispatch(clearFlowError());
});

const transactionsData = useFilterMetrics(period, transactions);
const periods = usePeriods(transactions?.metrics);

Expand All @@ -45,10 +55,10 @@ export const IncomingTransactions: FC = () => {
isFailed(getFlowDaoTransactionLoading)
}
/>

{error ? <p className={styles.error}>{error}</p> : null}
{transactionsData?.metrics?.length === 0 ? 'Not enough data' : null}
<div className={styles.metricsContainer}>
{transactionsData?.metrics?.length === 0 ? 'Not enough data' : null}
{transactionsData && transactionsData?.metrics?.length ? (
{transactionsData?.metrics?.length ? (
<ChartLine
data={transactionsData}
period={period}
Expand Down
22 changes: 12 additions & 10 deletions src/app/flow-dao/transactions/outgoing/outgoing-transactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import { useMount } from 'react-use';
import { ChartLine, LoadingContainer } from 'src/components';
import { useFilterMetrics, usePeriods } from 'src/hooks';
import { useAppDispatch, useAppSelector } from 'src/store';
import { selectFlowDaoTransactionsById } from 'src/app/shared/flow/selectors';
import {
selectFlowDaoTransactionsById,
selectFlowError,
} from 'src/app/shared/flow/selectors';
import { getFlowDaoTransactions } from 'src/app/shared/flow/slice';
import { selectActionLoading } from 'src/store/loading';
import { isFailed, isSuccess } from 'src/utils';
import { Params } from 'src/constants';
import { UrlParams } from 'src/constants';

import styles from 'src/styles/page.module.scss';

export const OutgoingTransactions: FC = () => {
const [period, setPeriod] = useState('All');
const { contract, dao } = useParams<Params>();
const { contract, dao } = useParams<UrlParams>();
const dispatch = useAppDispatch();
const error = useAppSelector(selectFlowError);
const transactions = useAppSelector(selectFlowDaoTransactionsById(dao));
const getFlowDaoTransactionsLoading = useAppSelector(
selectActionLoading(getFlowDaoTransactions.typePrefix),
Expand All @@ -29,9 +33,7 @@ export const OutgoingTransactions: FC = () => {
contract,
dao,
}),
).catch((error: unknown) => {
console.error(error);
});
).catch((err: unknown) => console.error(err));
}
});

Expand All @@ -46,18 +48,18 @@ export const OutgoingTransactions: FC = () => {
isFailed(getFlowDaoTransactionsLoading)
}
/>

{error ? <p className={styles.error}>{error}</p> : null}
{transactionsData?.metrics?.length === 0 ? 'Not enough data' : null}
<div className={styles.metricsContainer}>
{transactionsData?.metrics?.length === 0 ? 'Not enough data' : null}
{transactionsData && transactionsData?.metrics?.length ? (
{transactionsData?.metrics?.length ? (
<ChartLine
data={transactionsData}
period={period}
setPeriod={setPeriod}
periods={periods}
lines={[
{
name: 'Outgoing of Transactions',
name: 'Outgoing Transactions',
color: '#E33F84',
dataKey: 'outgoing',
},
Expand Down
Loading

0 comments on commit 1b6ded0

Please sign in to comment.