This commit is contained in:
Adrian Brzeziński 2024-02-20 22:41:06 +01:00
parent 6ae77f5077
commit 1345ea5185
5 changed files with 270 additions and 299 deletions

View File

@ -1,11 +1,7 @@
import {
ArrowPathIcon,
ChevronDownIcon,
ExclamationCircleIcon,
} from '@heroicons/react/20/solid'
import { ArrowPathIcon, ExclamationCircleIcon } from '@heroicons/react/20/solid'
import { useWallet } from '@solana/wallet-adapter-react'
import { useTranslation } from 'next-i18next'
import React, { useCallback, useEffect, useMemo, useState } from 'react'
import React, { useCallback, useMemo, useState } from 'react'
import NumberFormat, { NumberFormatValues } from 'react-number-format'
import mangoStore from '@store/mangoStore'
import { notify } from '../utils/notifications'
@ -24,17 +20,11 @@ import SecondaryConnectButton from './shared/SecondaryConnectButton'
import useMangoAccountAccounts from 'hooks/useMangoAccountAccounts'
import InlineNotification from './shared/InlineNotification'
import Link from 'next/link'
import LeverageSlider from './shared/LeverageSlider'
import useMangoGroup from 'hooks/useMangoGroup'
import FormatNumericValue from './shared/FormatNumericValue'
import { depositAndCreate, stakeAndCreate } from 'utils/transactions'
import { depositAndCreate } from 'utils/transactions'
// import { MangoAccount } from '@blockworks-foundation/mango-v4'
import { AnchorProvider } from '@project-serum/anchor'
import useBankRates from 'hooks/useBankRates'
import { Disclosure } from '@headlessui/react'
import SheenLoader from './shared/SheenLoader'
import useLeverageMax from 'hooks/useLeverageMax'
import { STAKEABLE_TOKENS_DATA } from 'utils/constants'
import { sleep } from 'utils'
import ButtonGroup from './forms/ButtonGroup'
import Decimal from 'decimal.js'
@ -63,7 +53,6 @@ export const walletBalanceForToken = (
: null
}
return {
maxAmount: walletToken ? walletToken.uiAmount : 0,
maxDecimals: bank?.mintDecimals || 6,
@ -199,7 +188,6 @@ function DespositForm({ token: selectedToken }: StakeFormProps) {
[tokenMax, depositBank],
)
return (
<>
<div className="flex flex-col justify-between">
@ -271,8 +259,7 @@ function DespositForm({ token: selectedToken }: StakeFormProps) {
</div>
</div>
{depositBank ? (
<div className="pt-8">
</div>
<div className="pt-8"></div>
) : !groupLoaded ? (
<div className="pt-8">
<SheenLoader className="flex flex-1 rounded-xl">

View File

@ -6,7 +6,6 @@ import TransactionHistory from './TransactionHistory'
import mangoStore, { ActiveTab } from '@store/mangoStore'
import { useCallback, useEffect } from 'react'
import { BOOST_ACCOUNT_PREFIX } from 'utils/constants'
import useMangoAccount from 'hooks/useMangoAccount'
const set = mangoStore.getState().set
@ -34,8 +33,6 @@ const HomePage = () => {
})
}, [selectedToken])
return (
<>
<div className="mb-6 grid grid-cols-3">

View File

@ -43,7 +43,8 @@ const Positions = ({
}: {
setActiveTab: (tab: ActiveTab) => void
}) => {
const [showInactivePositions, setShowInactivePositions] = useLocalStorageState(SHOW_INACTIVE_POSITIONS_KEY, true)
const [showInactivePositions, setShowInactivePositions] =
useLocalStorageState(SHOW_INACTIVE_POSITIONS_KEY, true)
const { borrowBank, positions } = usePositions(showInactivePositions)
console.log(showInactivePositions)
@ -55,7 +56,8 @@ const Positions = ({
return (
<>
<div className="mb-2 flex items-center justify-between rounded-lg border-2 border-th-fgd-1 bg-th-bkg-1 px-6 py-3.5">
<p className="font-medium">{`You have ${numberOfPositions} active position${numberOfPositions !== 1 ? 's' : ''
<p className="font-medium">{`You have ${numberOfPositions} active position${
numberOfPositions !== 1 ? 's' : ''
}`}</p>
<Switch
checked={showInactivePositions}
@ -133,21 +135,13 @@ const PositionItem = ({
const liqPriceChangePercentage =
((parseFloat(liqRatio) - currentPriceRatio) / currentPriceRatio) * 100
return [liqRatio, liqPriceChangePercentage.toFixed(2)]
}, [bank, borrowBalance, borrowBank, stakeBalance])
const liquidationPrice = useMemo(() => {
const borrowMaintLiabWeight = borrowBank?.maintLiabWeight
const stakeMaintAssetWeight = position.bank?.maintAssetWeight
const price = Number(position.bank?.uiPrice) * (Number(borrowMaintLiabWeight) / Number(stakeMaintAssetWeight)) * (1 - (1 / leverage))
return price
}, [position.bank, borrowBank, leverage])
const { estimatedNetAPY, borrowBankBorrowRate } = useBankRates(bank.name, leverage)
const { estimatedNetAPY, borrowBankBorrowRate } = useBankRates(
bank.name,
leverage,
)
const uiRate = bank.name == 'USDC' ? borrowBankBorrowRate : estimatedNetAPY
return (
@ -190,10 +184,9 @@ const PositionItem = ({
<FormatNumericValue value={uiRate} decimals={2} />%
</span>
</div>
{position.bank.name == 'USDC' ?
<>
</>
:
{position.bank.name == 'USDC' ? (
<></>
) : (
<>
<div>
<p className="mb-1 text-th-fgd-4">Leverage</p>
@ -225,8 +218,7 @@ const PositionItem = ({
</div>
</div>
</>
}
)}
</div>
</div>
)

View File

@ -9,7 +9,6 @@ import { formatTokenSymbol } from 'utils/tokens'
import { useViewport } from 'hooks/useViewport'
import { ArrowTopRightOnSquareIcon } from '@heroicons/react/20/solid'
import DespositForm from './DepositForm'
import WithdrawForm from './WithdrawForm'
const set = mangoStore.getState().set
@ -50,24 +49,23 @@ const Stake = () => {
onChange={(v) => setActiveFormTab(v)}
/>
</div>
{selectedToken == 'USDC' ?
{selectedToken == 'USDC' ? (
<>
{activeFormTab === 'Add' ? (
<DespositForm token='USDC' />
) : null}
{activeFormTab === 'Add' ? <DespositForm token="USDC" /> : null}
{activeFormTab === 'Remove' ? (
<UnstakeForm token='USDC' />
<UnstakeForm token="USDC" />
) : null}
</>
:
) : (
<>
{activeFormTab === 'Add' ? (
<StakeForm token={selectedToken} />
) : null}
{activeFormTab === 'Remove' ? (
<UnstakeForm token={selectedToken} />
) : null}</>
}
) : null}
</>
)}
</div>
</div>
</div>

View File

@ -13,14 +13,12 @@ const TokenButton = ({
handleTokenSelect: (v: string) => void
}) => {
const leverage = useLeverageMax(tokenName)
const {
stakeBankDepositRate,
borrowBankBorrowRate,
borrowBankStakeRate,
leveragedAPY,
estimatedNetAPY,
} = useBankRates(tokenName, leverage)
const UiRate = tokenName == 'USDC' ? borrowBankBorrowRate : borrowBankStakeRate
const { borrowBankBorrowRate, borrowBankStakeRate } = useBankRates(
tokenName,
leverage,
)
const UiRate =
tokenName == 'USDC' ? borrowBankBorrowRate : borrowBankStakeRate
return (
<button
@ -68,7 +66,6 @@ const TokenButton = ({
// ) :
`${UiRate.toFixed(2)}%`
}
</span>
</div>
</button>