Skip to content

Commit

Permalink
Merge branch 'crt' into fix/crt-follow-up
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/atlas/src/components/CrtPreviewLayout/CrtPreviewLayout.tsx
#	packages/atlas/src/components/_crt/CrtStatusWidget/CrtStatusWidget.tsx
#	packages/atlas/src/views/viewer/ChannelView/ChannelViewTabs/ChannelToken.tsx
  • Loading branch information
WRadoslaw committed Nov 13, 2023
2 parents 84f6eb7 + 63706f7 commit 4bac87a
Show file tree
Hide file tree
Showing 18 changed files with 649 additions and 345 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/atlas/src/api/queries/fragments.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ fragment FullCreatorToken on CreatorToken {
ammInitPrice
burnedByAmm
mintedByAmm
ammSlopeParameter
}
sales {
id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { ReactNode } from 'react'
import { Control, Controller, Validate } from 'react-hook-form'

import { FlexBox } from '@/components/FlexBox'
import { Information } from '@/components/Information'
import { Text } from '@/components/Text'
import { TextButton } from '@/components/_buttons/Button'
import { FormField } from '@/components/_inputs/FormField'
import { TokenInput } from '@/components/_inputs/TokenInput'
import { useTokenPrice } from '@/providers/joystream'

type AmmModalFormTemplateProps = {
validation?: Validate<number>
maxValue?: number
pricePerUnit?: number
control: Control<{ tokens: number }>
details?: {
title: string
content: ReactNode
tooltipText?: string
}[]
error?: string
}

export const AmmModalFormTemplate = ({
validation,
maxValue,
pricePerUnit,
details,
control,
error,
}: AmmModalFormTemplateProps) => {
const { convertTokensToUSD } = useTokenPrice()

return (
<FlexBox flow="column" gap={8}>
<Controller
name="tokens"
control={control}
rules={{
validate: {
...(validation ? { valid: validation } : {}),
},
}}
render={({ field }) => (
<FormField error={error}>
<TokenInput
value={field.value}
onChange={field.onChange}
placeholder="0"
nodeEnd={
<FlexBox gap={2} alignItems="baseline">
{pricePerUnit ? (
<Text variant="t300" as="p" color="colorTextMuted">
${convertTokensToUSD((field.value || 0) * pricePerUnit)?.toFixed(2)}
</Text>
) : null}
{maxValue ? <TextButton onClick={() => field.onChange(maxValue)}>Max</TextButton> : null}
</FlexBox>
}
/>
</FormField>
)}
/>
<FlexBox flow="column" gap={2}>
{details?.map((row, i) => (
<FlexBox key={row.title} alignItems="center" justifyContent="space-between">
<FlexBox width="auto" alignItems="center">
<Text variant={i + 1 === details.length ? 't200-strong' : 't200'} as="span" color="colorText">
{row.title}
</Text>
{row.tooltipText ? <Information text={row.tooltipText} /> : null}
</FlexBox>
{row.content}
</FlexBox>
))}
</FlexBox>
</FlexBox>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ReactNode } from 'react'

import { FlexBox } from '@/components/FlexBox'
import { Information } from '@/components/Information'
import { Text } from '@/components/Text'

type AmmModalSummaryTemplateProps = {
details?: {
title: string
content: ReactNode
tooltipText?: string
}[]
}

export const AmmModalSummaryTemplate = ({ details }: AmmModalSummaryTemplateProps) => {
return (
<FlexBox flow="column" gap={5}>
{details?.map((row, i) => (
<FlexBox key={row.title} alignItems="center" justifyContent="space-between">
<FlexBox width="auto" alignItems="center">
<Text variant={i + 1 === details.length ? 't200-strong' : 't200'} as="span" color="colorText">
{row.title}
</Text>
{row.tooltipText ? <Information text={row.tooltipText} /> : null}
</FlexBox>
{row.content}
</FlexBox>
))}
</FlexBox>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './AmmModalFormTemplate'
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useState } from 'react'

import { Button } from '@/components/_buttons/Button'
import { BuyMarketTokenModal } from '@/components/_crt/BuyMarketTokenModal'

type BuyFromMarketButtonProps = {
tokenId: string
}

export const BuyFromMarketButton = ({ tokenId }: BuyFromMarketButtonProps) => {
const [showModal, setShowModal] = useState(false)
return (
<>
<BuyMarketTokenModal tokenId={tokenId} show={showModal} onClose={() => setShowModal(false)} />
<Button size="large" onClick={() => setShowModal(true)}>
Buy
</Button>
</>
)
}
Loading

0 comments on commit 4bac87a

Please sign in to comment.