Skip to content

Commit

Permalink
Fix for not waiting for initialization of statsig
Browse files Browse the repository at this point in the history
  • Loading branch information
kent-white committed Aug 23, 2023
1 parent b9c0b3e commit 03d69d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/pages/Account/hooks/useLogEventWithBasic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useWallet} from "@aptos-labs/wallet-adapter-react";
import {Statsig} from "statsig-react";
import {useGlobalState} from "../../../global-config/GlobalConfig";
import {getStableID} from "../../../utils";

// Log event with basic info
export const useLogEventWithBasic = () => {
Expand All @@ -13,7 +14,7 @@ export const useLogEventWithBasic = () => {
extraMetadata?: Record<string, string> | null,
) => {
const metadata = {
stable_id: Statsig.getStableID(),
stable_id: getStableID(),
wallet_address: account?.address ?? "",
network_type: state.network_name,
...extraMetadata,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Validators/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import PageHeader from "../layout/PageHeader";
import {StakingBanner} from "./StakingBanner";
import ValidatorsPageTabs from "./Tabs";
import ValidatorsMap from "./ValidatorsMap";
import {getStableID} from "../../utils";

export default function ValidatorsPage() {
const [state, _] = useGlobalState();
const {account, wallet} = useWallet();
const {config} = useConfig(STAKING_BANNER_CONFIG_NAME);
const viewCountCap = config.getValue("view_count");
// Get the user's stable ID
const stableID = Statsig.getStableID();
const stableID = getStableID();

// Create a key for storing the view count and last visit timestamp in localStorage
const viewCountKey = `${stableID}_view_count`;
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {BCS, HexString, TxnBuilderTypes, Types} from "aptos";
import pako from "pako";
import {Statsig} from "statsig-react";
/**
* Helper function for exhaustiveness checks.
*
Expand Down Expand Up @@ -266,3 +267,8 @@ function assertType(val: any, types: string[] | string, message?: string) {
);
}
}

// We should not be using statsig for logging like this, we will transition to google analytics
export function getStableID(): string {
return Statsig.initializeCalled() ? Statsig.getStableID() : "not_initialized";
}

0 comments on commit 03d69d5

Please sign in to comment.