Skip to content

Commit

Permalink
fix(llm): add tracking on pull to refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasWerey committed Jun 6, 2024
1 parent 7e3f604 commit 7c8b44a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-fireants-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

add track on pull to refresh where a sync is triggered or not so we can quantify the amount of Sync requested to the backend
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTheme } from "@react-navigation/native";
import { useBridgeSync, useAccountSyncState } from "@ledgerhq/live-common/bridge/react/index";
import { useCountervaluesPolling } from "@ledgerhq/live-countervalues-react";
import { SYNC_DELAY } from "~/utils/constants";
import { track } from "~/analytics";

export interface Props {
accountId?: string;
Expand All @@ -24,6 +25,7 @@ export default <P,>(ScrollListLike: React.ComponentType<P>) => {
const [refreshing, setRefreshing] = useState(false);

function onPress() {
track("buttonClicked", { button: "pull to refresh" });
if (!accountId) return;
poll();
setSyncBehavior({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useBridgeSync } from "@ledgerhq/live-common/bridge/react/index";
import { useCountervaluesPolling } from "@ledgerhq/live-countervalues-react";
import { useIsFocused, useTheme } from "@react-navigation/native";
import { SYNC_DELAY } from "~/utils/constants";
import { track } from "~/analytics";

type Props = {
error?: Error;
Expand All @@ -28,6 +29,7 @@ export default <P,>(
reason: "user-pull-to-refresh",
});
setRefreshing(true);
track("buttonClicked", { button: "pull to refresh" });
}

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { useState, useCallback, useEffect } from "react";
import { track } from "~/analytics";

interface UsePullToRefreshProps {
loading: boolean;
refresh: () => void;
}

function usePullToRefresh({ loading, refresh }: UsePullToRefreshProps) {
const trackPullToRefresh = useCallback(() => {
track("button_clicked", {
button: "pull to refresh",
});
}, []);

const [refreshControlVisible, setRefreshControlVisible] = useState(false);
const handlePullToRefresh = useCallback(() => {
refresh();
setRefreshControlVisible(true);
}, [refresh]);
trackPullToRefresh();
}, [refresh, trackPullToRefresh]);

useEffect(() => {
if (refreshControlVisible && !loading) setRefreshControlVisible(false);
Expand Down
11 changes: 7 additions & 4 deletions apps/ledger-live-mobile/src/screens/Swap/History/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Share from "react-native-share";
import { useDispatch, useSelector } from "react-redux";
import type { Account } from "@ledgerhq/types-live";
import { updateAccountWithUpdater } from "~/actions/accounts";
import { TrackScreen } from "~/analytics";
import { track, TrackScreen } from "~/analytics";
import Alert from "~/components/Alert";
import Button from "~/components/Button";
import LText from "~/components/LText";
Expand Down Expand Up @@ -47,6 +47,11 @@ const History = () => {
setSections(getCompleteSwapHistory(accounts));
}, [accounts, setSections]);

const refreshSwapHistory = useCallback(() => {
setIsRefreshing(true);
track("buttonClicked", { button: "pull to refresh" });
}, [setIsRefreshing]);

const updateSwapStatus = useCallback(() => {
let cancelled = false;
async function fetchUpdatedSwapStatus() {
Expand Down Expand Up @@ -139,9 +144,7 @@ const History = () => {
style={styles.sectionList}
contentContainerStyle={styles.contentContainer}
ListEmptyComponent={_ => <EmptyState />}
refreshControl={
<RefreshControl refreshing={isRefreshing} onRefresh={() => setIsRefreshing(true)} />
}
refreshControl={<RefreshControl refreshing={isRefreshing} onRefresh={refreshSwapHistory} />}
ListHeaderComponent={
sections.length ? (
<Button
Expand Down

0 comments on commit 7c8b44a

Please sign in to comment.