Skip to content

Commit

Permalink
feat: Add Signless settings component to Manager Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Mar 3, 2025
1 parent 5cfb86c commit dba5c8d
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 0 deletions.
91 changes: 91 additions & 0 deletions apps/web/src/components/Settings/Manager/Signless.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import trackEvent from "@helpers/analytics";
import errorToast from "@helpers/errorToast";
import { APP_NAME } from "@hey/data/constants";
import { Errors } from "@hey/data/errors";
import { Events } from "@hey/data/events";
import {
useEnableSignlessMutation,
useRemoveSignlessMutation
} from "@hey/indexer";
import { Button, Card, CardHeader } from "@hey/ui";
import type { FC } from "react";
import { useState } from "react";
import toast from "react-hot-toast";
import useTransactionLifecycle from "src/hooks/useTransactionLifecycle";
import { useAccountStatus } from "src/store/non-persisted/useAccountStatus";
import { useAccountStore } from "src/store/persisted/useAccountStore";

const Signless: FC = () => {
const { isSignlessEnabled } = useAccountStore();
const { isSuspended } = useAccountStatus();
const [isSubmitting, setIsSubmitting] = useState(false);
const handleTransactionLifecycle = useTransactionLifecycle();

const onCompleted = () => {
setIsSubmitting(false);
trackEvent(Events.Account.UpdateSettings, { type: "toggle_signless" });
toast.success("Signless enabled");
};

const onError = (error: any) => {
setIsSubmitting(false);
errorToast(error);
};

const [enableSignless] = useEnableSignlessMutation({
onCompleted: async ({ enableSignless }) => {
return await handleTransactionLifecycle({
transactionData: enableSignless,
onCompleted,
onError
});
},
onError
});

const [removeSignless] = useRemoveSignlessMutation({
onCompleted: async ({ removeSignless }) => {
return await handleTransactionLifecycle({
transactionData: removeSignless,
onCompleted,
onError
});
},
onError
});

const handleToggleSignless = async () => {
if (isSuspended) {
return toast.error(Errors.Suspended);
}

setIsSubmitting(true);

return isSignlessEnabled ? await removeSignless() : await enableSignless();
};

return (
<Card>
<CardHeader
body={`You can enable Signless to interact with ${APP_NAME} without signing any of your transactions.`}
title={
isSignlessEnabled
? "Disable signless transactions"
: "Enable signless transactions"
}
/>
<div className="m-5">
<Button
className="mr-auto"
disabled={isSubmitting}
onClick={handleToggleSignless}
variant={isSignlessEnabled ? "danger" : "primary"}
>
{isSignlessEnabled ? "Disable" : "Enable"}
</Button>
</div>
</Card>
);
};

export default Signless;
2 changes: 2 additions & 0 deletions apps/web/src/components/Settings/Manager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { NextPage } from "next";
import { useAccountStore } from "src/store/persisted/useAccountStore";
import SettingsSidebar from "../Sidebar";
import AccountManager from "./AccountManager";
import Signless from "./Signless";

const ManagerSettings: NextPage = () => {
const { currentAccount } = useAccountStore();
Expand All @@ -21,6 +22,7 @@ const ManagerSettings: NextPage = () => {
<SettingsSidebar />
</GridItemFour>
<GridItemEight className="space-y-5">
<Signless />
<AccountManager />
</GridItemEight>
</GridLayout>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mutation EnableSignless {
enableSignless {
... on SelfFundedTransactionRequest {
...SelfFundedTransactionRequest
}
... on SponsoredTransactionRequest {
...SponsoredTransactionRequest
}
... on TransactionWillFail {
...TransactionWillFail
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mutation RemoveSignless {
removeSignless {
... on SelfFundedTransactionRequest {
...SelfFundedTransactionRequest
}
... on SponsoredTransactionRequest {
...SponsoredTransactionRequest
}
... on TransactionWillFail {
...TransactionWillFail
}
}
}
Loading

0 comments on commit dba5c8d

Please sign in to comment.