diff --git a/components/MarginInfo.tsx b/components/MarginInfo.tsx index 058388a1..85821483 100644 --- a/components/MarginInfo.tsx +++ b/components/MarginInfo.tsx @@ -7,7 +7,7 @@ import { HeartIcon } from '@heroicons/react/outline' import { useMemo } from 'react' import useMangoStore, { mangoClient, MNGO_INDEX } from '../stores/useMangoStore' import { notify } from '../utils/notifications' -import Button from './Button' +import Button, { LinkButton } from './Button' import FloatingElement from './FloatingElement' import { ElementTitle } from './styles' import Tooltip from './Tooltip' @@ -119,7 +119,7 @@ export default function MarginInfo() { - Earn MNGO by market making on the Perp markets.{' '} + Earn MNGO by market making on Perp markets.{' '}
- MNGO Accrued + MNGO Rewards
-
- { - - } +
+ {mangoGroup + ? nativeToUi( + mngoAccrued.toNumber(), + mangoGroup.tokens[MNGO_INDEX].decimals + ) + : 0} + + Claim +
diff --git a/components/account-page/AccountOverview.tsx b/components/account-page/AccountOverview.tsx index 983cf894..95531fd1 100644 --- a/components/account-page/AccountOverview.tsx +++ b/components/account-page/AccountOverview.tsx @@ -1,19 +1,28 @@ -import { useEffect, useCallback, useState } from 'react' +import { useEffect, useCallback, useMemo, useState } from 'react' import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table' import styled from '@emotion/styled' import { Menu } from '@headlessui/react' import Link from 'next/link' import { - ArrowSmDownIcon, ChartBarIcon, CurrencyDollarIcon, ExclamationIcon, DotsHorizontalIcon, + GiftIcon, HeartIcon, XIcon, } from '@heroicons/react/outline' -import { getTokenBySymbol, I80F48 } from '@blockworks-foundation/mango-client' -import useMangoStore, { mangoClient } from '../../stores/useMangoStore' +import { ArrowSmDownIcon, ArrowSmUpIcon } from '@heroicons/react/solid' +import { + getTokenBySymbol, + nativeToUi, + ZERO_BN, + I80F48, +} from '@blockworks-foundation/mango-client' +import useMangoStore, { + mangoClient, + MNGO_INDEX, +} from '../../stores/useMangoStore' import { useBalances } from '../../hooks/useBalances' import { useSortableData } from '../../hooks/useSortableData' import useLocalStorageState from '../../hooks/useLocalStorageState' @@ -130,6 +139,26 @@ export default function AccountOverview() { setUnsettled(unsettled) }, [mangoAccount]) + const maintHealthRatio = useMemo(() => { + return mangoAccount + ? mangoAccount.getHealthRatio(mangoGroup, mangoCache, 'Maint') + : 100 + }, [mangoAccount, mangoGroup, mangoCache]) + + const initHealthRatio = useMemo(() => { + return mangoAccount + ? mangoAccount.getHealthRatio(mangoGroup, mangoCache, 'Init') + : 100 + }, [mangoAccount, mangoGroup, mangoCache]) + + const mngoAccrued = useMemo(() => { + return mangoAccount + ? mangoAccount.perpAccounts.reduce((acc, perpAcct) => { + return perpAcct.mngoAccrued.add(acc) + }, ZERO_BN) + : ZERO_BN + }, [mangoAccount]) + const handleShowZeroBalances = (checked) => { if (checked) { setFilteredSpotPortfolio(spotPortfolio) @@ -171,6 +200,36 @@ export default function AccountOverview() { } } + const handleRedeemMngo = async () => { + const wallet = useMangoStore.getState().wallet.current + const mngoNodeBank = + mangoGroup.rootBankAccounts[MNGO_INDEX].nodeBankAccounts[0] + + try { + const txid = await mangoClient.redeemAllMngo( + mangoGroup, + mangoAccount, + wallet, + mangoGroup.tokens[MNGO_INDEX].rootBank, + mngoNodeBank.publicKey, + mngoNodeBank.vault + ) + actions.fetchMangoAccounts() + notify({ + title: 'Successfully redeemed MNGO', + description: '', + txid, + }) + } catch (e) { + notify({ + title: 'Error redeeming MNGO', + description: e.message, + txid: e.txid, + type: 'error', + }) + } + } + const handleOpenDepositModal = useCallback((symbol) => { setActionSymbol(symbol) setShowDepositModal(true) @@ -183,10 +242,10 @@ export default function AccountOverview() { return mangoAccount ? ( <> -
+
Account Value
-
+
{usdFormatter.format( @@ -194,10 +253,14 @@ export default function AccountOverview() { )}
+
+ + XX.XX today +
PNL
-
+
{usdFormatter.format( @@ -205,56 +268,58 @@ export default function AccountOverview() { )}
+
+ + XX.XX today +
-
-
-
Positions
-
-
- {spotPortfolio.length > 0 - ? usdFormatter.format( - spotPortfolio.reduce( - (acc, d) => d.market.includes('PERP') && acc + d.value, - 0 - ) +
Health Ratio
+
+ + + {maintHealthRatio.toFixed(2)}% + +
+
+
30 + ? 'bg-th-green' + : initHealthRatio > 0 + ? 'bg-th-orange' + : 'bg-th-red' + }`} + >
+
+
+
+
MNGO Rewards
+
+ + + {mangoGroup + ? nativeToUi( + mngoAccrued.toNumber(), + mangoGroup.tokens[MNGO_INDEX].decimals ) : 0} -
-
-
-
-
Deposits
-
-
- {usdFormatter.format( - +mangoAccount.getAssetsVal(mangoGroup, mangoCache) - )} -
-
-
-
-
Borrows
-
-
- {usdFormatter.format( - +mangoAccount.getLiabsVal(mangoGroup, mangoCache) - )} -
-
-
-
-
Health Ratio
-
- -
- {mangoAccount.getHealthRatio(mangoGroup, mangoCache, 'Maint')}% -
+
+ + Claim Reward +
{unsettled.length > 0 ? ( -
+
@@ -291,8 +356,33 @@ export default function AccountOverview() {
Perp Positions
-
-
Assets
+
Assets & Liabilities
+ +
+
+
Total Assets Value
+
+
+ {usdFormatter.format( + +mangoAccount.getAssetsVal(mangoGroup, mangoCache) + )} +
+
+
+
+
+ Total Liabilities Value +
+
+
+ {usdFormatter.format( + +mangoAccount.getLiabsVal(mangoGroup, mangoCache) + )} +
+
+
+
+
- {filteredSpotPortfolio.length > 0 ? (