Skip to content

Commit

Permalink
Merge branch 'main' of github.com:KyberNetwork/dmm-interface into rea…
Browse files Browse the repository at this point in the history
…ct-18
  • Loading branch information
viet-nv committed Aug 3, 2022
2 parents 3ece36a + c803f84 commit 97d5f2c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 38 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"@lingui/loader": "^3.14.0",
"@lingui/macro": "^3.14.0",
"@popperjs/core": "^2.4.4",
"@reach/dialog": "^0.10.3",
"@reach/portal": "^0.10.3",
"@reach/dialog": "^0.17.0",
"@reach/portal": "^0.17.0",
"@reduxjs/toolkit": "^1.7.1",
"@types/aos": "^3.0.4",
"@types/jest": "^25.2.1",
Expand Down
3 changes: 0 additions & 3 deletions src/components/NetworkModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import styled from 'styled-components'
import { Trans } from '@lingui/macro'

Expand Down Expand Up @@ -83,8 +82,6 @@ export default function NetworkModal(): JSX.Element | null {
const toggleNetworkModal = useNetworkModalToggle()
const { changeNetwork } = useActiveNetwork()

if (!chainId || !networkModalOpen) return null

return (
<Modal isOpen={networkModalOpen} onDismiss={toggleNetworkModal} maxWidth={624}>
<Wrapper>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Popups/PopupItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect } from 'react'
import { useCallback, useEffect } from 'react'
import { X } from 'react-feather'
import { useSpring } from 'react-spring/web'
import styled, { keyframes } from 'styled-components'
Expand Down
21 changes: 20 additions & 1 deletion src/hooks/useActiveNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ChainId } from '@kyberswap/ks-sdk-core'
import { useAppDispatch } from 'state/hooks'
import { updateChainIdWhenNotConnected } from 'state/application/actions'
import { UnsupportedChainIdError } from '@web3-react/core'
import { useAddPopup } from 'state/application/hooks'
import { t } from '@lingui/macro'

