2022-11-16 17:53:33 -08:00
|
|
|
import { TokenInstructions } from '@project-serum/serum'
|
2022-11-19 01:18:01 -08:00
|
|
|
import { useWallet } from '@solana/wallet-adapter-react'
|
2022-11-16 17:53:33 -08:00
|
|
|
import mangoStore from '@store/mangoStore'
|
|
|
|
import { useMemo } from 'react'
|
2022-11-17 20:43:23 -08:00
|
|
|
import { MIN_SOL_BALANCE } from 'utils/constants'
|
2022-11-16 17:53:33 -08:00
|
|
|
|
|
|
|
export default function useSolBalance() {
|
|
|
|
const walletTokens = mangoStore((s) => s.wallet.tokens)
|
2022-11-19 01:18:01 -08:00
|
|
|
const { connected } = useWallet()
|
2022-11-17 20:43:23 -08:00
|
|
|
const solBalance: number = useMemo(() => {
|
2022-11-19 01:18:01 -08:00
|
|
|
return connected
|
|
|
|
? walletTokens.find((t) =>
|
|
|
|
t.mint.equals(TokenInstructions.WRAPPED_SOL_MINT)
|
|
|
|
)?.uiAmount || 0
|
|
|
|
: 100
|
2022-11-16 17:53:33 -08:00
|
|
|
}, [walletTokens])
|
2022-11-17 20:43:23 -08:00
|
|
|
|
|
|
|
const maxSolDeposit: number = useMemo(() => {
|
|
|
|
return solBalance - MIN_SOL_BALANCE
|
|
|
|
}, [solBalance])
|
|
|
|
|
|
|
|
return { solBalance, maxSolDeposit }
|
2022-11-16 17:53:33 -08:00
|
|
|
}
|