Skip to content

Commit

Permalink
Merge pull request #2737 from getAlby/feat/onboarding-prompt
Browse files Browse the repository at this point in the history
feat: move onboarding prompt to enable screen
  • Loading branch information
rolznz authored Sep 18, 2023
2 parents 8da1278 + 8aa5748 commit c9e165d
Show file tree
Hide file tree
Showing 30 changed files with 942 additions and 110 deletions.
99 changes: 99 additions & 0 deletions src/app/components/Enable/AlbyEnable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { CheckIcon } from "@bitcoin-design/bitcoin-icons-react/filled";
import ConfirmOrCancel from "@components/ConfirmOrCancel";
import Container from "@components/Container";
import PublisherCard from "@components/PublisherCard";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import ScreenHeader from "~/app/components/ScreenHeader";
import toast from "~/app/components/Toast";
import { USER_REJECTED_ERROR } from "~/common/constants";
import msg from "~/common/lib/msg";
import type { OriginData } from "~/types";

type Props = {
origin: OriginData;
};
function AlbyEnableComponent(props: Props) {
const [loading, setLoading] = useState(false);
const { t } = useTranslation("translation", {
keyPrefix: "alby_enable",
});
const { t: tCommon } = useTranslation("common");

const enable = () => {
try {
setLoading(true);
msg.reply({
enabled: true,
remember: true,
});
} catch (e) {
console.error(e);
if (e instanceof Error) toast.error(`${tCommon("error")}: ${e.message}`);
} finally {
setLoading(false);
}
};

function reject(event: React.MouseEvent<HTMLAnchorElement>) {
event.preventDefault();
msg.error(USER_REJECTED_ERROR);
}

async function block(event: React.MouseEvent<HTMLAnchorElement>) {
event.preventDefault();
await msg.request("addBlocklist", {
domain: props.origin.domain,
host: props.origin.host,
});
alert(tCommon("enable.block_added", { host: props.origin.host }));
msg.error(USER_REJECTED_ERROR);
}

return (
<div className="h-full flex flex-col overflow-y-auto no-scrollbar">
<ScreenHeader title={t("title")} />
<Container justifyBetween maxWidth="sm">
<div>
<PublisherCard
title={props.origin.name}
image={props.origin.icon}
url={props.origin.host}
isSmall={false}
/>

<div className="dark:text-white pt-6">
<p className="mb-2">{tCommon("enable.allow")}</p>

<div className="mb-2 flex items-center">
<CheckIcon className="w-5 h-5 mr-2" />
<p className="dark:text-white">{tCommon("enable.request1")}</p>
</div>
<div className="mb-2 flex items-center">
<CheckIcon className="w-5 h-5 mr-2" />
<p className="dark:text-white">{t("request2")}</p>
</div>
</div>
</div>
<div className="text-center flex flex-col">
<ConfirmOrCancel
disabled={loading}
loading={loading}
label={tCommon("actions.connect")}
onConfirm={enable}
onCancel={reject}
/>
<a
className="mt-4 underline text-sm text-gray-400 overflow-hidden text-ellipsis whitespace-nowrap"
href="#"
onClick={block}
>
{tCommon("enable.block_and_ignore", { host: props.origin.host })}
</a>
</div>
</Container>
</div>
);
}

export default AlbyEnableComponent;
99 changes: 99 additions & 0 deletions src/app/components/Enable/LiquidEnable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { CheckIcon } from "@bitcoin-design/bitcoin-icons-react/filled";
import ConfirmOrCancel from "@components/ConfirmOrCancel";
import Container from "@components/Container";
import PublisherCard from "@components/PublisherCard";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import ScreenHeader from "~/app/components/ScreenHeader";
import toast from "~/app/components/Toast";
import { USER_REJECTED_ERROR } from "~/common/constants";
import msg from "~/common/lib/msg";
import type { OriginData } from "~/types";

