forked from Scaffold-Stark/scaffold-stark-2
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Challenge-decentralized-staking last Version Scaffold Stark
- Loading branch information
Showing
28 changed files
with
1,954 additions
and
492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use client"; | ||
|
||
import type { NextPage } from "next"; | ||
import { StakeContractInteraction } from "~~/components/stake/StakeContractInteraction"; | ||
import { useDeployedContractInfo } from "~~/hooks/scaffold-stark"; | ||
|
||
const StakerUI: NextPage = () => { | ||
const { data: StakerContract } = useDeployedContractInfo("Staker"); | ||
|
||
return ( | ||
<StakeContractInteraction | ||
key={StakerContract?.address} | ||
address={StakerContract?.address} | ||
/> | ||
); | ||
}; | ||
|
||
export default StakerUI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"use client"; | ||
import React from "react"; | ||
import { NextPage } from "next"; | ||
import { useScaffoldEventHistory } from "~~/hooks/scaffold-stark/useScaffoldEventHistory"; | ||
import { Address } from "~~/components/scaffold-stark"; | ||
import { formatEther } from "ethers"; | ||
|
||
interface StakeEvent { | ||
args: { | ||
sender: string; | ||
amount: bigint; | ||
}; | ||
} | ||
const Staking: NextPage = () => { | ||
// @ts-ignore | ||
const { data: stakeEvents, isLoading } = useScaffoldEventHistory<StakeEvent>({ | ||
contractName: "Staker", | ||
eventName: "contracts::Staker::Staker::Stake", | ||
watch: true, | ||
fromBlock: 0n, | ||
}); | ||
console.log(stakeEvents); | ||
|
||
if (isLoading) | ||
return ( | ||
<div className="flex justify-center items-center mt-10"> | ||
<span className="loading loading-spinner loading-lg"></span> | ||
</div> | ||
); | ||
|
||
return ( | ||
<div className="flex items-center flex-col flex-grow pt-10 text-neutral"> | ||
<div className="px-5"> | ||
<h1 className="text-center mb-3"> | ||
<span className="block text-2xl font-bold">All Staking Events</span> | ||
</h1> | ||
</div> | ||
<div className="overflow-x-auto border border-secondary"> | ||
<table className="table table-zebra w-full"> | ||
<thead> | ||
<tr> | ||
<th className="bg-secondary text-white">From</th> | ||
<th className="bg-secondary text-white">Value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{!stakeEvents || stakeEvents.length === 0 ? ( | ||
<tr> | ||
<td colSpan={3} className="text-center"> | ||
No events found | ||
</td> | ||
</tr> | ||
) : ( | ||
stakeEvents?.map((event: StakeEvent, index) => { | ||
return ( | ||
<tr key={index}> | ||
<td> | ||
<Address address={`0x${event.args.sender}`} /> | ||
</td> | ||
<td> | ||
{event.args.amount && | ||
formatEther(BigInt(event.args.amount))}{" "} | ||
ETH | ||
</td> | ||
</tr> | ||
); | ||
}) | ||
)} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Staking; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { ReactNode } from "react"; | ||
|
||
interface ButtonProps { | ||
onClick: () => void; | ||
children: ReactNode; | ||
isDisable?: boolean; | ||
} | ||
|
||
const Button: React.FC<ButtonProps> = ({ | ||
onClick, | ||
children, | ||
isDisable = false, | ||
}) => { | ||
return ( | ||
<button | ||
className={`py-[5px] px-[10px] sm:px-[20px] sm:py-[10px] bg-base-300 text-base-100 rounded-[8px] sm:text-[14px] text-[12px] ${isDisable ? "cursor-not-allowed opacity-50" : "cursor-pointer"}`} | ||
onClick={onClick} | ||
type="button" | ||
disabled={isDisable || children === "Coming Soon"} | ||
> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
export default Button; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.base_button__small { | ||
padding-block: 14px; | ||
padding-inline: 24px; | ||
border-radius: 7px; | ||
} | ||
|
||
.base_button__large { | ||
width: 490px; | ||
padding: 16px 33px; | ||
border: none; | ||
border-radius: 8px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
interface ButtonProps { | ||
children: string; | ||
size?: "small" | "large"; | ||
onClick?: () => void; | ||
} | ||
|
||
const ButtonStyle = ({ children, size = "small", onClick }: ButtonProps) => { | ||
const isSmall = size === "small"; | ||
return ( | ||
<button | ||
onClick={onClick} | ||
className={`btn btn-secondary my-4 base_button__${isSmall ? "small" : "large"}`} | ||
> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
export default ButtonStyle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.