From 32332dfc60029b1d6b3989b0daa45cd0fbdee866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Sim=C3=A3o?= Date: Sat, 12 Feb 2022 16:29:49 +0100 Subject: [PATCH] Added Redux Query for Near Quotes --- src/pages/swap.tsx | 209 +++++++++++++++++++++++++++++++++++++ src/redux/api/nearQuote.ts | 25 +++++ src/redux/store.ts | 12 +++ 3 files changed, 246 insertions(+) create mode 100644 src/pages/swap.tsx create mode 100644 src/redux/api/nearQuote.ts diff --git a/src/pages/swap.tsx b/src/pages/swap.tsx new file mode 100644 index 0000000..6da17cc --- /dev/null +++ b/src/pages/swap.tsx @@ -0,0 +1,209 @@ +import * as React from 'react' +import Head from 'next/head' +import { utils } from 'near-api-js' +import { Box, Text, Tabs, Tab, Button } from 'grommet' + +import { NearContext } from 'src/near/nearContext' +import { PledgeType, PoolStatsType } from 'src/near/types' + +import { CryptoInput } from 'src/components/CryptoInput' + +const Stake: React.FC = () => { + const { contract, currentUser } = React.useContext(NearContext) + const [depositAmnt, setDepositAmnt] = React.useState() + const [withdrawAmnt, setWithdrawAmnt] = React.useState() + const [isQuid, setIsQuid] = React.useState(false) + const [pledged, setPledged] = React.useState() + const [stats, setStats] = React.useState() + + const currentBalance = isQuid + ? utils.format.formatNearAmount(pledged?.credit || '0') + : utils.format.formatNearAmount(currentUser?.balance || '0') + + const currentSpBalance = isQuid + ? utils.format.formatNearAmount(pledged?.quid_sp || '0') + : utils.format.formatNearAmount(pledged?.near_sp || '0') + + const getNewPledgedAmnt = async () => { + const newPledges = await contract?.get_pledge({ + account: currentUser?.accountId, + }) + setPledged(newPledges) + } + const getStats = async () => { + const newStats = await contract?.get_pool_stats({}) + setStats(newStats) + } + + React.useEffect(() => { + getNewPledgedAmnt() + getStats() + }, [contract]) + + return ( + <> + + qUid Stable Currency - Stake + + + + + + Stake on qUid Solvency Pool + + {/* Deposit and Withdraw Box*/} + + + +
+ + setIsQuid(!isQuid)} + /> +
+