From 0702f19128248c2dbee427a9638c0159a0c15eca Mon Sep 17 00:00:00 2001 From: Danh Date: Tue, 17 Oct 2023 14:24:52 +0700 Subject: [PATCH] rm test code --- package.json | 2 +- src/pages/Oauth/AuthForm/AuthFormField.tsx | 14 ------- src/pages/Oauth/AuthForm/EmailLoginForm.tsx | 19 ++++------ src/pages/Oauth/AuthForm/index.tsx | 42 +-------------------- src/pages/Oauth/Login.tsx | 2 +- yarn.lock | 8 ++-- 6 files changed, 16 insertions(+), 71 deletions(-) delete mode 100644 src/pages/Oauth/AuthForm/AuthFormField.tsx diff --git a/package.json b/package.json index 67bdfd1df0..5507c781c7 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@blocto/web3-react-connector": "^1.0.0", "@coinbase/wallet-sdk": "^3.0.4", "@esbuild-plugins/node-globals-polyfill": "^0.2.3", - "@kybernetwork/oauth2": "1.0.1-rc.7", + "@kybernetwork/oauth2": "1.0.1-rc.8", "@kyberswap/krystal-walletconnect-v2": "0.0.1", "@kyberswap/ks-sdk-classic": "^1.0.3", "@kyberswap/ks-sdk-core": "1.0.11", diff --git a/src/pages/Oauth/AuthForm/AuthFormField.tsx b/src/pages/Oauth/AuthForm/AuthFormField.tsx deleted file mode 100644 index c5163e5831..0000000000 --- a/src/pages/Oauth/AuthForm/AuthFormField.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { LoginFlowUiNode } from '@kybernetwork/oauth2' -import React from 'react' - -interface AuthFormFieldProps extends React.InputHTMLAttributes { - field: LoginFlowUiNode - outline?: boolean -} - -const AuthFormField: React.FC = ({ field }) => { - const attributes = field.attributes - if (field.group === 'oidc') return null - return -} -export default AuthFormField diff --git a/src/pages/Oauth/AuthForm/EmailLoginForm.tsx b/src/pages/Oauth/AuthForm/EmailLoginForm.tsx index e0650a958f..6864000067 100644 --- a/src/pages/Oauth/AuthForm/EmailLoginForm.tsx +++ b/src/pages/Oauth/AuthForm/EmailLoginForm.tsx @@ -1,4 +1,4 @@ -import KyberOauth2 from '@kybernetwork/oauth2' +import KyberOauth2, { LoginMethod } from '@kybernetwork/oauth2' import { Trans, t } from '@lingui/macro' import { useState } from 'react' import styled from 'styled-components' @@ -8,6 +8,7 @@ import Column from 'components/Column' import useParsedQueryString from 'hooks/useParsedQueryString' import { useValidateEmail } from 'pages/NotificationCenter/NotificationPreference' import InputEmailWithVerification from 'pages/NotificationCenter/NotificationPreference/InputEmail' +import useAutoSignIn from 'pages/Oauth/AuthForm/useAutoSignIn' import { FlowStatus } from 'pages/Oauth/Login' import { isEmailValid, queryStringToObject } from 'utils/string' @@ -32,7 +33,7 @@ const EmailLoginForm = ({ flowStatus }: { flowStatus: FlowStatus }) => { setIsShowVerify(true) } - // useAutoSignIn({ method: LoginMethod.EMAIL, onClick: onVerifyEmail, flowStatus }) + useAutoSignIn({ method: LoginMethod.EMAIL, onClick: onVerifyEmail, flowStatus }) const onVerifyCode = async (data: { code: string; email: string }) => { const resp = await KyberOauth2.oauthUi.loginEmail(data) @@ -40,15 +41,11 @@ const EmailLoginForm = ({ flowStatus }: { flowStatus: FlowStatus }) => { } const onSendCode = async ({ email }: { email: string }) => { - return KyberOauth2.oauthUi.sendVerifyCode( - { email, flow: queryStringToObject(window.location.search).flow + '' }, - { - withCredentials: true, - headers: { - 'X-CSRF-Token': window.csrf, - }, - }, - ) + return KyberOauth2.oauthUi.sendVerifyCode({ + email, + flow: queryStringToObject(window.location.search).flow + '', + csrf: window.csrf, + }) } return ( diff --git a/src/pages/Oauth/AuthForm/index.tsx b/src/pages/Oauth/AuthForm/index.tsx index aa7df82896..bf50baa9a0 100644 --- a/src/pages/Oauth/AuthForm/index.tsx +++ b/src/pages/Oauth/AuthForm/index.tsx @@ -1,11 +1,9 @@ -import { LoginFlow, LoginFlowUiNode, LoginMethod } from '@kybernetwork/oauth2' -import axios from 'axios' +import { LoginFlow, LoginMethod } from '@kybernetwork/oauth2' import React, { Fragment, useMemo } from 'react' import { Flex } from 'rebass' import styled from 'styled-components' import useTheme from 'hooks/useTheme' -import AuthFormField from 'pages/Oauth/AuthForm/AuthFormField' import ButtonEth from 'pages/Oauth/AuthForm/ButtonEth' import ButtonGoogle from 'pages/Oauth/AuthForm/ButtonGoogle' import EmailLoginForm from 'pages/Oauth/AuthForm/EmailLoginForm' @@ -68,46 +66,10 @@ const AuthForm: React.FC = ({ formConfig, signInWithEth, flowStat if (!formConfig) return null const { ui } = formConfig - const test = async () => { - try { - const data = new FormData() - const data2 = { - email: 'danh.nguyen@kyber.network', - } - let csrf = '' - ui?.nodes.forEach(el => { - if (el.attributes.name === 'password' || el.attributes.name === 'identifier' || el.attributes.name === 'method') - return - if (el.attributes.name === 'csrf_token') { - csrf = el.attributes.value - } - // data.append(el.attributes.name, el.attributes.value) - // data2[el.attributes.name as any] = el.attributes.value - }) - const resp = await axios.post( - // 'https://identity-api.dev.kyberengineering.io/self-service/login/email/codes?flow=' + - // queryStringToObject(window.location.search).flow, - ui.action.replace('/login', '/login/email/codes'), - data2, - { - withCredentials: true, - headers: { - 'X-CSRF-Token': csrf, - }, - }, - ) - console.log(123, resp) - } catch (error) { - console.log(123, error) - } - } + return (
-
test
- {ui?.nodes?.map((field: LoginFlowUiNode, index: number) => ( - - ))} {nodes.map((el, i) => ( {el} diff --git a/src/pages/Oauth/Login.tsx b/src/pages/Oauth/Login.tsx index 9fc134c628..da6ea1ef5a 100644 --- a/src/pages/Oauth/Login.tsx +++ b/src/pages/Oauth/Login.tsx @@ -111,7 +111,7 @@ export function Login() { const { error_description, type } = queryStringToObject(window.location.search) try { KyberOauth2.initialize({ mode: ENV_KEY }) - const loginFlow = await KyberOauth2.oauthUi.getFlowLogin({ withCredentials: true }) + const loginFlow = await KyberOauth2.oauthUi.getFlowLogin() if (!loginFlow) return setAuthFormConfig(loginFlow) diff --git a/yarn.lock b/yarn.lock index 9e3e260514..9e6381caa5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2257,10 +2257,10 @@ bs58 "^5.0.0" uuid "^8.3.2" -"@kybernetwork/oauth2@1.0.1-rc.7": - version "1.0.1-rc.7" - resolved "https://npm.pkg.github.com/download/@kybernetwork/oauth2/1.0.1-rc.7/dfbdcb5c967e564e8f4fa0c2cb23da4a5d07efe0#dfbdcb5c967e564e8f4fa0c2cb23da4a5d07efe0" - integrity sha512-4VabqXzjY1Z/IhZcrxOQM8BCdCefTDkahHo5a8+lwbdskGipRdnZhx5vYWAcxgwDtGuTO2o8D8i9i4sG0LhRIw== +"@kybernetwork/oauth2@1.0.1-rc.8": + version "1.0.1-rc.8" + resolved "https://npm.pkg.github.com/download/@kybernetwork/oauth2/1.0.1-rc.8/5a3f98c8755ca20446bb0d9dd86ce26b8e33a968#5a3f98c8755ca20446bb0d9dd86ce26b8e33a968" + integrity sha512-xtqs1/Zg32z/O7o7rSK0QmAKfa+18XtqeSYK11f74YdgNJ3fo9bawAV2A5/8Cdvt/oN+f2O+mMfZAjBLmqZfyg== dependencies: axios "1.2.1" client-oauth2 "^4.3.3"