diff --git a/src/components/SwapForm/hooks/useBuildRoute.tsx b/src/components/SwapForm/hooks/useBuildRoute.tsx index 31008fd5ea..04588bacdc 100644 --- a/src/components/SwapForm/hooks/useBuildRoute.tsx +++ b/src/components/SwapForm/hooks/useBuildRoute.tsx @@ -4,6 +4,7 @@ import routeApi from 'services/route' import { BuildRouteData, BuildRoutePayload } from 'services/route/types/buildRoute' import { RouteSummary } from 'services/route/types/getRoute' +import { useGetRouteApiDomain } from 'components/SwapForm/hooks/useGetRoute' import { AGGREGATOR_API_PATHS } from 'constants/index' import { NETWORKS_INFO } from 'constants/networks' import { useActiveWeb3React } from 'hooks' @@ -31,8 +32,9 @@ const useBuildRoute = (args: Args) => { const { recipient, routeSummary, slippage, transactionTimeout, permit } = args const { chainId, account } = useActiveWeb3React() const abortControllerRef = useRef(new AbortController()) - const { aggregatorDomain, isEnableAuthenAggregator } = useKyberswapGlobalConfig() + const { isEnableAuthenAggregator } = useKyberswapGlobalConfig() const [buildRoute] = routeApi.useBuildRouteMutation() + const aggregatorDomain = useGetRouteApiDomain() const fetcher = useCallback(async (): Promise => { if (!account) { diff --git a/src/components/SwapForm/hooks/useGetRoute.ts b/src/components/SwapForm/hooks/useGetRoute.ts index 3a3b9e4fc9..c4b9daba28 100644 --- a/src/components/SwapForm/hooks/useGetRoute.ts +++ b/src/components/SwapForm/hooks/useGetRoute.ts @@ -6,6 +6,7 @@ import { GetRouteParams } from 'services/route/types/getRoute' import useGetSwapFeeConfig, { SwapFeeConfig } from 'components/SwapForm/hooks/useGetSwapFeeConfig' import useSelectedDexes from 'components/SwapForm/hooks/useSelectedDexes' +import { AGGREGATOR_API } from 'constants/env' import { AGGREGATOR_API_PATHS, ETHER_ADDRESS, @@ -17,6 +18,7 @@ import { NETWORKS_INFO, isEVM } from 'constants/networks' import { useActiveWeb3React } from 'hooks' import useDebounce from 'hooks/useDebounce' import { useKyberswapGlobalConfig } from 'hooks/useKyberSwapConfig' +import { useSessionInfo } from 'state/authen/hooks' import { useAppDispatch } from 'state/hooks' import { ChargeFeeBy } from 'types/route' import { Aggregator } from 'utils/aggregator' @@ -76,13 +78,21 @@ const getFeeConfigParams = ( } } +// default use aggregator, utils the first time sign-in successfully (guest/sign in eth) => use meta +export const useGetRouteApiDomain = () => { + const { aggregatorDomain } = useKyberswapGlobalConfig() + const { authenticationSuccess } = useSessionInfo() + return authenticationSuccess ? aggregatorDomain : AGGREGATOR_API +} + const useGetRoute = (args: ArgsGetRoute) => { - const { aggregatorDomain, isEnableAuthenAggregator } = useKyberswapGlobalConfig() + const { isEnableAuthenAggregator } = useKyberswapGlobalConfig() const { isSaveGas, parsedAmount, currencyIn, currencyOut, customChain, isProcessingSwap } = args const { chainId: currentChain } = useActiveWeb3React() const chainId = customChain || currentChain const [trigger, _result] = routeApi.useLazyGetRouteQuery() + const aggregatorDomain = useGetRouteApiDomain() const getSwapFeeConfig = useGetSwapFeeConfig() diff --git a/src/pages/App.tsx b/src/pages/App.tsx index cf5711d63b..5b93f5c9e1 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -119,7 +119,7 @@ const preloadImages = () => { const SwapPage = () => { const { chainId } = useActiveWeb3React() useSyncNetworkParamWithStore() - return {chainId === ChainId.SOLANA ? : } + return chainId === ChainId.SOLANA ? : } const RedirectWithNetworkPrefix = () => { diff --git a/src/state/authen/reducer.ts b/src/state/authen/reducer.ts index 993f7dedd7..7310fcf4f4 100644 --- a/src/state/authen/reducer.ts +++ b/src/state/authen/reducer.ts @@ -21,6 +21,7 @@ export interface AuthenState { readonly signedUserInfo: UserProfile | undefined readonly isLogin: boolean // is sign in eth readonly pendingAuthentication: boolean + readonly authenticationSuccess: boolean readonly isConnectingWallet: boolean readonly showConfirmProfile: boolean readonly autoSignIn: AutoSignIn // auto sign in after connect wallet @@ -31,6 +32,7 @@ const DEFAULT_AUTHEN_STATE: AuthenState = { signedUserInfo: undefined, isLogin: false, pendingAuthentication: true, + authenticationSuccess: false, isConnectingWallet: false, showConfirmProfile: false, autoSignIn: { @@ -61,6 +63,7 @@ const slice = createSlice({ state.anonymousUserInfo = undefined } state.isLogin = !isAnonymous + if (profile) state.authenticationSuccess = true }, setConfirmChangeProfile: (state, { payload }: PayloadAction) => { state.showConfirmProfile = payload