-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Signless settings component to Manager Settings
- Loading branch information
Showing
5 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/indexer/documents/mutations/account/EnableSignless.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/indexer/documents/mutations/account/RemoveSignless.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.