type Props = {
origin: OriginData;
};
function LiquidEnableComponent(props: Props) {
const [loading, setLoading] = useState(false);
const { t } = useTranslation("translation", {
keyPrefix: "liquid_enable",
});
const { t: tCommon } = useTranslation("common");

const enable = () => {
try {
setLoading(true);
msg.reply({
enabled: true,
remember: true,
});
} catch (e) {
console.error(e);
if (e instanceof Error) toast.error(`${tCommon("error")}: ${e.message}`);
} finally {
setLoading(false);
}
};

function reject(event: React.MouseEvent<HTMLAnchorElement>) {
event.preventDefault();
msg.error(USER_REJECTED_ERROR);
}

async function block(event: React.MouseEvent<HTMLAnchorElement>) {
event.preventDefault();
await msg.request("addBlocklist", {
domain: props.origin.domain,
host: props.origin.host,
});
alert(tCommon("enable.block_added", { host: props.origin.host }));
msg.error(USER_REJECTED_ERROR);
}

return (
<div className="h-full flex flex-col overflow-y-auto no-scrollbar">
<ScreenHeader title={t("title")} />
<Container justifyBetween maxWidth="sm">
<div>
<PublisherCard
title={props.origin.name}
image={props.origin.icon}
url={props.origin.host}
isSmall={false}
/>

<div className="dark:text-white pt-6">
<p className="mb-2">{tCommon("enable.allow")}</p>

<div className="mb-2 flex items-center">
<CheckIcon className="w-5 h-5 mr-2" />
<p className="dark:text-white">{tCommon("enable.request1")}</p>
</div>
<div className="mb-2 flex items-center">
<CheckIcon className="w-5 h-5 mr-2" />
<p className="dark:text-white">{t("request2")}</p>
</div>
</div>
</div>
<div className="text-center flex flex-col">
<ConfirmOrCancel
disabled={loading}
loading={loading}
label={tCommon("actions.connect")}
onConfirm={enable}
onCancel={reject}
/>
<a
className="mt-4 underline text-sm text-gray-400 overflow-hidden text-ellipsis whitespace-nowrap"
href="#"
onClick={block}
>
{tCommon("enable.block_and_ignore", { host: props.origin.host })}
</a>
</div>
</Container>
</div>
);
}

export default LiquidEnableComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CheckIcon } from "@bitcoin-design/bitcoin-icons-react/filled";
import ConfirmOrCancel from "@components/ConfirmOrCancel";
import Container from "@components/Container";
import PublisherCard from "@components/PublisherCard";
import { useCallback, useEffect, useRef, useState } from "react";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import ScreenHeader from "~/app/components/ScreenHeader";
import toast from "~/app/components/Toast";
Expand All @@ -13,16 +13,14 @@ import type { OriginData } from "~/types";
type Props = {
origin: OriginData;
};

