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

feat: read chainId from connected wallet to launch v4 projects + NFTs in create flow #4505

Merged
merged 2 commits into from
Nov 26, 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
2 changes: 1 addition & 1 deletion src/hooks/Wallet/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useWallet() {
const userAddress = useUserAddress()
const isConnected = useIsConnected()
const chain = useChain()
const chainUnsupported = false//useChainUnsupported()
const chainUnsupported = false //useChainUnsupported()
const balance = useWalletBalance()

const [, connect] = useConnectWallet()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Checkbox, Form } from 'antd'
import { useCallback, useContext, useEffect, useMemo, useState } from 'react'

import { CheckCircleFilled } from '@ant-design/icons'
import { Trans } from '@lingui/macro'
import { Checkbox, Form } from 'antd'
import { Callout } from 'components/Callout/Callout'
import ExternalLink from 'components/ExternalLink'
import TransactionModal from 'components/modals/TransactionModal'
Expand All @@ -10,7 +12,6 @@ import { emitConfirmationDeletionModal } from 'hooks/emitConfirmationDeletionMod
import useMobile from 'hooks/useMobile'
import { useModal } from 'hooks/useModal'
import { useRouter } from 'next/router'
import { useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { useDispatch } from 'react-redux'
import { useAppSelector } from 'redux/hooks/useAppSelector'
import { useSetCreateFurthestPageReached } from 'redux/hooks/useEditingCreateFurthestPageReached'
Expand Down Expand Up @@ -80,8 +81,8 @@ export const ReviewDeployPage = () => {
goToPage?.('projectDetails')
dispatch(editingV2ProjectActions.resetState())
}, [dispatch, goToPage, router])