const getAddNetworkParams = (chainId: ChainId) => ({
chainId: '0x' + chainId.toString(16),
Expand Down Expand Up @@ -36,6 +38,7 @@ export function useActiveNetwork() {
const location = useLocation()
const qs = useParsedQueryString()
const dispatch = useAppDispatch()
const addPopup = useAddPopup()

const locationWithoutNetworkId = useMemo(() => {
// Delete networkId from qs object
Expand Down Expand Up @@ -75,6 +78,15 @@ export function useActiveNetwork() {
if (switchError?.code === 4902 || switchError?.code === -32603 || isSwitchError) {
try {
await activeProvider.request({ method: 'wallet_addEthereumChain', params: [addNetworkParams] })
if (chainId !== desiredChainId) {
addPopup({
simple: {
title: t`Failed to switch network`,
success: false,
summary: t`In order to use KyberSwap on ${NETWORKS_INFO[desiredChainId].name}, you must change the network in your wallet.`,
},
})
}
successCallback && successCallback()
} catch (addError) {
console.error(addError)
Expand All @@ -84,11 +96,18 @@ export function useActiveNetwork() {
// handle other "switch" errors
console.error(switchError)
failureCallback && failureCallback()
addPopup({
simple: {
title: t`Failed to switch network`,
success: false,
summary: t`In order to use KyberSwap on ${NETWORKS_INFO[desiredChainId].name}, you must change the network in your wallet.`,
},
})
}
}
}
},
[dispatch, history, library, locationWithoutNetworkId, error],
[dispatch, history, library, locationWithoutNetworkId, error, addPopup, chainId],
)

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { lazy, Suspense, useEffect } from 'react'
import { lazy, Suspense, useEffect } from 'react'
import { Route, Switch } from 'react-router-dom'
import styled from 'styled-components'
import { ApolloProvider } from '@apollo/client'
Expand Down
55 changes: 25 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2956,34 +2956,34 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==

"@reach/dialog@^0.10.3":
version "0.10.5"
resolved "https://registry.yarnpkg.com/@reach/dialog/-/dialog-0.10.5.tgz#70bd832616fc2b0f31ed65aff81ae9e218c4dbc4"
integrity sha512-j2+VaHCen/M5zh+q6L/xMXETMeD5yVywdhjjs0kn2uQ3AolYSj32P8Go1xSpxQNAjS1/zChd02Y/4g02eL3afg==
"@reach/dialog@^0.17.0":
version "0.17.0"
resolved "https://registry.yarnpkg.com/@reach/dialog/-/dialog-0.17.0.tgz#81c48dd4405945dfc6b6c3e5e125db2c4324e9e8"
integrity sha512-AnfKXugqDTGbeG3c8xDcrQDE4h9b/vnc27Sa118oQSquz52fneUeX9MeFb5ZEiBJK8T5NJpv7QUTBIKnFCAH5A==
dependencies:
"@reach/portal" "0.10.5"
"@reach/utils" "0.10.5"
"@reach/portal" "0.17.0"
"@reach/utils" "0.17.0"
prop-types "^15.7.2"
react-focus-lock "^2.3.1"
react-remove-scroll "^2.3.0"
tslib "^2.0.0"
react-focus-lock "^2.5.2"
react-remove-scroll "^2.4.3"
tslib "^2.3.0"

"@reach/portal@0.10.5", "@reach/portal@^0.10.3":
version "0.10.5"
resolved "https://registry.yarnpkg.com/@reach/portal/-/portal-0.10.5.tgz#532ce8472fc99d6c556520f6c8d53333d89e49a4"
integrity sha512-K5K8gW99yqDPDCWQjEfSNZAbGOQWSx5AN2lpuR1gDVoz4xyWpTJ0k0LbetYJTDVvLP/InEcR7AU42JaDYDCXQw==
"@reach/portal@0.17.0", "@reach/portal@^0.17.0":
version "0.17.0"
resolved "https://registry.yarnpkg.com/@reach/portal/-/portal-0.17.0.tgz#1dd69ffc8ffc8ba3e26dd127bf1cc4b15f0c6bdc"
integrity sha512-+IxsgVycOj+WOeNPL2NdgooUdHPSY285wCtj/iWID6akyr4FgGUK7sMhRM9aGFyrGpx2vzr+eggbUmAVZwOz+A==
dependencies:
"@reach/utils" "0.10.5"
tslib "^2.0.0"
"@reach/utils" "0.17.0"
tiny-warning "^1.0.3"
tslib "^2.3.0"

"@reach/utils@0.10.5":
version "0.10.5"
resolved "https://registry.yarnpkg.com/@reach/utils/-/utils-0.10.5.tgz#fbac944d29565f6dd7abd0e1b13950e99b1e470b"
integrity sha512-5E/xxQnUbmpI/LrufBAOXjunl96DnqX6B4zC2MO2KH/dRzLug5gM5VuOwV26egsp0jvsSPxojwciOhS43px3qw==
"@reach/utils@0.17.0":
version "0.17.0"
resolved "https://registry.yarnpkg.com/@reach/utils/-/utils-0.17.0.tgz#3d1d2ec56d857f04fe092710d8faee2b2b121303"
integrity sha512-M5y8fCBbrWeIsxedgcSw6oDlAMQDkl5uv3VnMVJ7guwpf4E48Xlh1v66z/1BgN/WYe2y8mB/ilFD2nysEfdGeA==
dependencies:
"@types/warning" "^3.0.0"
tslib "^2.0.0"
warning "^4.0.3"
tiny-warning "^1.0.3"
tslib "^2.3.0"

"@rebass/forms@^4.0.6":
version "4.0.6"
Expand Down Expand Up @@ -4046,11 +4046,6 @@
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==

"@types/warning@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/warning/-/warning-3.0.0.tgz#0d2501268ad8f9962b740d387c4654f5f8e23e52"
integrity sha512-t/Tvs5qR47OLOr+4E9ckN8AmP2Tf16gWq+/qA4iUGS/OOyHVO8wv2vjJuX8SNOUTJyWb+2t7wJm6cXILFnOROA==

"@types/wcag-contrast@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/wcag-contrast/-/wcag-contrast-3.0.0.tgz#640a4c36a6b62d54f1dd64a74322595df465148d"
Expand Down Expand Up @@ -15934,7 +15929,7 @@ react-feather@^2.0.8:
dependencies:
prop-types "^15.7.2"

react-focus-lock@^2.3.1:
react-focus-lock@^2.5.2:
version "2.9.1"
resolved "https://registry.yarnpkg.com/react-focus-lock/-/react-focus-lock-2.9.1.tgz#094cfc19b4f334122c73bb0bff65d77a0c92dd16"
integrity sha512-pSWOQrUmiKLkffPO6BpMXN7SNKXMsuOakl652IBuALAu1esk+IcpJyM+ALcYzPTTFz1rD0R54aB9A4HuP5t1Wg==
Expand Down Expand Up @@ -16029,7 +16024,7 @@ react-remove-scroll-bar@^2.3.3:
react-style-singleton "^2.2.1"
tslib "^2.0.0"

react-remove-scroll@^2.3.0:
react-remove-scroll@^2.4.3:
version "2.5.5"
resolved "https://registry.yarnpkg.com/react-remove-scroll/-/react-remove-scroll-2.5.5.tgz#1e31a1260df08887a8a0e46d09271b52b3a37e77"
integrity sha512-ImKhrzJJsyXJfBZ4bzu8Bwpka14c/fQt0k+cyFp/PBhTfyDnU5hjOtM4AG/0AMyy8oKzOTR0lDgJIM7pYXI0kw==
Expand Down Expand Up @@ -19027,7 +19022,7 @@ walker@^1.0.7, walker@~1.0.5:
dependencies:
makeerror "1.0.12"

warning@^4.0.2, warning@^4.0.3:
warning@^4.0.2:
version "4.0.3"
resolved "https://registry.yarnpkg.com/warning/-/warning-4.0.3.tgz#16e9e077eb8a86d6af7d64aa1e05fd85b4678ca3"
integrity sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==
Expand Down

0 comments on commit 97d5f2c

Please sign in to comment.