Skip to content

Commit

Permalink
feat: push
Browse files Browse the repository at this point in the history
  • Loading branch information
harshaldulera committed Dec 7, 2024
1 parent 8c5d1c2 commit 8ad6136
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 235 deletions.
60 changes: 44 additions & 16 deletions packages/nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 (
<html suppressHydrationWarning>
<body>
<body className="bg-[#1a1a1a] text-white">
<ThemeProvider enableSystem>
<ScaffoldEthAppWithProviders>
<ApolloProvider>
Expand All @@ -93,4 +121,4 @@ const ScaffoldEthApp = ({ children }: { children: React.ReactNode }) => {
);
};

export default ScaffoldEthApp;
export default MomentumApp;
179 changes: 48 additions & 131 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -42,147 +41,65 @@ const Home: NextPage = () => {
};

return (
<>
<motion.div
style={{
opacity: bgOpacity,
position: "fixed",
top: 0,
left: 0,
right: 0,
bottom: 0,
background: "black",
pointerEvents: "none",
zIndex: 40,
}}
/>

<motion.div
drag="y"
dragConstraints={{ top: 0, bottom: 0 }}
dragElastic={0.9}
onDrag={handleDrag}
onDragEnd={handleDragEnd}
style={{ y }}
className="flex items-center flex-col flex-grow pt-10"
>
<motion.div
style={{
position: "fixed",
top: 20,
left: "50%",
transform: "translateX(-50%)",
opacity: useTransform(y, [0, 50], [0, 1]),
zIndex: 50,
}}
className="flex flex-col items-center gap-2"
>
<motion.div
animate={{ y: [0, 10, 0] }}
transition={{
duration: 2,
repeat: Infinity,
ease: "easeInOut",
}}
className="text-neon-green"
>
</motion.div>
<span className="text-neon-green font-bold bg-base-300 px-4 py-2 rounded-full shadow-lg">
Pull down for Leaderboard
<div className="flex items-center flex-col flex-grow pt-10">
<div className="px-5 max-w-4xl w-full">
<h1 className="text-center mb-8">
<span className="block text-4xl font-bold mb-2 bg-gradient-to-r from-[#11ce6f] to-[#3b82f6] text-transparent bg-clip-text">
Welcome to Momentum
</span>
<span className="text-xl text-[#a3a2a7]">
Stake your steps, earn rewards
</span>
</motion.div>
</h1>

<div className="mb-8 text-center text-sm text-gray-400 animate-pulse">
Swipe down to check the leaderboard rankings
{/* Stats Section */}
<div className="space-y-4 mb-8">
<StatsComponent stepsGoal={8000} />
<StepComponent totalSteps={8000} />
</div>

<div className="px-5">
<h1 className="text-center">
<span className="block text-2xl mb-2">
Welcome to
<span className="text-4xl font-bold ml-2">StakeFIT</span>
</span>
<>
<span className="text-2xl"> Stake </span>
<span className="text-4xl font-bold text-accent">your Health</span>
</>
</h1>

<div className="flex justify-center my-4">
<StatsComponent stepsGoal={6000} />
</div>

<div className="flex justify-center my-4">
<StepComponent totalSteps={6000} />
</div>

<div className="relative">
<div className="absolute -top-12 right-10 animate-bounce">
<div className="flex items-center text-neon-green">
<span className="mr-2 font-bold">Stake Now!</span>
<svg className="w-6 h-6 transform rotate-90" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 14l-7 7m0 0l-7-7m7 7V3" />
</svg>
</div>
</div>
<div className="relative">
<div className="absolute -left-4 top-1/2 animate-pulse"></div>
<StakeCard contractAddress={contractAddress} contractABI={contractABI} />
{/* Stake Card Section */}
<div className="relative mb-8">
<div className="absolute -top-12 right-10 animate-bounce">
<div className="flex items-center text-[#11ce6f]">
<span className="mr-2 font-bold">Stake Now!</span>
<svg className="w-6 h-6 transform rotate-90" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 14l-7 7m0 0l-7-7m7 7V3" />
</svg>
</div>
</div>
<StakeCard contractAddress={contractAddress} contractABI={contractABI} />
</div>

<div className="flex justify-center items-center space-x-2 flex-col sm:flex-row">
<p className="my-2 font-medium">Connected Address:</p>
{/* Connected Address */}
{connectedAddress && (
<div className="flex justify-center items-center gap-2 mb-8">
<span className="text-[#a3a2a7]">Connected:</span>
<Address address={connectedAddress} />
</div>
)}

<p className="text-center text-lg">
Get started by editing{" "}
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
packages/nextjs/app/page.tsx
</code>
</p>

<p className="text-center text-lg">
Edit your smart contract{" "}
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
YourContract.sol
</code>{" "}
in{" "}
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
packages/hardhat/contracts
</code>
</p>
</div>

<div className="flex-grow bg-base-300 w-full mt-16 px-8 py-12">
<div className="flex justify-center items-center gap-12 flex-col sm:flex-row">
<div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
<BugAntIcon className="h-8 w-8 fill-secondary" />
<p>
Tinker with your smart contract using the{" "}
<Link href="/debug" passHref className="link">
Debug Contracts
</Link>{" "}
tab.
</p>
</div>
<div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
<MagnifyingGlassIcon className="h-8 w-8 fill-secondary" />
<p>
Explore your local transactions with the{" "}
<Link href="/blockexplorer" passHref className="link">
Block Explorer
</Link>{" "}
tab.
</p>
</div>
</div>
{/* Footer Links */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-8">
<Link
href="/debug"
className="p-6 rounded-xl bg-[#2d2c2e] hover:bg-[#3d3c3e] transition-colors text-center"
>
<h3 className="text-lg font-semibold mb-2">Debug Contracts</h3>
<p className="text-[#a3a2a7]">Test and debug your smart contracts</p>
</Link>

<Link
href="/blockexplorer"
className="p-6 rounded-xl bg-[#2d2c2e] hover:bg-[#3d3c3e] transition-colors text-center"
>
<h3 className="text-lg font-semibold mb-2">Block Explorer</h3>
<p className="text-[#a3a2a7]">View transaction history and contract interactions</p>
</Link>
</div>
</motion.div>
</>
</div>
</div>
);
};

export default Home;
export default Home;
Loading

0 comments on commit 8ad6136

Please sign in to comment.