UNPKG

@particle-network/authkit

Version:

Auth Core provides MPC (Multi-Party Computation)-based threshold signatures.

8 lines (7 loc) 9.6 kB
{ "version": 3, "sources": ["../../src/pages/index/index.tsx", "../../src/components/socialLoading/index.tsx"], "sourcesContent": ["import { isConnected, isSocialAuthType } from '@particle-network/auth-core';\nimport { message } from 'antd';\nimport base64url from 'base64url';\nimport qs from 'qs';\nimport React, { useEffect, useState } from 'react';\nimport SocialLoading from '../../components/socialLoading';\nimport { useCustomNavigate, useParticleAuth } from '../../context';\nimport { useConnect } from '../../context/hooks';\nimport { isServer } from '../../utils';\nimport styles from './index.less';\n\nconst Index = () => {\n const { connect } = useConnect();\n const navigate = useCustomNavigate();\n const { setConnectionStatus, socialConnectCallback, setAuthCoreModal } = useParticleAuth();\n const [socialLoginLoading, setSocialLoginLoading] = React.useState(false);\n const [authType, setAuthType] = useState<string>('' as string);\n const [socialLoginFailed, setSocialLoginFailed] = useState(false);\n\n const onConnectCompleted = (detail: any) => {\n if (window.particle?.ethereum) {\n window.particle.ethereum.isSocialConnecting = false;\n }\n if (window.particle?.solana) {\n window.particle.solana.isSocialConnecting = false;\n }\n window.dispatchEvent(\n new CustomEvent('particle:socialConnectCompleted', {\n detail,\n })\n );\n };\n\n const thirdpartyLogin = async () => {\n try {\n const query = qs.parse(!isServer() ? window.location.search : '', {\n ignoreQueryPrefix: true,\n });\n const particleThirdpartyParamsContent = query?.particleThirdpartyParams as string;\n if (!particleThirdpartyParamsContent) {\n if (!isConnected()) {\n setConnectionStatus('disconnected');\n }\n return;\n }\n\n delete query.particleThirdpartyParams;\n const replaceUrl = (window.location.origin + window.location.pathname + '?' + qs.stringify(query)).replace(\n /\\?$/,\n ''\n );\n window.history.replaceState({}, document.title, replaceUrl);\n document.title = document.title || replaceUrl;\n\n const particleThirdpartyParams = JSON.parse(base64url.decode(particleThirdpartyParamsContent as string));\n const { code, nonce, appState, error } = particleThirdpartyParams;\n const appStateObj = appState ? JSON.parse(base64url.decode(appState as string)) : {};\n const { authorization, chain, purpose, verifyToken } = appStateObj;\n\n if (error) {\n if (!isConnected()) {\n setConnectionStatus('disconnected');\n }\n if (!purpose) {\n socialConnectCallback?.onError?.(new Error(error));\n } else {\n message.error(error);\n }\n\n if (purpose !== 'bindLoginAccount') {\n setSocialLoginFailed(true);\n }\n\n return;\n }\n\n const authType = nonce.split('@')[0];\n setAuthType(authType);\n\n if (purpose === 'bindLoginAccount') {\n navigate('/login-account/bind-loading', {\n state: {\n authType,\n verifyToken,\n code,\n nonce,\n },\n replace: true,\n });\n } else {\n if (isSocialAuthType(authType)) {\n setSocialLoginLoading(true);\n setAuthCoreModal({\n particleModalVisible: true,\n });\n }\n console.log(`auth-core-modal: social:${authType} connect start`);\n await connect({ socialType: authType, code, nonce, authorization, chain });\n }\n } catch (error: any) {\n console.error('after redirect, login or bind', error);\n if (!isConnected()) {\n setConnectionStatus('disconnected');\n }\n onConnectCompleted({\n result: Object.freeze(error),\n });\n }\n setSocialLoginLoading(false);\n };\n\n useEffect(() => {\n thirdpartyLogin();\n }, []);\n\n return (\n <div className='index-container'>\n <style>{styles as unknown as string}</style>\n {socialLoginLoading && <SocialLoading authType={authType} isFailed={socialLoginFailed} />}\n </div>\n );\n};\n\nexport default Index;\n", "import type { SocialAuthType } from '@particle-network/auth-core';\nimport React from 'react';\nimport loading from '../../common/images/loading2.png';\nimport { useParticleAuth, useTranslation } from '../../context';\nimport useLogin from '../../context/hooks/useLogin';\nimport { getLoginLogos } from '../../utils';\nimport SVGIcon from '../icon/svg-icon';\nimport PowerFooter from '../power-footer';\nimport styles from './index.less';\n\nconst SocialLoading = ({ authType, isFailed = true }: { authType: string; isFailed: boolean }) => {\n const { t } = useTranslation();\n\n const [spin, setSpin] = React.useState(!isFailed);\n\n const { socialAuthLogin } = useLogin();\n\n const { modalOptions } = useParticleAuth();\n\n return (\n <div className='social-loading-content'>\n <style>{styles as unknown as string}</style>\n <div className='wrap'>\n <div\n className={`social-logo-content ${isFailed ? 'failed' : ''}`}\n onClick={() => {\n if (!isFailed || spin) return;\n\n setSpin(true);\n socialAuthLogin({\n socialType: authType as SocialAuthType,\n });\n }}\n >\n <div className='logo'>\n <img src={getLoginLogos(modalOptions.themeType)[authType] || ''} alt='logo' />\n </div>\n {spin && (\n <div className='spin'>\n <img src={loading} alt='loading' />\n </div>\n )}\n\n {isFailed && !spin && (\n <div className='refresh-btn'>\n <SVGIcon className='refresh-icon' name='refresh_icon' />\n </div>\n )}\n </div>\n <div className='title'>{!isFailed ? t('login.logging_you_in') : t('login.request_failed')}</div>\n {isFailed && <div className='desc'>{t('login.something_wrong')}</div>}\n </div>\n <PowerFooter className='footer-box-v2' />\n </div>\n );\n};\n\nexport default SocialLoading;\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa,wBAAwB;AAC9C,SAAS,eAAe;AACxB,OAAO,eAAe;AACtB,OAAO,QAAQ;AACf,OAAOA,UAAS,WAAW,gBAAgB;;;ACH3C,OAAO,WAAW;;;;;;AASlB,IAAM,gBAAgB,CAAC,EAAE,UAAU,WAAW,KAAK,MAA+C;AAChG,QAAM,EAAE,EAAE,IAAI,eAAe;AAE7B,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,CAAC,QAAQ;AAEhD,QAAM,EAAE,gBAAgB,IAAI,iBAAS;AAErC,QAAM,EAAE,aAAa,IAAI,gBAAgB;AAEzC,SACE,oCAAC,SAAI,WAAU,4BACb,oCAAC,eAAO,qBAA4B,GACpC,oCAAC,SAAI,WAAU,UACb;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,uBAAuB,WAAW,WAAW;AAAA,MACxD,SAAS,MAAM;AACb,YAAI,CAAC,YAAY;AAAM;AAEvB,gBAAQ,IAAI;AACZ,wBAAgB;AAAA,UACd,YAAY;AAAA,QACd,CAAC;AAAA,MACH;AAAA;AAAA,IAEA,oCAAC,SAAI,WAAU,UACb,oCAAC,SAAI,KAAK,cAAc,aAAa,SAAS,EAAE,aAAa,IAAI,KAA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