Skip to content

Commit

Permalink
rm test code
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Oct 17, 2023
1 parent c845a04 commit 0702f19
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 71 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 0 additions & 14 deletions src/pages/Oauth/AuthForm/AuthFormField.tsx

This file was deleted.

19 changes: 8 additions & 11 deletions src/pages/Oauth/AuthForm/EmailLoginForm.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'

Expand All @@ -32,23 +33,19 @@ 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)
console.debug('resp loginEmail', resp)
}

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 (
Expand Down
42 changes: 2 additions & 40 deletions src/pages/Oauth/AuthForm/index.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -68,46 +66,10 @@ const AuthForm: React.FC<AuthFormProps> = ({ 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 (
<Form encType="application/x-www-form-urlencoded" action={ui.action} method={ui.method}>
<div onClick={test}>test</div>
<AuthFormFieldMessage messages={ui.messages} />
{ui?.nodes?.map((field: LoginFlowUiNode, index: number) => (
<AuthFormField key={index} field={field} />
))}
{nodes.map((el, i) => (
<Fragment key={i}>
{el}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Oauth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0702f19

Please sign in to comment.