-
Notifications
You must be signed in to change notification settings - Fork 0
feat: cancellation phase UI for nextjs-evm and react-evm examples #74
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a871f0d
Add CancelCard for NextJS exmaple
EByrdS 5bf30cd
Add CancelCard on React
EByrdS c6e30c3
Shows message if commited amount is 0
EByrdS 4b47221
fix(lint): expose entityState from useSaleContract hook
EByrdS 9096fa5
Add cancelBid and contractStage to SVM hooks; update IDL
EByrdS 92f9a9d
Cancellation phase UX: rename state, neutral styling, stage checks
EByrdS 7279a54
Prettier
EByrdS 746652f
Adds chain guard
EByrdS 50df443
Recovers from confirmation fail
EByrdS 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
109 changes: 109 additions & 0 deletions
109
examples/framework/nextjs-evm/src/app/components/sale/CancelCard.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,109 @@ | ||
| "use client"; | ||
|
|
||
| import { Hex } from "@echoxyz/sonar-core"; | ||
| import { useState } from "react"; | ||
| import { useSaleContract } from "../../hooks/use-sale-contract"; | ||
|
|
||
| const CANCELLATION_STAGE = 2; | ||
|
|
||
| function CancelSection({ saleSpecificEntityID }: { saleSpecificEntityID: Hex }) { | ||
| const { | ||
| cancelBid, | ||
| contractStage, | ||
| entityState, | ||
| entityStateError, | ||
| awaitingTxReceipt, | ||
| txReceipt, | ||
| awaitingTxReceiptError, | ||
| } = useSaleContract(saleSpecificEntityID); | ||
|
|
||
| const [loading, setLoading] = useState(false); | ||
| const [error, setError] = useState<Error | undefined>(undefined); | ||
|
|
||
| const isCancellationStage = contractStage === CANCELLATION_STAGE; | ||
|
|
||
| const cancel = async () => { | ||
| setLoading(true); | ||
| setError(undefined); | ||
| try { | ||
| await cancelBid(); | ||
| } catch (err) { | ||
| setError(err as Error); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| const committedAmount = entityState?.currentBid?.amount; | ||
| const hasCommitment = committedAmount !== undefined && committedAmount > BigInt(0); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-4 items-center"> | ||
| {entityStateError ? ( | ||
| <div className="bg-white p-2 rounded-md w-full"> | ||
| <p className="text-red-500 wrap-anywhere">{entityStateError.message}</p> | ||
| </div> | ||
| ) : hasCommitment ? ( | ||
| <> | ||
| <div className="bg-white p-2 rounded-md w-full"> | ||
| <p className="text-gray-900">Current committed amount: {`${Number(committedAmount) / 1e6} USDC`}</p> | ||
| </div> | ||
|
|
||
| {!isCancellationStage && ( | ||
| <div className="bg-amber-50 border border-amber-200 p-3 rounded-md w-full"> | ||
| <p className="text-amber-800 text-sm font-medium">Contract not in Cancellation stage</p> | ||
| <p className="text-amber-700 text-sm mt-1"> | ||
| The "Cancel Bid" button is only active when the contract is in the Cancellation stage. To test | ||
| this feature, use the founder's dashboard to open the cancellation state ( | ||
| <code className="font-mono bg-amber-100 px-1 rounded">openCancellation</code>). See the{" "} | ||
| <a | ||
| href="https://docs.echo.xyz/sonar/reference/contracts/settlement-sale" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="underline" | ||
| > | ||
| contract docs | ||
| </a> | ||
| . | ||
| </p> | ||
| </div> | ||
| )} | ||
|
|
||
| <button | ||
| disabled={loading || awaitingTxReceipt || !isCancellationStage} | ||
| className="bg-gray-700 hover:bg-gray-800 text-white font-medium py-2 px-6 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed w-full" | ||
| onClick={cancel} | ||
| > | ||
| <p className="text-gray-100">{loading || awaitingTxReceipt ? "Loading..." : "Cancel Bid"}</p> | ||
| </button> | ||
| </> | ||
| ) : committedAmount !== undefined ? ( | ||
| <div className="bg-gray-50 border border-gray-200 p-3 rounded-md w-full"> | ||
| <p className="text-gray-600 text-sm">No active commitment to cancel.</p> | ||
| </div> | ||
| ) : ( | ||
| <div className="bg-white p-2 rounded-md w-full"> | ||
| <p className="text-gray-500 text-sm">Loading...</p> | ||
| </div> | ||
| )} | ||
|
|
||
| {awaitingTxReceipt && !txReceipt && <p className="text-gray-900">Waiting for transaction receipt...</p>} | ||
| {txReceipt?.status === "success" && ( | ||
| <p className="text-green-500">Cancellation successful — your funds have been refunded</p> | ||
| )} | ||
| {txReceipt?.status === "reverted" && <p className="text-red-500">Cancellation reverted</p>} | ||
| {error && <p className="text-red-500 wrap-anywhere">{error.message}</p>} | ||
| {awaitingTxReceiptError && <p className="text-red-500 wrap-anywhere">{awaitingTxReceiptError.message}</p>} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function CancelCard({ saleSpecificEntityID }: { saleSpecificEntityID: Hex }) { | ||
| return ( | ||
| <div className="flex flex-col gap-4 p-4 bg-linear-to-r from-indigo-50 to-blue-50 rounded-lg border border-indigo-200"> | ||
| <CancelSection saleSpecificEntityID={saleSpecificEntityID} /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default CancelCard; | ||
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
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
Oops, something went wrong.
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.