Adds more null checks
This commit is contained in:
parent
60cb08a5a5
commit
39e4a6def5
|
@ -76,14 +76,13 @@ export default function AccountInfo() {
|
|||
return perpAcct.mngoAccrued.add(acc)
|
||||
}, ZERO_BN)
|
||||
: ZERO_BN
|
||||
// console.log('rerendering account info', mangoAccount, mngoAccrued.toNumber())
|
||||
|
||||
const handleRedeemMngo = async () => {
|
||||
const mangoClient = useMangoStore.getState().connection.client
|
||||
const mngoNodeBank =
|
||||
mangoGroup?.rootBankAccounts?.[MNGO_INDEX]?.nodeBankAccounts[0]
|
||||
|
||||
if (!mngoNodeBank || !mangoAccount) {
|
||||
if (!mngoNodeBank || !mangoAccount || !wallet) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -92,17 +91,19 @@ export default function AccountInfo() {
|
|||
const txids = await mangoClient.redeemAllMngo(
|
||||
mangoGroup,
|
||||
mangoAccount,
|
||||
wallet?.adapter,
|
||||
wallet.adapter,
|
||||
mangoGroup.tokens[MNGO_INDEX].rootBank,
|
||||
mngoNodeBank.publicKey,
|
||||
mngoNodeBank.vault
|
||||
)
|
||||
for (const txid of txids) {
|
||||
notify({
|
||||
title: t('redeem-success'),
|
||||
description: '',
|
||||
txid,
|
||||
})
|
||||
if (txids) {
|
||||
for (const txid of txids) {
|
||||
notify({
|
||||
title: t('redeem-success'),
|
||||
description: '',
|
||||
txid,
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
notify({
|
||||
|
|
|
@ -34,7 +34,7 @@ const AccountNameModal: FunctionComponent<AccountNameModalProps> = ({
|
|||
|
||||
const submitName = async () => {
|
||||
const mangoClient = useMangoStore.getState().connection.client
|
||||
|
||||
if (!wallet || !mangoAccount || !mangoGroup) return
|
||||
try {
|
||||
const txid = await mangoClient.addMangoAccountInfo(
|
||||
mangoGroup,
|
||||
|
|
|
@ -132,15 +132,19 @@ const BalancesTable = ({
|
|||
return
|
||||
}
|
||||
|
||||
const txids: TransactionSignature[] = await mangoClient.settleAll(
|
||||
mangoGroup,
|
||||
mangoAccount,
|
||||
spotMarkets,
|
||||
wallet?.adapter
|
||||
)
|
||||
const txids: TransactionSignature[] | undefined =
|
||||
await mangoClient.settleAll(
|
||||
mangoGroup,
|
||||
mangoAccount,
|
||||
spotMarkets,
|
||||
wallet?.adapter
|
||||
)
|
||||
// FIXME: Add error if txids is undefined
|
||||
|
||||
for (const txid of txids) {
|
||||
notify({ title: t('settle-success'), txid })
|
||||
if (txids) {
|
||||
for (const txid of txids) {
|
||||
notify({ title: t('settle-success'), txid })
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Error settling all:', e)
|
||||
|
|
|
@ -98,7 +98,7 @@ const CloseAccountModal: FunctionComponent<CloseAccountModalProps> = ({
|
|||
const closeAccount = async () => {
|
||||
const mangoClient = useMangoStore.getState().connection.client
|
||||
|
||||
if (!mangoGroup || !mangoAccount || !mangoCache) {
|
||||
if (!mangoGroup || !mangoAccount || !mangoCache || !wallet) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ const CloseAccountModal: FunctionComponent<CloseAccountModalProps> = ({
|
|||
mangoAccount,
|
||||
mangoCache,
|
||||
MNGO_INDEX,
|
||||
wallet?.adapter
|
||||
wallet.adapter
|
||||
)
|
||||
|
||||
await actions.fetchAllMangoAccounts(wallet)
|
||||
|
@ -121,11 +121,14 @@ const CloseAccountModal: FunctionComponent<CloseAccountModalProps> = ({
|
|||
})
|
||||
|
||||
onClose?.()
|
||||
for (const txid of txids) {
|
||||
notify({
|
||||
title: t('close-account:transaction-confirmed'),
|
||||
txid,
|
||||
})
|
||||
// FIXME: Throw error if txids is undefined
|
||||
if (txids) {
|
||||
for (const txid of txids) {
|
||||
notify({
|
||||
title: t('close-account:transaction-confirmed'),
|
||||
txid,
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Error deleting account:', err)
|
||||
|
|
|
@ -68,7 +68,9 @@ export const ConnectWalletButton: React.FC = () => {
|
|||
}, [wallets, installedWallets])
|
||||
|
||||
const handleConnect = useCallback(() => {
|
||||
handleWalletConnect(wallet)
|
||||
if (wallet) {
|
||||
handleWalletConnect(wallet)
|
||||
}
|
||||
}, [wallet])
|
||||
|
||||
const handleCloseAccounts = useCallback(() => {
|
||||
|
|
|
@ -21,7 +21,7 @@ const MangoDatePicker = ({ date, setDate, ...props }) => {
|
|||
const generateArrayOfYears = () => {
|
||||
const max = new Date().getFullYear()
|
||||
const min = max - (max - 2020)
|
||||
const years = []
|
||||
const years: number[] = []
|
||||
|
||||
for (let i = max; i >= min; i--) {
|
||||
years.push(i)
|
||||
|
|
|
@ -30,7 +30,11 @@ const DelegateModal: FunctionComponent<DelegateModalProps> = ({
|
|||
const { wallet } = useWallet()
|
||||
|
||||
const [keyBase58, setKeyBase58] = useState(
|
||||
delegate.equals(PublicKey.default) ? '' : delegate.toBase58()
|
||||
delegate && delegate.equals(PublicKey.default)
|
||||
? ''
|
||||
: delegate
|
||||
? delegate.toBase58()
|
||||
: ''
|
||||
)
|
||||
const [invalidKeyMessage, setInvalidKeyMessage] = useState('')
|
||||
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
|
||||
|
@ -40,6 +44,8 @@ const DelegateModal: FunctionComponent<DelegateModalProps> = ({
|
|||
const setDelegate = async () => {
|
||||
const mangoClient = useMangoStore.getState().connection.client
|
||||
|
||||
if (!mangoGroup || !mangoAccount || !wallet) return
|
||||
|
||||
try {
|
||||
const key = keyBase58.length
|
||||
? new PublicKey(keyBase58)
|
||||
|
@ -47,11 +53,11 @@ const DelegateModal: FunctionComponent<DelegateModalProps> = ({
|
|||
const txid = await mangoClient.setDelegate(
|
||||
mangoGroup,
|
||||
mangoAccount,
|
||||
wallet?.adapter,
|
||||
wallet.adapter,
|
||||
key
|
||||
)
|
||||
actions.reloadMangoAccount()
|
||||
onClose()
|
||||
onClose?.()
|
||||
notify({
|
||||
title: t('delegate:delegate-updated'),
|
||||
txid,
|
||||
|
|
|
@ -61,6 +61,7 @@ const DepositModal: FunctionComponent<DepositModalProps> = ({
|
|||
|
||||
const handleDeposit = () => {
|
||||
const mangoAccount = useMangoStore.getState().selectedMangoAccount.current
|
||||
if (!wallet || !mangoAccount) return
|
||||
|
||||
setSubmitting(true)
|
||||
deposit({
|
||||
|
|
|
@ -23,7 +23,9 @@ const FloatingElement: FunctionComponent<FloatingElementProps> = ({
|
|||
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
|
||||
|
||||
const handleConnect = useCallback(() => {
|
||||
handleWalletConnect(wallet)
|
||||
if (wallet) {
|
||||
handleWalletConnect(wallet)
|
||||
}
|
||||
}, [wallet])
|
||||
|
||||
return (
|
||||
|
|
|
@ -178,8 +178,10 @@ class IntroTips extends Component<Props, State> {
|
|||
if (nextStepIndex === 1) {
|
||||
this.steps.updateStepElement(nextStepIndex)
|
||||
const el = document.querySelector<HTMLElement>('.introjs-nextbutton')
|
||||
el.style.pointerEvents = 'auto'
|
||||
el.style.opacity = '100%'
|
||||
if (el) {
|
||||
el.style.pointerEvents = 'auto'
|
||||
el.style.opacity = '100%'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ export default function MarketBalances() {
|
|||
const isMobile = width ? width < breakpoints.sm : false
|
||||
|
||||
const handleSizeClick = (size, symbol) => {
|
||||
if (!selectedMarket || !mangoGroup || !mangoGroupCache) return
|
||||
const minOrderSize = selectedMarket.minOrderSize
|
||||
const sizePrecisionDigits = getPrecisionDigits(minOrderSize)
|
||||
const marketIndex = marketConfig.marketIndex
|
||||
|
@ -59,10 +60,10 @@ export default function MarketBalances() {
|
|||
})
|
||||
}
|
||||
|
||||
if (!mangoGroup || !selectedMarket) return null
|
||||
if (!mangoGroup || !selectedMarket || !mangoGroupCache) return null
|
||||
|
||||
return (
|
||||
<div className={!connected ? 'blur filter' : null}>
|
||||
<div className={!connected ? 'blur filter' : ''}>
|
||||
{!isMobile ? (
|
||||
<ElementTitle className="hidden 2xl:flex">{t('balances')}</ElementTitle>
|
||||
) : null}
|
||||
|
|
|
@ -35,13 +35,17 @@ export const settlePosPnl = async (
|
|||
const actions = useMangoStore.getState().actions
|
||||
const mangoClient = useMangoStore.getState().connection.client
|
||||
|
||||
const rootBankAccount = mangoGroup?.rootBankAccounts[QUOTE_INDEX]
|
||||
|
||||
if (!mangoGroup || !mangoCache || !mangoAccount || !rootBankAccount) return
|
||||
|
||||
try {
|
||||
const txids = await mangoClient.settlePosPnl(
|
||||
mangoGroup,
|
||||
mangoCache,
|
||||
mangoAccount,
|
||||
perpMarkets,
|
||||
mangoGroup.rootBankAccounts[QUOTE_INDEX],
|
||||
rootBankAccount,
|
||||
wallet?.adapter,
|
||||
mangoAccounts
|
||||
)
|
||||
|
|
|
@ -55,6 +55,7 @@ const NewAccount: FunctionComponent<NewAccountProps> = ({
|
|||
}
|
||||
|
||||
const handleNewAccountDeposit = () => {
|
||||
if (!wallet) return
|
||||
setSubmitting(true)
|
||||
deposit({
|
||||
amount: parseFloat(inputAmount),
|
||||
|
|
|
@ -342,8 +342,8 @@ const OpenOrdersTable = () => {
|
|||
const { asPath } = useRouter()
|
||||
const { wallet } = useWallet()
|
||||
const openOrders = useMangoStore((s) => s.selectedMangoAccount.openOrders)
|
||||
const [cancelId, setCancelId] = useState(null)
|
||||
const [modifyId, setModifyId] = useState(null)
|
||||
const [cancelId, setCancelId] = useState<any>(null)
|
||||
const [modifyId, setModifyId] = useState<any>(null)
|
||||
const [editOrderIndex, setEditOrderIndex] = useState(null)
|
||||
const actions = useMangoStore((s) => s.actions)
|
||||
const { width } = useViewport()
|
||||
|
@ -361,12 +361,12 @@ const OpenOrdersTable = () => {
|
|||
setCancelId(order.orderId)
|
||||
let txid
|
||||
try {
|
||||
if (!selectedMangoGroup || !selectedMangoAccount) return
|
||||
if (!selectedMangoGroup || !selectedMangoAccount || !wallet) return
|
||||
if (market instanceof Market) {
|
||||
txid = await mangoClient.cancelSpotOrder(
|
||||
selectedMangoGroup,
|
||||
selectedMangoAccount,
|
||||
wallet?.adapter,
|
||||
wallet.adapter,
|
||||
market,
|
||||
order as Order
|
||||
)
|
||||
|
@ -377,7 +377,7 @@ const OpenOrdersTable = () => {
|
|||
txid = await mangoClient.removeAdvancedOrder(
|
||||
selectedMangoGroup,
|
||||
selectedMangoAccount,
|
||||
wallet?.adapter,
|
||||
wallet.adapter,
|
||||
(order as PerpTriggerOrder).orderId
|
||||
)
|
||||
actions.reloadOrders()
|
||||
|
@ -385,7 +385,7 @@ const OpenOrdersTable = () => {
|
|||
txid = await mangoClient.cancelPerpOrder(
|
||||
selectedMangoGroup,
|
||||
selectedMangoAccount,
|
||||
wallet?.adapter,
|
||||
wallet.adapter,
|
||||
market,
|
||||
order as PerpOrder,
|
||||
false
|
||||
|
|
|
@ -136,10 +136,10 @@ export default function Orderbook({ depth = 8 }) {
|
|||
const isMobile = width ? width < breakpoints.sm : false
|
||||
|
||||
const currentOrderbookData = useRef<any>(null)
|
||||
const nextOrderbookData = useRef(null)
|
||||
const nextOrderbookData = useRef<any>(null)
|
||||
const previousDepth = usePrevious(depth)
|
||||
|
||||
const [openOrderPrices, setOpenOrderPrices] = useState([])
|
||||
const [openOrderPrices, setOpenOrderPrices] = useState<any[]>([])
|
||||
const [orderbookData, setOrderbookData] = useState<any | null>(null)
|
||||
const [defaultLayout, setDefaultLayout] = useState(true)
|
||||
const [displayCumulativeSize, setDisplayCumulativeSize] = useState(false)
|
||||
|
@ -156,17 +156,18 @@ export default function Orderbook({ depth = 8 }) {
|
|||
|
||||
useInterval(() => {
|
||||
if (
|
||||
!currentOrderbookData.current ||
|
||||
!isEqualLodash(
|
||||
currentOrderbookData.current.bids,
|
||||
nextOrderbookData.current.bids
|
||||
) ||
|
||||
!isEqualLodash(
|
||||
currentOrderbookData.current.asks,
|
||||
nextOrderbookData.current.asks
|
||||
) ||
|
||||
previousDepth !== depth ||
|
||||
previousGrouping !== grouping
|
||||
nextOrderbookData?.current?.bids &&
|
||||
(!currentOrderbookData.current ||
|
||||
!isEqualLodash(
|
||||
currentOrderbookData.current.bids,
|
||||
nextOrderbookData.current.bids
|
||||
) ||
|
||||
!isEqualLodash(
|
||||
currentOrderbookData.current.asks,
|
||||
nextOrderbookData.current.asks
|
||||
) ||
|
||||
previousDepth !== depth ||
|
||||
previousGrouping !== grouping)
|
||||
) {
|
||||
// check if user has open orders so we can highlight them on orderbook
|
||||
const openOrders =
|
||||
|
|
|
@ -43,6 +43,7 @@ export const RedeemDropdown: React.FC = () => {
|
|||
const loading = settling || settlingPosPnl
|
||||
|
||||
const handleSettleAll = async () => {
|
||||
if (!wallet) return
|
||||
setOpen(false)
|
||||
setSettling(true)
|
||||
for (const p of unsettledPositions) {
|
||||
|
@ -54,6 +55,7 @@ export const RedeemDropdown: React.FC = () => {
|
|||
}
|
||||
|
||||
const handleSettlePosPnl = async () => {
|
||||
if (!wallet) return
|
||||
setOpen(false)
|
||||
setSettlingPosPnl(true)
|
||||
for (const p of unsettledPositivePositions) {
|
||||
|
|
|
@ -55,9 +55,11 @@ const PositionsTable: React.FC = () => {
|
|||
}
|
||||
|
||||
const handleSettlePnl = async (perpMarket, perpAccount, index) => {
|
||||
setSettleSinglePos(index)
|
||||
await settlePnl(perpMarket, perpAccount, t, undefined, wallet)
|
||||
setSettleSinglePos(null)
|
||||
if (wallet) {
|
||||
setSettleSinglePos(index)
|
||||
await settlePnl(perpMarket, perpAccount, t, undefined, wallet)
|
||||
setSettleSinglePos(null)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -17,7 +17,7 @@ export default function RecentMarketTrades() {
|
|||
const market = useMangoStore((s) => s.selectedMarket.current)
|
||||
const { width } = useViewport()
|
||||
const isMobile = width ? width < breakpoints.sm : false
|
||||
const [trades, setTrades] = useState([])
|
||||
const [trades, setTrades] = useState<any[]>([])
|
||||
|
||||
const fetchTradesForChart = useCallback(async () => {
|
||||
if (!marketConfig) return
|
||||
|
|
|
@ -38,7 +38,7 @@ const SwapTokenInfo: FunctionComponent<SwapTokenInfoProps> = ({
|
|||
const [outputTokenInfo, setOutputTokenInfo] = useState<any>(null)
|
||||
const [mouseData, setMouseData] = useState<string | null>(null)
|
||||
const [daysToShow, setDaysToShow] = useState(1)
|
||||
const [topHolders, setTopHolders] = useState(null)
|
||||
const [topHolders, setTopHolders] = useState<any>(null)
|
||||
const { observe, width, height } = useDimensions()
|
||||
const { t } = useTranslation(['common', 'swap'])
|
||||
|
||||
|
@ -102,7 +102,7 @@ const SwapTokenInfo: FunctionComponent<SwapTokenInfoProps> = ({
|
|||
const inputData = await inputResponse.json()
|
||||
const outputData = await outputResponse.json()
|
||||
|
||||
let data = []
|
||||
let data: any[] = []
|
||||
if (Array.isArray(inputData)) {
|
||||
data = data.concat(inputData)
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ const TradeHistoryFilterModal: FunctionComponent<
|
|||
> = ({ filters, setFilters, isOpen, onClose }) => {
|
||||
const { t } = useTranslation('common')
|
||||
const [newFilters, setNewFilters] = useState({ ...filters })
|
||||
const [dateFrom, setDateFrom] = useState(null)
|
||||
const [dateTo, setDateTo] = useState(null)
|
||||
const [dateFrom, setDateFrom] = useState<Date | null>(null)
|
||||
const [dateTo, setDateTo] = useState<Date | null>(null)
|
||||
const [sizeFrom, setSizeFrom] = useState(filters?.size?.values?.from || '')
|
||||
const [sizeTo, setSizeTo] = useState(filters?.size?.values?.to || '')
|
||||
const [valueFrom, setValueFrom] = useState(filters?.value?.values?.from || '')
|
||||
|
@ -152,8 +152,8 @@ const TradeHistoryFilterModal: FunctionComponent<
|
|||
const handleResetFilters = () => {
|
||||
setFilters({})
|
||||
setNewFilters({})
|
||||
setDateFrom('')
|
||||
setDateTo('')
|
||||
setDateFrom(null)
|
||||
setDateTo(null)
|
||||
setSizeFrom('')
|
||||
setSizeTo('')
|
||||
setValueFrom('')
|
||||
|
|
|
@ -355,7 +355,7 @@ const TVChartContainer = () => {
|
|||
|
||||
function drawLine(order, market) {
|
||||
const orderSizeUi = roundPerpSize(order.size, market.config.baseSymbol)
|
||||
if (!tvWidgetRef?.current?.chart()) return
|
||||
if (!tvWidgetRef?.current?.chart() || !wallet) return
|
||||
return tvWidgetRef.current
|
||||
.chart()
|
||||
.createOrderLine({ disableUndo: false })
|
||||
|
|
|
@ -18,6 +18,7 @@ export const WalletListener: React.FC = () => {
|
|||
|
||||
useEffect(() => {
|
||||
const onConnect = async () => {
|
||||
if (!wallet) return
|
||||
set((state) => {
|
||||
state.selectedMangoAccount.initialLoad = true
|
||||
})
|
||||
|
|
|
@ -49,7 +49,7 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
|
|||
const [maxAmount, setMaxAmount] = useState(0)
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
const [includeBorrow, setIncludeBorrow] = useState(borrow)
|
||||
const [simulation, setSimulation] = useState(null)
|
||||
const [simulation, setSimulation] = useState<any | null>(null)
|
||||
const [showSimulation, setShowSimulation] = useState(false)
|
||||
const { wallet } = useWallet()
|
||||
const actions = useMangoStore((s) => s.actions)
|
||||
|
@ -63,7 +63,8 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
|
|||
() => tokens.find((t) => t.symbol === withdrawTokenSymbol),
|
||||
[withdrawTokenSymbol, tokens]
|
||||
)
|
||||
const tokenIndex = mangoGroup ? mangoGroup.getTokenIndex(token.mintKey) : 0
|
||||
const tokenIndex =
|
||||
mangoGroup && token ? mangoGroup.getTokenIndex(token.mintKey) : 0
|
||||
|
||||
useEffect(() => {
|
||||
if (!mangoGroup || !mangoAccount || !withdrawTokenSymbol || !mangoCache)
|
||||
|
@ -100,7 +101,7 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
|
|||
: maxWithBorrows
|
||||
}
|
||||
|
||||
if (maxWithdraw.gt(I80F48.fromNumber(0))) {
|
||||
if (maxWithdraw.gt(I80F48.fromNumber(0)) && token) {
|
||||
setMaxAmount(
|
||||
floorToDecimal(parseFloat(maxWithdraw.toFixed()), token.decimals)
|
||||
)
|
||||
|
@ -157,7 +158,7 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
|
|||
])
|
||||
|
||||
const handleWithdraw = () => {
|
||||
if (!mangoGroup) {
|
||||
if (!mangoGroup || !wallet) {
|
||||
return
|
||||
}
|
||||
setSubmitting(true)
|
||||
|
@ -277,19 +278,21 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
|
|||
const mangoCache = useMangoStore.getState().selectedMangoGroup.cache
|
||||
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
|
||||
|
||||
return tokens.map((token) => {
|
||||
const tokenIndex = mangoGroup.getTokenIndex(token.mintKey)
|
||||
return {
|
||||
symbol: token.symbol,
|
||||
balance: mangoAccount
|
||||
?.getUiDeposit(
|
||||
mangoCache.rootBankCache[tokenIndex],
|
||||
mangoGroup,
|
||||
tokenIndex
|
||||
)
|
||||
?.toFixed(tokenPrecision[token.symbol]),
|
||||
}
|
||||
})
|
||||
if (mangoGroup && mangoCache) {
|
||||
return tokens.map((token) => {
|
||||
const tokenIndex = mangoGroup.getTokenIndex(token.mintKey)
|
||||
return {
|
||||
symbol: token.symbol,
|
||||
balance: mangoAccount
|
||||
?.getUiDeposit(
|
||||
mangoCache.rootBankCache[tokenIndex],
|
||||
mangoGroup,
|
||||
tokenIndex
|
||||
)
|
||||
?.toFixed(tokenPrecision[token.symbol]),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (!withdrawTokenSymbol) return null
|
||||
|
@ -297,7 +300,7 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
|
|||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose}>
|
||||
<>
|
||||
{!showSimulation ? (
|
||||
{!showSimulation && mangoCache && mangoGroup ? (
|
||||
<>
|
||||
<Modal.Header>
|
||||
<ElementTitle noMarginBottom>
|
||||
|
@ -333,7 +336,7 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
|
|||
}
|
||||
onChange={(asset) => handleSetSelectedAsset(asset)}
|
||||
>
|
||||
{getTokenBalances().map(({ symbol, balance }) => (
|
||||
{getTokenBalances()?.map(({ symbol, balance }) => (
|
||||
<Select.Option key={symbol} value={symbol}>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center">
|
||||
|
@ -451,7 +454,7 @@ const WithdrawModal: FunctionComponent<WithdrawModalProps> = ({
|
|||
<div className="pt-2 text-th-fgd-4">{`${t(
|
||||
'includes-borrow'
|
||||
)} ~${getBorrowAmount().toFixed(
|
||||
mangoGroup.tokens[tokenIndex].decimals
|
||||
mangoGroup?.tokens[tokenIndex].decimals
|
||||
)} ${withdrawTokenSymbol}`}</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
|
|
@ -298,6 +298,7 @@ export default function SimpleTradeForm({ initLeverage }) {
|
|||
description: t('try-again'),
|
||||
type: 'error',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const orderType = ioc ? 'ioc' : postOnly ? 'postOnly' : 'limit'
|
||||
|
@ -348,7 +349,8 @@ export default function SimpleTradeForm({ initLeverage }) {
|
|||
}
|
||||
|
||||
const { max, deposits, borrows } = useMemo(() => {
|
||||
if (!mangoAccount) return { max: 0 }
|
||||
if (!mangoAccount || !mangoGroup || !mangoCache || !market)
|
||||
return { max: 0 }
|
||||
const priceOrDefault = price
|
||||
? I80F48.fromNumber(price)
|
||||
: mangoGroup.getPrice(marketIndex, mangoCache)
|
||||
|
|
|
@ -90,7 +90,7 @@ function parsePerpOpenOrders(
|
|||
const advancedOrdersForMarket = mangoAccount.advancedOrders
|
||||
.map((o, i) => {
|
||||
const pto = o.perpTrigger
|
||||
if (pto.isActive && pto.marketIndex == config.marketIndex) {
|
||||
if (pto && pto.isActive && pto.marketIndex == config.marketIndex) {
|
||||
return {
|
||||
...o,
|
||||
orderId: i,
|
||||
|
|
|
@ -2,11 +2,11 @@ import { I80F48 } from '@blockworks-foundation/mango-client'
|
|||
import { useCallback, useEffect, useState } from 'react'
|
||||
import useMangoStore from '../stores/useMangoStore'
|
||||
|
||||
export default function useOraclePrice(): I80F48 {
|
||||
export default function useOraclePrice(): I80F48 | null {
|
||||
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
|
||||
const mangoCache = useMangoStore((s) => s.selectedMangoGroup.cache)
|
||||
const selectedMarket = useMangoStore((s) => s.selectedMarket.config)
|
||||
const [oraclePrice, setOraclePrice] = useState(null)
|
||||
const [oraclePrice, setOraclePrice] = useState<any>(null)
|
||||
|
||||
const fetchOraclePrice = useCallback(() => {
|
||||
if (mangoGroup && mangoCache) {
|
||||
|
|
|
@ -217,7 +217,7 @@ export default function Account() {
|
|||
const mngoNodeBank =
|
||||
mangoGroup?.rootBankAccounts?.[MNGO_INDEX]?.nodeBankAccounts?.[0]
|
||||
|
||||
if (!mangoAccount || !mngoNodeBank || !mangoGroup) {
|
||||
if (!mangoAccount || !mngoNodeBank || !mangoGroup || !wallet) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -225,19 +225,22 @@ export default function Account() {
|
|||
const txids = await mangoClient.redeemAllMngo(
|
||||
mangoGroup,
|
||||
mangoAccount,
|
||||
wallet?.adapter,
|
||||
wallet.adapter,
|
||||
mangoGroup.tokens[MNGO_INDEX].rootBank,
|
||||
mngoNodeBank.publicKey,
|
||||
mngoNodeBank.vault
|
||||
)
|
||||
actions.reloadMangoAccount()
|
||||
setMngoAccrued(ZERO_BN)
|
||||
for (const txid of txids) {
|
||||
notify({
|
||||
title: t('redeem-success'),
|
||||
description: '',
|
||||
txid,
|
||||
})
|
||||
// FIXME: Throw error if txids is undefined
|
||||
if (txids) {
|
||||
for (const txid of txids) {
|
||||
notify({
|
||||
title: t('redeem-success'),
|
||||
description: '',
|
||||
txid,
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
notify({
|
||||
|
|
|
@ -153,7 +153,9 @@ export default function Referral() {
|
|||
}
|
||||
|
||||
const handleConnect = useCallback(() => {
|
||||
handleWalletConnect(wallet)
|
||||
if (wallet) {
|
||||
handleWalletConnect(wallet)
|
||||
}
|
||||
}, [wallet])
|
||||
|
||||
const submitRefLink = async () => {
|
||||
|
@ -168,13 +170,13 @@ export default function Referral() {
|
|||
return
|
||||
}
|
||||
|
||||
if (!inputError && mangoGroup && mangoAccount) {
|
||||
if (!inputError && mangoGroup && mangoAccount && wallet) {
|
||||
try {
|
||||
const mangoClient = useMangoStore.getState().connection.client
|
||||
const txid = await mangoClient.registerReferrerId(
|
||||
mangoGroup,
|
||||
mangoAccount,
|
||||
wallet?.adapter,
|
||||
wallet.adapter,
|
||||
encodedRefLink
|
||||
)
|
||||
notify({
|
||||
|
|
|
@ -34,7 +34,7 @@ export default function Swap() {
|
|||
if (!connection) return null
|
||||
|
||||
const userPublicKey =
|
||||
publicKey && !zeroKey.equals(publicKey) ? publicKey : null
|
||||
publicKey && !zeroKey.equals(publicKey) ? publicKey : undefined
|
||||
|
||||
return (
|
||||
<JupiterProvider
|
||||
|
|
|
@ -360,8 +360,8 @@ const useMangoStore = create<
|
|||
connection,
|
||||
wallet.adapter.publicKey
|
||||
)
|
||||
const tokens = []
|
||||
ownedTokenAccounts.forEach((account) => {
|
||||
const tokens: any = []
|
||||
ownedTokenAccounts?.forEach((account) => {
|
||||
const config = getTokenByMint(groupConfig, account.mint)
|
||||
if (config) {
|
||||
const uiBalance = nativeToUi(account.amount, config.decimals)
|
||||
|
@ -555,7 +555,7 @@ const useMangoStore = create<
|
|||
set((state) => {
|
||||
state.selectedMangoGroup.markets = allMarkets
|
||||
state.selectedMarket.current = allMarketAccounts.find((mkt) =>
|
||||
mkt.publicKey.equals(selectedMarketConfig.publicKey)
|
||||
mkt?.publicKey.equals(selectedMarketConfig.publicKey)
|
||||
)
|
||||
|
||||
allBidsAndAsksAccountInfos.forEach(
|
||||
|
@ -666,6 +666,8 @@ const useMangoStore = create<
|
|||
const connection = get().connection.current
|
||||
const mangoClient = get().connection.client
|
||||
|
||||
if (!mangoAccount) return
|
||||
|
||||
const [reloadedMangoAccount, lastSlot] =
|
||||
await mangoAccount.reloadFromSlot(connection, mangoClient.lastSlot)
|
||||
const lastSeenSlot = get().selectedMangoAccount.lastSlot
|
||||
|
@ -756,7 +758,10 @@ const useMangoStore = create<
|
|||
async loadReferralData() {
|
||||
const set = get().set
|
||||
const mangoAccount = get().selectedMangoAccount.current
|
||||
const pk = mangoAccount.publicKey.toString()
|
||||
const pk = mangoAccount?.publicKey.toString()
|
||||
if (!pk) {
|
||||
return
|
||||
}
|
||||
|
||||
const getData = async (type: 'history' | 'total') => {
|
||||
const res = await fetch(
|
||||
|
@ -823,6 +828,7 @@ const useMangoStore = create<
|
|||
const mangoAccount = get().selectedMangoAccount.current
|
||||
const mangoGroup = get().selectedMangoGroup.current
|
||||
const mangoCache = get().selectedMangoGroup.cache
|
||||
if (!mangoGroup || !mangoAccount || !mangoCache) return
|
||||
const currentAccHealth = await mangoAccount.getHealthRatio(
|
||||
mangoGroup,
|
||||
mangoCache,
|
||||
|
|
|
@ -111,7 +111,7 @@ export function calculateTradePrice(
|
|||
side: 'buy' | 'sell',
|
||||
price: string | number,
|
||||
triggerPrice?: string | number
|
||||
): number {
|
||||
): number | undefined {
|
||||
if (tradeType === 'Market' && kind === 'spot') {
|
||||
return calculateMarketPrice(orderBook, baseSize, side)
|
||||
} else if (TRIGGER_ORDER_TYPES.includes(tradeType)) {
|
||||
|
@ -128,7 +128,7 @@ export const calculateMarketPrice = (
|
|||
orderBook: Orderbook,
|
||||
size: number,
|
||||
side: 'buy' | 'sell'
|
||||
): number => {
|
||||
): number | undefined => {
|
||||
const orders = side === 'buy' ? orderBook.asks : orderBook.bids
|
||||
let acc = 0
|
||||
let selectedOrder
|
||||
|
@ -311,7 +311,10 @@ export function getBrowserDocumentHiddenProp() {
|
|||
}
|
||||
|
||||
export function getIsDocumentHidden() {
|
||||
return !document[getBrowserDocumentHiddenProp()]
|
||||
const index = getBrowserDocumentHiddenProp()
|
||||
if (typeof index === 'number') {
|
||||
return !document[index]
|
||||
}
|
||||
}
|
||||
|
||||
export const numberCompactFormatter = Intl.NumberFormat('en', {
|
||||
|
|
|
@ -21,7 +21,7 @@ export async function deposit({
|
|||
const mangoClient = useMangoStore.getState().connection.client
|
||||
const referrer = useMangoStore.getState().referrerPk
|
||||
|
||||
if (typeof tokenIndex !== 'number') {
|
||||
if (typeof tokenIndex !== 'number' || !referrer) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -78,9 +78,11 @@ export async function withdraw({
|
|||
}) {
|
||||
const mangoAccount = useMangoStore.getState().selectedMangoAccount.current
|
||||
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
|
||||
const tokenIndex = mangoGroup.getTokenIndex(token)
|
||||
const tokenIndex = mangoGroup?.getTokenIndex(token)
|
||||
const mangoClient = useMangoStore.getState().connection.client
|
||||
|
||||
if (!tokenIndex) return
|
||||
|
||||
const publicKey =
|
||||
mangoGroup?.rootBankAccounts?.[tokenIndex]?.nodeBankAccounts[0].publicKey
|
||||
const vault =
|
||||
|
|
Loading…
Reference in New Issue