Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Dec 16, 2024
1 parent 9359f43 commit 85a06ad
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
8 changes: 4 additions & 4 deletions components/Discovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ export default function Discovery() {
} else if (service.method === FCL_SERVICE_METHODS.EXT && rpcEnabled) {
setCurrentView(VIEWS.CONNECT_EXTENSION)
} else {
telemetry.trackWalletConnected({
walletUid: wallet.uid,
serviceMethod: service.method as FCL_SERVICE_METHODS,
})
fcl.WalletUtils.redirect(service)
telemetry.trackWalletConnected(
wallet.uid,
service.method as FCL_SERVICE_METHODS,
)
}

setSelectedWallet(wallet)
Expand Down
16 changes: 7 additions & 9 deletions helpers/telemetry/telemetry.client.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import * as mixpanel from 'mixpanel-browser'
import mixpanel from 'mixpanel-browser'
import { TelemetryDataClient } from './types'
import { FCL_SERVICE_METHODS } from '../constants'

let hasInitialized = false

export function getTelemetryClient(baseData: TelemetryDataClient) {
if (process.env.NEXT_PUBLIC_MIXPANEL_ID && !hasInitialized) {
mixpanel.init(process.env.NEXT_PUBLIC_MIXPANEL_ID)
hasInitialized = true
}
console.log(process.env.NEXT_PUBLIC_MIXPANEL_ID)
if (process.env.NEXT_PUBLIC_MIXPANEL_ID) {
mixpanel.init(process.env.NEXT_PUBLIC_MIXPANEL_ID)
}

export function clientTelemetry(baseData: TelemetryDataClient) {
return {
trackWalletConnected: async ({
walletUid,
Expand All @@ -19,7 +17,7 @@ export function getTelemetryClient(baseData: TelemetryDataClient) {
serviceMethod: FCL_SERVICE_METHODS
}) => {
return new Promise<void>(resolve => {
mixpanel?.track(
mixpanel.track(
'Wallet Connected',
{
walletUid: walletUid,
Expand Down
9 changes: 4 additions & 5 deletions helpers/telemetry/telemetry.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import Mixpanel from 'mixpanel'
import { TelemetryDataServer } from './types'

let mixpanel: Mixpanel.Mixpanel | null = null
if (process.env.NEXT_PUBLIC_MIXPANEL_ID) {
Mixpanel.init(process.env.NEXT_PUBLIC_MIXPANEL_ID)
}

export function getTelemetryServer(baseData: TelemetryDataServer) {
if (process.env.NEXT_PUBLIC_MIXPANEL_ID && !mixpanel) {
Mixpanel.init(process.env.NEXT_PUBLIC_MIXPANEL_ID)
}

export function serverTelemetry(baseData: TelemetryDataServer) {
return {
trackWalletDiscoveryRequest: async () =>
new Promise<void>(resolve => {
Expand Down
4 changes: 2 additions & 2 deletions hooks/useTelemetry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useConfig } from '../contexts/FclContext'
import { getTelemetryClient } from '../helpers/telemetry/telemetry.client'
import { clientTelemetry } from '../helpers/telemetry/telemetry.client'

export function useTelemetry() {
const cfg = useConfig()
return getTelemetryClient({
return clientTelemetry({
network: cfg.network,
type: 'UI',
fclVersion: cfg.appVersion,
Expand Down
4 changes: 2 additions & 2 deletions pages/api/[network]/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { findMatchingPipeVersion } from '../../../helpers/version'
import { NETWORKS } from '../../../helpers/constants'
import { getWalletPipes } from '../../../helpers/wallet-pipes'
import { NextApiRequest } from 'next'
import { getTelemetryServer } from '../../../helpers/telemetry/telemetry.server'
import { serverTelemetry } from '../../../helpers/telemetry/telemetry.server'

// Initializing the cors middleware
export const cors = Cors({
Expand Down Expand Up @@ -41,7 +41,7 @@ export async function getWalletsFromRequest(
const discoveryRequestType = discoveryType || 'API'
const services = clientServices || extensions || []

getTelemetryServer({
serverTelemetry({
type: discoveryRequestType as 'UI' | 'API',
network,
fclVersion,
Expand Down

0 comments on commit 85a06ad

Please sign in to comment.