show mango accounts
This commit is contained in:
parent
cb43ab0a5d
commit
bc4476cafa
|
@ -19,11 +19,16 @@ const Layout = ({ children }) => {
|
|||
const connection = useMangoStore((s) => s.connection)
|
||||
const wallet = useWallet()
|
||||
const { setClient } = useReimbursementStore()
|
||||
const actions = useMangoStore.getState().actions
|
||||
|
||||
useEffect(() => {
|
||||
console.log("connection", connection.current)
|
||||
|
||||
if (wallet.connected && wallet.publicKey?.toBase58()) {
|
||||
setClient(connection.current, wallet)
|
||||
if (wallet?.wallet) {
|
||||
actions.fetchAllMangoAccounts(wallet.wallet)
|
||||
}
|
||||
}
|
||||
}, [
|
||||
wallet.connected,
|
||||
|
|
|
@ -59,11 +59,7 @@ const TableRow = ({
|
|||
: null}
|
||||
</div>
|
||||
<div className="col-span-3 flex justify-end">
|
||||
{isClaimed ? (
|
||||
<CheckIcon className="w-5"></CheckIcon>
|
||||
) : (
|
||||
<XIcon className="w-5"></XIcon>
|
||||
)}
|
||||
{isClaimed ? <CheckIcon className="w-5"></CheckIcon> : <span>—</span>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { useEffect } from 'react'
|
||||
import { AccountInfo, PublicKey } from '@solana/web3.js'
|
||||
import useMangoStore, { programId, SECONDS } from '../stores/useMangoStore'
|
||||
import useInterval from './useInterval'
|
||||
import { Market, Orderbook as SpotOrderBook } from '@project-serum/serum'
|
||||
import { useEffect } from "react"
|
||||
import { AccountInfo, PublicKey } from "@solana/web3.js"
|
||||
import useMangoStore, { programId, SECONDS } from "../stores/useMangoStore"
|
||||
import useInterval from "./useInterval"
|
||||
import { Market, Orderbook as SpotOrderBook } from "@project-serum/serum"
|
||||
import {
|
||||
BookSide,
|
||||
BookSideLayout,
|
||||
|
@ -11,7 +11,7 @@ import {
|
|||
PerpMarket,
|
||||
ReferrerMemory,
|
||||
ReferrerMemoryLayout,
|
||||
} from '@blockworks-foundation/mango-client'
|
||||
} from "@blockworks-foundation/mango-client"
|
||||
import {
|
||||
actionsSelector,
|
||||
connectionSelector,
|
||||
|
@ -19,8 +19,8 @@ import {
|
|||
marketConfigSelector,
|
||||
marketSelector,
|
||||
marketsSelector,
|
||||
} from '../stores/selectors'
|
||||
import { useWallet } from '@solana/wallet-adapter-react'
|
||||
} from "../stores/selectors"
|
||||
import { useWallet } from "@solana/wallet-adapter-react"
|
||||
|
||||
function decodeBookL2(market, accInfo: AccountInfo<Buffer>): number[][] {
|
||||
if (market && accInfo?.data) {
|
||||
|
@ -81,35 +81,35 @@ const useHydrateStore = () => {
|
|||
}, [actions])
|
||||
|
||||
// Fetch markets info once mango group is loaded
|
||||
useEffect(() => {
|
||||
actions.fetchMarketsInfo()
|
||||
}, [actions])
|
||||
// useEffect(() => {
|
||||
// actions.fetchMarketsInfo()
|
||||
// }, [actions])
|
||||
|
||||
useInterval(() => {
|
||||
actions.fetchMangoGroupCache()
|
||||
}, 12 * SECONDS)
|
||||
// useInterval(() => {
|
||||
// actions.fetchMangoGroupCache()
|
||||
// }, 12 * SECONDS)
|
||||
|
||||
useInterval(() => {
|
||||
if (mangoAccount) {
|
||||
actions.reloadOrders()
|
||||
}
|
||||
}, 20 * SECONDS)
|
||||
// useInterval(() => {
|
||||
// if (mangoAccount) {
|
||||
// actions.reloadOrders()
|
||||
// }
|
||||
// }, 20 * SECONDS)
|
||||
|
||||
useInterval(() => {
|
||||
if (mangoAccount) {
|
||||
actions.reloadMangoAccount()
|
||||
actions.fetchTradeHistory()
|
||||
actions.updateOpenOrders()
|
||||
}
|
||||
}, 90 * SECONDS)
|
||||
// useInterval(() => {
|
||||
// if (mangoAccount) {
|
||||
// actions.reloadMangoAccount()
|
||||
// actions.fetchTradeHistory()
|
||||
// actions.updateOpenOrders()
|
||||
// }
|
||||
// }, 90 * SECONDS)
|
||||
|
||||
useInterval(() => {
|
||||
actions.fetchMangoGroup()
|
||||
actions.fetchMarketsInfo()
|
||||
if (wallet) {
|
||||
actions.fetchWalletTokens(wallet)
|
||||
}
|
||||
}, 120 * SECONDS)
|
||||
// useInterval(() => {
|
||||
// actions.fetchMangoGroup()
|
||||
// actions.fetchMarketsInfo()
|
||||
// if (wallet) {
|
||||
// actions.fetchWalletTokens(wallet)
|
||||
// }
|
||||
// }, 120 * SECONDS)
|
||||
|
||||
useEffect(() => {
|
||||
if (!marketConfig || !markets) return
|
||||
|
@ -184,7 +184,7 @@ const useHydrateStore = () => {
|
|||
const [referrerMemoryPk] = await PublicKey.findProgramAddress(
|
||||
[
|
||||
mangoAccount.publicKey.toBytes(),
|
||||
new Buffer('ReferrerMemory', 'utf-8'),
|
||||
new Buffer("ReferrerMemory", "utf-8"),
|
||||
],
|
||||
programId
|
||||
)
|
||||
|
@ -199,7 +199,7 @@ const useHydrateStore = () => {
|
|||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Unable to fetch referrer', e)
|
||||
console.error("Unable to fetch referrer", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,7 @@ const useHydrateStore = () => {
|
|||
let previousBidInfo: AccountInfo<Buffer> | null = null
|
||||
let previousAskInfo: AccountInfo<Buffer> | null = null
|
||||
if (!marketConfig || !selectedMarket) return
|
||||
console.log('in orderbook WS useEffect')
|
||||
console.log("in orderbook WS useEffect")
|
||||
|
||||
const bidSubscriptionId = connection.onAccountChange(
|
||||
marketConfig.bidsKey,
|
||||
|
@ -226,7 +226,7 @@ const useHydrateStore = () => {
|
|||
) {
|
||||
previousBidInfo = info
|
||||
|
||||
info['parsed'] = decodeBook(selectedMarket, info)
|
||||
info["parsed"] = decodeBook(selectedMarket, info)
|
||||
setMangoStore((state) => {
|
||||
state.accountInfos[marketConfig.bidsKey.toString()] = info
|
||||
state.selectedMarket.orderBook.bids = decodeBookL2(
|
||||
|
@ -249,7 +249,7 @@ const useHydrateStore = () => {
|
|||
) {
|
||||
previousAskInfo = info
|
||||
|
||||
info['parsed'] = decodeBook(selectedMarket, info)
|
||||
info["parsed"] = decodeBook(selectedMarket, info)
|
||||
setMangoStore((state) => {
|
||||
state.accountInfos[marketConfig.asksKey.toString()] = info
|
||||
state.selectedMarket.orderBook.asks = decodeBookL2(
|
||||
|
|
|
@ -35,6 +35,7 @@ import {
|
|||
import Checkbox from "components/Checkbox"
|
||||
import { abbreviateAddress } from "utils"
|
||||
import AgreementModal from "components/reimbursement_page/AgreementModal"
|
||||
import { mangoAccountSelector } from "stores/selectors"
|
||||
|
||||
const GROUP_NUM = 0
|
||||
|
||||
|
@ -70,6 +71,8 @@ const MainPage = () => {
|
|||
const [reimbursementAccount, setReimbursementAccount] =
|
||||
useState<ReimbursementAccount | null>(null)
|
||||
const [transferClaim, setTransferClaim] = useState(false)
|
||||
const mangoAccounts = useMangoStore((s) => s.mangoAccounts)
|
||||
|
||||
const hasClaimedAll =
|
||||
reimbursementAccount !== null &&
|
||||
reimbursementAccount.reimbursed !== 0 &&
|
||||
|
@ -414,14 +417,33 @@ const MainPage = () => {
|
|||
. If you have more than one Mango Account for your connected wallet
|
||||
the refund amounts are combined.
|
||||
</p>
|
||||
<div className="flex items-center pb-4 pt-6">
|
||||
<h3 className="mr-3">Your Refund</h3>
|
||||
{wallet.connected ? (
|
||||
<div className="flex flex-row items-center rounded-full bg-th-bkg-3 py-1 px-3 text-xs">
|
||||
<WalletIcon className="mr-2 h-4 w-4 text-th-green"></WalletIcon>
|
||||
{abbreviateAddress(wallet.publicKey!)}
|
||||
{wallet.connected ? (
|
||||
<>
|
||||
<div className="flex items-center pb-4 pt-6">
|
||||
<h3 className="mr-3">Connected Wallet:</h3>
|
||||
<div className="flex flex-row items-center rounded-full bg-th-bkg-3 py-1 px-3 text-xs">
|
||||
<WalletIcon className="mr-2 h-4 w-4 text-th-green"></WalletIcon>
|
||||
{abbreviateAddress(wallet.publicKey!)}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
{mangoAccounts?.length ? (
|
||||
<div className="flex flex-col pb-4 pt-1">
|
||||
<h3 className="mr-3">Mango Accounts:</h3>
|
||||
<div className="mt-2 flex flex-col">
|
||||
{mangoAccounts.map((mangoAccount) => {
|
||||
return (
|
||||
<div className="pl-8 text-xs text-th-fgd-4">
|
||||
{mangoAccount.publicKey.toString()}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
<div className="flex items-center pb-4 pt-1">
|
||||
<h3 className="mr-3">Your Refund:</h3>
|
||||
</div>
|
||||
{wallet.connected ? (
|
||||
<div>
|
||||
|
@ -525,7 +547,7 @@ const MainPage = () => {
|
|||
<Button
|
||||
onClick={() => setIsAgreementModalOpen(true)}
|
||||
disabled={transferLoading || !table.length || hasClaimedAll}
|
||||
className="px-14 py-3 text-base"
|
||||
className="px-16 py-3 text-base"
|
||||
>
|
||||
{transferLoading ? <Loading></Loading> : "Claim Tokens"}
|
||||
</Button>
|
||||
|
|
Loading…
Reference in New Issue