Skip to content

Commit

Permalink
Merge pull request #772 from threshold-network/backport-fix-wallet-co…
Browse files Browse the repository at this point in the history
…nnect-update-issue

[Backport] Fix update handler validation
  • Loading branch information
evandrosaturnino authored Jul 30, 2024
2 parents 352fe8b + 0a5d6dd commit 1b2e90b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { useSubscribeToToppedUpEvent } from "./hooks/useSubscribeToToppedUpEvent
import { pages } from "./pages"
import { useCheckBonusEligibility } from "./hooks/useCheckBonusEligibility"
import { useFetchStakingRewards } from "./hooks/useFetchStakingRewards"
import { isSameETHAddress } from "./web3/utils"
import { isSameChainId, isSameETHAddress } from "./web3/utils"
import { ThresholdProvider } from "./contexts/ThresholdContext"
import { LedgerLiveAppProvider } from "./contexts/LedgerLiveAppContext"
import {
Expand Down Expand Up @@ -133,17 +133,17 @@ const useSubscribeToVendingMachineContractEvents = () => {

const AppBody = () => {
const dispatch = useDispatch()
const { connector, account, deactivate } = useWeb3React()
const { connector, account, chainId, deactivate } = useWeb3React()

useEffect(() => {
const updateHandler = (update: ConnectorUpdate) => {
// if chain is changed then just deactivate the current provider and reset
// store
if (update.chainId) {
if (update.chainId && !isSameChainId(update.chainId, chainId as number)) {
dispatch(resetStoreAction())
deactivate()
} else if (
!update.account ||
update.account &&
!isSameETHAddress(update.account, account as string)
) {
// dispatch(resetStoreAction())
Expand Down
1 change: 1 addition & 0 deletions src/web3/utils/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from "@ethersproject/address"
import { AddressZero } from "@ethersproject/constants"
export { unprefixedAndUncheckedAddress } from "../../threshold-ts/utils"
import { ethers } from "ethers"

export const getAddress = (address: string) => ethersGetAddress(address)

Expand Down
1 change: 1 addition & 0 deletions src/web3/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./multicall"
export * from "./events"
export * from "./address"
export * from "./files"
export * from "./network"
9 changes: 9 additions & 0 deletions src/web3/utils/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ethers } from "ethers"

export const toHex = (value: string | number): string =>
ethers.utils.hexlify(value)

export const isSameChainId = (
chainId1: string | number,
chainId2: string | number
): boolean => toHex(chainId1) === toHex(chainId2)

0 comments on commit 1b2e90b

Please sign in to comment.