From deedbbe8ad55e457709c65aa41b8f062599d79ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Sim=C3=A3o?= Date: Thu, 17 Feb 2022 20:58:35 +0100 Subject: [PATCH] Finished first versions of Stake and Swap --- src/components/CryptoInput/index.tsx | 3 +- src/components/CryptoInput/types.ts | 1 + src/components/CryptoInput/utils.ts | 5 - src/components/Navbar/index.tsx | 1 + src/components/SwapInput/index.tsx | 163 ++++++++++++++++ src/components/SwapInput/types.ts | 12 ++ src/hooks/useGetBalance.ts | 52 ++++++ src/hooks/useGetStats.ts | 63 +++++++ src/near/config.ts | 2 +- src/near/initContract.ts | 2 +- src/near/types.ts | 12 ++ src/pages/stake.tsx | 73 ++++---- src/pages/swap.tsx | 269 +++++++++++---------------- src/redux/walletSlice.ts | 4 +- 14 files changed, 455 insertions(+), 207 deletions(-) delete mode 100644 src/components/CryptoInput/utils.ts create mode 100644 src/components/SwapInput/index.tsx create mode 100644 src/components/SwapInput/types.ts create mode 100644 src/hooks/useGetBalance.ts create mode 100644 src/hooks/useGetStats.ts diff --git a/src/components/CryptoInput/index.tsx b/src/components/CryptoInput/index.tsx index 3f49640..8b93bc3 100644 --- a/src/components/CryptoInput/index.tsx +++ b/src/components/CryptoInput/index.tsx @@ -9,6 +9,7 @@ export const CryptoInput: React.FC = ({ currencyQuote, onChange, onChangeCurrency, + showBalance = true, }) => { const [currency, setCurrency] = React.useState( t.CurrencyTypeEnum.NEAR @@ -33,7 +34,7 @@ export const CryptoInput: React.FC = ({ return ( <> - {maxValue ? ( + {showBalance && maxValue ? ( void maxValue?: string currencyQuote?: number + showBalance?: boolean } export enum CurrencyTypeEnum { diff --git a/src/components/CryptoInput/utils.ts b/src/components/CryptoInput/utils.ts deleted file mode 100644 index c85b624..0000000 --- a/src/components/CryptoInput/utils.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const fetchFiatValue = async (): Promise => { - const response = await fetch(`https://near-contract-helper.onrender.com/fiat`) - const data = await response.json() - return Number(data?.near.usd) -} diff --git a/src/components/Navbar/index.tsx b/src/components/Navbar/index.tsx index 2d0c799..8273a8e 100644 --- a/src/components/Navbar/index.tsx +++ b/src/components/Navbar/index.tsx @@ -87,6 +87,7 @@ export const Navbar: React.FC = () => { weight="normal" size="medium" reverse={false} + onClick={() => router.push('/swap')} /> = ({ + value, + maxValue, + swapQuote, + onChange, + onChangeCurrency, +}) => { + const [currency, setCurrency] = React.useState( + t.CurrencyTypeEnum.NEAR + ) + const handleChangeCurrency = () => { + const newCurrency = + currency === t.CurrencyTypeEnum.NEAR + ? t.CurrencyTypeEnum.QUID + : t.CurrencyTypeEnum.NEAR + setCurrency(newCurrency) + onChangeCurrency && onChangeCurrency(newCurrency) + } + + return ( + + {maxValue ? ( + + Pay: + + + balance: {Number(maxValue || 0).toFixed(3)} + +