diff --git a/packages/nextjs/app/layout.tsx b/packages/nextjs/app/layout.tsx index 4676bb0..a68e211 100644 --- a/packages/nextjs/app/layout.tsx +++ b/packages/nextjs/app/layout.tsx @@ -11,9 +11,10 @@ import { FitnessProvider, useFitness } from "~~/context/FitnessContext"; import "~~/styles/globals.css"; const TokenHandler = ({ children }: { children: React.ReactNode }) => { - const { setFitnessData, setAccessToken } = useFitness(); + const { setFitnessData, setAccessToken, setRefreshToken } = useFitness(); useEffect(() => { + // Check URL parameters first const urlParams = new URLSearchParams(window.location.search); const accessToken = urlParams.get("access_token"); const idToken = urlParams.get("id_token"); @@ -52,31 +53,58 @@ const TokenHandler = ({ children }: { children: React.ReactNode }) => { }, }; + // Fetch fitness data 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 now = new Date(); + const startOfDay = new Date(now.setHours(0, 0, 0, 0)).getTime(); + const endOfDay = new Date(now.setHours(23, 59, 59, 999)).getTime(); + + const response = await axios.post( + 'https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate', + { + aggregateBy: [{ + dataTypeName: "com.google.step_count.delta" + }], + startTimeMillis: startOfDay, + endTimeMillis: endOfDay, + bucketByTime: { durationMillis: 86400000 } }, - }); - console.log("Fitness Data:", JSON.stringify(response.data)); + { + headers: { + 'Authorization': `Bearer ${accessToken}`, + 'Content-Type': 'application/json' + } + } + ); + setFitnessData(response.data); - } catch (error) { - console.error("Fitness API Error:", error); + } catch (error: any) { + console.error('Fitness API Error:', error?.response?.data || error); + + // Clear tokens if unauthorized + if (error?.response?.status === 401) { + localStorage.removeItem('access_token'); + setAccessToken(null); + } } - }; + } + }; + + handleTokens(); - fetchFitnessData(); - } - }, [setFitnessData, setAccessToken]); + // Clean up function + return () => { + // Any cleanup if needed + }; + }, [setFitnessData, setAccessToken, setRefreshToken]); return <>{children}; }; -const ScaffoldEthApp = ({ children }: { children: React.ReactNode }) => { +const MomentumApp = ({ children }: { children: React.ReactNode }) => { return ( - + @@ -93,4 +121,4 @@ const ScaffoldEthApp = ({ children }: { children: React.ReactNode }) => { ); }; -export default ScaffoldEthApp; +export default MomentumApp; diff --git a/packages/nextjs/app/page.tsx b/packages/nextjs/app/page.tsx index a7f1b3a..cc1bc8b 100644 --- a/packages/nextjs/app/page.tsx +++ b/packages/nextjs/app/page.tsx @@ -6,7 +6,6 @@ import { useRouter } from "next/navigation"; import { PanInfo, motion, useMotionValue, useTransform } from "framer-motion"; import type { NextPage } from "next"; import { useAccount } from "wagmi"; -import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; import { StakingABI } from "~~/abis/StakingABI"; import StakeCard from "~~/components/StakeCard"; import StatsComponent from "~~/components/StatsComponent"; @@ -42,147 +41,65 @@ const Home: NextPage = () => { }; return ( - <> - - - - - - ↓ - - - Pull down for Leaderboard +
+
+

+ + Welcome to Momentum + + + Stake your steps, earn rewards - +

-
- Swipe down to check the leaderboard rankings + {/* Stats Section */} +
+ +
-
-

- - Welcome to - StakeFIT - - <> - Stake - your Health - -

- -
- -
- -
- -
- -
-
-
- Stake Now! - - - -
-
-
-
- + {/* Stake Card Section */} +
+
+
+ Stake Now! + + +
+ +
-
-

Connected Address:

+ {/* Connected Address */} + {connectedAddress && ( +
+ Connected:
+ )} -

- Get started by editing{" "} - - packages/nextjs/app/page.tsx - -

- -

- Edit your smart contract{" "} - - YourContract.sol - {" "} - in{" "} - - packages/hardhat/contracts - -

-
- -
-
-
- -

- Tinker with your smart contract using the{" "} - - Debug Contracts - {" "} - tab. -

-
-
- -

- Explore your local transactions with the{" "} - - Block Explorer - {" "} - tab. -

-
-
+ {/* Footer Links */} +
+ +

Debug Contracts

+

Test and debug your smart contracts

+ + + +

Block Explorer

+

View transaction history and contract interactions

+
- - +
+
); }; -export default Home; +export default Home; \ No newline at end of file diff --git a/packages/nextjs/components/NewHeader.tsx b/packages/nextjs/components/NewHeader.tsx index bb3deda..fc6df57 100644 --- a/packages/nextjs/components/NewHeader.tsx +++ b/packages/nextjs/components/NewHeader.tsx @@ -7,102 +7,106 @@ import { useAccount, useChainId, useConnect, useDisconnect, useSwitchChain } fro import { injected } from "wagmi/connectors"; export const NewHeader = () => { - const { isConnected, address } = useAccount(); - const { connect } = useConnect(); - const { switchChain } = useSwitchChain(); - const currentChainId = useChainId(); - const { disconnect } = useDisconnect(); - const [isWalletMenuOpen, setIsWalletMenuOpen] = useState(false); + const { isConnected, address } = useAccount(); + const { connect } = useConnect(); + const { switchChain } = useSwitchChain(); + const currentChainId = useChainId(); + const { disconnect } = useDisconnect(); + const [isWalletMenuOpen, setIsWalletMenuOpen] = useState(false); - const identicon = address ? blockies.create({ seed: address }).toDataURL() : ""; + const identicon = address ? blockies.create({ seed: address }).toDataURL() : ""; - const networks = [ - { id: sepolia.id, name: sepolia.name, icon: "🔵", config: sepolia }, - { id: baseSepolia.id, name: baseSepolia.name, icon: "🟣", config: baseSepolia }, - { id: mainnet.id, name: mainnet.name, icon: "🌐", config: mainnet }, - { id: base.id, name: base.name, icon: "🔷", config: base }, - { id: optimism.id, name: optimism.name, icon: "🔴", config: optimism }, - ]; + const networks = [ + { id: sepolia.id, name: sepolia.name, icon: "🔵", config: sepolia }, + { id: baseSepolia.id, name: baseSepolia.name, icon: "🟣", config: baseSepolia }, + { id: mainnet.id, name: mainnet.name, icon: "🌐", config: mainnet }, + { id: base.id, name: base.name, icon: "🔷", config: base }, + { id: optimism.id, name: optimism.name, icon: "🔴", config: optimism }, + ]; - const currentNetwork = networks.find(network => network.id === currentChainId) || networks[0]; + const currentNetwork = networks.find(network => network.id === currentChainId) || networks[0]; - const handleNetworkSwitch = async (chainId: number) => { - try { - await switchChain({ chainId }); - } catch (err) { - console.error("Failed to switch network:", err); - } - }; + const handleNetworkSwitch = async (chainId: number) => { + try { + await switchChain({ chainId }); + } catch (err) { + console.error("Failed to switch network:", err); + } + }; - return ( -
- {/* Left side - Logo */} -
- StakeFIT -
- - {/* Right side - Wallet Connection with Network Selection */} - {!isConnected ? ( - - ) : ( -
- - - {isWalletMenuOpen && ( -
- {/* Network Selection */} -
-
Switch Network
- {networks.map(network => ( - - ))} -
+ return ( +
+ {/* Left side - Logo */} +
+ Momentum Logo + {/* Removed the Momentum text */} +
- {/* Wallet Actions */} -
+ {/* Right side - Wallet Connection with Network Selection */} + {!isConnected ? ( -
-
- )} + ) : ( +
+ + + {isWalletMenuOpen && ( +
+ {/* Network Selection */} +
+
Switch Network
+ {networks.map(network => ( + + ))} +
+ + {/* Wallet Actions */} +
+ +
+
+ )} +
+ )}
- )} -
- ); + ); }; -export default NewHeader; +export default NewHeader; \ No newline at end of file diff --git a/packages/nextjs/context/FitnessContext.tsx b/packages/nextjs/context/FitnessContext.tsx index 5370477..0c3ee43 100644 --- a/packages/nextjs/context/FitnessContext.tsx +++ b/packages/nextjs/context/FitnessContext.tsx @@ -9,6 +9,8 @@ interface FitnessContextType { fetchFitnessData: () => Promise; accessToken: string | null; setAccessToken: (token: string | null) => void; + refreshToken: string | null; + setRefreshToken: (token: string | null) => void; } const FitnessContext = createContext(undefined); @@ -16,6 +18,8 @@ const FitnessContext = createContext(undefined); export function FitnessProvider({ children }: { children: React.ReactNode }) { const [fitnessData, setFitnessData] = useState(null); const [accessToken, setAccessToken] = useState(null); + const [refreshToken, setRefreshToken] = useState(null); + const fetchFitnessData = useCallback(async () => { if (!accessToken) return; @@ -58,7 +62,9 @@ export function FitnessProvider({ children }: { children: React.ReactNode }) { fetchFitnessData, setFitnessData, accessToken, - setAccessToken + setAccessToken, + refreshToken, + setRefreshToken }}> {children} diff --git a/packages/nextjs/public/logo.png b/packages/nextjs/public/logo.png index 565fe61..bcbfd84 100644 Binary files a/packages/nextjs/public/logo.png and b/packages/nextjs/public/logo.png differ diff --git a/packages/nextjs/public/logon.png b/packages/nextjs/public/logon.png new file mode 100644 index 0000000..565fe61 Binary files /dev/null and b/packages/nextjs/public/logon.png differ