Skip to content

Commit

Permalink
refactor: some JBChainId things
Browse files Browse the repository at this point in the history
  • Loading branch information
aeolianeth committed Jan 12, 2025
1 parent 0a99826 commit 8902db3
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 23 deletions.
16 changes: 10 additions & 6 deletions src/constants/networks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { JBChainId } from 'juice-sdk-core'
import { NetworkName } from 'models/networkName'
import { isBrowser } from 'utils/isBrowser'

Expand All @@ -9,7 +10,7 @@ type NetworkInfo = {
name: NetworkName
label: string
color: string
chainId: number, // should be JBChainId
chainId: number // should be JBChainId
blockExplorer: string
rpcUrl: string
token: string
Expand Down Expand Up @@ -40,8 +41,8 @@ export const NETWORKS: Record<number, NetworkInfo> = {
token: 'SepETH',
},
42161: {
name: NetworkName.arbitrumOne,
label: 'Arbitrum One',
name: NetworkName.arbitrum,
label: 'Arbitrum',
color: '#28a0f0',
chainId: 42161,
token: 'ArbETH',
Expand Down Expand Up @@ -70,7 +71,7 @@ export const NETWORKS: Record<number, NetworkInfo> = {
name: NetworkName.optimismSepolia,
label: 'Optimism Sepolia Testnet',
color: '#f01f70',
chainId: 11155420,
chainId: 11155420,
token: 'OpETH',
rpcUrl: `https://sepolia.optimism.io`,
blockExplorer: 'https://optimism-sepolia.blockscout.com',
Expand Down Expand Up @@ -113,7 +114,9 @@ export const NETWORKS: Record<number, NetworkInfo> = {
},
}

export const TESTNET_IDS = new Set<number>([11155111, 421614, 11155420, 84531, 1442]);
export const TESTNET_IDS = new Set<number>([
11155111, 421614, 11155420, 84531, 1442,
])

export const NETWORKS_BY_NAME = Object.values(NETWORKS).reduce(
(acc, curr) => ({
Expand All @@ -123,7 +126,8 @@ export const NETWORKS_BY_NAME = Object.values(NETWORKS).reduce(
{} as Record<NetworkName, NetworkInfo>,
)

export const DEFAULT_PROJECT_CHAIN_ID = NETWORKS_BY_NAME.mainnet.chainId
export const DEFAULT_PROJECT_CHAIN_ID = NETWORKS_BY_NAME.mainnet
.chainId as unknown as JBChainId // TODO once mainnet is a JBChainId, this wont be necessary

export const readNetwork =
NETWORKS_BY_NAME[process.env.NEXT_PUBLIC_INFURA_NETWORK]
2 changes: 1 addition & 1 deletion src/models/networkName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export enum NetworkName {
localhost = 'localhost',
mainnet = 'mainnet',
sepolia = 'sepolia',
arbitrumOne = 'arbitrumOne',
arbitrum = 'arbitrum',
arbitrumSepolia = 'arbitrumSepolia',
optimism = 'optimism',
optimismSepolia = 'optimismSepolia',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import {
DEFAULT_REDUX_STATE,
creatingV2ProjectActions,
} from 'redux/slices/v2v3/creatingV2Project'
import { CreateState, ProjectState } from 'redux/slices/v2v3/shared/v2ProjectTypes'
import {
CreateState,
ProjectState,
} from 'redux/slices/v2v3/shared/v2ProjectTypes'

import { ETH_TOKEN_ADDRESS } from 'constants/juiceboxTokens'
import { DEFAULT_PROJECT_CHAIN_ID } from 'constants/networks'
import isEqual from 'lodash/isEqual'
import { CreatePage } from 'models/createPage'
import { ProjectTokensSelection } from 'models/projectTokenSelection'
Expand Down Expand Up @@ -101,7 +105,7 @@ const parseCreateFlowStateFromInitialState = (
}

return {
projectChainId: 84532, // not necessary for v2v3
projectChainId: DEFAULT_PROJECT_CHAIN_ID, // not necessary for v2v3
fundingCyclesPageSelection,
treasurySelection,
fundingTargetSelection: undefined, // TODO: Remove
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { DEFAULT_PROJECT_CHAIN_ID, NETWORKS } from "constants/networks"

import { JuiceListbox } from "components/inputs/JuiceListbox"
import { JBChainId } from "juice-sdk-react"
import { JuiceListbox } from 'components/inputs/JuiceListbox'
import { DEFAULT_PROJECT_CHAIN_ID, NETWORKS } from 'constants/networks'
import { JB_CHAINS } from 'juice-sdk-core'
import { JBChainId } from 'juice-sdk-react'

export const ProjectChainSelect: React.FC<
React.PropsWithChildren<{
value?: JBChainId
onChange?: (value: JBChainId) => void
}>
> = ({ value, onChange }) => {

const networkOptions = () => Object.entries(NETWORKS).map(
([chainId, networkInfo]) => ({
label: networkInfo.label,
value: parseInt(chainId) as JBChainId,
})
)
const networkOptions = () =>
Object.values(JB_CHAINS).map(chain => ({
label: chain.name,
value: chain.chain.id as JBChainId,
}))

return (
<JuiceListbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Form } from 'antd'
import { useForm } from 'antd/lib/form/Form'
import { DEFAULT_PROJECT_CHAIN_ID } from 'constants/networks'
import { useWallet } from 'hooks/Wallet'
import { JBChainId } from 'juice-sdk-core'
import { ProjectTagName } from 'models/project-tags'
import { V2V3CurrencyOption } from 'packages/v2v3/models/currencyOption'
import { V2V3_CURRENCY_USD } from 'packages/v2v3/utils/currency'
Expand All @@ -18,7 +19,7 @@ import { AmountInputValue } from '../ProjectDetailsPage'

type ProjectDetailsFormProps = Partial<{
projectName: string
projectChainId: number // v4TODO: should be JBChainId
projectChainId: JBChainId
projectTagline: string
projectDescription: string
logo: string
Expand Down
3 changes: 2 additions & 1 deletion src/redux/slices/v2v3/shared/v2ProjectDefaultState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from 'packages/v2v3/utils/serializers'
import { CreateState, ProjectState } from './v2ProjectTypes'

import { DEFAULT_PROJECT_CHAIN_ID } from 'constants/networks'
import { ONE_MILLION } from 'constants/numbers'
import { JB721TiersHookFlags } from 'packages/v4/models/nfts'
import { projectDescriptionTemplate } from 'templates/create/projectDescriptionTemplate'
Expand Down Expand Up @@ -119,7 +120,7 @@ const DEFAULT_PROJECT_METADATA_STATE: ProjectMetadata = {
}

const DEFAULT_CREATE_STATE: CreateState = {
projectChainId: 1, // not necessary for v2v3
projectChainId: DEFAULT_PROJECT_CHAIN_ID, // not necessary for v2v3
treasurySelection: 'zero',
reconfigurationRuleSelection: undefined,
fundingCyclesPageSelection: undefined,
Expand Down
3 changes: 2 additions & 1 deletion src/redux/slices/v2v3/shared/v2ProjectTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
SerializedV2V3FundingCycleMetadata,
} from 'packages/v2v3/utils/serializers'

import { JBChainId } from 'juice-sdk-core'
import { CreatePage } from 'models/createPage'
import { FundingTargetType } from 'models/fundingTargetType'
import { NftPostPayModalConfig } from 'models/nftPostPayModal'
Expand All @@ -36,7 +37,7 @@ export type NftRewardsData = {

export interface CreateState {
fundingCyclesPageSelection: 'automated' | 'manual' | undefined
projectChainId: number // v4TODO: should be JBChainId
projectChainId: JBChainId
treasurySelection: TreasurySelection | undefined
fundingTargetSelection: FundingTargetType | undefined
payoutsSelection: PayoutsSelection | undefined
Expand Down

0 comments on commit 8902db3

Please sign in to comment.