diff --git a/src/app/pages/TempleTapAirdrop/confirmed.svg b/src/app/pages/TempleTapAirdrop/confirmed.svg new file mode 100644 index 000000000..c0ef2e4f5 --- /dev/null +++ b/src/app/pages/TempleTapAirdrop/confirmed.svg @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/src/app/pages/TempleTapAirdrop/index.tsx b/src/app/pages/TempleTapAirdrop/index.tsx index c8d6d8778..814b5814f 100644 --- a/src/app/pages/TempleTapAirdrop/index.tsx +++ b/src/app/pages/TempleTapAirdrop/index.tsx @@ -1,13 +1,23 @@ -import React, { FC, memo, PropsWithChildren, useMemo } from 'react'; +import React, { FC, memo, PropsWithChildren, useCallback, useMemo, useState } from 'react'; -import { Alert, Anchor } from 'app/atoms'; +import { isAxiosError } from 'axios'; +import { OnSubmit, useForm } from 'react-hook-form'; + +import { Alert, Anchor, FormField, FormSubmitButton } from 'app/atoms'; import { ReactComponent as TelegramSvg } from 'app/icons/social-tg.svg'; import { ReactComponent as XSocialSvg } from 'app/icons/social-x.svg'; import PageLayout from 'app/layouts/PageLayout'; +import { sendTempleTapAirdropUsernameConfirmation } from 'lib/apis/temple-tap'; +import { t } from 'lib/i18n'; import { useAccount } from 'lib/temple/front'; import { TempleAccountType } from 'lib/temple/types'; import BannerImgSrc from './banner.png'; +import { ReactComponent as ConfirmedSvg } from './confirmed.svg'; + +interface FormData { + username: string; +} export const TempleTapAirdropPage = memo(() => { const account = useAccount(); @@ -17,6 +27,32 @@ export const TempleTapAirdropPage = memo(() => { [account.type] ); + const { register, handleSubmit, errors, setError, clearError, formState, reset } = useForm(); + + const submitting = formState.isSubmitting; + const [confirmSent, setConfirmSent] = useState(false); + const [confirmed, setConfirmed] = useState(false); + + const onSubmit = useCallback>( + async ({ username }) => { + clearError(); + + try { + await sendTempleTapAirdropUsernameConfirmation(account.publicKeyHash, username); + + setConfirmSent(true); + reset(); + } catch (error: any) { + if (isAxiosError(error) && error.response?.data.code === 'ACCOUNT_CONFIRMED') { + return void setConfirmed(true); + } + + setError('username', 'submit-error', error?.response.data?.message || 'Something went wrong...'); + } + }, + [reset, clearError, setError, account.publicKeyHash] + ); + return (
@@ -33,18 +69,59 @@ export const TempleTapAirdropPage = memo(() => { How to receive TKEY? + {confirmSent && ( + + )} + {canSign ? ( - -
- Your address: - {account.publicKeyHash} -
-
+ confirmed ? ( + + + + ) : ( + +
+ Your address: + {account.publicKeyHash} +
+ +
+ + + + Confirm + + +
+ ) ) : ( - + )} > = ({ title, description, children }) => ( -
+
{title}

{description}

@@ -96,3 +173,5 @@ const SocialItem: FC = ({ title, IconComp, followUrl }) => (
); + +const TG_USERNAME_REGEX = /^@[a-zA-Z0-9](?:[a-zA-Z0-9_]{3,}[a-zA-Z0-9])$/; diff --git a/src/lib/apis/temple-tap.ts b/src/lib/apis/temple-tap.ts new file mode 100644 index 000000000..f84a641a6 --- /dev/null +++ b/src/lib/apis/temple-tap.ts @@ -0,0 +1,8 @@ +import { templeWalletApi } from './temple/endpoints/templewallet.api'; + +export function sendTempleTapAirdropUsernameConfirmation(accountPkh: string, username: string) { + return templeWalletApi.post('/temple-tap/confirm-airdrop-username', { + accountPkh, + username + }); +}