Skip to content

Commit

Permalink
Fix: network switch bug (#174)
Browse files Browse the repository at this point in the history
* fix: bug

* test

* fix: fix

* fix: remove clg

* feat: comment getNfts

* refactor: use connection with hook instead of props

* fix: make sure type from local stor is correct

* chore: uncomment getNfts [skip ci]

* refactor: include the isDevnet query check inside the useRpc hook

* feat: mainnet as default network

* fix: fix Cannot assign to read only property '_nextClientSubscriptionId' of object '#<Connection>'

* fix: remove view cm id
  • Loading branch information
aspnxdd authored Jul 25, 2022
1 parent c697df5 commit 50b6845
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions components/NetworkSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const NetworkSelector: FC = () => {
setNetwork({ network: _network, url: getUrl(_network), connection: new Connection(getUrl(_network)) })
window.localStorage.setItem('network-gg', _network)
}
if (!_network) {
setNetwork({ network: 'Mainnet', url: getUrl('Mainnet'), connection: new Connection(getUrl('Mainnet')) })
window.localStorage.setItem('network-gg', 'Mainnet')
}
}, [])
function changeNetwork(_network: Network) {
setNetwork({ network: _network, url: getUrl(_network), connection: new Connection(getUrl(_network)) })
Expand Down
13 changes: 6 additions & 7 deletions components/forms/CreateCandyMachine.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AnchorProvider, BN } from '@project-serum/anchor'
import { useAnchorWallet, useWallet } from '@solana/wallet-adapter-react'
import { LAMPORTS_PER_SOL } from '@solana/web3.js'
import { Connection, LAMPORTS_PER_SOL } from '@solana/web3.js'
import { useForm, useRPC, useUploadCache, useUploadFiles } from 'hooks'
import { DEFAULT_GATEKEEPER } from 'lib/candy-machine/constants'
import { StorageType } from 'lib/candy-machine/enums'
Expand All @@ -11,11 +11,12 @@ import { getCurrentDate, getCurrentTime, parseDateFromDateBN, parseDateToUTC, pa
import React, { FC, useState, useEffect } from 'react'
import { Box, Button, Spinner, StyledOcticon } from '@primer/react'
import { AlertIcon } from '@primer/octicons-react'
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'

const CreateCandyMachine: FC = () => {
const { publicKey } = useWallet()
const anchorWallet = useAnchorWallet()
const { connection } = useRPC()
const { connection, network } = useRPC()

const { files, uploadAssets } = useUploadFiles()
const [isInteractingWithCM, setIsInteractingWithCM] = useState(false)
Expand Down Expand Up @@ -101,10 +102,9 @@ const CreateCandyMachine: FC = () => {
uuid: null,
}

if (publicKey && anchorWallet && connection) {
if (publicKey && anchorWallet && connection && network) {
const { supportedFiles, elemCount } = verifyAssets(files, config.storage, config.number)

const provider = new AnchorProvider(connection, anchorWallet, {
const provider = new AnchorProvider(new Connection(connection.rpcEndpoint), anchorWallet, {
preflightCommitment: 'recent',
})

Expand Down Expand Up @@ -135,13 +135,12 @@ const CreateCandyMachine: FC = () => {
} = await getCandyMachineV2Config(publicKey, config, anchorProgram)

const startMilliseconds = Date.now()

console.log('started at: ' + startMilliseconds.toString())
try {
const _candyMachine = await uploadV2({
files: supportedFiles,
cacheName: 'example',
env: 'devnet',
env: WalletAdapterNetwork[network] as Exclude<WalletAdapterNetwork, WalletAdapterNetwork.Testnet>,
totalNFTs: elemCount,
gatekeeper,
storage,
Expand Down
1 change: 1 addition & 0 deletions hooks/useRPC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const useRPC = () => {
return {
connection: network?.connection,
isDevnet: network?.url.includes('devnet') ? '?cluster=devnet' : '',
network: network?.network,
}
}

Expand Down

0 comments on commit 50b6845

Please sign in to comment.