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

fix: v4 launch erc20 tx #4468

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/components/buttons/AddTokenToMetamaskButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Trans } from '@lingui/macro'
import type { MetaMaskInpageProvider } from '@metamask/providers'
import { Button } from 'antd'
import { providers } from 'ethers'
import useNameOfERC20 from 'hooks/ERC20/useNameOfERC20'
import useSymbolOfERC20 from 'hooks/ERC20/useSymbolOfERC20'
import { twMerge } from 'tailwind-merge'
import { Hash } from 'viem'

Expand All @@ -28,7 +28,7 @@ const useMetamask = () => {

function useAddTokenToWalletRequest({ tokenAddress }: { tokenAddress: Hash }) {
const ethereum = useMetamask()
const { data: tokenSymbol } = useNameOfERC20(tokenAddress)
const { data: tokenSymbol } = useSymbolOfERC20(tokenAddress)

if (!ethereum) {
return
Expand Down
20 changes: 12 additions & 8 deletions src/packages/v4/hooks/useV4IssueErc20TokenTx.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useCallback, useContext } from 'react'

import { TxHistoryContext } from 'contexts/Transaction/TxHistoryContext'
import { useJBContractContext, useWriteJbTokensDeployErc20For } from 'juice-sdk-react'
import { zeroAddress } from 'viem'
import { useJBContractContext, useWriteJbControllerDeployErc20For } from 'juice-sdk-react'
import { Address, zeroAddress } from 'viem'
import { BaseTxOpts } from '../models/transactions'

export function useV4IssueErc20TokenTx() {
const { addTransaction } = useContext(TxHistoryContext)
const { projectId, contracts } = useJBContractContext()

const { writeContractAsync: deployErc20 } = useWriteJbTokensDeployErc20For()
const { writeContractAsync: deployErc20Tx } = useWriteJbControllerDeployErc20For()

return useCallback (
async ({ name, symbol }: {
Expand All @@ -33,17 +33,20 @@ export function useV4IssueErc20TokenTx() {
try {
// SIMULATE TX:
// const encodedData = encodeFunctionData({
// abi: jbTokensAbi, // ABI of the contract
// functionName: 'deployErc20For',
// abi: jbControllerAbi, // ABI of the contract
// functionName: 'deployERC20For',
// args,
// })
// console.log('contract', contracts.controller.data)
// console.log('encodedData', encodedData)

const hash = await deployErc20({
const hash = await deployErc20Tx({
args,
address: contracts.controller.data as Address
})

onTransactionPendingCallback(hash)
addTransaction?.('Edit Ruleset', { hash })
addTransaction?.('Launch ERC20 Token', { hash })
// const transactionReceipt: WaitForTransactionReceiptReturnType = await waitForTransactionReceipt(
// wagmiConfig,
// {
Expand All @@ -59,9 +62,10 @@ export function useV4IssueErc20TokenTx() {
}
},
[
deployErc20,
deployErc20Tx,
projectId,
addTransaction,
contracts.controller.data,
],
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const issueErc20TokenTx = useV4IssueErc20TokenTx()

const canCreateErc20Token = !projectHasErc20Token && hasIssueTicketsPermission

async function onSetENSNameFormSaved(values: IssueErc20TokenTxArgs) {
async function onIssueErc20FormSaved(values: IssueErc20TokenTxArgs) {
await form.validateFields()

if (!issueErc20TokenTx) {
Expand Down Expand Up @@ -78,7 +78,7 @@ const issueErc20TokenTx = useV4IssueErc20TokenTx()
<Form
className="mt-5 w-full md:max-w-sm"
form={form}
onFinish={onSetENSNameFormSaved}
onFinish={onIssueErc20FormSaved}
>
<Form.Item
name="name"
Expand Down
Loading