Skip to content

Commit

Permalink
show loading when checking session
Browse files Browse the repository at this point in the history
env stg


retry refresh token


retry refresh token anonymous as well


update uxx


c


sdk
  • Loading branch information
nguyenhoaidanh committed Jun 13, 2023
1 parent 8346c6a commit 1c48159
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 44 deletions.
47 changes: 22 additions & 25 deletions .env.adpr
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
VITE_DEFAULT_AGGREGATOR_API=https://meta-aggregator.dev.kyberengineering.io
VITE_AGGREGATOR_API=https://aggregator-api.dev.kyberengineering.io
VITE_AGGREGATOR_STATS_API=https://aggregator-stats.dev.kyberengineering.io
VITE_DEFAULT_AGGREGATOR_API=https://meta-aggregator.stg.kyberengineering.io
VITE_AGGREGATOR_API=https://aggregator-api.stg.kyberengineering.io
VITE_AGGREGATOR_STATS_API=https://aggregator-stats.kyberswap.com
VITE_SENTRY_DNS=https://d94ee2d3c22043bdaec966758680b5a8@sentry.ops.kyberengineering.io/4

VITE_SERVICE_WORKER=true
VITE_SERVICE_WORKER=false
VITE_MIXPANEL_PROJECT_TOKEN=ff1eea26c19dcf4a7c35ebbc8631e714
VITE_REWARD_SERVICE_API=https://reward.stg.kyberengineering.io/api/v1

VITE_MIXPANEL_PROJECT_TOKEN=fca28a30cb98d872c2079f214955cd5e
VITE_REWARD_SERVICE_API=https://reward.dev.kyberengineering.io/api/v1
VITE_PRICE_CHART_API=https://price-chart.kyberswap.com/api
VITE_PRICE_API=https://price.stg.kyberengineering.io

VITE_PRICE_CHART_API=https://price-chart.dev.kyberengineering.io/api
VITE_PRICE_API=https://price.dev.kyberengineering.io
VITE_NOTIFICATION_API=https://notification.stg.kyberengineering.io/api

VITE_NOTIFICATION_API=https://notification.dev.kyberengineering.io/api

VITE_CAMPAIGN_BASE_URL=https://campaigns.dev.kyberengineering.io
VITE_TYPE_AND_SWAP_URL=https://type-swap.dev.kyberengineering.io/api
VITE_CAMPAIGN_BASE_URL=https://campaigns.stg.kyberengineering.io
VITE_TYPE_AND_SWAP_URL=https://type-swap.stg.kyberengineering.io/api

VITE_TRANSAK_URL=https://staging-global.transak.com
VITE_TRANSAK_API_KEY=327b8b63-626b-4376-baf2-70a304c48488

VITE_KS_SETTING_API=https://ks-setting.dev.kyberengineering.io/api
VITE_KS_SETTING_API=https://ks-setting.stg.kyberengineering.io/api

VITE_GTM_ID=

VITE_GOOGLE_RECAPTCHA_KEY=6Lc7yg0iAAAAALhS4C4Ez5hqMBub8hKdFvvr9sfc
VITE_POOL_FARM_BASE_URL=https://pool-farm.dev.kyberengineering.io
VITE_POOL_FARM_BASE_URL=https://pool-farm.kyberswap.com

VITE_LIMIT_ORDER_API_WRITE=https://limit-order.dev.kyberengineering.io/write/api
VITE_LIMIT_ORDER_API_READ=https://limit-order.dev.kyberengineering.io/read-ks/api
VITE_LIMIT_ORDER_API_WRITE=https://limit-order.stg.kyberengineering.io/write/api
VITE_LIMIT_ORDER_API_READ=https://limit-order.stg.kyberengineering.io/read-ks/api
VITE_BLOCK_SERVICE_API=https://block.kyberswap.com

# Kyber DAO Apis
VITE_KYBER_DAO_STATS_API=https://kyberswap-dao-stats.dev.kyberengineering.io

VITE_KYBER_DAO_STATS_API=https://kyberswap-dao-stats.stg.kyberengineering.io
VITE_PRICE_ALERT_API=https://price-alert.stg.kyberengineering.io/api
# oauth
VITE_ENV=development
VITE_OAUTH_CLIENT_ID=a2f76ad4-895f-401a-ba75-952a929d782c

VITE_PRICE_ALERT_API=https://price-alert.dev.kyberengineering.io/api
VITE_BFF_API=https://kyberswap-bff.dev.kyberengineering.io/api
VITE_ENV=staging
VITE_OAUTH_CLIENT_ID=bce9bf52-b788-4c25-9c6c-a07dff080403
VITE_BFF_API=https://kyberswap-bff.stg.kyberengineering.io/api
VITE_KYBER_AI_REFERRAL_ID=1
VITE_KYBER_AI_TOPIC_ID=14
VITE_KYBER_AI_TOPIC_ID=11

VITE_BUCKET_NAME=ks-setting-a3aa20b7
VITE_BUCKET_NAME=ks-setting-6d114fd1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@apollo/client": "^3.7.1",
"@datadog/browser-rum": "^4.23.3",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@kybernetwork/oauth2": "0.0.3",
"@kybernetwork/oauth2": "0.0.5-rc.6",
"@kyberswap/ks-sdk-classic": "^1.0.3",
"@kyberswap/ks-sdk-core": "^1.0.5",
"@kyberswap/ks-sdk-elastic": "^1.1.2",
Expand Down
12 changes: 5 additions & 7 deletions src/components/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { useEffect, useRef } from 'react'
import { Navigate } from 'react-router-dom'
import kyberAIApi from 'services/kyberAISubscription'

