-
Notifications
You must be signed in to change notification settings - Fork 53
feat: add claim n mint button to fxparams, allow to claim the chepeast ticket and mint in one batch #735
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
Open
GemN
wants to merge
4
commits into
dev
Choose a base branch
from
feat/params-use-claimable-ticket
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add claim n mint button to fxparams, allow to claim the chepeast ticket and mint in one batch #735
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
95a37fb
feat: add claim n mint button to fxparams, allow to claim the chepeas…
GemN 9a454a0
feat: add button explore params / use ticket if ticket available on t…
GemN 92840b6
run lint fix
GemN f2bd27c
fix: claim n mint contract work with values rounded, only show use ti…
GemN 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
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,55 @@ | ||
| import React, { memo, useContext } from "react" | ||
| import { GenerativeToken } from "../../../types/entities/GenerativeToken" | ||
| import Link from "next/link" | ||
| import { getGenerativeTokenUrl } from "../../../utils/generative-token" | ||
| import { Button } from "../../../components/Button" | ||
| import { UserContext } from "../../UserProvider" | ||
| import { useQuery } from "@apollo/client" | ||
| import { Qu_mintTickets } from "../../../queries/mint-ticket" | ||
| import style from "./GenerativeDisplay.module.scss" | ||
|
|
||
| interface ButtonExploreParamsProps { | ||
| token: GenerativeToken | ||
| } | ||
|
|
||
| const _ButtonExploreParams = ({ token }: ButtonExploreParamsProps) => { | ||
| const { user } = useContext(UserContext) | ||
| const { data } = useQuery(Qu_mintTickets, { | ||
| variables: { | ||
| take: 1, | ||
| skip: 0, | ||
| filters: { | ||
| token_eq: token.id, | ||
| owner_eq: user?.id, | ||
| underAuction_eq: false, | ||
| }, | ||
| }, | ||
| skip: !user, | ||
| }) | ||
| const hasAtLeastOneTicket = user && data?.mintTickets.length > 0 | ||
| return ( | ||
| <Link href={`${getGenerativeTokenUrl(token)}/explore-params`} passHref> | ||
| <Button | ||
| isLink={true} | ||
| size="regular" | ||
| color={hasAtLeastOneTicket ? "secondary" : "black"} | ||
| iconSide="right" | ||
| className={style.button} | ||
| > | ||
| {hasAtLeastOneTicket ? ( | ||
| <> | ||
| use ticket | ||
| <i className="fa-sharp fa-solid fa-ticket" aria-hidden /> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| explore params{" "} | ||
| <i aria-hidden className="fa-sharp fa-regular fa-slider" /> | ||
| </> | ||
| )} | ||
| </Button> | ||
| </Link> | ||
| ) | ||
| } | ||
|
|
||
| export const ButtonExploreParams = memo(_ButtonExploreParams) | ||
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
75 changes: 75 additions & 0 deletions
75
src/containers/MintWithTicket/Panel/ButtonClaimAndMint.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,75 @@ | ||
| import React, { memo, useCallback, useContext, useMemo } from "react" | ||
| import { useQuery } from "@apollo/client" | ||
| import { Qu_genTokenClaimableMintTickets } from "../../../queries/generative-token" | ||
| import { BaseButton } from "../../../components/FxParams/BaseInput" | ||
| import style from "./PanelControls.module.scss" | ||
| import { GenerativeToken } from "../../../types/entities/GenerativeToken" | ||
| import useNow from "../../../hooks/useNow" | ||
| import { MintTicket } from "../../../types/entities/MintTicket" | ||
| import { getMintTicketDAPrice } from "../../../utils/mint-ticket" | ||
| import { DisplayTezos } from "../../../components/Display/DisplayTezos" | ||
| import { displayMutez } from "../../../utils/units" | ||
| import { UserContext } from "../../UserProvider" | ||
|
|
||
| type GenerativeTokenWithDaMintTickets = GenerativeToken & { | ||
| daMintTickets: MintTicket[] | ||
| } | ||
| interface ClaimAndMintProps { | ||
| token: GenerativeToken | ||
| onClick: (ticket: MintTicket) => void | ||
| } | ||
|
|
||
| const _ButtonClaimAndMint = ({ token, onClick }: ClaimAndMintProps) => { | ||
| const { user } = useContext(UserContext) | ||
| const now = useNow(15000) | ||
| const { data } = useQuery<{ | ||
| generativeToken: GenerativeTokenWithDaMintTickets | ||
| }>(Qu_genTokenClaimableMintTickets, { | ||
| variables: { | ||
| id: token.id, | ||
| ownerId: user?.id || "nobody", | ||
| }, | ||
| }) | ||
| const cheapestTicket = useMemo<MintTicket | null>(() => { | ||
| if (!data?.generativeToken) return null | ||
| const [cheapestDaTicket] = data.generativeToken.daMintTickets | ||
| .map((ticket) => { | ||
| return { | ||
| ...ticket, | ||
| daPrice: getMintTicketDAPrice( | ||
| now, | ||
| new Date(ticket.taxationPaidUntil), | ||
| ticket.price | ||
| ), | ||
| } | ||
| }) | ||
| .sort((a, b) => (a.daPrice > b.daPrice ? 1 : -1)) | ||
| const [cheapestClaimableTicket] = data.generativeToken.mintTickets | ||
| if (cheapestDaTicket && cheapestClaimableTicket) { | ||
| return cheapestDaTicket.daPrice < cheapestClaimableTicket.price | ||
| ? cheapestDaTicket | ||
| : cheapestClaimableTicket | ||
| } | ||
| return cheapestDaTicket || cheapestClaimableTicket || null | ||
| }, [data, now]) | ||
| const handleClickClaimAndMint = useCallback(() => { | ||
| if (cheapestTicket) { | ||
| onClick(cheapestTicket) | ||
| } | ||
| }, [cheapestTicket, onClick]) | ||
| const cheapestTicketPrice = | ||
| cheapestTicket && (cheapestTicket.daPrice || cheapestTicket.price) | ||
| return cheapestTicketPrice ? ( | ||
| <BaseButton | ||
| color="main" | ||
| onClick={handleClickClaimAndMint} | ||
| className={style.submitButton} | ||
| title={`claim & mint with ${displayMutez(cheapestTicketPrice)} tezos`} | ||
| > | ||
| claim & mint{" "} | ||
| <DisplayTezos mutez={cheapestTicketPrice} formatBig={false} /> | ||
| </BaseButton> | ||
| ) : null | ||
| } | ||
|
|
||
| export const ButtonClaimAndMint = memo(_ButtonClaimAndMint) |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does skip: 0 do anything here?