Skip to content

Commit

Permalink
feat: V4 send payouts button and modal [1/n] (#4396)
Browse files Browse the repository at this point in the history
Co-authored-by: aeolian <94939382+aeolianeth@users.noreply.github.com>
  • Loading branch information
johnnyd-eth and aeolianeth authored Jul 22, 2024
1 parent 522e53a commit a588de7
Show file tree
Hide file tree
Showing 116 changed files with 2,089 additions and 313 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"he": "^1.2.0",
"jsonwebtoken": "^9.0.0",
"juice-sdk-core": "^9.1.3-alpha",
"juice-sdk-react": "^9.2.4-alpha",
"juice-sdk-react": "^9.2.5-alpha",
"juicebox-metadata-helper": "0.1.7",
"less": "4.1.2",
"lodash": "^4.17.21",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import CurrencySwitch from 'components/currency/CurrencySwitch'
import EthereumAddress from 'components/EthereumAddress'
import FormattedNumberInput from 'components/inputs/FormattedNumberInput'
import { Parenthesis } from 'components/Parenthesis'
import { Split } from 'models/splits'
import V2V3ProjectHandleLink from 'packages/v2v3/components/shared/V2V3ProjectHandleLink'
import { ExternalLinkWithIcon } from 'packages/v2v3/components/V2V3Project/ProjectDashboard/components/ui/ExternalLinkWithIcon'
import { V2V3CurrencyOption } from 'packages/v2v3/models/currencyOption'
import { Split } from 'packages/v2v3/models/splits'
import {
V2V3_CURRENCY_ETH,
V2V3_CURRENCY_USD,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Form } from 'antd'
import { CURRENCY_METADATA, CurrencyName } from 'constants/currency'
import { Split } from 'models/splits'
import { PayoutsTable } from 'packages/v2v3/components/shared/PayoutsTable/PayoutsTable'
import { Split } from 'packages/v2v3/models/splits'
import {
V2V3CurrencyName,
getV2V3CurrencyOption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Trans } from '@lingui/macro'
import type { MetaMaskInpageProvider } from '@metamask/providers'
import { Button } from 'antd'
import { providers } from 'ethers'
import { V2V3ProjectContext } from 'packages/v2v3/contexts/Project/V2V3ProjectContext'
import { useContext } from 'react'
import useNameOfERC20 from 'hooks/ERC20/useNameOfERC20'
import { twMerge } from 'tailwind-merge'
import { Hash } from 'viem'

declare global {
interface Window {
Expand All @@ -26,9 +26,13 @@ const useMetamask = () => {
return ethereum as unknown as MetaMaskInpageProvider
}

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

if (!ethereum) {
return
Expand All @@ -49,8 +53,16 @@ function useAddTokenToWalletRequest() {
}
}

export function AddTokenToMetamaskButton({ className }: { className: string }) {
const addToken = useAddTokenToWalletRequest()
export function AddTokenToMetamaskButton({
className,
tokenAddress
}: {
className: string,
tokenAddress: Hash
}) {
const addToken = useAddTokenToWalletRequest({
tokenAddress
})
if (!addToken) return null

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/formItems/formHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isAddress } from 'ethers/lib/utils'
import { PayoutMod } from 'packages/v1/models/mods'
import { permyriadToPercent } from 'utils/format/formatNumber'

import { Split } from 'models/splits'
import { Split } from 'packages/v2v3/models/splits'
import { isEqualAddress, isZeroAddress } from 'utils/address'
import { percentToPermyriad } from 'utils/format/formatNumber'

Expand Down
2 changes: 1 addition & 1 deletion src/constants/splits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ETHPayoutSplitGroup, ReservedTokensSplitGroup } from 'models/splits'
import { ETHPayoutSplitGroup, ReservedTokensSplitGroup } from 'packages/v2v3/models/splits'

export const ETH_PAYOUT_SPLIT_GROUP: ETHPayoutSplitGroup = 1
export const RESERVED_TOKEN_SPLIT_GROUP: ReservedTokensSplitGroup = 2
3 changes: 3 additions & 0 deletions src/locales/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3242,6 +3242,9 @@ msgstr ""
msgid "Start over"
msgstr ""

msgid "<0/>fee"
msgstr ""

msgid "Juicebox provides trustless payroll capabilities to run automated payouts completely on-chain. <0>Learn more about payouts</0>"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion src/models/outgoingProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
V2V3FundAccessConstraint,
V2V3FundingCycle,
} from 'packages/v2v3/models/fundingCycle'
import { SplitParams } from './splits'
import { SplitParams } from 'packages/v2v3/models/splits'

type OutgoingGroupedSplit = {
splits: SplitParams[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AmountInCurrency } from 'components/currency/AmountInCurrency'
import { BigNumber } from 'ethers'
import { Split } from 'models/splits'
import { useProjectContext } from 'packages/v2v3/components/V2V3Project/ProjectDashboard/hooks/useProjectContext'
import { V2V3CurrencyOption } from 'packages/v2v3/models/currencyOption'
import { Split } from 'packages/v2v3/models/splits'
import { V2V3CurrencyName } from 'packages/v2v3/utils/currency'
import { isJuiceboxProjectSplit } from 'packages/v2v3/utils/distributions'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Button } from 'antd'
import EthereumAddress from 'components/EthereumAddress'
import { TitleDescriptionDisplayCard } from 'components/Project/ProjectTabs/TitleDescriptionDisplayCard'
import { TokenAmount } from 'components/TokenAmount'
import { AddTokenToMetamaskButton } from 'components/buttons/AddTokenToMetamaskButton'
import { IssueErc20TokenButton } from 'components/buttons/IssueErc20TokenButton'
import { useTokensPanel } from 'packages/v2v3/components/V2V3Project/ProjectDashboard/hooks/useTokensPanel'
import { useYourBalanceMenuItems } from 'packages/v2v3/components/V2V3Project/ProjectDashboard/hooks/useYourBalanceMenuItems/useYourBalanceMenuItems'
Expand All @@ -11,8 +12,8 @@ import { V2V3ClaimTokensModal } from 'packages/v2v3/components/V2V3Project/V2V3M
import { V2V3MintModal } from 'packages/v2v3/components/V2V3Project/V2V3ManageTokensSection/AccountBalanceDescription/V2V3MintModal'
import { useCallback, useState } from 'react'
import { reloadWindow } from 'utils/windowUtils'
import { Hash } from 'viem'
import { TokenHoldersModal } from '../TokenHoldersModal/TokenHoldersModal'
import { AddTokenToMetamaskButton } from './components/AddTokenToMetamaskButton'
import { MigrateTokensButton } from './components/MigrateTokensButton'
import { RedeemTokensButton } from './components/RedeemTokensButton'
import { ReservedTokensSubPanel } from './components/ReservedTokensSubPanel'
Expand Down Expand Up @@ -187,8 +188,11 @@ const ProjectTokenCard = () => {
</span>
)}
</div>
{projectHasErc20Token && (
<AddTokenToMetamaskButton className="mt-2" />
{projectTokenAddress && projectHasErc20Token && (
<AddTokenToMetamaskButton
className="mt-2"
tokenAddress={projectTokenAddress as Hash}
/>
)}
{canCreateErc20Token && (
<IssueErc20TokenButton onCompleted={reloadWindow} type="link" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Trans, t } from '@lingui/macro'
import { TitleDescriptionDisplayCard } from 'components/Project/ProjectTabs/TitleDescriptionDisplayCard'
import { reservedTokensTooltip } from 'components/Project/ProjectTabs/TokensPanelTooltips'
import { twMerge } from 'tailwind-merge'
import { ProjectAllocationRow } from '../../ProjectAllocationRow/ProjectAllocationRow'
import { reservedTokensTooltip } from '../TokensPanelTooltips'
import { useReservedTokensSubPanel } from '../hooks/useReservedTokensSubPanel'
import { ExportTokensCsvItem } from './ExportTokensCsvItem'
import { SendReservedTokensButton } from './SendReservedTokensButton'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { t } from '@lingui/macro'
import { ProjectMetadataContext } from 'contexts/ProjectMetadataContext'
import { BigNumber } from 'ethers'
import { Split } from 'models/splits'
import { V2V3ProjectContext } from 'packages/v2v3/contexts/Project/V2V3ProjectContext'
import { Split } from 'packages/v2v3/models/splits'
import { formatSplitPercent } from 'packages/v2v3/utils/math'
import { getProjectOwnerRemainderSplit } from 'packages/v2v3/utils/v2v3Splits'
import { useContext, useState } from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
ETHPayoutGroupedSplits,
ReservedTokensGroupedSplits,
} from 'models/splits'
import {
V2V3FundAccessConstraint,
V2V3FundingCycleData,
V2V3FundingCycleMetadata,
} from 'packages/v2v3/models/fundingCycle'
import {
ETHPayoutGroupedSplits,
ReservedTokensGroupedSplits,
} from 'packages/v2v3/models/splits'
import {
useAppSelector,
useEditingV2V3FundAccessConstraintsSelector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
RESERVED_TOKEN_SPLIT_GROUP,
} from 'constants/splits'
import { ProjectMetadataContext } from 'contexts/ProjectMetadataContext'
import { Split } from 'models/splits'
import { ETH_TOKEN_ADDRESS } from 'packages/v2v3/constants/juiceboxTokens'
import { V2V3ContractsContext } from 'packages/v2v3/contexts/Contracts/V2V3ContractsContext'
import { NftRewardsContext } from 'packages/v2v3/contexts/NftRewards/NftRewardsContext'
import { V2V3ProjectContext } from 'packages/v2v3/contexts/Project/V2V3ProjectContext'
import useProjectDistributionLimit from 'packages/v2v3/hooks/contractReader/useProjectDistributionLimit'
import useProjectQueuedFundingCycle from 'packages/v2v3/hooks/contractReader/useProjectQueuedFundingCycle'
import useProjectSplits from 'packages/v2v3/hooks/contractReader/useProjectSplits'
import { Split } from 'packages/v2v3/models/splits'
import { NO_CURRENCY, V2V3_CURRENCY_ETH } from 'packages/v2v3/utils/currency'
import {
SerializedV2V3FundAccessConstraint,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DurationOption } from 'components/inputs/DurationInput'
import { CurrencyName } from 'constants/currency'
import { Split } from 'models/splits'
import { Split } from 'packages/v2v3/models/splits'
import { NftRewardsData } from 'redux/slices/editingV2Project/types'

type DetailsSectionFields = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Form } from 'antd'
import { useWatch } from 'antd/lib/form/Form'
import { JuiceSwitch } from 'components/inputs/JuiceSwitch'
import { CurrencyName } from 'constants/currency'
import { Split } from 'models/splits'
import { PayoutsTable } from 'packages/v2v3/components/shared/PayoutsTable/PayoutsTable'
import { Split } from 'packages/v2v3/models/splits'
import { AdvancedDropdown } from '../AdvancedDropdown'
import { useEditCycleFormContext } from '../EditCycleFormContext'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CurrencyName } from 'constants/currency'
import { Split } from 'models/splits'
import { V2V3ProjectContext } from 'packages/v2v3/contexts/Project/V2V3ProjectContext'
import { V2V3CurrencyOption } from 'packages/v2v3/models/currencyOption'
import { Split } from 'packages/v2v3/models/splits'
import { V2V3CurrencyName } from 'packages/v2v3/utils/currency'
import { distributionLimitsEqual } from 'packages/v2v3/utils/distributions'
import { MAX_DISTRIBUTION_LIMIT } from 'packages/v2v3/utils/math'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useWatch } from 'antd/lib/form/Form'
import { FormItems } from 'components/formItems'
import { ItemNoInput } from 'components/formItems/ItemNoInput'
import { JuiceSwitch } from 'components/inputs/JuiceSwitch'
import { Split } from 'models/splits'
import { ExternalLinkWithIcon } from 'packages/v2v3/components/V2V3Project/ProjectDashboard/components/ui/ExternalLinkWithIcon'
import { Split } from 'packages/v2v3/models/splits'
import { SPLITS_TOTAL_PERCENT } from 'packages/v2v3/utils/math'
import { totalSplitsPercent } from 'packages/v2v3/utils/v2v3Splits'
import { useState } from 'react'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { BigNumber } from '@ethersproject/bignumber'
import {
ETHPayoutGroupedSplits,
ReservedTokensGroupedSplits,
} from 'models/splits'
import { ETH_TOKEN_ADDRESS } from 'packages/v2v3/constants/juiceboxTokens'
import { V2V3ProjectContractsContext } from 'packages/v2v3/contexts/ProjectContracts/V2V3ProjectContractsContext'
import {
V2V3FundAccessConstraint,
V2V3FundingCycleData,
V2V3FundingCycleMetadata,
} from 'packages/v2v3/models/fundingCycle'
import {
ETHPayoutGroupedSplits,
ReservedTokensGroupedSplits,
} from 'packages/v2v3/models/splits'
import { getV2V3CurrencyOption } from 'packages/v2v3/utils/currency'
import {
MAX_DISTRIBUTION_LIMIT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Trans } from '@lingui/macro'
import { Button } from 'antd'

