|
| 1 | +import { CheckIcon } from "@bitcoin-design/bitcoin-icons-react/filled"; |
| 2 | +import ConfirmOrCancel from "@components/ConfirmOrCancel"; |
| 3 | +import Container from "@components/Container"; |
| 4 | +import PublisherCard from "@components/PublisherCard"; |
| 5 | +import Checkbox from "@components/form/Checkbox"; |
| 6 | +import { useState } from "react"; |
| 7 | +import { useTranslation } from "react-i18next"; |
| 8 | +import ScreenHeader from "~/app/components/ScreenHeader"; |
| 9 | +import { useNavigationState } from "~/app/hooks/useNavigationState"; |
| 10 | +import { USER_REJECTED_ERROR } from "~/common/constants"; |
| 11 | +import msg from "~/common/lib/msg"; |
| 12 | +import utils from "~/common/lib/utils"; |
| 13 | +import { OriginData } from "~/types"; |
| 14 | + |
| 15 | +function NostrConfirm() { |
| 16 | + const { t } = useTranslation("translation", { |
| 17 | + keyPrefix: "nostr", |
| 18 | + }); |
| 19 | + const { t: tCommon } = useTranslation("common"); |
| 20 | + const navState = useNavigationState(); |
| 21 | + const origin = navState.origin as OriginData; |
| 22 | + const description = navState.args?.description; |
| 23 | + const details = navState.args?.details; |
| 24 | + const [loading, setLoading] = useState(false); |
| 25 | + const [rememberPermission, setRememberPermission] = useState(false); |
| 26 | + |
| 27 | + function confirm() { |
| 28 | + setLoading(true); |
| 29 | + msg.reply({ |
| 30 | + confirm: true, |
| 31 | + rememberPermission, |
| 32 | + }); |
| 33 | + setLoading(false); |
| 34 | + } |
| 35 | + |
| 36 | + function reject(event: React.MouseEvent<HTMLAnchorElement>) { |
| 37 | + event.preventDefault(); |
| 38 | + msg.error(USER_REJECTED_ERROR); |
| 39 | + } |
| 40 | + |
| 41 | + async function block(event: React.MouseEvent<HTMLAnchorElement>) { |
| 42 | + event.preventDefault(); |
| 43 | + await utils.call("addBlocklist", { |
| 44 | + domain: origin.domain, |
| 45 | + host: origin.host, |
| 46 | + }); |
| 47 | + msg.error(USER_REJECTED_ERROR); |
| 48 | + } |
| 49 | + |
| 50 | + return ( |
| 51 | + <div className="h-full flex flex-col overflow-y-auto no-scrollbar"> |
| 52 | + <ScreenHeader title={t("title")} /> |
| 53 | + <Container justifyBetween maxWidth="sm"> |
| 54 | + <div> |
| 55 | + <PublisherCard |
| 56 | + title={origin.name} |
| 57 | + image={origin.icon} |
| 58 | + url={origin.host} |
| 59 | + isSmall={false} |
| 60 | + /> |
| 61 | + <div className="dark:text-white pt-6 mb-4"> |
| 62 | + <p className="mb-2">{t("allow", { host: origin.host })}</p> |
| 63 | + <p className="dark:text-white"> |
| 64 | + <CheckIcon className="w-5 h-5 mr-2 inline" /> |
| 65 | + {description} |
| 66 | + {details && ( |
| 67 | + <> |
| 68 | + <br /> |
| 69 | + <i className="ml-7">{details}</i> |
| 70 | + </> |
| 71 | + )} |
| 72 | + </p> |
| 73 | + </div> |
| 74 | + |
| 75 | + <div className="flex items-center"> |
| 76 | + <Checkbox |
| 77 | + id="remember_permission" |
| 78 | + name="remember_permission" |
| 79 | + checked={rememberPermission} |
| 80 | + onChange={(event) => { |
| 81 | + setRememberPermission(event.target.checked); |
| 82 | + }} |
| 83 | + /> |
| 84 | + <label |
| 85 | + htmlFor="remember_permission" |
| 86 | + className="cursor-pointer ml-2 block text-sm text-gray-900 font-medium dark:text-white" |
| 87 | + > |
| 88 | + {t("confirm_sign_message.remember.label")} |
| 89 | + </label> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + <div className="mb-4 text-center flex flex-col"> |
| 93 | + <ConfirmOrCancel |
| 94 | + disabled={loading} |
| 95 | + loading={loading} |
| 96 | + label={tCommon("actions.confirm")} |
| 97 | + onConfirm={confirm} |
| 98 | + onCancel={reject} |
| 99 | + /> |
| 100 | + <a |
| 101 | + className="underline text-sm text-gray-400 mx-4 overflow-hidden text-ellipsis whitespace-nowrap" |
| 102 | + href="#" |
| 103 | + onClick={block} |
| 104 | + > |
| 105 | + {t("block_and_ignore", { host: origin.host })} |
| 106 | + </a> |
| 107 | + </div> |
| 108 | + </Container> |
| 109 | + </div> |
| 110 | + ); |
| 111 | +} |
| 112 | + |
| 113 | +export default NostrConfirm; |
0 commit comments