Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Unfork Statsig for web (#3192)

authored by

dan and committed by
GitHub
7af338ed 202adb6d

-96
-1
package.json
··· 179 179 "react-responsive": "^9.0.2", 180 180 "rn-fetch-blob": "^0.12.0", 181 181 "sentry-expo": "~7.0.1", 182 - "statsig-react": "^1.36.0", 183 182 "statsig-react-native-expo": "^4.6.1", 184 183 "tippy.js": "^6.3.7", 185 184 "tlds": "^1.234.0",
-75
src/lib/statsig/statsig.web.tsx
··· 1 - import React from 'react' 2 - import { 3 - Statsig, 4 - StatsigProvider, 5 - useGate as useStatsigGate, 6 - } from 'statsig-react' 7 - import {useSession} from '../../state/session' 8 - import {sha256} from 'js-sha256' 9 - 10 - const statsigOptions = { 11 - environment: { 12 - tier: process.env.NODE_ENV === 'development' ? 'development' : 'production', 13 - }, 14 - // Don't block on waiting for network. The fetched config will kick in on next load. 15 - // This ensures the UI is always consistent and doesn't update mid-session. 16 - // Note this makes cold load (no local storage) and private mode return `false` for all gates. 17 - initTimeoutMs: 1, 18 - } 19 - 20 - export function logEvent( 21 - eventName: string, 22 - value?: string | number | null, 23 - metadata?: Record<string, string> | null, 24 - ) { 25 - Statsig.logEvent(eventName, value, metadata) 26 - } 27 - 28 - export function useGate(gateName: string) { 29 - const {isLoading, value} = useStatsigGate(gateName) 30 - if (isLoading) { 31 - // This should not happen because of waitForInitialization={true}. 32 - console.error('Did not expected isLoading to ever be true.') 33 - } 34 - return value 35 - } 36 - 37 - function toStatsigUser(did: string | undefined) { 38 - let userID: string | undefined 39 - if (did) { 40 - userID = sha256(did) 41 - } 42 - return {userID} 43 - } 44 - 45 - export function Provider({children}: {children: React.ReactNode}) { 46 - const {currentAccount} = useSession() 47 - const currentStatsigUser = React.useMemo( 48 - () => toStatsigUser(currentAccount?.did), 49 - [currentAccount?.did], 50 - ) 51 - 52 - React.useEffect(() => { 53 - function refresh() { 54 - // Intentionally refetching the config using the JS SDK rather than React SDK 55 - // so that the new config is stored in cache but isn't used during this session. 56 - // It will kick in for the next reload. 57 - Statsig.updateUser(currentStatsigUser) 58 - } 59 - const id = setInterval(refresh, 3 * 60e3 /* 3 min */) 60 - return () => clearInterval(id) 61 - }, [currentStatsigUser]) 62 - 63 - return ( 64 - <StatsigProvider 65 - sdkKey="client-SXJakO39w9vIhl3D44u8UupyzFl4oZ2qPIkjwcvuPsV" 66 - mountKey={currentStatsigUser.userID} 67 - user={currentStatsigUser} 68 - // This isn't really blocking due to short initTimeoutMs above. 69 - // However, it ensures `isLoading` is always `false`. 70 - waitForInitialization={true} 71 - options={statsigOptions}> 72 - {children} 73 - </StatsigProvider> 74 - ) 75 - }
-20
yarn.lock
··· 15059 15059 resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.10.1.tgz#b40104ba1368e823fdd5f41b66b104b15a0da60d" 15060 15060 integrity sha512-5obBtsz9301ULlsgggLg542s/jqtddfOpV5KJc4hajc9JV8GeY2gZHSVpYBn4nWqAUTJ9v+xwtbJ1mIBgIH5Vw== 15061 15061 15062 - js-sha256@^0.11.0: 15063 - version "0.11.0" 15064 - resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.11.0.tgz#256a921d9292f7fe98905face82e367abaca9576" 15065 - integrity sha512-6xNlKayMZvds9h1Y1VWc0fQHQ82BxTXizWPEtEeGvmOUYpBRy4gbWroHLpzowe6xiQhHpelCQiE7HEdznyBL9Q== 15066 - 15067 15062 js-sha256@^0.9.0: 15068 15063 version "0.9.0" 15069 15064 resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966" ··· 20082 20077 js-sha256 "^0.10.1" 20083 20078 uuid "^8.3.2" 20084 20079 20085 - statsig-js@4.49.0: 20086 - version "4.49.0" 20087 - resolved "https://registry.yarnpkg.com/statsig-js/-/statsig-js-4.49.0.tgz#8470a9ac218a93d36f4b7b306ff9377e48064740" 20088 - integrity sha512-N4drx6fzI168Q4NndFY3IJbSDqpWSBWvS290H/RnT/g3Et58SvtXzG5qqgzmqy4CwcmwH+IL8K15pL7hPnfvUQ== 20089 - dependencies: 20090 - js-sha256 "^0.11.0" 20091 - uuid "^8.3.2" 20092 - 20093 20080 statsig-react-native-expo@^4.6.1: 20094 20081 version "4.6.1" 20095 20082 resolved "https://registry.yarnpkg.com/statsig-react-native-expo/-/statsig-react-native-expo-4.6.1.tgz#0bdf49fee7112f7f28bff2405f4ba0c1727bb3d6" ··· 20109 20096 integrity sha512-KLN7dhq6FvAl25Z0QN6IINFBgM3yn0GMafoE698tYZqRf911xvevFaR7qUXiTz3W9vmFYrmFRouqVMfCv7DW0A== 20110 20097 dependencies: 20111 20098 statsig-js "4.45.1" 20112 - 20113 - statsig-react@^1.36.0: 20114 - version "1.36.0" 20115 - resolved "https://registry.yarnpkg.com/statsig-react/-/statsig-react-1.36.0.tgz#c2171268a6c76eee534849ec9556b836baba04b6" 20116 - integrity sha512-QcTHla3ypfn2RvrnHGNlqWbiC2W/ZjcMM5LT6ExNV4skH7Xhspto3dMS3JVzBhOb74OEDZK4DbxQj9Wdz6XW0w== 20117 - dependencies: 20118 - statsig-js "4.49.0" 20119 20099 20120 20100 statuses@2.0.1: 20121 20101 version "2.0.1"