Skip to content

Commit

Permalink
Merge pull request #493 from mithraiclabs/fix/open-orders-requests
Browse files Browse the repository at this point in the history
Fix open orders useEffect being calling many times
  • Loading branch information
evanpipta authored Aug 12, 2021
2 parents e386ecf + 9f9bff9 commit 812e688
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/OpenOrders/OpenOrders.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react'
import React, { useEffect, useState } from 'react'
import Box from '@material-ui/core/Box'
import Table from '@material-ui/core/Table'
import TableHead from '@material-ui/core/TableHead'
Expand Down Expand Up @@ -28,12 +28,19 @@ const OpenOrders: React.FC<{
const { wallet, pubKey, connected } = useWallet()
const { serumMarkets } = useSerum()
const [openOrders, setOpenOrders] = useSerumOpenOrders()
const [openOrdersLoaded, setOpenOrdersLoaded] = useState(false)

/**
* Load open orders for each serum market if we haven't already done so
*/
useEffect(() => {
if (connection && serumMarkets && pubKey && openOrders) {
if (
connection &&
serumMarkets &&
pubKey &&
openOrders &&
!openOrdersLoaded
) {
const serumKeys = Object.keys(serumMarkets)
;(async () => {
const openOrdersRes = await SerumOpenOrdersClass.findForOwner(
Expand All @@ -56,6 +63,7 @@ const OpenOrders: React.FC<{
...prevOpenOrders,
...newOpenOrders,
}))
setOpenOrdersLoaded(true)
})()
}
}, [
Expand All @@ -66,6 +74,7 @@ const OpenOrders: React.FC<{
pubKey,
openOrders,
setOpenOrders,
openOrdersLoaded,
])

const openOrdersArray = optionMarkets
Expand Down

0 comments on commit 812e688

Please sign in to comment.