import { useInvalidateTags } from 'components/Announcement/helper'
import LocalLoader from 'components/LocalLoader'
import { RTK_QUERY_TAGS } from 'constants/index'
import { useSessionInfo } from 'state/authen/hooks'
import { useIsWhiteListKyberAI } from 'state/user/hooks'

Expand All @@ -26,16 +23,17 @@ export const ProtectedRouteKyberAI = ({
}: Props & {
waitUtilAuthenEndOnly?: boolean
}) => {
const { loading, isWhiteList } = useIsWhiteListKyberAI()
const { loading, isWhiteList, refetch } = useIsWhiteListKyberAI()
const { userInfo } = useSessionInfo()
const invalidate = useInvalidateTags(kyberAIApi.reducerPath)
const loadedPage = useRef(false)
const canAccessPage = isWhiteList || waitUtilAuthenEndOnly

useEffect(() => {
// change account sign in => refresh participant info
invalidate(RTK_QUERY_TAGS.GET_PARTICIPANT_INFO_KYBER_AI)
}, [userInfo?.identityId, invalidate])
try {
refetch()
} catch (error) {}
}, [userInfo?.identityId, refetch])

if (loading && !loadedPage.current) return <LocalLoader />
if (!canAccessPage) return <Navigate to={redirectUrl} replace />
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const useLogin = () => {
}
if (requestingSession.current !== walletAddress) {
requestingSession.current = walletAddress
setLoading(true)
await KyberOauth2.getSession({ method: LoginMethod.ETH, walletAddress })
await getProfile(walletAddress)
setLoading(false)
Expand Down
11 changes: 7 additions & 4 deletions src/pages/TrueSightV2/pages/RegisterWhitelist/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function RegisterWhitelist({ showForm = true }: { showForm?: bool
const toggleWalletModal = useWalletModalToggle()
const { isLogin } = useSessionInfo()

const { isWhiteList, isWaitList } = useIsWhiteListKyberAI()
const { isWhiteList, isWaitList, loading: isCheckingPermission } = useIsWhiteListKyberAI()

const [verifyModalState, setVerifyModalState] = useState({
isOpen: false,
Expand Down Expand Up @@ -92,10 +92,13 @@ export default function RegisterWhitelist({ showForm = true }: { showForm?: bool
</ConnectWalletButton>
)

if (!isLogin)
if (!isLogin || isCheckingPermission)
return (
<ConnectWalletButton onClick={() => KyberOauth2.authenticate({ wallet_address: account ?? '' })}>
<Trans>Sign-In to Continue</Trans>
<ConnectWalletButton
onClick={() => KyberOauth2.authenticate({ wallet_address: account ?? '' })}
disabled={isCheckingPermission}
>
{isCheckingPermission ? <Trans>Checking data...</Trans> : <Trans>Sign-In to Continue</Trans>}
</ConnectWalletButton>
)

Expand Down
9 changes: 6 additions & 3 deletions src/state/user/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useOldStaticFeeFactoryContract,
useStaticFeeFactoryContract,
} from 'hooks/useContract'
import useDebounce from 'hooks/useDebounce'
import { ParticipantInfo, ParticipantStatus } from 'pages/TrueSightV2/types'
import { AppDispatch, AppState } from 'state'
import { useSessionInfo } from 'state/authen/hooks'
Expand Down Expand Up @@ -520,16 +521,18 @@ export const useIsWhiteListKyberAI = () => {
data: rawData,
isFetching,
isError,
refetch,
} = useGetParticipantInfoQuery(undefined, {
skip: !userInfo,
})
const participantInfo = isError ? participantDefault : rawData

const participantInfo = isError || pendingAuthentication ? participantDefault : rawData
const isLoading = useDebounce(isFetching || pendingAuthentication, 100)
return {
loading: isFetching || pendingAuthentication,
loading: isLoading,
isWhiteList:
isLogin && (participantInfo?.status === ParticipantStatus.WHITELISTED || userInfo?.data?.hasAccessToKyberAI),
isWaitList: isLogin && participantInfo?.status === ParticipantStatus.WAITLISTED,
refetch,
}
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2303,10 +2303,10 @@
bs58 "^5.0.0"
uuid "^8.3.2"

"@kybernetwork/oauth2@0.0.3":
version "0.0.3"
resolved "https://npm.pkg.github.com/download/@kybernetwork/oauth2/0.0.3/6a555baf6b62a781d532d06186ca8faf6eeef923#6a555baf6b62a781d532d06186ca8faf6eeef923"
integrity sha512-SvTpvVPeiGNau13abVX5v7ItC5ZtCb7+Qx2AbK7L2G8kNLH8IEpr9C0w8sSMOGi8CEU6UDaUI02RjtxVOPyN4A==
"@kybernetwork/oauth2@0.0.5-rc.6":
version "0.0.5-rc.6"
resolved "https://npm.pkg.github.com/download/@kybernetwork/oauth2/0.0.5-rc.6/ff3722c3724165be81789cf08cdb50912075b359#ff3722c3724165be81789cf08cdb50912075b359"
integrity sha512-EdjdH2iDNhiEyuahnfmRPkdY2RGkpL4MyYX5crfLlqMlAcbtvpoUBwi+0oOHjZ1rJh0Bsm5rfzUa5iT1PZNiSw==
dependencies:
axios "1.2.1"
client-oauth2 "^4.3.3"
Expand Down

0 comments on commit 1c48159

Please sign in to comment.