Skip to content

Commit

Permalink
fix: network
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Oct 27, 2023
1 parent 065397e commit 483e4c3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ import { isAddressString, isSupportLimitOrder, shortenAddress } from 'utils'
import ElasticLegacyNotice from './ElasticLegacy/ElasticLegacyNotice'
import VerifyAuth from './Verify/VerifyAuth'

const IframeTest = () => {
return (
<iframe
style={{ margin: 'auto' }}
width="500px"
height="900px"
src={`${window.location.origin}/partner-swap?tab=swap&inputCurrency=ETH&outputCurrency=0xe4DDDfe67E7164b0FE14E218d80dC4C08eDC01cB&isInBps=1&chargeFeeBy=currency_in&feeReceiver=0xDcFCD5dD752492b95ac8C1964C83F992e7e39FA9&feeAmount=500&clientId=viet-nv&chainId=42161`}
/>
)
}

const Login = lazy(() => import('./Oauth/Login'))
const Logout = lazy(() => import('./Oauth/Logout'))
const Consent = lazy(() => import('./Oauth/Consent'))
Expand Down Expand Up @@ -320,7 +331,7 @@ export default function App() {
<Routes>
{/* From react-router-dom@6.5.0, :fromCurrency-to-:toCurrency no long works, need to manually parse the params */}
<Route path={`${APP_PATHS.SWAP}/:network/:currency?`} element={<SwapPage />} />
<Route path={`${APP_PATHS.PARTNER_SWAP}/:network`} element={<PartnerSwap />} />
<Route path={`${APP_PATHS.PARTNER_SWAP}`} element={<PartnerSwap />} />
{CHAINS_SUPPORT_CROSS_CHAIN.includes(chainId) && (
<Route path={`${APP_PATHS.CROSS_CHAIN}`} element={<SwapV3 />} />
)}
Expand Down Expand Up @@ -434,6 +445,8 @@ export default function App() {
<Route path={APP_PATHS.IAM_LOGOUT} element={<Logout />} />
<Route path={APP_PATHS.IAM_CONSENT} element={<Consent />} />

<Route path={'/iframe-test'} element={<IframeTest />} />

<Route path="*" element={<RedirectPathToSwapV3Network />} />
</Routes>
</Web3ReactManager>
Expand Down
25 changes: 22 additions & 3 deletions src/pages/PartnerSwap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import {
SwapFormWrapper,
highlight,
} from 'components/swapv2/styleds'
import { SUPPORTED_NETWORKS } from 'constants/networks'
import { useActiveWeb3React } from 'hooks'
import { useAllTokens, useIsLoadedTokenDefault } from 'hooks/Tokens'
import useTheme from 'hooks/useTheme'
import { useSyncNetworkParamWithStore } from 'hooks/web3/useSyncNetworkParamWithStore'
import { useChangeNetwork } from 'hooks/web3/useChangeNetwork'
import { BodyWrapper } from 'pages/AppBody'
import CrossChain from 'pages/CrossChain'
import CrossChainLink from 'pages/CrossChain/CrossChainLink'
Expand Down Expand Up @@ -80,10 +81,28 @@ export const RoutingIconWrapper = styled(RoutingIcon)`
`

export default function Swap() {
useSyncNetworkParamWithStore()
const { chainId } = useActiveWeb3React()
const isShowTradeRoutes = useShowTradeRoutes()
const [searchParams, setSearchParams] = useSearchParams()

const requestChainId = searchParams.get('chainId')
const { changeNetwork } = useChangeNetwork()

const [triedToChangeNetwork, setTriedToChangeNetwork] = useState(false)

useEffect(() => {
// if wallet has already connected, request connect onnce
if (
!triedToChangeNetwork &&
requestChainId &&
SUPPORTED_NETWORKS.includes(+requestChainId) &&
chainId !== +requestChainId
) {
setTriedToChangeNetwork(true)
changeNetwork(+requestChainId)
}
}, [chainId, requestChainId, changeNetwork, triedToChangeNetwork])

const isShowTradeRoutes = useShowTradeRoutes()
const [routeSummary, setRouteSummary] = useState<DetailedRouteSummary>()
const [isSelectCurrencyManually, setIsSelectCurrencyManually] = useState(false) // true when: select token input, output manually or click rotate token.

Expand Down

0 comments on commit 483e4c3

Please sign in to comment.