Skip to content

Commit

Permalink
feat: read chainId from connectedWallet to launch v4 projects
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyd-eth committed Nov 19, 2024
1 parent 2a8b376 commit 3214ed9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 34 deletions.
2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const CONNECT_SRC = [
'https://api.ensideas.com',
'https://cloudflare-eth.com',
'https://rpc.sepolia.org/',
'https://sepolia-rollup.arbitrum.io/rpc',
'https://sepolia.optimism.io'
]

const FRAME_ANCESTORS = [
Expand Down
18 changes: 18 additions & 0 deletions src/constants/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ export const NETWORKS: Record<number, NetworkInfo> = {
rpcUrl: `https://sepolia.infura.io/v3/${infuraId}`,
token: 'SepETH',
},
421614: {
name: NetworkName.arbitrumSepolia,
label: 'Arbitrum Sepolia Testnet',
color: '#96bedc',
chainId: 421614,
token: 'ArbETH',
rpcUrl: `https://sepolia-rollup.arbitrum.io/rpc`,
blockExplorer: 'https://sepolia-explorer.arbitrum.io',
},
11155420: {
name: NetworkName.optimismSepolia,
label: 'Optimism Sepolia Testnet',
color: '#f01f70',
chainId: 11155420,
token: 'OpETH',
rpcUrl: `https://sepolia.optimism.io`,
blockExplorer: 'https://optimism-sepolia.blockscout.com',
},
}

export const NETWORKS_BY_NAME = Object.values(NETWORKS).reduce(
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/Wallet/useWallet.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useConnectWallet } from '@web3-onboard/react'
import {
useChain,
useChainUnsupported,
useChangeNetworks,
useDisconnect,
useIsConnected,
useSigner,
useUserAddress,
useWalletBalance,
useWalletBalance
} from './hooks'

import { useConnectWallet } from '@web3-onboard/react'

