From 052ba0ac9184b70a5f938fd2f4db1697568499e3 Mon Sep 17 00:00:00 2001 From: yjshi <495054021@qq.com> Date: Sun, 24 Nov 2024 17:09:57 +0800 Subject: [PATCH 1/3] optimize domain display --- .../components/accounts/NicknameDialog.tsx | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/apps/wallet/src/ui/app/components/accounts/NicknameDialog.tsx b/apps/wallet/src/ui/app/components/accounts/NicknameDialog.tsx index 515d07b7c1652..0ad0dda0e8993 100644 --- a/apps/wallet/src/ui/app/components/accounts/NicknameDialog.tsx +++ b/apps/wallet/src/ui/app/components/accounts/NicknameDialog.tsx @@ -1,6 +1,7 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { useResolveSuiNSName } from '_app/hooks/useAppResolveSuinsName'; import { Dialog, DialogContent, @@ -10,7 +11,7 @@ import { DialogTrigger, } from '_src/ui/app/shared/Dialog'; import { useZodForm } from '@mysten/core'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import toast from 'react-hot-toast'; import { z } from 'zod'; @@ -22,6 +23,7 @@ import { TextField } from '../../shared/forms/TextField'; const formSchema = z.object({ nickname: z.string().trim(), + useDomain: z.boolean().optional(), }); interface NicknameDialogProps { @@ -29,30 +31,51 @@ interface NicknameDialogProps { trigger: JSX.Element; } +type FormValues = { + nickname: string; + useDomain?: boolean; +}; + export function NicknameDialog({ accountID, trigger }: NicknameDialogProps) { const [open, setOpen] = useState(false); const backgroundClient = useBackgroundClient(); const { data: accounts } = useAccounts(); const account = accounts?.find((account) => account.id === accountID); + const domainName = useResolveSuiNSName(account?.address); const form = useZodForm({ mode: 'all', schema: formSchema, defaultValues: { nickname: account?.nickname ?? '', + useDomain: false, }, }); + const { register, + watch, + setValue, formState: { isSubmitting, isValid }, } = form; - const onSubmit = async ({ nickname }: { nickname: string }) => { + const useDomain = watch('useDomain'); + + useEffect(() => { + if (useDomain) { + setValue('nickname', ''); + } else { + setValue('nickname', account?.nickname ?? ''); + } + }, [useDomain, account?.nickname, setValue]); + + const onSubmit = async ({ nickname, useDomain }: FormValues) => { if (account && accountID) { try { + const finalNickname = useDomain ? null : nickname; await backgroundClient.setAccountNickname({ id: accountID, - nickname: nickname || null, + nickname: finalNickname, }); setOpen(false); } catch (e) { @@ -72,7 +95,22 @@ export function NicknameDialog({ accountID, trigger }: NicknameDialogProps) {
- + {domainName && ( +
+ + +
+ )} +
); -} +} \ No newline at end of file From f3588691d6ff0b039115224cb39365e1b28e0ff2 Mon Sep 17 00:00:00 2001 From: yjshi <495054021@qq.com> Date: Sun, 24 Nov 2024 17:29:06 +0800 Subject: [PATCH 2/3] Adjustment of text --- apps/wallet/src/ui/app/components/accounts/NicknameDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wallet/src/ui/app/components/accounts/NicknameDialog.tsx b/apps/wallet/src/ui/app/components/accounts/NicknameDialog.tsx index 0ad0dda0e8993..f0a0e4ae184ee 100644 --- a/apps/wallet/src/ui/app/components/accounts/NicknameDialog.tsx +++ b/apps/wallet/src/ui/app/components/accounts/NicknameDialog.tsx @@ -99,7 +99,7 @@ export function NicknameDialog({ accountID, trigger }: NicknameDialogProps) {