function Enable(props: Props) {
const hasFetchedData = useRef(false);
function NostrEnableComponent(props: Props) {
const [loading, setLoading] = useState(false);
const { t } = useTranslation("translation", {
keyPrefix: "enable",
keyPrefix: "nostr_enable",
});
const { t: tCommon } = useTranslation("common");

const enable = useCallback(() => {
const enable = () => {
try {
setLoading(true);
msg.reply({
Expand All @@ -35,7 +33,7 @@ function Enable(props: Props) {
} finally {
setLoading(false);
}
}, [tCommon]);
};

function reject(event: React.MouseEvent<HTMLAnchorElement>) {
event.preventDefault();
Expand All @@ -48,32 +46,10 @@ function Enable(props: Props) {
domain: props.origin.domain,
host: props.origin.host,
});
alert(t("block_added", { host: props.origin.host }));
alert(tCommon("enable.block_added", { host: props.origin.host }));
msg.error(USER_REJECTED_ERROR);
}

useEffect(() => {
async function getAllowance() {
try {
const allowance = await msg.request("getAllowance", {
domain: props.origin.domain,
host: props.origin.host,
});
if (allowance && allowance.enabled) {
enable();
}
} catch (e) {
if (e instanceof Error) console.error(e.message);
}
}

// Run once.
if (!hasFetchedData.current) {
getAllowance();
hasFetchedData.current = true;
}
}, [enable, props.origin.domain, props.origin.host]);

return (
<div className="h-full flex flex-col overflow-y-auto no-scrollbar">
<ScreenHeader title={t("title")} />
Expand All @@ -87,7 +63,7 @@ function Enable(props: Props) {
/>

<div className="dark:text-white pt-6">
<p className="mb-2">{t("allow")}</p>
<p className="mb-2">{tCommon("enable.allow")}</p>

<div className="mb-2 flex items-center">
<CheckIcon className="w-5 h-5 mr-2" />
Expand All @@ -112,12 +88,12 @@ function Enable(props: Props) {
href="#"
onClick={block}
>
{t("block_and_ignore", { host: props.origin.host })}
{tCommon("enable.block_and_ignore", { host: props.origin.host })}
</a>
</div>
</Container>
</div>
);
}

export default Enable;
export default NostrEnableComponent;
99 changes: 99 additions & 0 deletions src/app/components/Enable/WebbtcEnable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { CheckIcon } from "@bitcoin-design/bitcoin-icons-react/filled";
import ConfirmOrCancel from "@components/ConfirmOrCancel";
import Container from "@components/Container";
import PublisherCard from "@components/PublisherCard";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import ScreenHeader from "~/app/components/ScreenHeader";
import toast from "~/app/components/Toast";
import { USER_REJECTED_ERROR } from "~/common/constants";
import msg from "~/common/lib/msg";
import type { OriginData } from "~/types";

type Props = {
origin: OriginData;
};
function WebbtcEnableComponent(props: Props) {
const [loading, setLoading] = useState(false);
const { t } = useTranslation("translation", {
keyPrefix: "webbtc_enable",
});
const { t: tCommon } = useTranslation("common");

const enable = () => {
try {
setLoading(true);
msg.reply({
enabled: true,
remember: true,
});
} catch (e) {
console.error(e);
if (e instanceof Error) toast.error(`${tCommon("error")}: ${e.message}`);
} finally {
setLoading(false);
}
};

function reject(event: React.MouseEvent<HTMLAnchorElement>) {
event.preventDefault();
msg.error(USER_REJECTED_ERROR);
}

async function block(event: React.MouseEvent<HTMLAnchorElement>) {
event.preventDefault();
await msg.request("addBlocklist", {
domain: props.origin.domain,
host: props.origin.host,
});
alert(tCommon("enable.block_added", { host: props.origin.host }));
msg.error(USER_REJECTED_ERROR);
}

return (
<div className="h-full flex flex-col overflow-y-auto no-scrollbar">
<ScreenHeader title={t("title")} />
<Container justifyBetween maxWidth="sm">
<div>
<PublisherCard
title={props.origin.name}
image={props.origin.icon}
url={props.origin.host}
isSmall={false}
/>

<div className="dark:text-white pt-6">
<p className="mb-2">{tCommon("enable.allow")}</p>

<div className="mb-2 flex items-center">
<CheckIcon className="w-5 h-5 mr-2" />
<p className="dark:text-white">{tCommon("enable.request1")}</p>
</div>
<div className="mb-2 flex items-center">
<CheckIcon className="w-5 h-5 mr-2" />
<p className="dark:text-white">{t("request2")}</p>
</div>
</div>
</div>
<div className="text-center flex flex-col">
<ConfirmOrCancel
disabled={loading}
loading={loading}
label={tCommon("actions.connect")}
onConfirm={enable}
onCancel={reject}
/>
<a
className="mt-4 underline text-sm text-gray-400 overflow-hidden text-ellipsis whitespace-nowrap"
href="#"
onClick={block}
>
{tCommon("enable.block_and_ignore", { host: props.origin.host })}
</a>
</div>
</Container>
</div>
);
}

export default WebbtcEnableComponent;
Loading

0 comments on commit c9e165d

Please sign in to comment.