MCPcopy Create free account
hub / github.com/dailydotdev/apps / BootDataProvider

Function BootDataProvider

packages/shared/src/contexts/BootProvider.tsx:143–539  ·  view source on GitHub ↗
({
  children,
  app,
  version,
  deviceId,
  localBootData,
  getRedirectUri,
  getPage,
}: BootDataProviderProps)

Source from the content-addressed store, hash-verified

141};
142
143export const BootDataProvider = ({
144 children,
145 app,
146 version,
147 deviceId,
148 localBootData,
149 getRedirectUri,
150 getPage,
151}: BootDataProviderProps): ReactElement => {
152 const queryClient = useQueryClient();
153
154 const [initialLoad, setInitialLoad] = useState<boolean>();
155 const [cachedBootData, setCachedBootDataState] =
156 useState<Partial<BootCacheData>>();
157 const cachedBootDataRef = useRef<Partial<BootCacheData>>();
158 // Checked once on load, so the feed doesn't lose its query as the cached
159 // token nears expiry while boot is in flight
160 const [validTokenCache, setValidTokenCache] =
161 useState<Partial<BootCacheData>>();
162 const [cachedTokenWasInvalid, setCachedTokenWasInvalid] = useState(false);
163 const setCachedBootData = useCallback(
164 (data: Partial<BootCacheData> | undefined) => {
165 cachedBootDataRef.current = data;
166 setCachedBootDataState(data);
167 },
168 [],
169 );
170
171 useEffect(() => {
172 if (localBootData) {
173 setCachedBootData(localBootData);
174 setValidTokenCache(
175 isCachedTokenValid(localBootData) ? localBootData : undefined,
176 );
177
178 return;
179 }
180
181 const boot = getLocalBootData();
182
183 if (!boot) {
184 setCachedBootData(undefined);
185
186 return;
187 }
188
189 if (boot?.settings?.theme) {
190 applyTheme(themeModes[boot.settings.theme]);
191 }
192
193 setCachedBootData(boot);
194 setValidTokenCache(isCachedTokenValid(boot) ? boot : undefined);
195 }, [localBootData, setCachedBootData]);
196
197 const { hostGranted } = useHostStatus();
198 const isExtension = checkIsExtension();
199 const logged = cachedBootData?.user as LoggedUser;
200 const shouldRefetch = !!logged?.providers && !!logged?.id;

Callers

nothing calls this directly

Calls 15

applyThemeFunction · 0.90
useHostStatusFunction · 0.90
checkIsExtensionFunction · 0.90
getBootDataFunction · 0.90
useRefreshTokenFunction · 0.90
generateQueryKeyFunction · 0.90
getDailyClientPlatformFunction · 0.90
clearSignedOutFunction · 0.90
getApiErrorFunction · 0.90
isIOSNativeFunction · 0.90
isConnectionErrorFunction · 0.90
isCachedTokenValidFunction · 0.85

Tested by

no test coverage detected