Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7f477e3
install react-query
pingustar Jun 22, 2022
38076e8
refactor statistics to use react-query
pingustar Jun 22, 2022
f711874
react-query tmp commit
pingustar Jun 23, 2022
5620a4d
react-query tmp commit
pingustar Jul 4, 2022
dd5d377
Merge branch 'main' into feature/react-query
pingustar Jul 4, 2022
40522df
Merge remote-tracking branch 'origin/feature/react-query' into featur…
pingustar Jul 4, 2022
5ab79b3
fix merge conflicts
pingustar Jul 4, 2022
b8cf770
Merge branch 'main' into feature/react-query
pingustar Jul 4, 2022
2ae3e54
core functionality proof of concept
pingustar Jul 5, 2022
d60264a
remove alert when BNT
pingustar Jul 8, 2022
97b579b
introduce new api for getting pool data
pingustar Jul 11, 2022
f8812a9
introduce new api for pool table and top pools
pingustar Jul 12, 2022
9b36912
Merge branch 'main' into feature/react-query
pingustar Jul 12, 2022
bc6a8b7
cleanup part 1
pingustar Jul 12, 2022
5321734
refactor vote to for usePoolPick react-query hook
pingustar Jul 19, 2022
ca2cd9a
remove unneeded zod dependency
pingustar Jul 19, 2022
c8b1573
remove unneeded zod dependency
pingustar Jul 19, 2022
f2a73a5
remove unneeded error boundry component
pingustar Jul 19, 2022
3274bd6
Merge branch 'main' into feature/react-query
pingustar Jul 19, 2022
01ff24d
remove unneeded debug / test code
pingustar Jul 19, 2022
d00a886
remove unneeded debug / test code
pingustar Jul 19, 2022
4e627b9
rename to useChainBalances.ts
pingustar Jul 19, 2022
7867fe9
cleanup file/folder structure for queries
pingustar Jul 19, 2022
0f58941
change usePoolPick getMany to not require ids to be passed
pingustar Jul 19, 2022
acd95c2
Merge branch 'main' into feature/react-query
pingustar Jul 19, 2022
0de50c1
Merge branch 'main' into feature/react-query
pingustar Jul 20, 2022
bcaa638
update react-query to v4
pingustar Jul 20, 2022
e8da648
add index file and default exports for queries folder
pingustar Jul 20, 2022
a385971
extract query client provider in separate file
pingustar Jul 20, 2022
009ba72
add depositingEnabled to usePoolPick
pingustar Jul 21, 2022
8b837a9
cleanup
pingustar Jul 21, 2022
675fc8a
add rate to usePoolPick
pingustar Jul 21, 2022
7ca6b80
remove unused code
pingustar Jul 21, 2022
77d702b
add sentry error reporting
pingustar Jul 21, 2022
d8a9c86
polish and small bug fixes
pingustar Jul 21, 2022
ddfed89
fix vote approval tmp
pingustar Jul 21, 2022
a08bef5
Merge branch 'main' into feature/react-query
pingustar Jul 25, 2022
cc424a0
fix subscribeToObservables based on pathname
pingustar Jul 26, 2022
a9798c5
Merge remote-tracking branch 'origin/main' into feature/react-query
pingustar Aug 1, 2022
cc9c571
align with main and resolve conflicts
pingustar Aug 1, 2022
da9ab92
fix react query keys and key factory
pingustar Aug 1, 2022
81061ea
use trading liquidity from api and fix react query error boundary
pingustar Aug 1, 2022
68f692d
adapted deposit modal
zavelevsky Aug 1, 2022
67e8122
refactor useApproveModal.tsx to use no token interface
pingustar Aug 1, 2022
492a776
signed commit test
pingustar Aug 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
REACT_APP_DEBUG_MODE=
REACT_APP_ALCHEMY_MAINNET=
REACT_APP_ALCHEMY_ROPSTEN=
REACT_APP_PORTIS_DAPP_ID=
REACT_APP_FORTMATIC_API_KEY=
REACT_APP_APY_VISION_TOKEN=
REACT_APP_INTOTHEBLOCK_KEY=
REACT_APP_SENTRY_DSN=
REACT_APP_BANCOR_DEPLOYER=
GENERATE_SOURCEMAP=false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
Your app is ready to be deployed.

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"@headlessui/react": "^1.3.0",
"@popperjs/core": "^2.9.3",
"@reduxjs/toolkit": "^1.6.2",
"@sentry/react": "^7.7.0",
"@sentry/tracing": "^7.7.0",
"@tanstack/react-query": "^4.0.5",
"@tanstack/react-query-devtools": "^4.0.5",
"@types/jest": "^26.0.15",
"@types/lodash": "^4.14.170",
"@types/node": "^12.0.0",
Expand Down Expand Up @@ -56,10 +60,10 @@
"@storybook/addon-actions": "6.5.9",
"@storybook/addon-essentials": "6.5.9",
"@storybook/addon-links": "6.5.9",
"@storybook/node-logger": "6.5.9",
"@storybook/preset-create-react-app": "4.1.2",
"@storybook/builder-webpack5": "6.5.9",
"@storybook/manager-webpack5": "6.5.9",
"@storybook/node-logger": "6.5.9",
"@storybook/preset-create-react-app": "4.1.2",
"@storybook/react": "6.5.9",
"@typechain/ethers-v5": "^8.0.2",
"@types/json-bigint": "^1.0.0",
Expand Down
10 changes: 2 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import {
setSlippageTolerance,
setUsdToggle,
} from 'store/user/user';
import {
Notification,
setNotifications,
} from 'store/notification/notification';
import { setNotifications } from 'store/notification/notification';
import { store, useAppSelector } from 'store';
import { googleTagManager } from 'services/api/googleTagManager';
import {
Expand All @@ -23,7 +20,6 @@ import {
getUsdToggleLS,
setNotificationsLS,
} from 'utils/localStorage';
import { subscribeToObservables } from 'services/observables/triggers';
import { isUnsupportedNetwork } from 'utils/helperFunctions';
import { MobileBottomNav } from 'elements/layoutHeader/MobileBottomNav';
import { useWeb3React } from '@web3-react/core';
Expand All @@ -41,7 +37,7 @@ export const App = () => {
const { chainId, account } = useWeb3React();
useAutoConnect();
const unsupportedNetwork = isUnsupportedNetwork(chainId);
const notifications = useAppSelector<Notification[]>(
const notifications = useAppSelector(
(state) => state.notification.notifications
);

Expand Down Expand Up @@ -75,8 +71,6 @@ export const App = () => {
const slippage = getSlippageToleranceLS();
if (slippage) dispatch(setSlippageTolerance(slippage));

subscribeToObservables(dispatch);

const dark = getDarkModeLS();
dispatch(setDarkMode(dark));
}, [dispatch]);
Expand Down
10 changes: 5 additions & 5 deletions src/components/tokenInput/TokenInputV3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { memo, useMemo } from 'react';
import { prettifyNumber } from 'utils/helperFunctions';
import { useResizeTokenInput } from 'components/tokenInput/useResizeTokenInput';
import { useTokenInputV3 } from 'components/tokenInput/useTokenInputV3';
import { Token } from 'services/observables/tokens';
import useDimensions from 'hooks/useDimensions';
import { Image } from 'components/image/Image';
import { getBancorLogoUrl } from 'utils/pureFunctions';

export interface TokenInputV3Props {
token: Token;
dltId: string;
inputTkn: string;
setInputTkn: (amount: string) => void;
inputFiat: string;
Expand All @@ -17,7 +17,7 @@ export interface TokenInputV3Props {
}

const TokenInputV3 = ({
token,
dltId,
inputTkn,
setInputTkn,
inputFiat,
Expand All @@ -27,7 +27,7 @@ const TokenInputV3 = ({
}: TokenInputV3Props) => {
const { handleChange, inputUnit, oppositeUnit, isFocused, setIsFocused } =
useTokenInputV3({
token,
dltId,
setInputTkn,
setInputFiat,
isFiat,
Expand Down Expand Up @@ -55,7 +55,7 @@ const TokenInputV3 = ({
} ${isError ? 'border-error text-error' : ''}`}
>
<Image
src={token.logoURI}
src={getBancorLogoUrl(dltId)}
alt={'Token Logo'}
className="absolute w-[40px] h-[40px] ml-20 !rounded-full"
/>
Expand Down
18 changes: 13 additions & 5 deletions src/components/tokenInput/useTokenInputV3.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeEvent, useCallback, useMemo, useState } from 'react';
import { ChangeEvent, useCallback, useState } from 'react';
import { calcFiatValue, calcTknValue } from 'utils/helperFunctions';
import { Token } from 'services/observables/tokens';
import { sanitizeNumberInput } from 'utils/pureFunctions';
import { usePoolPick } from 'queries/index';

export const calcOppositeValue = (
isFiat: boolean,
Expand All @@ -17,27 +17,35 @@ export const calcOppositeValue = (
};

export interface useTokenInputV3Props {
token: Token;
dltId: string;
setInputTkn: (amount: string) => void;
setInputFiat: (amount: string) => void;
isFiat: boolean;
}

export const useTokenInputV3 = ({
token,
dltId,
setInputTkn,
setInputFiat,
isFiat,
}: useTokenInputV3Props) => {
const { getOne } = usePoolPick(['symbol', 'decimals', 'rate']);
const { data } = getOne(dltId);
const symbol = data?.symbol;
const usdPrice = data?.rate?.usd;
const decimals = data?.decimals;
const [isFocused, setIsFocused] = useState(false);
const { symbol, usdPrice, decimals } = useMemo(() => token, [token]);
const inputUnit = isFiat ? 'USD' : symbol;

const oppositeUnit = isFiat ? symbol : 'USD';

const handleChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
const value = sanitizeNumberInput(e.target.value);
if (!usdPrice || !decimals) {
console.error('Missing or still loading data for calculation');
return;
}

if (isFiat) {
const oppositeValue = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import TokenInputV3, {
} from 'components/tokenInput/TokenInputV3';
import { useEffect, useState } from 'react';
import { calcFiatValue, prettifyNumber } from 'utils/helperFunctions';
import { usePoolPick } from 'queries/index';

interface TokenInputPercentageV3Props extends TokenInputV3Props {
interface TokenInputPercentageV3Props extends Omit<TokenInputV3Props, 'token'> {
dltId: string;
label: string;
balance?: string;
balanceLabel?: string;
}
const percentages = [25, 50, 75, 100];

export const TokenInputPercentageV3 = ({
token,
export const TokenInputPercentageV3New = ({
dltId,
balance,
inputTkn,
setInputTkn,
inputFiat,
Expand All @@ -23,50 +27,46 @@ export const TokenInputPercentageV3 = ({
label,
balanceLabel = 'Balance',
}: TokenInputPercentageV3Props) => {
const fieldBalance = token.balance
? token.balance
: token && token.balance
? token.balance
: undefined;

const { getOne } = usePoolPick(['decimals', 'rate']);
const { data: token } = getOne(dltId);
const [selPercentage, setSelPercentage] = useState<number>(-1);

const handleSetPercentage = (percent: number) => {
setSelPercentage(percentages.indexOf(percent));
if (fieldBalance !== undefined) {
const amount = new BigNumber(fieldBalance).times(percent / 100);
if (balance !== undefined && !!token) {
const amount = new BigNumber(balance).times(percent / 100);
setInputTkn(amount.toString());
setInputFiat(calcFiatValue(amount, token.usdPrice));
setInputFiat(calcFiatValue(amount, token.rate?.usd ?? 0));
}
};

useEffect(() => {
if (fieldBalance !== undefined) {
if (balance !== undefined) {
const percentage = new BigNumber(inputTkn)
.div(fieldBalance)
.div(balance)
.times(100)
.toNumber()
.toFixed(10);
setSelPercentage(
percentages.findIndex((x) => percentage === x.toFixed(10))
);
}
}, [fieldBalance, inputTkn]);
}, [balance, inputTkn]);

return (
<div className="w-full">
<div className="flex justify-between items-end mb-10">
<span>{label}</span>
{fieldBalance && (
{balance && (
<button
onClick={() => handleSetPercentage(100)}
className={`text-12 ${isError ? 'text-error' : ''}`}
>
{balanceLabel}: {prettifyNumber(fieldBalance)}{' '}
{balanceLabel}: {prettifyNumber(balance)}{' '}
<span className="text-secondary">
(
{prettifyNumber(
calcFiatValue(fieldBalance, token.usdPrice),
calcFiatValue(balance, token?.rate?.usd ?? 0),
true
)}
)
Expand All @@ -76,7 +76,7 @@ export const TokenInputPercentageV3 = ({
</div>
{token && (
<TokenInputV3
token={token}
dltId={dltId}
inputTkn={inputTkn}
setInputTkn={setInputTkn}
inputFiat={inputFiat}
Expand Down
65 changes: 34 additions & 31 deletions src/elements/earn/pools/Statistics.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
import { useAppSelector } from 'store';
import './Statistics.css';
import { useApiStatistics } from 'queries/api/useApiStatistics';

export const Statistics = () => {
const stats = useAppSelector((state) => state.bancor.statistics);
const first = stats[0];
const { data: stats } = useApiStatistics();

return (
<section className="content-block p-20">
{!stats.length ? (
[...Array(4)].map((_, i) => (
if (!stats) {
return (
<>
{[...Array(4)].map((_, i) => (
<div key={`stats-loading-key-${i}`}>
<div className="loading-skeleton w-1/2 h-20 mx-auto mb-10"></div>
<div className="loading-skeleton w-2/3 h-14 mx-auto"></div>
</div>
))
) : (
))}
</>
);
}

const first = stats[0];

return (
<>
<div className="flex items-end">
<div>
<div className="flex items-end">
<div>
<div className="text-secondary mb-15">{first.label}</div>
<div className="text-[30px] text-black-medium dark:text-white-medium uppercase">
{first.value}
</div>
</div>
<div className="text-secondary mb-15">{first.label}</div>
<div className="text-[30px] text-black-medium dark:text-white-medium uppercase">
{first.value}
</div>
<hr className="border-fog dark:border-grey my-20" />
<div className="grid grid-cols-2 gap-20">
{stats.slice(1).map((item, i) => (
<div key={`stats-key-${i}`}>
<div className="flex items-end">
<div>
<div className="text-secondary">{item.label}</div>
<div className="text-20 text-black-medium dark:text-white-medium uppercase">
{item.value}
</div>
</div>
</div>
</div>
<hr className="border-fog dark:border-grey my-20" />
<div className="grid grid-cols-2 gap-20">
{stats.slice(1).map((item, i) => (
<div key={`stats-key-${i}`}>
<div className="flex items-end">
<div>
<div className="text-secondary">{item.label}</div>
<div className="text-20 text-black-medium dark:text-white-medium uppercase">
{item.value}
</div>
</div>
))}
</div>
</div>
</div>
)}
</section>
))}
</div>
</>
);
};
Loading