Skip to content

Commit

Permalink
remove api check to hide secondary token charts
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbuedo committed Oct 16, 2024
1 parent 5a5e38e commit 8f137dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import {invalid, isRight} from '@yoroi/common'
import {Portfolio} from '@yoroi/types'
import {invalid} from '@yoroi/common'
import {produce} from 'immer'
import * as React from 'react'
import {useQuery} from 'react-query'

import {useSelectedNetwork} from '../../WalletManager/common/hooks/useSelectedNetwork'

export const PortfolioDetailsTab = {
Performance: 'Performance',
Expand Down Expand Up @@ -36,15 +32,13 @@ const defaultActions: PortfolioActions = {
} as const

const defaultState: PortfolioState = {
isTokenHistoryApiAvailable: false,
isPrimaryTokenActive: false,
detailsTab: PortfolioDetailsTab.Overview,
listTab: PortfolioListTab.Wallet,
dappsTab: PortfolioDappsTab.LiquidityPool,
} as const

type PortfolioState = {
isTokenHistoryApiAvailable: boolean
isPrimaryTokenActive: boolean
detailsTab: PortfolioDetailsTab
listTab: PortfolioListTab
Expand All @@ -56,33 +50,13 @@ const PortfolioContext = React.createContext<PortfolioState & PortfolioActions>(
...defaultActions,
})

const useIsTokenHistoryApiAvailable = () => {
const {
networkManager: {tokenManager},
} = useSelectedNetwork()
const {data} = useQuery({
queryKey: ['isTokenHistoryApiAvailable'],
initialData: () => false,
queryFn: async () => {
const response = await tokenManager.api.tokenHistory(
'279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f.534e454b',
Portfolio.Token.HistoryPeriod.OneDay,
)
if (isRight(response)) return true
return false
},
})
return data ?? false
}

export const PortfolioProvider = ({
children,
initialState,
}: {
children: React.ReactNode
initialState?: Partial<PortfolioState>
}) => {
const isTokenHistoryApiAvailable = useIsTokenHistoryApiAvailable()
const [portfolioState, dispatch] = React.useReducer(portfolioReducer, {...defaultState, ...initialState})

const actions = React.useRef<PortfolioActions>({
Expand All @@ -102,8 +76,8 @@ export const PortfolioProvider = ({
}).current

const context = React.useMemo<PortfolioState & PortfolioActions>(
() => ({...portfolioState, ...actions, isTokenHistoryApiAvailable}),
[actions, portfolioState, isTokenHistoryApiAvailable],
() => ({...portfolioState, ...actions}),
[actions, portfolioState],
)

return <PortfolioContext.Provider value={context}>{children}</PortfolioContext.Provider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {isPrimaryTokenInfo} from '@yoroi/portfolio'
import {useTheme} from '@yoroi/theme'
import {App} from '@yoroi/types'
import * as React from 'react'
Expand All @@ -24,14 +23,13 @@ import {PortfolioTokenInfo} from './PortfolioTokenInfo/PortfolioTokenInfo'

export const PortfolioTokenDetailsScreen = () => {
const strings = useStrings()
const {detailsTab, setDetailsTab, isTokenHistoryApiAvailable} = usePortfolio()
const {detailsTab, setDetailsTab} = usePortfolio()
const {track} = useMetrics()
const [isStickyTab, setIsStickyTab] = React.useState(false)
const {id: tokenId} = usePortfolioTokenDetailParams()
const {wallet} = useSelectedWallet()
const tokenInfo = wallet.balances.records.get(tokenId)?.info
const isPrimaryToken = isPrimaryTokenInfo(tokenInfo)
const HEADER_HEIGHT = isPrimaryToken || isTokenHistoryApiAvailable ? 304 : 85
const HEADER_HEIGHT = 304
const {styles} = useStyles(HEADER_HEIGHT)

if (!tokenInfo) throwLoggedError(new App.Errors.InvalidState('Token info not found, invalid state'))
Expand Down Expand Up @@ -92,13 +90,9 @@ export const PortfolioTokenDetailsScreen = () => {

<Spacer height={16} />

{(isPrimaryToken || isTokenHistoryApiAvailable) && (
<>
<PortfolioTokenChart />
<PortfolioTokenChart />

<Spacer height={16} />
</>
)}
<Spacer height={16} />
</Animated.View>

<Animated.View>{renderTabs}</Animated.View>
Expand Down

0 comments on commit 8f137dc

Please sign in to comment.