-
Notifications
You must be signed in to change notification settings - Fork 16
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
1 parent
42f1570
commit 6459885
Showing
7 changed files
with
209 additions
and
50 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 |
---|---|---|
|
@@ -25,4 +25,4 @@ | |
"@types/prettier": "2", | ||
"@types/qrcode": "1" | ||
} | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
packages/nextjs/components/hats-demo-day/hooks/CadentReputationDistributorHooks.tsx
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,21 @@ | ||
import { useScaffoldContractRead, useScaffoldContractWrite } from "~~/hooks/scaffold-eth"; | ||
|
||
export function useGetRemainingTime(address?: string) { | ||
const { data: remainingTime } = useScaffoldContractRead({ | ||
contractName: "CadentRepDistributor", | ||
functionName: "getRemainingTime", | ||
args: [address], | ||
}); | ||
|
||
return remainingTime; | ||
} | ||
|
||
export function useClaimReputation() { | ||
const { writeAsync: writeClaimRep } = useScaffoldContractWrite({ | ||
contractName: "CadentRepDistributor", | ||
functionName: "claim", | ||
blockConfirmations: 1, | ||
}); | ||
|
||
return writeClaimRep; | ||
} |
71 changes: 71 additions & 0 deletions
71
packages/nextjs/components/hats-demo-day/hooks/hatsHooks.tsx
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,71 @@ | ||
import { useEffect, useState } from "react"; | ||
import { HatsClient } from "@hatsprotocol/sdk-v1-core"; | ||
import { PublicClient, WalletClient, usePublicClient, useWalletClient } from "wagmi"; | ||
|
||
export function useHatsClient(chainId: number) { | ||
const [hatsClient, setHatsClient] = useState<HatsClient>(); | ||
|
||
const { data: walletClient } = useWalletClient(); | ||
const publicClient = usePublicClient(); | ||
|
||
async function getHatsClient(walletClient: WalletClient, publicClient: PublicClient, chainId: number) { | ||
const hatsClient = new HatsClient({ | ||
chainId, | ||
publicClient, | ||
walletClient, | ||
}); | ||
|
||
setHatsClient(hatsClient); | ||
} | ||
|
||
useEffect(() => { | ||
if (!walletClient) return; | ||
|
||
getHatsClient(walletClient, publicClient, chainId); | ||
}, [walletClient, publicClient, chainId]); | ||
|
||
return { hatsClient, getHatsClient }; | ||
} | ||
|
||
export function useHatsCanClaim(hatsClient: HatsClient | undefined, hatId: string, account: string | undefined) { | ||
const [canClaim, setCanClaim] = useState(false); | ||
|
||
async function getCanClaim(hatsClient: HatsClient | undefined, hatId: string, account: string | undefined) { | ||
if (!hatsClient) return; | ||
|
||
if (!account) return; | ||
|
||
const canClaim = await hatsClient.accountCanClaim({ | ||
hatId: BigInt(hatId), | ||
account, | ||
}); | ||
|
||
setCanClaim(canClaim); | ||
} | ||
|
||
useEffect(() => { | ||
getCanClaim(hatsClient, hatId, account); | ||
}, [hatsClient, account, hatId]); | ||
|
||
return { canClaim, getCanClaim }; | ||
} | ||
|
||
export function useClaimHat(hatsClient: HatsClient | undefined, hatId: string, account: string | undefined) { | ||
async function claimHat() { | ||
if (!hatsClient) return; | ||
if (!account) return; | ||
|
||
await hatsClient.claimHat({ | ||
account, | ||
hatId: BigInt(hatId), | ||
}); | ||
} | ||
|
||
return { claimHat }; | ||
} | ||
|
||
// export function useHatsClientWrite(hatsClient: HatsClient, functionName: string, args: object[]) { | ||
// async function clientWrite(hatsClient: HatsClient, functionName: string, args: object[]) { | ||
// await hatsClient[functionName](args); | ||
// } | ||
// } |
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
Oops, something went wrong.