-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
280 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Box, BoxProps, Center, Icon, Image } from '@chakra-ui/react' | ||
|
||
import Twitter from '../assets/twitter.svg?react' | ||
|
||
interface Props extends BoxProps { | ||
omitBadge?: boolean | ||
size?: number | ||
src?: string | ||
} | ||
|
||
export function TwitterAvatar({ size, src, omitBadge, ...props }: Props) { | ||
return ( | ||
<Box pos="relative" width={size} height={size} {...props}> | ||
<Image | ||
width={size} | ||
height={size} | ||
border="2px solid" | ||
borderColor="gradient.purple" | ||
borderRadius="50%" | ||
objectFit="cover" | ||
draggable={false} | ||
userSelect="none" | ||
src={src} | ||
fallbackSrc={new URL('../assets/default-avatar.svg', import.meta.url).href} | ||
alt="user name" | ||
/> | ||
{omitBadge ? null : ( | ||
<Center width="14px" height="14px" pos="absolute" bg="white" rounded={14} right={0} bottom="-4px" color="black"> | ||
<Icon as={Twitter} width="10px" height="10px" /> | ||
</Center> | ||
)} | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query' | ||
import { fetchJSON } from '../helpers/fetchJSON' | ||
import { FIREFLY_API_ROOT } from '../constants/api' | ||
import urlcat from 'urlcat' | ||
import { UpdateUserInfoParams, UpdateUserInfoResponse } from '../types/api' | ||
import { useAccount, useSignMessage } from 'wagmi' | ||
|
||
// Any message is ok. | ||
const message = 'Update Profile' | ||
export function useUpdateUserInfo() { | ||
const { signMessageAsync } = useSignMessage() | ||
const account = useAccount() | ||
const queryClient = useQueryClient() | ||
return useMutation({ | ||
mutationKey: ['update-user-info', account.address], | ||
mutationFn: async (params: Pick<UpdateUserInfoParams, 'show_avatar' | 'display_username'>) => { | ||
if (!account.address) return | ||
const signed = await signMessageAsync({ message }) | ||
const url = urlcat(FIREFLY_API_ROOT, '/v1/mask_stake/twitter/update') | ||
const payload: UpdateUserInfoParams = { | ||
...params, | ||
original_message: message, | ||
signature_message: signed.slice(2), // omit 0x | ||
wallet_address: account.address, | ||
} | ||
return fetchJSON<UpdateUserInfoResponse>(url, { | ||
method: 'POST', | ||
body: JSON.stringify(payload), | ||
}) | ||
}, | ||
onSuccess() { | ||
queryClient.refetchQueries({ queryKey: ['user-info'] }) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Button, Flex, FormControl, FormLabel, Input, ModalProps, Switch, useToast } from '@chakra-ui/react' | ||
import { t } from '@lingui/macro' | ||
import { useId, useState } from 'react' | ||
import { GradientButton } from '../components/GradientButton' | ||
import { TwitterAvatar } from '../components/TwitterAvatar' | ||
import { useUpdateUserInfo } from '../hooks/useUpdateUserInfo' | ||
import { useUserInfo } from '../hooks/useUserInfo' | ||
import { BaseModal } from './BaseModal' | ||
|
||
export function ProfileModal(props: ModalProps) { | ||
const { data: userInfo } = useUserInfo() | ||
const switchId = useId() | ||
const [username = userInfo?.twitter_display_name, setUsername] = useState<string>() | ||
const [showAvatar = userInfo?.twitter_show_image, setShowAvatar] = useState<boolean>() | ||
const updateUserInfo = useUpdateUserInfo() | ||
const toast = useToast() | ||
return ( | ||
<BaseModal title={t`Profile`} width={450} height={468} {...props}> | ||
<FormControl> | ||
<FormLabel mb={3}>{t`Profile Name`}</FormLabel> | ||
<Input | ||
size="lg" | ||
color="neutrals.4" | ||
rounded={12} | ||
fontSize={14} | ||
fontFamily="input" | ||
fontWeight={700} | ||
type="text" | ||
value={username} | ||
onChange={(e) => { | ||
setUsername(e.currentTarget.value) | ||
}} | ||
/> | ||
</FormControl> | ||
<FormControl mt={6}> | ||
<FormLabel mb={3}>{t`Avatar`}</FormLabel> | ||
<TwitterAvatar size={90} src={userInfo?.twitter_image} omitBadge /> | ||
</FormControl> | ||
<FormControl mt={6} display="flex" flexDir="row" alignItems="center"> | ||
<Switch | ||
size="lg" | ||
isChecked={showAvatar} | ||
id={switchId} | ||
onChange={(e) => { | ||
setShowAvatar(e.currentTarget.checked) | ||
}} | ||
/> | ||
<FormLabel htmlFor={switchId} mb={0} ml={3} fontSize={12} color="neutrals.1">{t`Show Avatar`}</FormLabel> | ||
</FormControl> | ||
<Flex justifyContent="space-between" gap={3} mt={6}> | ||
<Button rounded={24} flexGrow={1}>{t`Cancel`}</Button> | ||
<GradientButton | ||
flexGrow={1} | ||
disabled={!username} | ||
onClick={async () => { | ||
if (!username) { | ||
toast({ | ||
status: 'error', | ||
title: t`Profile Name is required`, | ||
}) | ||
return | ||
} | ||
const res = await updateUserInfo.mutateAsync({ | ||
display_username: username, | ||
show_avatar: !!showAvatar, | ||
}) | ||
if (res?.code !== 0 && res?.reason) { | ||
toast({ | ||
status: 'error', | ||
title: res.reason, | ||
}) | ||
return | ||
} | ||
props.onClose() | ||
}} | ||
>{t`Confirm`}</GradientButton> | ||
</Flex> | ||
</BaseModal> | ||
) | ||
} |
Oops, something went wrong.