Skip to content

Commit

Permalink
v4 project nft init
Browse files Browse the repository at this point in the history
  • Loading branch information
wraeth-eth committed Nov 26, 2024
1 parent 353fb87 commit 465f1f5
Show file tree
Hide file tree
Showing 31 changed files with 1,292 additions and 164 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useWallet } from 'hooks/Wallet'
import { useReadJb721TiersHookPayCreditsOf } from 'juice-sdk-react'
import { useV4NftRewards } from 'packages/v4/contexts/V4NftRewards/V4NftRewardsProvider'
import { V4CurrencyOption } from 'packages/v4/models/v4CurrencyOption'
import React from 'react'
import { useProjectDispatch } from './redux/hooks'
// import { projectCartActions } from './redux/projectCartSlice'
import { projectCartActions } from './redux/projectCartSlice'

export type ProjectCartCurrencyAmount = {
amount: number
Expand All @@ -20,26 +22,26 @@ export const ReduxProjectCartProvider = ({
}: {
children: React.ReactNode
}) => {
// const { rewardTiers } = useContext(NftRewardsContext).nftRewards
const {
nftRewards: { rewardTiers },
} = useV4NftRewards()

const { userAddress } = useWallet()
// const userNftCredits = useNftCredits(userAddress)
const { data: nftCredits } = useReadJb721TiersHookPayCreditsOf({
address: userAddress,
})

const dispatch = useProjectDispatch()

// Set the nfts on load
// useEffect(() => {
// dispatch(projectCartActions.setAllNftRewards(rewardTiers ?? []))
// }, [dispatch, rewardTiers])
React.useEffect(() => {
dispatch(projectCartActions.setAllNftRewards(rewardTiers ?? []))
}, [dispatch, rewardTiers])

// Set the user's NFT credits on load
// useEffect(() => {
// dispatch(
// projectCartActions.setUserNftCredits(
// userNftCredits.data?.toBigInt() ?? 0n,
// ),
// )
// }, [dispatch, userNftCredits.data])
React.useEffect(() => {
dispatch(projectCartActions.setUserNftCredits(nftCredits ?? 0n))
}, [dispatch, nftCredits])

return <>{children}</>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Trans } from '@lingui/macro'
import { CartItemBadge } from 'components/CartItemBadge'
import { SmallNftSquare } from 'components/NftRewards/SmallNftSquare'
import { useNftCartItem } from 'packages/v4/hooks/useNftCartItem'
import { twMerge } from 'tailwind-merge'
import { ProjectCartNftReward } from '../../../ReduxProjectCartProvider'

export const ReceiveNftItem = ({
className,
nftReward,
}: {
className?: string
nftReward: ProjectCartNftReward
}) => {
const { fileUrl, name, quantity } = useNftCartItem(nftReward)

return (
<div className={twMerge('flex flex-col gap-4', className)}>
<div className="flex items-center justify-between gap-3">
<div className="flex items-center">
<SmallNftSquare
className="h-12 w-12"
nftReward={{
fileUrl: fileUrl ?? '',
name: name ?? '',
}}
/>
<span className="ml-3">{name}</span>
<CartItemBadge className="ml-2">
<Trans>NFT</Trans>
</CartItemBadge>
</div>
<div>{quantity}</div>
</div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '../hooks/usePayProjectModal/usePayProjectModal'
import { useProjectPaymentTokens } from '../hooks/useProjectPaymentTokens'
import { EditRewardBeneficiary } from './EditRewardBeneficiary'
import { ReceiveNftItem } from './ReceiveNftItem'
import { ReceiveTokensItem } from './ReceiveTokensItem'

export const ReceiveSection = ({ className }: { className?: string }) => {
Expand Down Expand Up @@ -36,6 +37,13 @@ export const ReceiveSection = ({ className }: { className?: string }) => {
</span>
</div>
<ReceiveTokensItem className="mt-5" />
{nftRewards.map(nftReward => (
<ReceiveNftItem
key={nftReward.id}
nftReward={nftReward}
className="mt-5"
/>
))}
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import { ProjectPayReceipt } from 'packages/v4/views/V4ProjectDashboard/hooks/us
// import { useProjectHasErc20 } from 'packages/v4/hooks/useProjectHasErc20'
import { waitForTransactionReceipt } from '@wagmi/core'
import { TxHistoryContext } from 'contexts/Transaction/TxHistoryContext'
import { NATIVE_TOKEN } from 'juice-sdk-core'
import { DEFAULT_METADATA, NATIVE_TOKEN } from 'juice-sdk-core'
import {
useJBContractContext,
useJBRulesetContext,
usePreparePayMetadata,
useWriteJbMultiTerminalPay,
} from 'juice-sdk-react'
// import { useProjectHasErc20 } from 'packages/v2v3/hooks/useProjectHasErc20'
import { useV4NftRewards } from 'packages/v4/contexts/V4NftRewards/V4NftRewardsProvider'
import { V4_CURRENCY_ETH } from 'packages/v4/utils/currency'
import { wagmiConfig } from 'packages/v4/wagmiConfig'
import { useCallback, useContext, useMemo } from 'react'
Expand Down Expand Up @@ -42,11 +45,12 @@ export const usePayProjectTx = ({
const { payAmount, chosenNftRewards } = useProjectSelector(
state => state.projectCart,
)
// const {
// nftRewards: { rewardTiers },
// } = useContext(NftRewardsContext)
const {
nftRewards: { rewardTiers },
} = useV4NftRewards()
const converter = useCurrencyConverter()
const { receivedTickets } = useProjectPaymentTokens()
// TODO: implement
// const projectHasErc20 = useProjectHasErc20()

const buildPayReceipt = useCallback(
Expand Down Expand Up @@ -76,10 +80,21 @@ export const usePayProjectTx = ({
}
}, [payAmount, converter])

// const prepareDelegateMetadata = usePrepareDelegatePayMetadata(weiAmount, {
// nftRewards: chosenNftRewards,
// receivedTickets,
// })
const {
rulesetMetadata: { data: rulesetMetadata },
} = useJBRulesetContext()
const metadata = usePreparePayMetadata(
rulesetMetadata?.dataHook
? {
jb721Hook: {
dataHookAddress: rulesetMetadata.dataHook,
tierIdsToMint: chosenNftRewards
.map(({ id, quantity }) => Array(quantity).fill(BigInt(id)))
.flat(),
},
}
: undefined,
)

const { writeContractAsync: writePay } = useWriteJbMultiTerminalPay()
const { contracts, projectId } = useJBContractContext()
Expand All @@ -103,13 +118,13 @@ export const usePayProjectTx = ({
const memo = buildPaymentMemo({
text: messageString,
imageUrl: attachedUrl,
// nftUrls: chosenNftRewards
// .map(
// ({ id }) =>
// (rewardTiers ?? []).find(({ id: tierId }) => tierId === id)
// ?.fileUrl,
// )
// .filter((url): url is string => !!url),
nftUrls: chosenNftRewards
.map(
({ id }) =>
(rewardTiers ?? []).find(({ id: tierId }) => tierId === id)
?.fileUrl,
)
.filter((url): url is string => !!url),
})
const beneficiary = (values.beneficiaryAddress ?? userAddress) as Address
const args = [
Expand All @@ -119,7 +134,8 @@ export const usePayProjectTx = ({
beneficiary,
0n,
memo,
'0x0',
// metadata ?? DEFAULT_METADATA,
DEFAULT_METADATA,
] as const

try {
Expand Down Expand Up @@ -147,21 +163,19 @@ export const usePayProjectTx = ({
}
},
[
// projectHasErc20,
buildPayReceipt,
// chosenNftRewards,
onTransactionConfirmedCallback,
onTransactionErrorCallback,
onTransactionPendingCallback,
// payProjectTx,
// rewardTiers,
weiAmount,
contracts.primaryNativeTerminal.data,
userAddress,
// prepareDelegateMetadata,
chosenNftRewards,
projectId,
metadata,
rewardTiers,
writePay,
contracts.primaryNativeTerminal.data,
onTransactionPendingCallback,
addTransaction,
onTransactionConfirmedCallback,
buildPayReceipt,
onTransactionErrorCallback,
],
)
}
Loading

0 comments on commit 465f1f5

Please sign in to comment.