forked from Scaffold-Stark/scaffold-stark-2
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,651 additions
and
313 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
"prettier": "^3.2.5" | ||
}, | ||
"dependencies": { | ||
"humanize-duration": "^3.32.1", | ||
"postcss": "^8.4.38" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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={event.args.sender as `0x${string}`} /> | ||
</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
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,52 @@ | ||
import { useCallback, useState } from "react"; | ||
import { useGlobalState } from "~~/services/store/store"; | ||
import { useTargetNetwork } from "~~/hooks/scaffold-stark/useTargetNetwork"; | ||
|
||
type TBalanceProps = { | ||
value?: string; | ||
className?: string; | ||
}; | ||
|
||
export const ETHToPrice = ({ value, className = "" }: TBalanceProps) => { | ||
const [isEthBalance, setIsEthBalance] = useState(true); | ||
const { targetNetwork } = useTargetNetwork(); | ||
const price = useGlobalState((state) => state.nativeCurrencyPrice); | ||
|
||
const onToggleBalance = useCallback(() => { | ||
if (price > 0) { | ||
setIsEthBalance(!isEthBalance); | ||
} | ||
}, [isEthBalance, price]); | ||
|
||
if (!value) { | ||
return ( | ||
<div className="animate-pulse flex space-x-4"> | ||
<div className="flex items-center space-y-6"> | ||
<div className="h-5 w-12 bg-slate-300 rounded"></div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<button | ||
className={`btn btn-sm btn-ghost flex flex-col font-normal items-center hover:bg-transparent ${className}`} | ||
onClick={onToggleBalance} | ||
> | ||
<div className="w-full flex items-center justify-center"> | ||
{isEthBalance ? ( | ||
<> | ||
<span>{parseFloat(value).toFixed(4)}</span> | ||
<span className="text-xs font-bold ml-1"> | ||
{targetNetwork.nativeCurrency.symbol} | ||
</span> | ||
</> | ||
) : ( | ||
<> | ||
<span className="text-xs font-bold mr-1">$</span> | ||
<span>{(parseFloat(value) * price).toFixed(2)}</span> | ||
</> | ||
)} | ||
</div> | ||
</button> | ||
); | ||
}; |
Oops, something went wrong.