Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add a flag to save the first loading status of the FFs #1051

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions webapp/src/components/AssetProvider/AssetProvider.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 { AssetType } from '../../modules/asset/types'
import { Props } from './AssetProvider.types'

Expand All @@ -18,11 +18,18 @@ const AssetProvider = (props: Props) => {
isLoadingFeatureFlags
} = props

const [hasLoadedInitialFlags, setHasLoadedInitialFlags] = useState(false)
useEffect(() => {
if (!isLoadingFeatureFlags) {
setHasLoadedInitialFlags(true)
}
}, [isLoadingFeatureFlags])
Comment on lines +21 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that it's a bit more work, but, what if we move this logic to the features flag reducer so we can eventually use it somewhere else in the future? That is, when the FF are fetched successful for the first time, we can store a flag in the feature flags state and retrieve it later with a selector.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be implemented when #290 is implemented


useEffect(() => {
if (contractAddress && tokenId) {
switch (type) {
case AssetType.NFT:
if (!isLoadingFeatureFlags) {
if (!hasLoadedInitialFlags) {
onFetchNFT(contractAddress, tokenId, { rentalStatus })
}
break
Expand All @@ -40,7 +47,8 @@ const AssetProvider = (props: Props) => {
onFetchNFT,
onFetchItem,
rentalStatus,
isLoadingFeatureFlags
isLoadingFeatureFlags,
hasLoadedInitialFlags
])

return (
Expand All @@ -49,7 +57,7 @@ const AssetProvider = (props: Props) => {
asset,
order,
rental,
isLoading || (isLoadingFeatureFlags && type === AssetType.NFT)
isLoading || (!hasLoadedInitialFlags && type === AssetType.NFT)
)}
</>
)
Expand Down