Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: recover account section in settings #190

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/wallet/src/apis/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
10 changes: 3 additions & 7 deletions apps/wallet/src/pages/account-manage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, AuthenticatorType> = {
'telegram': AuthenticatorType.Telegram
}
import { authProviderTypeMap } from "../../utils/auth";

const AccountManagePage: FC = () => {
const { t } = useTranslation()
Expand All @@ -29,8 +25,8 @@ const AccountManagePage: FC = () => {
{userLoginsQuery.data?.map((login) => (
<li className="flex justify-between items-center" key={login.loginProvider}>
<div className="flex items-center gap-4">
<AuthenticatorLogo type={authProviderLogoMap[login.loginProvider]} className="size-6" />
<span className="text-xs">{login.providerKey}</span>
<AuthenticatorLogo type={authProviderTypeMap[login.loginProvider]} className="size-6" />
<span className="text-xs">{login.userDisplayName}</span>
</div>
{/* // TODO: delete api */}
{userLoginsQuery.data?.length > 1 && (
Expand Down
38 changes: 24 additions & 14 deletions apps/wallet/src/pages/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className="h-full px-6 overflow-auto">
<PageHeader title={t('page_settings_title')} />

{/* // TODO: TEMP HIDE */}
{/* <div className="mt-6">
<div className="mt-6">
<p className="label-text text-neutral text-sm font-bold">
{t('page_settings_account')}
</p>
<div className="mt-2 flex justify-between items-center">
<div className="flex items-center gap-2 text-xs">
<AuthenticatorLogo type={AuthenticatorType.Telegram} className="size-6" />
<span>{userName}</span>
</div>
<button className="btn btn-link btn-sm no-underline p-0" onClick={() => {
{!loginInfo ? (
<span className="loading loading-spinner"></span>
) : (
<div className="flex items-center gap-2 text-xs">
<AuthenticatorLogo type={authProviderTypeMap[loginInfo.loginProvider]} className="size-6" />
<span>{loginInfo.userDisplayName}</span>
</div>
)}
{/* // TODO: TEMP HIDE */}
{/* <button className="btn btn-link btn-sm no-underline p-0" onClick={() => {
navigate('/account-manage')
}}>
{t('page_settings_linkMore')}
</button>
</button> */}
</div>
</div> */}
</div>

<div className="mt-6">
<p className="label-text text-neutral text-sm font-bold">
Expand Down
9 changes: 9 additions & 0 deletions apps/wallet/src/utils/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, AuthenticatorType> = {
'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,
Expand Down