export function useWallet() {
const signer = useSigner()
const userAddress = useUserAddress()
const isConnected = useIsConnected()
const chain = useChain()
const chainUnsupported = useChainUnsupported()
const chainUnsupported = false//useChainUnsupported()
const balance = useWalletBalance()

const [, connect] = useConnectWallet()
Expand Down
2 changes: 2 additions & 0 deletions src/models/networkName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export enum NetworkName {
localhost = 'localhost',
mainnet = 'mainnet',
sepolia = 'sepolia',
arbitrumSepolia = 'arbitrumSepolia',
optimismSepolia = 'optimismSepolia',
}
20 changes: 10 additions & 10 deletions src/packages/v4/hooks/useLaunchProjectTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import { NATIVE_TOKEN } from 'juice-sdk-core'
import { useWriteJbControllerLaunchProjectFor } from 'juice-sdk-react'
import { LaunchV2V3ProjectData } from 'packages/v2v3/hooks/transactor/useLaunchProjectTx'
import { DEFAULT_MUST_START_AT_OR_AFTER } from 'redux/slices/editingV2Project'
import { sepolia } from 'viem/chains'
import { useChainId } from 'wagmi'
import { wagmiConfig } from '../wagmiConfig'
import { useCurrentRouteChainId } from './useCurrentRouteChainId'

const CREATE_EVENT_IDX = 2
const PROJECT_ID_TOPIC_IDX = 1
Expand Down Expand Up @@ -69,14 +68,15 @@ export function useLaunchProjectTx() {
const { writeContractAsync: writeLaunchProject } =
useWriteJbControllerLaunchProjectFor()

const chainId = useCurrentRouteChainId() ?? sepolia.id // default to sepolia
const terminalAddress = chainId
? SUPPORTED_JB_MULTITERMINAL_ADDRESS[chainId]
: undefined

const controllerAddress = chainId
? SUPPORTED_JB_CONTROLLER_ADDRESS[chainId]
: undefined
const chainId = useChainId()
const chainIdStr = chainId?.toString() as keyof typeof SUPPORTED_JB_MULTITERMINAL_ADDRESS
const terminalAddress = chainId
? SUPPORTED_JB_MULTITERMINAL_ADDRESS[chainIdStr]
: undefined

const controllerAddress = chainId
? SUPPORTED_JB_CONTROLLER_ADDRESS[chainIdStr]
: undefined

const { addTransaction } = useContext(TxHistoryContext)

Expand Down
38 changes: 20 additions & 18 deletions src/packages/v4/hooks/useLaunchProjectWithNftsTx.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
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 { DEFAULT_MEMO, NATIVE_TOKEN, NATIVE_TOKEN_DECIMALS } from 'juice-sdk-core'
import {
jbPricesAddress,
useJBContractContext,
useReadJb721TiersHookStoreTiersOf,
useWriteJb721TiersHookProjectDeployerLaunchProjectFor,
} from 'juice-sdk-react'
import { isValidMustStartAtOrAfter } from 'packages/v2v3/utils/fundingCycle'
import {
JBDeploy721TiersHookConfig,
LaunchProjectWithNftsTxArgs,
} from 'packages/v4/models/nfts'
import { useContext } from 'react'
import { DEFAULT_MUST_START_AT_OR_AFTER } from 'redux/slices/editingV2Project'
import { ipfsUri } from 'utils/ipfs'
import {
Address,
WaitForTransactionReceiptReturnType,
toBytes,
toHex,
WaitForTransactionReceiptReturnType,
zeroAddress,
} from 'viem'
import { sepolia } from 'viem/chains'
import {
LaunchV2V3ProjectArgs,
transformV2V3CreateArgsToV4,
} from '../utils/launchProjectTransformers'
import { wagmiConfig } from '../wagmiConfig'
import { useCurrentRouteChainId } from './useCurrentRouteChainId'
import {
LaunchTxOpts,
SUPPORTED_JB_CONTROLLER_ADDRESS,
SUPPORTED_JB_MULTITERMINAL_ADDRESS
} 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 { 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 }))
Expand Down Expand Up @@ -79,15 +79,17 @@ export function useLaunchProjectWithNftsTx() {
const { addTransaction } = useContext(TxHistoryContext)

const { userAddress } = useWallet()
const chainId = useCurrentRouteChainId() ?? sepolia.id // default to sepolia
const chainId = useChainId()
const chainIdStr = chainId?.toString() as keyof typeof SUPPORTED_JB_MULTITERMINAL_ADDRESS

const defaultJBController = chainId
? SUPPORTED_JB_CONTROLLER_ADDRESS[chainId]
? SUPPORTED_JB_CONTROLLER_ADDRESS[chainIdStr]
: undefined
const defaultJBETHPaymentTerminal = chainId
? SUPPORTED_JB_MULTITERMINAL_ADDRESS[chainId]
? SUPPORTED_JB_MULTITERMINAL_ADDRESS[chainIdStr]
: undefined
const JBTiered721DelegateStoreAddress = chainId
? SUPPORTED_JB_721_TIER_STORE[chainId]
? SUPPORTED_JB_721_TIER_STORE[chainIdStr]
: undefined

const { writeContractAsync: writeLaunchProject } =
Expand Down Expand Up @@ -158,7 +160,7 @@ export function useLaunchProjectWithNftsTx() {
tiersConfig: {
currency,
decimals: NATIVE_TOKEN_DECIMALS,
prices: jbPricesAddress[chainId],
prices: jbPricesAddress[chainIdStr],
tiers,
},
reserveBeneficiary: zeroAddress,
Expand Down Expand Up @@ -209,7 +211,7 @@ export function useLaunchProjectWithNftsTx() {
// })

const hash = await writeLaunchProject({
chainId,
chainId: chainId as 84532 | 421614 | 11155111 | 11155420, // TODO: cleanup
args,
})

Expand Down
4 changes: 2 additions & 2 deletions src/packages/v4/wagmiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export const wagmiConfig = createConfig({
`https://sepolia.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_ID}`,
),
[optimismSepolia.id]: http(
`https://optimism-sepolia.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_ID}`,
'https://sepolia.optimism.io'
),
[baseSepolia.id]: http(
`https://api.developer.coinbase.com/rpc/v1/base-sepolia/${process.env.NEXT_PUBLIC_BASE_ID}`,
),
[arbitrumSepolia.id]: http(
`https://arbitrum-sepolia.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_ID}`,
`https://sepolia-rollup.arbitrum.io/rpc`,
),
},
})

0 comments on commit 3214ed9

Please sign in to comment.