From 9f9a032c549aa58b90f0b93c70e8be5011fcdfee Mon Sep 17 00:00:00 2001 From: johnnyd-eth Date: Mon, 9 Sep 2024 14:14:49 +1000 Subject: [PATCH] feat: v4 create erc20 --- .../CreateErc20TokenSettingsPage.tsx | 131 ++++++++++++++++++ .../ProjectSettingsContent.tsx | 3 +- 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 src/packages/v4/views/V4ProjectSettings/CreateErc20TokenSettingsPage.tsx diff --git a/src/packages/v4/views/V4ProjectSettings/CreateErc20TokenSettingsPage.tsx b/src/packages/v4/views/V4ProjectSettings/CreateErc20TokenSettingsPage.tsx new file mode 100644 index 0000000000..f70858deb5 --- /dev/null +++ b/src/packages/v4/views/V4ProjectSettings/CreateErc20TokenSettingsPage.tsx @@ -0,0 +1,131 @@ +import { Trans, t } from '@lingui/macro' +import { Button, Form, Input } from 'antd' +import { IssueErc20TokenTxArgs } from 'components/buttons/IssueErc20TokenButton' +import TransactionModal from 'components/modals/TransactionModal' +import { ISSUE_ERC20_EXPLANATION } from 'components/strings' +import { useIssueErc20TokenTx } from 'hooks/useIssueErc20TokenTx' +import { useV4WalletHasPermission } from 'packages/v4/hooks/useV4WalletHasPermission' +import { V4OperatorPermission } from 'packages/v4/models/v4Permissions' +import { useState } from 'react' +import { emitErrorNotification } from 'utils/notifications' + +export function CreateErc20TokenSettingsPage() { + const [form] = Form.useForm() + const [loading, setLoading] = useState() + const [transactionModalOpen, setTransactionModalOpen] = + useState(false) + const [transactionPending, setTransactionPending] = useState(false) + const issueErc20TokenTx = useIssueErc20TokenTx() + const projectHasErc20Token = false //v4TODO: useProjectHasErc20Token() + const hasIssueTicketsPermission = useV4WalletHasPermission( + V4OperatorPermission.DEPLOY_ERC20, + ) + + const canCreateErc20Token = !projectHasErc20Token && hasIssueTicketsPermission + + async function onSetENSNameFormSaved(values: IssueErc20TokenTxArgs) { + await form.validateFields() + + if (!issueErc20TokenTx) { + emitErrorNotification(t`ERC20 transaction not ready. Try again.`) + return + } + + setLoading(true) + + const txSuccess = await issueErc20TokenTx( + { name: values.name, symbol: values.symbol }, + { + onDone: () => { + setTransactionPending(true) + setTransactionModalOpen(true) + }, + onConfirmed: () => { + setTransactionPending(false) + setTransactionModalOpen(false) + setLoading(false) + setTimeout(() => { + window.location.reload() + }, 1000) + }, + onError: (e: Error) => { + setTransactionPending(false) + setTransactionModalOpen(false) + setLoading(false) + emitErrorNotification(e.message) + }, + }, + ) + + if (!txSuccess) { + emitErrorNotification( + t`Failed to create ERC20 token. Check transaction and try again.`, + ) + + setLoading(false) + setTransactionPending(false) + setTransactionModalOpen(false) + } + } + + if (!canCreateErc20Token) { + return ( +
+

+ Token is already created or you do not have permission to create it. +

+
+ ) + } + + return ( + <> +

{ISSUE_ERC20_EXPLANATION}

+
+ + + + + + form.setFieldsValue({ symbol: e.target.value.toUpperCase() }) + } + /> + + +
+ + setTransactionModalOpen(false)} + onOk={() => setTransactionModalOpen(false)} + confirmLoading={loading} + centered + /> + + ) +} diff --git a/src/packages/v4/views/V4ProjectSettings/ProjectSettingsContent.tsx b/src/packages/v4/views/V4ProjectSettings/ProjectSettingsContent.tsx index b15fb65127..d49acdaf0a 100644 --- a/src/packages/v4/views/V4ProjectSettings/ProjectSettingsContent.tsx +++ b/src/packages/v4/views/V4ProjectSettings/ProjectSettingsContent.tsx @@ -5,6 +5,7 @@ import { Button, Layout } from 'antd' import Link from 'next/link' import { useMemo } from 'react' import { twJoin } from 'tailwind-merge' +import { CreateErc20TokenSettingsPage } from './CreateErc20TokenSettingsPage' import { EditCyclePage } from './EditCyclePage/EditCyclePage' import { useSettingsPagePath } from './hooks/useSettingsPagePath' import { ProjectDetailsSettingsPage } from './ProjectDetailsSettingsPage/ProjectDetailsSettingsPage' @@ -23,7 +24,7 @@ const SettingsPageComponents: { transferownership: () => null, //TransferOwnershipSettingsPage, archiveproject: () => null, //ArchiveProjectSettingsPage, heldfees: () => null, //ProcessHeldFeesPage, - createerc20: () => null, //CreateErc20TokenSettingsPage, + createerc20: CreateErc20TokenSettingsPage, } const V4SettingsPageKeyTitleMap = (