Skip to content
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

[1/2] Improve launch NFT collection tx UI #4063

Merged
merged 4 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ interface AddEditRewardModalFormProps {
externalUrl?: string | undefined
}

const NFT_FILE_UPLOAD_EXTRA = t`Images will be cropped to a 1:1 square in thumbnail previews on the Juicebox app.`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix weird i18n encoding thing

const NFT_FILE_UPLOAD_EXTRA = (
<Trans>
Images will be cropped to a 1:1 square in thumbnail previews on the Juicebox
app.
</Trans>
)
const MAX_NFT_FILE_SIZE_MB = 100

// This assumes an existing NFT ID (from the contracts) will never be >= 1000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { Button, Modal } from 'antd'
import { ProjectMetadataContext } from 'contexts/shared/ProjectMetadataContext'
import { V2V3ProjectContext } from 'contexts/v2v3/Project/V2V3ProjectContext'
import Link from 'next/link'
import { useContext } from 'react'
import { ReactNode, useContext } from 'react'
import { settingsPagePath, v2v3ProjectRoute } from 'utils/routes'

export function EditCycleSuccessModal({
export function TransactionSuccessModal({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes this component reusable across edit cycle and nfts settings pages

open,
onClose,
content,
}: {
open: boolean
onClose: VoidFunction
content: ReactNode
}) {
const { projectId } = useContext(ProjectMetadataContext)
const { handle } = useContext(V2V3ProjectContext)
Expand All @@ -35,15 +37,7 @@ export function EditCycleSuccessModal({
>
<div className="flex w-full flex-col items-center gap-4 pt-2 text-center">
{checkIconWithBackground}
<div className="w-80 pt-1 text-2xl font-medium">
<Trans>Your updated cycle has been deployed</Trans>
</div>
<div className="text-secondary pb-6">
<Trans>
Changes will take effect in your next cycle as long as it starts
after your edit deadline.
</Trans>
</div>
{content}
<div className="flex gap-2.5">
<Link href={settingsPagePath(undefined, { projectId, handle })}>
<Button type="ghost" className={buttonClasses}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { CreateCollapse } from 'components/Create/components/CreateCollapse'
import { JuiceTextArea } from 'components/inputs/JuiceTextArea'
import TransactionModal from 'components/modals/TransactionModal'
import { useState } from 'react'
import { TransactionSuccessModal } from '../../../TransactionSuccessModal'
import { useReconfigureFundingCycle } from '../../ReconfigureFundingCycleSettingsPage/hooks/useReconfigureFundingCycle'
import { useEditCycleFormContext } from '../EditCycleFormContext'
import { usePrepareSaveEditCycleData } from '../hooks/usePrepareSaveEditCycleData'
import { DetailsSectionDiff } from './DetailsSectionDiff'
import { EditCycleSuccessModal } from './EditCycleSuccessModal'
import { PayoutsSectionDiff } from './PayoutsSectionDiff'
import { SectionCollapseHeader } from './SectionCollapseHeader'
import { TokensSectionDiff } from './TokensSectionDiff'
Expand Down Expand Up @@ -123,9 +123,22 @@ export function ReviewConfirmModal({
/>
</Form.Item>
</TransactionModal>
<EditCycleSuccessModal
<TransactionSuccessModal
open={editCycleSuccessModalOpen}
onClose={() => setEditCycleSuccessModalOpen(false)}
content={
<>
<div className="w-80 pt-1 text-2xl font-medium">
<Trans>Your updated cycle has been deployed</Trans>
</div>
<div className="text-secondary pb-6">
<Trans>
Changes will take effect in your next cycle as long as it starts
after your edit deadline.
</Trans>
</div>
</>
}
/>
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ export function EnableNftsModal({
setLoading(false)
reloadWindow()
},
onDone() {
setLoading(false)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obv bug

},
onError() {
setLoading(false)
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Trans } from '@lingui/macro'
import { Button } from 'antd'
import TransactionModal from 'components/modals/TransactionModal'
import { useState } from 'react'
import { useAppSelector } from 'redux/hooks/useAppSelector'
import { pinNftCollectionMetadata, pinNftRewards } from 'utils/nftRewards'
import { TransactionSuccessModal } from '../../../TransactionSuccessModal'
import {
EditingFundingCycleConfig,
useEditingFundingCycleConfig,
Expand All @@ -15,19 +17,23 @@ export function UploadAndLaunchNftsButton({
className?: string
}) {
const [ipfsUploading, setIpfsUploading] = useState<boolean>(false)
const [successModalOpen, setSuccessModalOpen] = useState<boolean>(false)

const {
projectMetadata: { logoUri },
} = useAppSelector(state => state.editingV2Project)

const editingFundingCycleConfig = useEditingFundingCycleConfig()
const { reconfigureLoading, reconfigureFundingCycle } =
const { reconfigureLoading, reconfigureFundingCycle, txPending } =
useReconfigureFundingCycle({
editingFundingCycleConfig,
memo: 'First NFT collection',
launchedNewNfts: true,
onComplete: () => setSuccessModalOpen(true),
})

const buttonLoading = ipfsUploading || reconfigureLoading

const {
editingPayoutGroupedSplits,
editingReservedTokensGroupedSplits,
Expand Down Expand Up @@ -83,13 +89,33 @@ export function UploadAndLaunchNftsButton({
}

return (
<Button
type="primary"
onClick={uploadNftsToIpfs}
loading={ipfsUploading || reconfigureLoading}
className={className}
>
<Trans>Deploy NFT collection</Trans>
</Button>
<>
<Button
type="primary"
onClick={uploadNftsToIpfs}
loading={buttonLoading}
className={className}
>
<Trans>Deploy NFT collection</Trans>
</Button>
<TransactionModal transactionPending open={txPending} />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds pending and success modal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, good attn to detail 🙏

<TransactionSuccessModal
open={successModalOpen}
onClose={() => setSuccessModalOpen(false)}
content={
<>
<div className="w-80 pt-1 text-2xl font-medium">
<Trans>Your new NFTs have been deployed</Trans>
</div>
<div className="text-secondary pb-6">
<Trans>
New NFTs will be available in your next cycle as long as it
starts after your edit deadline.
</Trans>
</div>
</>
}
/>
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const useReconfigureFundingCycle = ({

const [reconfigureTxLoading, setReconfigureTxLoading] =
useState<boolean>(false)
const [txPending, setTxPending] = useState<boolean>(false)

const reconfigureV2V3FundingCycleTx = useReconfigureV2V3FundingCycleTx()
const reconfigureV2V3FundingCycleWithNftsTx =
Expand Down Expand Up @@ -120,6 +121,9 @@ export const useReconfigureFundingCycle = ({
}

const txOpts = {
onDone() {
setTxPending(true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture tx pending state in reconfigure hook

},
async onConfirmed() {
if (projectId) {
await revalidateProject({
Expand All @@ -128,14 +132,20 @@ export const useReconfigureFundingCycle = ({
})
}
setReconfigureTxLoading(false)
setTxPending(false)
if (onComplete) {
onComplete()
} else {
reloadWindow()
}
},
onCancelled() {
setTxPending(false)
},
onError() {
setTxPending(false)
},
}

let txSuccessful: boolean
if (launchedNewNfts && editingNftRewards?.rewardTiers) {
txSuccessful = await reconfigureV2V3FundingCycleWithNftsTx(
Expand All @@ -154,6 +164,7 @@ export const useReconfigureFundingCycle = ({

if (!txSuccessful) {
setReconfigureTxLoading(false)
setTxPending(false)
}
},
[
Expand All @@ -169,5 +180,9 @@ export const useReconfigureFundingCycle = ({
],
)

return { reconfigureLoading: reconfigureTxLoading, reconfigureFundingCycle }
return {
reconfigureLoading: reconfigureTxLoading,
reconfigureFundingCycle,
txPending,
}
}
6 changes: 6 additions & 0 deletions src/locales/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,9 @@ msgstr ""
msgid "Receive ERC-20 tokens"
msgstr ""

msgid "New NFTs will be available in your next cycle as long as it starts after your edit deadline."
msgstr ""

msgid "Confirm"
msgstr ""

Expand Down Expand Up @@ -4424,6 +4427,9 @@ msgstr ""
msgid "Add recipient"
msgstr ""

msgid "Your new NFTs have been deployed"
msgstr ""

msgid "Your balance"
msgstr ""

Expand Down