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(stats page): fix race condition - missing data on chart/table #1127

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AWS_BUCKET=sputnik-dao
AWS_REGION=eu-central-1
AWS_IDENTITY_POOL_ID=eu-central-1:5887fd21-7b40-4871-a6cb-21097fe079a2
GOOGLE_ANALYTICS_KEY=G-2SWGMFRYJ8
LOG_ROCKET_APP_ID=mp/astrodao
#LOG_ROCKET_APP_ID=mp/astrodao
RELEASE_NOTES=https://github.com/near-daos/astro-ui/releases/latest
I18_RELOAD_ON_PRERENDER=false
STATS_API_URL=https://mainnet.api.daostats.io
Expand Down
4 changes: 3 additions & 1 deletion astro_2.0/components/SideFilter/SideFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface SideFilterProps {
hideAllOption?: boolean;
shallowUpdate?: boolean;
itemClassName?: string;
markerOffset?: number;
}

export const SideFilter = ({
Expand All @@ -37,6 +38,7 @@ export const SideFilter = ({
hideAllOption = false,
shallowUpdate = false,
forceHorizontalView = false,
markerOffset = 0,
}: SideFilterProps): JSX.Element => {
const { t } = useTranslation();

Expand All @@ -56,7 +58,7 @@ export const SideFilter = ({

const transformVal =
index === -1
? 0
? markerOffset
: index * HUNDRED_PERCENT + (hideAllOption ? 0 : HUNDRED_PERCENT);

return {
Expand Down
6 changes: 3 additions & 3 deletions astro_2.0/features/Discover/components/Flow/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const Flow: FC = () => {
setLeaderboardData,
chartData,
setChartData,
resetData,
setActiveView,
activeView,
} = useDiscoveryState(items);

Expand All @@ -110,9 +110,9 @@ export const Flow: FC = () => {
return;
}

resetData(id);
setActiveView(id);
},
[resetData, isMounted]
[setActiveView, isMounted]
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const GeneralInfo: FC = () => {
setLeaderboardData,
chartData,
setChartData,
resetData,
setActiveView,
activeView,
} = useDiscoveryState(items);

Expand All @@ -72,9 +72,9 @@ export const GeneralInfo: FC = () => {
return;
}

resetData(id);
setActiveView(id);
},
[resetData, isMounted]
[setActiveView, isMounted]
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const Governance: FC = () => {
setLeaderboardData,
chartData,
setChartData,
resetData,
setActiveView,
activeView,
} = useDiscoveryState(items);

Expand All @@ -91,9 +91,9 @@ export const Governance: FC = () => {
return;
}

resetData(id);
setActiveView(id);
},
[resetData, isMounted]
[setActiveView, isMounted]
);

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions astro_2.0/features/Discover/components/Tokens/Tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const Tokens: FC = () => {
setLeaderboardData,
chartData,
setChartData,
resetData,
setActiveView,
activeView,
} = useDiscoveryState(items);

Expand All @@ -82,9 +82,9 @@ export const Tokens: FC = () => {
return;
}

resetData(id);
setActiveView(id);
},
[resetData, isMounted]
[setActiveView, isMounted]
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const TopicsFilter: FC = () => {
<SideFilter
shallowUpdate
hideAllOption
markerOffset={-100}
queryName="topic"
list={overviewOptions}
title={t('discover.daoActivity')}
Expand All @@ -120,6 +121,7 @@ export const TopicsFilter: FC = () => {
<SideFilter
shallowUpdate
hideAllOption
markerOffset={-100}
queryName="topic"
list={financialOptions}
title={t('discover.financial')}
Expand Down
6 changes: 3 additions & 3 deletions astro_2.0/features/Discover/components/Tvl/Tvl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const Tvl: FC = () => {
setLeaderboardData,
chartData,
setChartData,
resetData,
setActiveView,
activeView,
} = useDiscoveryState(items);

Expand All @@ -103,9 +103,9 @@ export const Tvl: FC = () => {
return;
}

resetData(id);
setActiveView(id);
},
[isMounted, resetData]
[isMounted, setActiveView]
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ export const UsersAndActivity: FC = () => {
setLeaderboardData,
chartData,
setChartData,
resetData,
activeView,
setActiveView,
} = useDiscoveryState(items);

const handleTopicSelect = useCallback(
Expand All @@ -144,9 +144,9 @@ export const UsersAndActivity: FC = () => {
return;
}

resetData(id);
setActiveView(id);
},
[resetData, isMounted]
[isMounted, setActiveView]
);

useEffect(() => {
Expand Down
7 changes: 3 additions & 4 deletions astro_2.0/features/Discover/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,16 @@ export const useDiscoveryState = (items: TControlTab[]): DiscoveryState => {
const [chartData, setChartData] = useState<ChartDataElement[] | null>(null);
const [activeView, setActiveView] = useState(items[0].id);

const resetData = useCallback((id: string) => {
const resetData = useCallback(() => {
setOffset(0);
setTotal(0);
setLeaderboardData(null);
setChartData(null);
setActiveView(id);
}, []);

useEffect(() => {
resetData(items[0].id);
}, [items, query.dao, resetData]);
resetData();
}, [query.dao, resetData]);

return {
resetData,
Expand Down