From 77f31e55a6f9d2cfc178e8d43bc9cb7d41853570 Mon Sep 17 00:00:00 2001 From: Rustin Date: Wed, 30 Oct 2024 17:05:52 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20recover=20account=20section?= =?UTF-8?q?=20in=20settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wallet/src/apis/models.ts | 7 ++-- .../wallet/src/pages/account-manage/index.tsx | 10 ++--- apps/wallet/src/pages/settings/index.tsx | 38 ++++++++++++------- apps/wallet/src/utils/auth/index.ts | 9 +++++ 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/apps/wallet/src/apis/models.ts b/apps/wallet/src/apis/models.ts index 73e0164..edbbb35 100644 --- a/apps/wallet/src/apis/models.ts +++ b/apps/wallet/src/apis/models.ts @@ -409,9 +409,10 @@ export class UpdateMnemonicResult extends GetMnemonicResult { } export class GetUserLoginsResultItem { - providerKey!: string - loginProvider!: string - providerDisplayName!: string + providerKey!: string // user id + loginProvider!: string // provider id, eg. 'telegram', 'google', 'twitter' + providerDisplayName!: string // provider name + userDisplayName!: string // user name } export type GetUserLoginsResult = GetUserLoginsResultItem[] diff --git a/apps/wallet/src/pages/account-manage/index.tsx b/apps/wallet/src/pages/account-manage/index.tsx index 26d6794..3000f5a 100644 --- a/apps/wallet/src/pages/account-manage/index.tsx +++ b/apps/wallet/src/pages/account-manage/index.tsx @@ -2,14 +2,10 @@ import { FC } from "react"; import SvgTrash from '../../assets/trash.svg?react' import { useNavigate } from "react-router-dom"; import AuthenticatorLogo from "../../components/AuthenticatorLogo"; -import { AuthenticatorType } from "@delandlabs/hibit-id-sdk"; import { useTranslation } from "react-i18next"; import { useUserLoginsQuery } from "../../apis/react-query/auth"; import PageHeader from "../../components/PageHeader"; - -const authProviderLogoMap: Record = { - 'telegram': AuthenticatorType.Telegram -} +import { authProviderTypeMap } from "../../utils/auth"; const AccountManagePage: FC = () => { const { t } = useTranslation() @@ -29,8 +25,8 @@ const AccountManagePage: FC = () => { {userLoginsQuery.data?.map((login) => (
  • - - {login.providerKey} + + {login.userDisplayName}
    {/* // TODO: delete api */} {userLoginsQuery.data?.length > 1 && ( diff --git a/apps/wallet/src/pages/settings/index.tsx b/apps/wallet/src/pages/settings/index.tsx index d94725c..7ff111a 100644 --- a/apps/wallet/src/pages/settings/index.tsx +++ b/apps/wallet/src/pages/settings/index.tsx @@ -1,42 +1,52 @@ import { observer } from "mobx-react"; -import { FC } from "react"; +import { FC, useMemo } from "react"; import { useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; import AuthenticatorLogo from "../../components/AuthenticatorLogo"; -import { AuthenticatorType } from "@delandlabs/hibit-id-sdk"; import hibitIdSession from "../../stores/session"; import PageHeader from "../../components/PageHeader"; import SvgGo from '../../assets/right-arrow.svg?react' import { languages } from "../../utils/lang"; +import { useUserLoginsQuery } from "../../apis/react-query/auth"; +import { authProviderTypeMap } from "../../utils/auth"; const SettingsPage: FC = observer(() => { const navigate = useNavigate() const { t } = useTranslation() + const userLoginsQuery = useUserLoginsQuery() + + const loginInfo = useMemo(() => { + if (!userLoginsQuery.data?.length) { + return null + } + return userLoginsQuery.data[0] + }, [userLoginsQuery.data]) - const userName: string = (hibitIdSession.auth?.decodedIdToken?.preferred_username - || hibitIdSession.auth?.decodedIdToken?.unique_name) as string - return (
    - {/* // TODO: TEMP HIDE */} - {/*
    +

    {t('page_settings_account')}

    -
    - - {userName} -
    - + */}
    -
    */} +

    diff --git a/apps/wallet/src/utils/auth/index.ts b/apps/wallet/src/utils/auth/index.ts index 04fb774..faa3bfe 100644 --- a/apps/wallet/src/utils/auth/index.ts +++ b/apps/wallet/src/utils/auth/index.ts @@ -5,7 +5,16 @@ import { prOidc } from "../oidc"; import { GoogleAuthenticateProvider } from "./providers/google"; import { XAuthenticateProvider } from "./providers/x"; +// TODO: add more auth parties +export const authProviderTypeMap: Record = { + 'telegram': AuthenticatorType.Telegram, + 'google': AuthenticatorType.Google, + 'x': AuthenticatorType.X, + 'twitter': AuthenticatorType.X, +} + export class AuthManager { + // TODO: add more auth parties public static readonly supportedAuthenticators: AuthenticatorType[] = [ AuthenticatorType.Telegram, AuthenticatorType.Google,