From 1408521348fc71adc8f2bb89483714c16f0a5b5d Mon Sep 17 00:00:00 2001 From: schmanu Date: Wed, 1 Nov 2023 18:24:20 +0100 Subject: [PATCH] fix: login error handling --- src/components/common/SocialSigner/index.tsx | 54 +++++++++++--------- src/services/exceptions/ErrorCodes.ts | 1 + src/services/mpc/SocialWalletService.ts | 7 +-- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/components/common/SocialSigner/index.tsx b/src/components/common/SocialSigner/index.tsx index 8b14e58160..bbd3c06c67 100644 --- a/src/components/common/SocialSigner/index.tsx +++ b/src/components/common/SocialSigner/index.tsx @@ -18,6 +18,8 @@ import { TxModalContext } from '@/components/tx-flow' import { COREKIT_STATUS } from '@web3auth/mpc-core-kit' import useSocialWallet from '@/hooks/wallets/mpc/useSocialWallet' import madProps from '@/utils/mad-props' +import { asError } from '@/services/exceptions/utils' +import ErrorMessage from '@/components/tx/ErrorMessage' export const _getSupportedChains = (chains: ChainInfo[]) => { return chains @@ -54,6 +56,7 @@ export const SocialSigner = ({ onLogin, }: SocialSignerLoginProps) => { const [loginPending, setLoginPending] = useState(false) + const [loginError, setLoginError] = useState(undefined) const { setTxFlow } = useContext(TxModalContext) const userInfo = socialWalletService?.getUserInfo() const isDisabled = loginPending || !isMPCLoginEnabled @@ -76,39 +79,44 @@ export const SocialSigner = ({ if (!socialWalletService) return setLoginPending(true) + setLoginError(undefined) + try { + const status = await socialWalletService.loginAndCreate() - const status = await socialWalletService.loginAndCreate() + if (status === COREKIT_STATUS.LOGGED_IN) { + onLogin?.() + setLoginPending(false) + return + } - if (status === COREKIT_STATUS.LOGGED_IN) { - onLogin?.() + if (status === COREKIT_STATUS.REQUIRED_SHARE) { + setTxFlow( + { + onLogin?.() + setLoginPending(false) + }} + />, + () => {}, + false, + ) + return + } + } catch (err) { + const error = asError(err) + setLoginError(error.message) + } finally { setLoginPending(false) - return } - - if (status === COREKIT_STATUS.REQUIRED_SHARE) { - setTxFlow( - { - onLogin?.() - setLoginPending(false) - }} - />, - () => {}, - false, - ) - return - } - - // TODO: Show error if login fails - setLoginPending(false) } const isSocialLogin = isSocialLoginWallet(wallet?.label) return ( <> - + + {loginError && {loginError}} {isSocialLogin && userInfo ? (