|
1 | 1 | import { InformationCircleIcon } from "@heroicons/react/24/outline";
|
| 2 | +import { useLocalStorageValue } from "@react-hookz/web"; |
2 | 3 | import Image from "next/image";
|
3 |
| -import { type ComponentProps, type ReactNode, useCallback } from "react"; |
| 4 | +import { |
| 5 | + type ComponentProps, |
| 6 | + type FormEvent, |
| 7 | + type ReactNode, |
| 8 | + useCallback, |
| 9 | + useState, |
| 10 | +} from "react"; |
4 | 11 | import {
|
5 | 12 | DialogTrigger,
|
| 13 | + Form, |
6 | 14 | Button as ReactAriaButton,
|
7 | 15 | } from "react-aria-components";
|
8 | 16 |
|
9 | 17 | import background from "./background.png";
|
10 | 18 | import { type States, StateType as ApiStateType } from "../../hooks/use-api";
|
11 | 19 | import { StateType, useAsync } from "../../hooks/use-async";
|
12 |
| -import { Button } from "../Button"; |
| 20 | +import { Button, LinkButton } from "../Button"; |
| 21 | +import { Checkbox } from "../Checkbox"; |
| 22 | +import { Link } from "../Link"; |
13 | 23 | import { ModalDialog } from "../ModalDialog";
|
14 | 24 | import { Tokens } from "../Tokens";
|
15 |
| -import { TransferButton } from "../TransferButton"; |
| 25 | +import { TransferButton, TransferDialog } from "../TransferButton"; |
16 | 26 |
|
17 | 27 | type Props = {
|
18 | 28 | api: States[ApiStateType.Loaded] | States[ApiStateType.LoadedNoStakeAccount];
|
@@ -108,13 +118,7 @@ export const AccountSummary = ({
|
108 | 118 | </>
|
109 | 119 | )}
|
110 | 120 | <div className="mt-3 flex flex-row items-center gap-4 sm:mt-8">
|
111 |
| - <TransferButton |
112 |
| - actionDescription="Add funds to your balance" |
113 |
| - actionName="Add Tokens" |
114 |
| - max={walletAmount} |
115 |
| - transfer={api.deposit} |
116 |
| - enableWithZeroMax |
117 |
| - /> |
| 121 | + <AddTokensButton walletAmount={walletAmount} api={api} /> |
118 | 122 | {availableToWithdraw === 0n ? (
|
119 | 123 | <DialogTrigger>
|
120 | 124 | <Button variant="secondary" className="xl:hidden">
|
@@ -354,3 +358,147 @@ const ClaimButton = ({ api, ...props }: ClaimButtonProps) => {
|
354 | 358 | </Button>
|
355 | 359 | );
|
356 | 360 | };
|
| 361 | + |
| 362 | +type AddTokensButtonProps = { |
| 363 | + walletAmount: bigint; |
| 364 | + api: States[ApiStateType.Loaded] | States[ApiStateType.LoadedNoStakeAccount]; |
| 365 | +}; |
| 366 | + |
| 367 | +const AddTokensButton = ({ walletAmount, api }: AddTokensButtonProps) => { |
| 368 | + const hasAcknowledgedLegal = useLocalStorageValue("has-acknowledged-legal"); |
| 369 | + const [transferOpen, setTransferOpen] = useState(false); |
| 370 | + const openTransfer = useCallback(() => { |
| 371 | + setTransferOpen(true); |
| 372 | + }, [setTransferOpen]); |
| 373 | + const acknowledgeLegal = useCallback(() => { |
| 374 | + hasAcknowledgedLegal.set("true"); |
| 375 | + openTransfer(); |
| 376 | + }, [hasAcknowledgedLegal, openTransfer]); |
| 377 | + |
| 378 | + return ( |
| 379 | + <> |
| 380 | + {hasAcknowledgedLegal.value ? ( |
| 381 | + <Button onPress={openTransfer}>Add Tokens</Button> |
| 382 | + ) : ( |
| 383 | + <DisclosureButton onAcknowledge={acknowledgeLegal} /> |
| 384 | + )} |
| 385 | + <TransferDialog |
| 386 | + title="Add tokens" |
| 387 | + description="Add funds to your balance" |
| 388 | + max={walletAmount} |
| 389 | + transfer={api.deposit} |
| 390 | + submitButtonText="Add tokens" |
| 391 | + isOpen={transferOpen} |
| 392 | + onOpenChange={setTransferOpen} |
| 393 | + /> |
| 394 | + </> |
| 395 | + ); |
| 396 | +}; |
| 397 | + |
| 398 | +type DisclosureButtonProps = { |
| 399 | + onAcknowledge: () => void; |
| 400 | +}; |
| 401 | + |
| 402 | +const DisclosureButton = ({ onAcknowledge }: DisclosureButtonProps) => { |
| 403 | + const [understood, setUnderstood] = useState(false); |
| 404 | + const [agreed, setAgreed] = useState(false); |
| 405 | + const [open, setOpen] = useState(false); |
| 406 | + const acknowledge = useCallback( |
| 407 | + (e: FormEvent<HTMLFormElement>) => { |
| 408 | + e.preventDefault(); |
| 409 | + setOpen(false); |
| 410 | + setTimeout(onAcknowledge, 400); |
| 411 | + }, |
| 412 | + [setOpen, onAcknowledge], |
| 413 | + ); |
| 414 | + |
| 415 | + return ( |
| 416 | + <> |
| 417 | + <DialogTrigger isOpen={open} onOpenChange={setOpen}> |
| 418 | + <Button>Add Tokens</Button> |
| 419 | + <ModalDialog title="Disclosure"> |
| 420 | + <Form onSubmit={acknowledge}> |
| 421 | + <p className="max-w-prose text-sm opacity-60"> |
| 422 | + THE SERVICES WERE NOT DEVELOPED FOR, AND ARE NOT AVAILABLE TO |
| 423 | + PERSONS OR ENTITIES WHO RESIDE IN, ARE LOCATED IN, ARE |
| 424 | + INCORPORATED IN, OR HAVE A REGISTERED OFFICE OR PRINCIPAL PLACE OF |
| 425 | + BUSINESS IN THE UNITED STATES OF AMERICA, THE UNITED KINGDOM OR |
| 426 | + CANADA (COLLECTIVELY, “BLOCKED PERSONS”). MOREOVER, THE SERVICES |
| 427 | + ARE NOT OFFERED TO PERSONS OR ENTITIES WHO RESIDE IN, ARE CITIZENS |
| 428 | + OF, ARE LOCATED IN, ARE INCORPORATED IN, OR HAVE A REGISTERED |
| 429 | + OFFICE OR PRINCIPAL PLACE OF BUSINESS IN ANY RESTRICTED |
| 430 | + JURISDICTION OR COUNTRY SUBJECT TO ANY SANCTIONS OR RESTRICTIONS |
| 431 | + PURSUANT TO ANY APPLICABLE LAW, INCLUDING THE CRIMEA REGION, CUBA, |
| 432 | + IRAN, NORTH KOREA, SYRIA, MYANMAR (BURMA, DONETSK, LUHANSK, OR ANY |
| 433 | + OTHER COUNTRY TO WHICH THE UNITED STATES, THE UNITED KINGDOM, THE |
| 434 | + EUROPEAN UNION OR ANY OTHER JURISDICTIONS EMBARGOES GOODS OR |
| 435 | + IMPOSES SIMILAR SANCTIONS, INCLUDING THOSE LISTED ON OUR SERVICES |
| 436 | + (COLLECTIVELY, THE “RESTRICTED JURISDICTIONS” AND EACH A |
| 437 | + “RESTRICTED JURISDICTION”) OR ANY PERSON OWNED, CONTROLLED, |
| 438 | + LOCATED IN OR ORGANIZED UNDER THE LAWS OF ANY JURISDICTION UNDER |
| 439 | + EMBARGO OR CONNECTED OR AFFILIATED WITH ANY SUCH PERSON |
| 440 | + (COLLECTIVELY, “RESTRICTED PERSONS”). THE WEBSITE WAS NOT |
| 441 | + SPECIFICALLY DEVELOPED FOR, AND IS NOT AIMED AT OR BEING ACTIVELY |
| 442 | + MARKETED TO, PERSONS OR ENTITIES WHO RESIDE IN, ARE LOCATED IN, |
| 443 | + ARE INCORPORATED IN, OR HAVE A REGISTERED OFFICE OR PRINCIPAL |
| 444 | + PLACE OF BUSINESS IN THE EUROPEAN UNION. THERE ARE NO EXCEPTIONS. |
| 445 | + IF YOU ARE A BLOCKED PERSON OR A RESTRICTED PERSON, THEN DO NOT |
| 446 | + USE OR ATTEMPT TO USE THE SERVICES. USE OF ANY TECHNOLOGY OR |
| 447 | + MECHANISM, SUCH AS A VIRTUAL PRIVATE NETWORK (“VPN”) TO CIRCUMVENT |
| 448 | + THE RESTRICTIONS SET FORTH HEREIN IS PROHIBITED. |
| 449 | + </p> |
| 450 | + <Checkbox |
| 451 | + className="my-4 block max-w-prose" |
| 452 | + isSelected={understood} |
| 453 | + onChange={setUnderstood} |
| 454 | + > |
| 455 | + I understand |
| 456 | + </Checkbox> |
| 457 | + <Checkbox |
| 458 | + className="my-4 block max-w-prose" |
| 459 | + isSelected={agreed} |
| 460 | + onChange={setAgreed} |
| 461 | + > |
| 462 | + By checking the box and access the Services, you acknowledge and |
| 463 | + agree to the terms and conditions of our{" "} |
| 464 | + <Link |
| 465 | + href="https://www.pyth.network/terms-of-use" |
| 466 | + target="_blank" |
| 467 | + className="underline" |
| 468 | + > |
| 469 | + Terms of Use |
| 470 | + </Link>{" "} |
| 471 | + and{" "} |
| 472 | + <Link |
| 473 | + href="https://www.pyth.network/privacy-policy" |
| 474 | + target="_blank" |
| 475 | + className="underline" |
| 476 | + > |
| 477 | + Privacy Policy |
| 478 | + </Link> |
| 479 | + . |
| 480 | + </Checkbox> |
| 481 | + <div className="mt-14 flex flex-col gap-8 sm:flex-row sm:justify-between"> |
| 482 | + <LinkButton |
| 483 | + className="w-full sm:w-auto" |
| 484 | + href="https://pyth.network/" |
| 485 | + variant="secondary" |
| 486 | + size="noshrink" |
| 487 | + > |
| 488 | + Exit |
| 489 | + </LinkButton> |
| 490 | + <Button |
| 491 | + className="w-full sm:w-auto" |
| 492 | + size="noshrink" |
| 493 | + type="submit" |
| 494 | + isDisabled={!understood || !agreed} |
| 495 | + > |
| 496 | + Confirm |
| 497 | + </Button> |
| 498 | + </div> |
| 499 | + </Form> |
| 500 | + </ModalDialog> |
| 501 | + </DialogTrigger> |
| 502 | + </> |
| 503 | + ); |
| 504 | +}; |
0 commit comments