import { Split } from 'models/splits'
import { V2V3ProjectContext } from 'packages/v2v3/contexts/Project/V2V3ProjectContext'
import { useSetProjectSplits } from 'packages/v2v3/hooks/transactor/useSetProjectSplitsTx'
import { Split } from 'packages/v2v3/models/splits'
import { getTotalSplitsPercentage } from 'packages/v2v3/utils/distributions'
import { useCallback, useContext, useMemo, useState } from 'react'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { t, Trans } from '@lingui/macro'
import { CsvUpload } from 'components/inputs/CsvUpload'
import { Split } from 'models/splits'
import { V2V3ProjectContext } from 'packages/v2v3/contexts/Project/V2V3ProjectContext'
import { Split } from 'packages/v2v3/models/splits'
import { getTotalSplitsPercentage } from 'packages/v2v3/utils/distributions'
import { useCallback, useContext, useEffect, useMemo } from 'react'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Trans } from '@lingui/macro'
import { Button } from 'antd'
import { RESERVED_TOKEN_SPLIT_GROUP } from 'constants/splits'
import { Split } from 'models/splits'
import { V2V3ProjectContext } from 'packages/v2v3/contexts/Project/V2V3ProjectContext'
import { useSetProjectSplits } from 'packages/v2v3/hooks/transactor/useSetProjectSplitsTx'
import { Split } from 'packages/v2v3/models/splits'
import { preciseFormatSplitPercent } from 'packages/v2v3/utils/math'
import { useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { emitErrorNotification } from 'utils/notifications'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Trans } from '@lingui/macro'
import { Callout } from 'components/Callout/Callout'
import { CsvUpload } from 'components/inputs/CsvUpload'
import { Split } from 'models/splits'
import { AllocationSplit } from 'packages/v2v3/components/shared/Allocation/Allocation'
import { ReservedTokensList } from 'packages/v2v3/components/shared/ReservedTokensList'
import { Split } from 'packages/v2v3/models/splits'
import { useCallback } from 'react'
import { parseV2SplitsCsv } from 'utils/csv'
import { allocationToSplit, splitToAllocation } from 'utils/splitToAllocation'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Button } from 'antd'
import { ETH_PAYOUT_SPLIT_GROUP } from 'constants/splits'
import { ProjectMetadataContext } from 'contexts/ProjectMetadataContext'
import { BigNumber } from 'ethers'
import { GroupedSplits, Split, SplitGroup } from 'models/splits'
import { V2V3ProjectContext } from 'packages/v2v3/contexts/Project/V2V3ProjectContext'
import { GroupedSplits, Split, SplitGroup } from 'packages/v2v3/models/splits'
import { formatSplitPercent } from 'packages/v2v3/utils/math'
import { getProjectOwnerRemainderSplit } from 'packages/v2v3/utils/v2v3Splits'
import { PropsWithChildren, useContext, useState } from 'react'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
} from 'constants/splits'
import { ProjectMetadataContext } from 'contexts/ProjectMetadataContext'
import useMobile from 'hooks/useMobile'
import { ETHPayoutSplitGroup, ReservedTokensSplitGroup } from 'models/splits'
import Link from 'next/link'
import { V2V3ProjectContext } from 'packages/v2v3/contexts/Project/V2V3ProjectContext'
import { useAddToBalanceTx } from 'packages/v2v3/hooks/transactor/AddToBalanceTx'
import { useDeployProjectPayerTx } from 'packages/v2v3/hooks/transactor/useDeployProjectPayerTx'
import { ETHPayoutSplitGroup, ReservedTokensSplitGroup } from 'packages/v2v3/models/splits'
import { useContext } from 'react'
import { v2v3ProjectRoute } from 'utils/routes'
import { ExportSplitsButton } from './ExportSplitsButton'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber } from 'ethers'
import { FormItemInput } from 'models/formItemInput'
import { Split } from 'models/splits'
import { V2V3CurrencyOption } from 'packages/v2v3/models/currencyOption'
import { Split } from 'packages/v2v3/models/splits'
import { createContext, useContext } from 'react'
import { AllocationItem } from './AllocationItem'
import { AllocationList } from './AllocationList'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import EthereumAddress from 'components/EthereumAddress'
import { Split } from 'models/splits'
import { Split } from 'packages/v2v3/models/splits'
import { DiffedItem } from '../../DiffedItem'
import { JuiceboxProjectBeneficiary } from '../../SplitItem/JuiceboxProjectBeneficiary'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber } from 'ethers'
import { Split } from 'models/splits'
import { Split } from 'packages/v2v3/models/splits'
import {
isFiniteDistributionLimit,
isInfiniteDistributionLimit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber } from 'ethers'
import round from 'lodash/round'
import { Split } from 'models/splits'
import { useProjectContext } from 'packages/v2v3/components/V2V3Project/ProjectDashboard/hooks/useProjectContext'
import { Split } from 'packages/v2v3/models/splits'
import { formatSplitPercent } from 'packages/v2v3/utils/math'
import {
getProjectOwnerRemainderSplit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import FormattedNumberInput from 'components/inputs/FormattedNumberInput'
import round from 'lodash/round'
import { Split } from 'models/splits'
import {
AddEditAllocationModal,
AddEditAllocationModalEntity,
} from 'packages/v2v3/components/shared/Allocation/AddEditAllocationModal'
import { Split } from 'packages/v2v3/models/splits'
import { useState } from 'react'
import { PayoutSplitRowMenu } from './PayoutSplitRowMenu'
import { PayoutTitle } from './PayoutTitle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { LockFilled } from '@ant-design/icons'
import { t } from '@lingui/macro'
import { Tooltip } from 'antd'
import EthereumAddress from 'components/EthereumAddress'
import { Split } from 'models/splits'
import V2V3ProjectHandleLink from 'packages/v2v3/components/shared/V2V3ProjectHandleLink'
import { Split } from 'packages/v2v3/models/splits'
import { formatDate } from 'utils/format/formatDate'
import { usePayoutsTableContext } from './context/PayoutsTableContext'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CurrencyName } from 'constants/currency'
import { Split } from 'models/splits'
import { Split } from 'packages/v2v3/models/splits'
import { ReactNode, createContext, useContext } from 'react'

export interface PayoutsTableContextProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { NULL_ALLOCATOR_ADDRESS } from 'constants/contracts/mainnet/Allocators'
import { ONE_BILLION, WAD_DECIMALS } from 'constants/numbers'
import isEqual from 'lodash/isEqual'
import round from 'lodash/round'
import { Split } from 'models/splits'
import { AddEditAllocationModalEntity } from 'packages/v2v3/components/shared/Allocation/AddEditAllocationModal'
import { V2V3CurrencyOption } from 'packages/v2v3/models/currencyOption'
import { Split } from 'packages/v2v3/models/splits'
import {
V2V3CurrencyName,
V2V3_CURRENCY_METADATA,
Expand Down
Loading

0 comments on commit a588de7

Please sign in to comment.