Skip to content

Commit

Permalink
Merge pull request #339 from LinkdropHQ/dev
Browse files Browse the repository at this point in the history
Switch Network Bug Fix
  • Loading branch information
Dobrokhvalov authored Aug 16, 2024
2 parents 8b92df7 + 7544d09 commit e69e5d1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
25 changes: 20 additions & 5 deletions src/components/pages/claim-page/change-network/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,24 @@ import {
Image
} from './styled-components'
import { defineRealNetworkName } from 'helpers'
import { RootState } from 'data/store'
import { RootState, IAppDispatch } from 'data/store'
import { connect } from 'react-redux'
import { switchNetwork } from 'data/store/reducers/user/async-actions'
import * as userAsyncActions from 'data/store/reducers/user/async-actions'
import Wrongetwork from 'images/network.png'
import { Dispatch } from 'redux'
import { UserActions } from 'data/store/reducers/user/types'

const mapDispatcherToProps = (dispatch: Dispatch<UserActions> & IAppDispatch) => {
return {
switchNetwork: (
chainId: number,
callback?: () => void
) => dispatch(userAsyncActions.switchNetwork(
chainId,
callback
))
}
}

const mapStateToProps = ({
user: { address, chainId: userChainId, userProvider },
Expand All @@ -31,13 +45,14 @@ const mapStateToProps = ({
campaignId
})

type ReduxType = ReturnType<typeof mapStateToProps>
type ReduxType = ReturnType<typeof mapStateToProps> & ReturnType<typeof mapDispatcherToProps>

const ChangeNetwork: FC<ReduxType> = ({
chainId,
userProvider,
campaignId,
type
type,
switchNetwork
}) => {
const networkName = defineRealNetworkName(chainId)
return <Container>
Expand All @@ -58,4 +73,4 @@ const ChangeNetwork: FC<ReduxType> = ({
</Container>
}

export default connect(mapStateToProps)(ChangeNetwork)
export default connect(mapStateToProps, mapDispatcherToProps)(ChangeNetwork)
30 changes: 26 additions & 4 deletions src/components/pages/claim-page/initial-screen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import { plausibleApi } from 'data/api'
import { ERC20TokenPreview, PoweredByFooter } from 'components/pages/common'
import { connect } from 'react-redux'
import { switchNetwork } from 'data/store/reducers/user/async-actions'
import { UserActions } from 'data/store/reducers/user/types'
import * as userAsyncActions from 'data/store/reducers/user/async-actions'


const { REACT_APP_CLIENT} = process.env
const config = defineApplicationConfig()

Expand Down Expand Up @@ -90,7 +94,14 @@ const mapDispatcherToProps = (dispatch: Dispatch<DropActions> & Dispatch<TokenAc
true
)
),
setStep: (step: TDropStep) => dispatch(dropActions.setStep(step))
setStep: (step: TDropStep) => dispatch(dropActions.setStep(step)),
switchNetwork: (
chainId: number,
callback?: () => void
) => dispatch(userAsyncActions.switchNetwork(
chainId,
callback
))
}
}

Expand Down Expand Up @@ -122,7 +133,8 @@ const InitialScreen: FC<ReduxType> = ({
decimals,
userProvider,
email,
autoclaim
autoclaim,
switchNetwork
}) => {

const system = defineSystem()
Expand All @@ -135,7 +147,7 @@ const InitialScreen: FC<ReduxType> = ({
const coinbaseConnector = connectors.find(connector => connector.id === "coinbaseWalletSDK")
const isAuthorized = await coinbaseConnector?.isAuthorized()
if (isAuthorized) {
await switchNetwork( chainId as number, () => {
switchNetwork( chainId as number, () => {
if (type === 'ERC1155') {
return claimERC1155()
}
Expand All @@ -154,7 +166,17 @@ const InitialScreen: FC<ReduxType> = ({
system !== 'desktop'
) {
if (chainId) {
await switchNetwork(chainId as number, () => {})
return switchNetwork(chainId as number, () => {
if (type === 'ERC1155') {
return claimERC1155()
}
if (type === 'ERC721') {
return claimERC721()
}
if (type === 'ERC20') {
return claimERC20()
}
})
} else {
alert('No chain provided')
}
Expand Down
5 changes: 4 additions & 1 deletion src/components/pages/page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const mapStateToProps = ({

const mapDispatcherToProps = (dispatch: IAppDispatch) => {
return {
switchNetwork: (chain: number, callback: () => void) => dispatch(userAsyncActions.switchNetwork(
switchNetwork: (
chain: number,
callback: () => void
) => dispatch(userAsyncActions.switchNetwork(
chain,
callback
)),
Expand Down

0 comments on commit e69e5d1

Please sign in to comment.