const onFinish = useCallback(async () => {

if (chainUnsupported) {
await changeNetworks()
return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { ONE_BILLION } from 'constants/numbers'
import { DEFAULT_JB_721_TIER_CATEGORY } from 'constants/transactionDefaults'
import { JBTiered721Flags, NftRewardTier } from 'models/nftRewards'
import { LaunchTxOpts } from 'packages/v4/hooks/useLaunchProjectTx'
import { useLaunchProjectWithNftsTx } from 'packages/v4/hooks/useLaunchProjectWithNftsTx'
import { JB721TierConfig, JB721TiersHookFlags } from 'packages/v4/models/nfts'
import { useCallback } from 'react'
import {
useAppSelector,
useEditingV2V3FundAccessConstraintsSelector,
useEditingV2V3FundingCycleDataSelector,
useEditingV2V3FundingCycleMetadataSelector,
} from 'redux/hooks/useAppSelector'
import { Address, parseEther, zeroAddress } from 'viem'

import { ONE_BILLION } from 'constants/numbers'
import { DEFAULT_JB_721_TIER_CATEGORY } from 'constants/transactionDefaults'
import { useLaunchProjectWithNftsTx } from 'packages/v4/hooks/JB721Delegate/transactor/useLaunchProjectWithNftsTx'
import { LaunchTxOpts } from 'packages/v4/hooks/useLaunchProjectTx'
import { useCallback } from 'react'
import { DEFAULT_NFT_FLAGS } from 'redux/slices/editingV2Project'
import { encodeIpfsUri } from 'utils/ipfs'
import { NFT_FUNDING_CYCLE_METADATA_OVERRIDES } from 'utils/nftFundingCycleMetadataOverrides'
import { sortNftsByContributionFloor } from 'utils/nftRewards'
import { Address, parseEther, zeroAddress } from 'viem'

export const DEFAULT_NFT_MAX_SUPPLY = ONE_BILLION - 1

function nftRewardTierToJB721TierConfig(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { LaunchTxOpts, useLaunchProjectTx } from 'packages/v4/hooks/useLaunchProjectTx'
import { useCallback } from 'react'
import {
useAppSelector,
useEditingV2V3FundAccessConstraintsSelector,
useEditingV2V3FundingCycleDataSelector,
useEditingV2V3FundingCycleMetadataSelector,
} from 'redux/hooks/useAppSelector'

import { useCallback } from 'react'

/**
* Hook that returns a function that deploys a v4 project.
*
Expand Down Expand Up @@ -35,6 +36,7 @@ export const useDeployStandardProject = () => {
metadataCid: string
} & LaunchTxOpts) => {
const groupedSplits = [payoutGroupedSplits, reservedTokensGroupedSplits]

return await launchProjectTx(
{
owner: inputProjectOwner?.length ? inputProjectOwner : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,28 @@ import {
import {
Address,
WaitForTransactionReceiptReturnType,
toBytes,
toHex,
zeroAddress,
zeroAddress
} from 'viem'
import {
LaunchV2V3ProjectArgs,
transformV2V3CreateArgsToV4,
} from '../utils/launchProjectTransformers'
} from '../../../utils/launchProjectTransformers'
import {
LaunchTxOpts,
SUPPORTED_JB_CONTROLLER_ADDRESS,
SUPPORTED_JB_MULTITERMINAL_ADDRESS
} from './useLaunchProjectTx'
} from '../../useLaunchProjectTx'

import { waitForTransactionReceipt } from '@wagmi/core'
import { JUICEBOX_MONEY_PROJECT_METADATA_DOMAIN } from 'constants/metadataDomain'
import { TxHistoryContext } from 'contexts/Transaction/TxHistoryContext'
import { useWallet } from 'hooks/Wallet'
import { isValidMustStartAtOrAfter } from 'packages/v2v3/utils/fundingCycle'
import { wagmiConfig } from 'packages/v4/wagmiConfig'
import { useContext } from 'react'
import { DEFAULT_MUST_START_AT_OR_AFTER } from 'redux/slices/editingV2Project'
import { ipfsUri } from 'utils/ipfs'
import { useChainId } from 'wagmi'
import { wagmiConfig } from '../wagmiConfig'

function createSalt() {
const base: string = '0x' + Math.random().toString(16).slice(2) // idk lol
const salt = toHex(toBytes(base, { size: 32 }))

return salt
}

/**
* Return the project ID created from a `launchProjectFor` transaction.
Expand Down Expand Up @@ -70,10 +61,6 @@ export const SUPPORTED_JB_721_TIER_STORE = {
'11155420': '0x4DeF0AA5B9CA095d11705284221b2878731ab4EF' as Address,
}

/**
*
* TODO still wip
*/
export function useLaunchProjectWithNftsTx() {
const { contracts } = useJBContractContext()
const { addTransaction } = useContext(TxHistoryContext)
Expand Down
1 change: 0 additions & 1 deletion src/packages/v4/hooks/useLaunchProjectTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export function useLaunchProjectTx() {
// functionName: 'launchProjectFor',
// args,
// })

const hash = await writeLaunchProject({
chainId,
address: controllerAddress,
Expand Down
3 changes: 2 additions & 1 deletion src/packages/v4/models/nfts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { JBRulesetData, JBRulesetMetadata } from 'juice-sdk-core'
import { Address, ContractFunctionReturnType } from 'viem'

import { jb721TiersHookStoreAbi } from 'juice-sdk-react'
import { LaunchV2V3ProjectData } from 'packages/v2v3/hooks/transactor/useLaunchProjectTx'
import { Address, ContractFunctionReturnType } from 'viem'
import { LaunchV4ProjectGroupedSplit } from '../utils/launchProjectTransformers'
import { FundAccessLimitGroup } from './fundAccessLimits'
import { LaunchProjectJBTerminal } from './terminals'
Expand Down
9 changes: 6 additions & 3 deletions src/packages/v4/utils/launchProjectTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {
NATIVE_TOKEN_DECIMALS,
SplitGroup,
} from 'juice-sdk-core'
import round from 'lodash/round'
import { V2FundingCycleMetadata } from 'packages/v2/models/fundingCycle'
import {
V2V3FundAccessConstraint,
V2V3FundingCycleData,
} from 'packages/v2v3/models/fundingCycle'

import round from 'lodash/round'
import { V2FundingCycleMetadata } from 'packages/v2/models/fundingCycle'
import { GroupedSplits as V2V3GroupedSplits } from 'packages/v2v3/models/splits'
import { V3FundingCycleMetadata } from 'packages/v3/models/fundingCycle'
import { Address } from 'viem'
Expand Down Expand Up @@ -136,7 +137,9 @@ export function transformV2V3SplitsToV4({
}): LaunchV4ProjectGroupedSplit[] {
return v2v3Splits.map(group => ({
groupId:
group.group === SplitGroup.ETHPayout ? BigInt(NATIVE_TOKEN) : 1n, // TODO dont hardcode reserved token group as 1n
group.group === SplitGroup.ETHPayout
? BigInt(NATIVE_TOKEN)
: 1n, // TODO dont hardcode reserved token group as 1n
splits: group.splits.map(split => ({
preferAddToBalance: Boolean(split.preferClaimed),
percent: split.percent,
Expand Down
Loading