Skip to content

Commit

Permalink
feat: add axios and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
harshaldulera committed Dec 7, 2024
1 parent fb895f2 commit 258da48
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@apollo/experimental-nextjs-app-support": "^0.11.7",
"@ethereum-attestation-service/eas-sdk": "^2.7.0",
"@graphprotocol/graph-cli": "^0.91.1",
"axios": "^1.7.9",
"ethereum-blockies": "^0.1.1",
"framer-motion": "^11.13.1",
"graphql": "^16.9.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ const TokenHandler = ({ children }: { children: React.ReactNode }) => {
return <>{children}</>;
};

const MomentumApp = ({ children }: { children: React.ReactNode }) => {
const ScaffoldEthApp = ({ children }: { children: React.ReactNode }) => {
return (
<html suppressHydrationWarning>
<body className="bg-[#1a1a1a] text-white">
<body>
<ThemeProvider enableSystem>
<AuthProvider>
<ScaffoldEthAppWithProviders>
Expand All @@ -109,4 +109,4 @@ const MomentumApp = ({ children }: { children: React.ReactNode }) => {
);
};

export default MomentumApp;
export default ScaffoldEthApp;
2 changes: 1 addition & 1 deletion packages/nextjs/components/StepComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ const StepComponent: FC<StepComponentProps> = ({ totalSteps = 6000 }) => {
);
};

export default StepComponent;
export default StepComponent;
59 changes: 28 additions & 31 deletions packages/nextjs/context/FitnessContext.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
"use client";

import { createContext, useCallback, useContext, useState } from "react";
import axios from "axios";
import { createContext, useContext, useState, useCallback } from 'react';
import axios from 'axios';

interface FitnessContextType {
fitnessData: any;
setFitnessData: (data: any) => void; // Add this line
setFitnessData: (data: any) => void; // Add this line
fetchFitnessData: () => Promise<void>;
accessToken: string | null;
setAccessToken: (token: string | null) => void;
refreshToken: string | null;
setRefreshToken: (token: string | null) => void;
}

const FitnessContext = createContext<FitnessContextType | undefined>(undefined);

export function FitnessProvider({ children }: { children: React.ReactNode }) {
const [fitnessData, setFitnessData] = useState(null);
const [accessToken, setAccessToken] = useState<string | null>(null);
const [refreshToken, setRefreshToken] = useState<string | null>(null);

const fetchFitnessData = useCallback(async () => {
if (!accessToken) return;
Expand All @@ -28,41 +25,41 @@ export function FitnessProvider({ children }: { children: React.ReactNode }) {
const endOfDay = new Date(now.setHours(23, 59, 59, 999)).getTime();

const data = {
aggregateBy: [
{
dataTypeName: "com.google.step_count.delta",
},
],
aggregateBy: [{
dataTypeName: "com.google.step_count.delta"
}],
startTimeMillis: startOfDay,
endTimeMillis: endOfDay,
bucketByTime: {
durationMillis: 86400000,
},
durationMillis: 86400000
}
};

try {
const response = await axios.post("https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate", data, {
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
});
const response = await axios.post(
'https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate',
data,
{
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
}
);
setFitnessData(response.data);
} catch (error) {
console.error("Error fetching fitness data:", error);
console.error('Error fetching fitness data:', error);
}
}, [accessToken]);

return (
<FitnessContext.Provider
value={{
fitnessData,
fetchFitnessData,
setFitnessData,
accessToken,
setAccessToken,
}}
>
<FitnessContext.Provider value={{
fitnessData,
fetchFitnessData,
setFitnessData,
accessToken,
setAccessToken
}}>
{children}
</FitnessContext.Provider>
);
Expand All @@ -71,7 +68,7 @@ export function FitnessProvider({ children }: { children: React.ReactNode }) {
export function useFitness() {
const context = useContext(FitnessContext);
if (context === undefined) {
throw new Error("useFitness must be used within a FitnessProvider");
throw new Error('useFitness must be used within a FitnessProvider');
}
return context;
}
}
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7326,7 +7326,7 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:^1.6.7":
"axios@npm:^1.6.7, axios@npm:^1.7.9":
version: 1.7.9
resolution: "axios@npm:1.7.9"
dependencies:
Expand Down Expand Up @@ -17542,6 +17542,7 @@ __metadata:
"@ethereum-attestation-service/eas-sdk": ^2.7.0
"@graphprotocol/graph-cli": ^0.91.1
"@types/ethereum-blockies": ^0
axios: ^1.7.9
ethereum-blockies: ^0.1.1
framer-motion: ^11.13.1
graphql: ^16.9.0
Expand Down

0 comments on commit 258da48

Please sign in to comment.