-
Notifications
You must be signed in to change notification settings - Fork 3
feat: batch claim fraction #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0ec6afe
feat(profile): implement unclaimed hypercerts table view
tnkshuuhei cae4a5a
refactor(hypercerts): extract extra content creation to separate comp…
tnkshuuhei 0518237
feat(profile): enhance unclaimed hypercert claim flow with step-by-st…
tnkshuuhei dd15830
feat(profile): add batch claim functionality for unclaimed hypercerts
tnkshuuhei e59ff97
refactor(profile): remove unclaimed hypercert list item component
tnkshuuhei f5ad0ea
feat(profile): add chain filtering to unclaimed hypercerts table
tnkshuuhei 64bfe4d
feat(profile): add chain switching for claiming unclaimed hypercert
tnkshuuhei 9f97c56
feat(profile): automatically set chainId filter to connected chainId
tnkshuuhei 5c064bb
feat(profile): disable to choose multiple chain ATST
tnkshuuhei 1226659
chore: increased default pagesize
tnkshuuhei 533a6ee
fix(profile): correct dropdownItem for viewing hypercert
tnkshuuhei 4032a18
chore: disabled batch claim button when user is not selected
tnkshuuhei 33e901b
refactor(profile): improve unclaimed hypercerts table design and add …
tnkshuuhei 207c95a
feat(profile): add sorting to unclaimed hypercerts table units/total_…
tnkshuuhei 8246187
refactor(profile): improve table toolbar and row selection logic
tnkshuuhei d1bddb8
style(profile): responsive table view and some UX improvement
tnkshuuhei debdc00
feat(profile): unclaimed hypercerts with metadata
tnkshuuhei 3ae229b
feat(hypercerts): introduced a new `getHypercertMetadata` function to…
tnkshuuhei 8931982
refactor(profile): change button validation, text unification and so on
tnkshuuhei aabe2a1
refactor(components): migrate extra-content to React JSX syntax
tnkshuuhei 0b5088f
refactor(profile): remove tx confirmations
tnkshuuhei 5478440
refactor(components): update createExtraContent and claim buttons
tnkshuuhei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,64 @@ | ||
import { Button, buttonVariants } from "@/components/ui/button"; | ||
import { createElement } from "react"; | ||
import type { Chain, TransactionReceipt } from "viem"; | ||
import { generateBlockExplorerLink } from "@/lib/utils"; | ||
|
||
export const createExtraContent = ( | ||
receipt: TransactionReceipt, | ||
hypercertId?: string, | ||
chain?: Chain, | ||
) => { | ||
const receiptButton = | ||
receipt && | ||
createElement( | ||
tnkshuuhei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"a", | ||
{ | ||
href: generateBlockExplorerLink(chain, receipt.transactionHash), | ||
target: "_blank", | ||
rel: "noopener noreferrer", | ||
}, | ||
createElement( | ||
Button, | ||
{ | ||
size: "default", | ||
className: buttonVariants({ variant: "secondary" }), | ||
}, | ||
"View transaction", | ||
), | ||
); | ||
|
||
const hypercertButton = | ||
hypercertId && | ||
createElement( | ||
"a", | ||
{ | ||
href: `/hypercerts/${hypercertId}`, | ||
target: "_blank", | ||
rel: "noopener noreferrer", | ||
}, | ||
createElement( | ||
Button, | ||
{ | ||
size: "default", | ||
className: buttonVariants({ variant: "default" }), | ||
}, | ||
"View hypercert", | ||
), | ||
); | ||
|
||
return createElement( | ||
"div", | ||
{ className: "flex flex-col space-y-2" }, | ||
createElement( | ||
"p", | ||
{ className: "text-sm font-medium" }, | ||
"Your hypercert has been minted successfully!", | ||
), | ||
createElement( | ||
"div", | ||
{ className: "flex space-x-4" }, | ||
receiptButton, | ||
hypercertButton, | ||
), | ||
); | ||
}; |
145 changes: 145 additions & 0 deletions
145
components/profile/unclaimed-hypercert-butchClaim-button.tsx
This file contains hidden or 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,145 @@ | ||
"use client"; | ||
|
||
import { AllowListRecord } from "@/allowlists/getAllowListRecordsForAddressByClaimed"; | ||
import { Button } from "../ui/button"; | ||
import { useHypercertClient } from "@/hooks/use-hypercert-client"; | ||
import { waitForTransactionReceipt } from "viem/actions"; | ||
import { useAccount, useSwitchChain, useWalletClient } from "wagmi"; | ||
import { useRouter } from "next/navigation"; | ||
import { useStepProcessDialogContext } from "../global/step-process-dialog"; | ||
import { revalidatePathServerAction } from "@/app/actions/revalidatePathServerAction"; | ||
import { useState } from "react"; | ||
import { Hex, ByteArray } from "viem"; | ||
import { errorToast } from "@/lib/errorToast"; | ||
import { ChainFactory } from "@/lib/chainFactory"; | ||
|
||
interface TransformedClaimData { | ||
hypercertTokenIds: bigint[]; | ||
units: bigint[]; | ||
proofs: (Hex | ByteArray)[][]; | ||
roots?: (Hex | ByteArray)[]; | ||
} | ||
|
||
function transformAllowListRecords( | ||
records: AllowListRecord[], | ||
): TransformedClaimData { | ||
return { | ||
hypercertTokenIds: records.map((record) => BigInt(record.token_id!)), | ||
units: records.map((record) => BigInt(record.units!)), | ||
proofs: records.map((record) => record.proof as (Hex | ByteArray)[]), | ||
roots: records.map((record) => record.root as Hex | ByteArray), | ||
}; | ||
} | ||
|
||
export default function UnclaimedHypercertBatchClaimButton({ | ||
allowListRecords, | ||
selectedChainId, | ||
}: { | ||
allowListRecords: AllowListRecord[]; | ||
selectedChainId: number | null; | ||
}) { | ||
const { client } = useHypercertClient(); | ||
const { data: walletClient } = useWalletClient(); | ||
const account = useAccount(); | ||
const { refresh } = useRouter(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const { setDialogStep, setSteps, setOpen, setTitle } = | ||
useStepProcessDialogContext(); | ||
const { switchChain } = useSwitchChain(); | ||
|
||
const selectedChain = selectedChainId | ||
? ChainFactory.getChain(selectedChainId) | ||
: null; | ||
|
||
const claimHypercert = async () => { | ||
setIsLoading(true); | ||
setOpen(true); | ||
setSteps([ | ||
{ id: "preparing", description: "Preparing to claim hypercert..." }, | ||
{ id: "claiming", description: "Claiming hypercert on-chain..." }, | ||
{ id: "confirming", description: "Waiting for on-chain confirmation" }, | ||
{ id: "done", description: "Claiming complete!" }, | ||
]); | ||
setTitle("Claim Hypercert from Allowlist"); | ||
if (!client) { | ||
throw new Error("No client found"); | ||
} | ||
if (!walletClient) { | ||
throw new Error("No wallet client found"); | ||
} | ||
if (!account) { | ||
throw new Error("No address found"); | ||
} | ||
|
||
const claimData = transformAllowListRecords(allowListRecords); | ||
await setDialogStep("preparing, active"); | ||
console.log(allowListRecords); | ||
tnkshuuhei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
await setDialogStep("claiming", "active"); | ||
|
||
const tx = await client.batchClaimFractionsFromAllowlists(claimData); | ||
console.log(tx); | ||
tnkshuuhei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!tx) { | ||
await setDialogStep("claiming", "error"); | ||
throw new Error("Failed to claim hypercert"); | ||
} | ||
await setDialogStep("confirming", "active"); | ||
const receipt = await waitForTransactionReceipt(walletClient, { | ||
confirmations: 3, | ||
hash: tx, | ||
}); | ||
if (receipt.status == "success") { | ||
await setDialogStep("done", "completed"); | ||
await revalidatePathServerAction([ | ||
`/profile/${account.address}`, | ||
`/profile/${account.address}?tab=hypercerts-claimable`, | ||
bitbeckers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]); | ||
} else if (receipt.status == "reverted") { | ||
await setDialogStep("confirming", "error", "Transaction reverted"); | ||
} | ||
console.log({ receipt }); | ||
tnkshuuhei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setTimeout(() => { | ||
refresh(); | ||
}, 5000); | ||
} catch (error) { | ||
console.error(error); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
return ( | ||
<> | ||
{account.chainId === selectedChainId ? ( | ||
<Button | ||
variant={"outline"} | ||
size={"sm"} | ||
onClick={claimHypercert} | ||
disabled={ | ||
tnkshuuhei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isLoading || | ||
!allowListRecords.length || | ||
!account || | ||
!client || | ||
account.address !== allowListRecords[0].user_address | ||
tnkshuuhei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
> | ||
Claim Selected | ||
</Button> | ||
) : ( | ||
<Button | ||
variant={"outline"} | ||
size="sm" | ||
disabled={!account.isConnected || !selectedChainId} | ||
onClick={() => { | ||
if (!selectedChainId) | ||
return errorToast("Hypercert is not selected"); | ||
switchChain({ chainId: selectedChainId }); | ||
tnkshuuhei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}} | ||
> | ||
{selectedChainId | ||
? `Switch to ${selectedChain?.name}` | ||
: "Select Hypercert"} | ||
</Button> | ||
)} | ||
</> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.