only show swap history loader on initial load
This commit is contained in:
parent
d19cea05e5
commit
c5c0a6f493
|
@ -1,5 +1,4 @@
|
|||
import { useMemo, useState } from 'react'
|
||||
import mangoStore from '@store/mangoStore'
|
||||
import TabButtons from '../shared/TabButtons'
|
||||
import TokenList from '../TokenList'
|
||||
import SwapHistoryTable from '../swap/SwapHistoryTable'
|
||||
|
@ -43,8 +42,6 @@ const AccountTabs = () => {
|
|||
}
|
||||
|
||||
const TabContent = ({ activeTab }: { activeTab: string }) => {
|
||||
const swapHistory = mangoStore((s) => s.mangoAccount.stats.swapHistory.data)
|
||||
const loading = mangoStore((s) => s.mangoAccount.stats.swapHistory.loading)
|
||||
const unsettledSpotBalances = useUnsettledSpotBalances()
|
||||
const unsettledPerpPositions = useUnsettledPerpPositions()
|
||||
switch (activeTab) {
|
||||
|
@ -53,7 +50,7 @@ const TabContent = ({ activeTab }: { activeTab: string }) => {
|
|||
case 'activity:activity':
|
||||
return <ActivityFeed />
|
||||
case 'swap:swap-history':
|
||||
return <SwapHistoryTable swapHistory={swapHistory} loading={loading} />
|
||||
return <SwapHistoryTable />
|
||||
case 'trade:unsettled':
|
||||
return (
|
||||
<UnsettledTrades
|
||||
|
|
|
@ -12,7 +12,7 @@ import { useViewport } from '../../hooks/useViewport'
|
|||
import { IconButton } from '../shared/Button'
|
||||
import { Transition } from '@headlessui/react'
|
||||
import SheenLoader from '../shared/SheenLoader'
|
||||
import mangoStore, { SwapHistoryItem } from '@store/mangoStore'
|
||||
import mangoStore from '@store/mangoStore'
|
||||
import {
|
||||
countLeadingZeros,
|
||||
formatFixedDecimals,
|
||||
|
@ -27,14 +27,12 @@ import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
|
|||
import { EXPLORERS } from '@components/settings/PreferredExplorerSettings'
|
||||
import useMangoAccount from 'hooks/useMangoAccount'
|
||||
|
||||
const SwapHistoryTable = ({
|
||||
swapHistory,
|
||||
loading,
|
||||
}: {
|
||||
swapHistory: SwapHistoryItem[]
|
||||
loading: boolean
|
||||
}) => {
|
||||
const SwapHistoryTable = () => {
|
||||
const { t } = useTranslation(['common', 'settings', 'swap'])
|
||||
const swapHistory = mangoStore((s) => s.mangoAccount.stats.swapHistory.data)
|
||||
const initialLoad = mangoStore(
|
||||
(s) => s.mangoAccount.stats.swapHistory.initialLoad
|
||||
)
|
||||
const { mangoTokens } = useJupiterMints()
|
||||
const [showSwapDetails, setSwapDetails] = useState('')
|
||||
const actions = mangoStore.getState().actions
|
||||
|
@ -56,7 +54,7 @@ const SwapHistoryTable = ({
|
|||
showSwapDetails ? setSwapDetails('') : setSwapDetails(signature)
|
||||
}
|
||||
|
||||
return !loading ? (
|
||||
return initialLoad ? (
|
||||
mangoAccount && swapHistory.length ? (
|
||||
showTableView ? (
|
||||
<Table>
|
||||
|
|
|
@ -9,8 +9,6 @@ const SwapInfoTabs = () => {
|
|||
const [selectedTab, setSelectedTab] = useState('balances')
|
||||
const openOrders = mangoStore((s) => s.mangoAccount.openOrders)
|
||||
const { mangoAccount } = useMangoAccount()
|
||||
const swapHistory = mangoStore((s) => s.mangoAccount.stats.swapHistory.data)
|
||||
const loading = mangoStore((s) => s.mangoAccount.stats.swapHistory.loading)
|
||||
|
||||
const tabsWithCount: [string, number][] = useMemo(() => {
|
||||
return [
|
||||
|
@ -30,9 +28,7 @@ const SwapInfoTabs = () => {
|
|||
/>
|
||||
</div>
|
||||
{selectedTab === 'balances' ? <SwapTradeBalances /> : null}
|
||||
{selectedTab === 'swap:swap-history' ? (
|
||||
<SwapHistoryTable swapHistory={swapHistory} loading={loading} />
|
||||
) : null}
|
||||
{selectedTab === 'swap:swap-history' ? <SwapHistoryTable /> : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -240,7 +240,10 @@ export type MangoStore = {
|
|||
stats: {
|
||||
interestTotals: { data: TotalInterestDataItem[]; loading: boolean }
|
||||
performance: { data: PerformanceDataItem[]; loading: boolean }
|
||||
swapHistory: { data: SwapHistoryItem[]; loading: boolean }
|
||||
swapHistory: {
|
||||
data: SwapHistoryItem[]
|
||||
initialLoad: boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
mangoAccounts: MangoAccount[]
|
||||
|
@ -372,7 +375,7 @@ const mangoStore = create<MangoStore>()(
|
|||
stats: {
|
||||
interestTotals: { data: [], loading: false },
|
||||
performance: { data: [], loading: false },
|
||||
swapHistory: { data: [], loading: false },
|
||||
swapHistory: { data: [], initialLoad: false },
|
||||
},
|
||||
},
|
||||
mangoAccounts: [],
|
||||
|
@ -823,9 +826,6 @@ const mangoStore = create<MangoStore>()(
|
|||
const set = get().set
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
set((state) => {
|
||||
state.mangoAccount.stats.swapHistory.loading = true
|
||||
})
|
||||
const history = await fetch(
|
||||
`https://mango-transaction-log.herokuapp.com/v4/stats/swap-history?mango-account=${mangoAccountPk}`
|
||||
)
|
||||
|
@ -841,11 +841,11 @@ const mangoStore = create<MangoStore>()(
|
|||
|
||||
set((state) => {
|
||||
state.mangoAccount.stats.swapHistory.data = sortedHistory
|
||||
state.mangoAccount.stats.swapHistory.loading = false
|
||||
state.mangoAccount.stats.swapHistory.initialLoad = true
|
||||
})
|
||||
} catch {
|
||||
set((state) => {
|
||||
state.mangoAccount.stats.swapHistory.loading = false
|
||||
state.mangoAccount.stats.swapHistory.initialLoad = true
|
||||
})
|
||||
notify({
|
||||
title: 'Failed to load account swap history data',
|
||||
|
|
Loading…
Reference in New Issue