Skip to content

Commit

Permalink
Migrate to Lens v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoginth committed Dec 6, 2024
1 parent b46042d commit ff56266
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import errorToast from "@helpers/errorToast";
import { Errors } from "@hey/data/errors";
import selfFundedTransactionData from "@hey/helpers/selfFundedTransactionData";
import sponsoredTransactionData from "@hey/helpers/sponsoredTransactionData";
import { useEnableSignlessMutation } from "@hey/indexer";
import {
useEnableSignlessMutation,
useRemoveSignlessMutation
} from "@hey/indexer";
import { Button } from "@hey/ui";
import cn from "@hey/ui/cn";
import type { FC } from "react";
Expand All @@ -21,7 +24,7 @@ interface ToggleLensManagerProps {
const ToggleLensManager: FC<ToggleLensManagerProps> = ({
buttonSize = "md"
}) => {
const { currentAccount } = useAccountStore();
const { isSignlessEnabled } = useAccountStore();
const { isSuspended } = useAccountStatus();
const [isLoading, setIsLoading] = useState(false);
const [txHash, setTxHash] = useState<`0x${string}` | null>(null);
Expand Down Expand Up @@ -70,14 +73,47 @@ const ToggleLensManager: FC<ToggleLensManagerProps> = ({
onError
});

const [removeSignless] = useRemoveSignlessMutation({
onCompleted: async ({ removeSignless }) => {
if (walletClient) {
try {
if (removeSignless.__typename === "SponsoredTransactionRequest") {
const hash = await sendEip712Transaction(walletClient, {
account: walletClient.account,
...sponsoredTransactionData(removeSignless.raw)
});

return onCompleted(hash);
}

if (removeSignless.__typename === "SelfFundedTransactionRequest") {
const hash = await sendTransaction(walletClient, {
account: walletClient.account,
...selfFundedTransactionData(removeSignless.raw)
});

return onCompleted(hash);
}
} catch (error) {
return onError(error);
}
}

if (removeSignless.__typename === "TransactionWillFail") {
return toast.error(removeSignless.reason);
}
},
onError
});

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

setIsLoading(true);

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

return txHash ? (
Expand All @@ -89,9 +125,9 @@ const ToggleLensManager: FC<ToggleLensManagerProps> = ({
className={cn({ "text-sm": buttonSize === "sm" }, "mr-auto")}
disabled={isLoading}
onClick={handleToggleDispatcher}
variant={currentAccount?.isSignless ? "danger" : "primary"}
variant={isSignlessEnabled ? "danger" : "primary"}
>
{currentAccount?.isSignless ? "Disable" : "Enable"}
{isSignlessEnabled ? "Disable" : "Enable"}
</Button>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { useAccountStore } from "src/store/persisted/useAccountStore";
import ToggleLensManager from "./ToggleLensManager";

const LensManager: FC = () => {
const { currentAccount } = useAccountStore();
const { isSignlessEnabled } = useAccountStore();

return (
<Card>
<CardHeader
body={`You can enable Lens manager to interact with ${APP_NAME} without
signing any of your transactions.`}
title={
currentAccount?.isSignless
isSignlessEnabled
? "Disable signless transactions"
: "Signless transactions"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mutation RemoveSignless {
removeSignless {
... on SelfFundedTransactionRequest {
...SelfFundedTransactionRequestFields
}
... on SponsoredTransactionRequest {
...SponsoredTransactionRequestFields
}
... on TransactionWillFail {
reason
}
}
}
37 changes: 37 additions & 0 deletions packages/indexer/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6246,6 +6246,17 @@ export type RemoveAccountManagerMutation = { __typename?: 'Mutation', removeAcco
& SponsoredTransactionRequestFieldsFragment
) | { __typename?: 'TransactionWillFail', reason: string } };

export type RemoveSignlessMutationVariables = Exact<{ [key: string]: never; }>;


export type RemoveSignlessMutation = { __typename?: 'Mutation', removeSignless: (
{ __typename?: 'SelfFundedTransactionRequest' }
& SelfFundedTransactionRequestFieldsFragment
) | (
{ __typename?: 'SponsoredTransactionRequest' }
& SponsoredTransactionRequestFieldsFragment
) | { __typename?: 'TransactionWillFail', reason: string } };

export type ReportAccountMutationVariables = Exact<{
request: ReportAccountRequest;
}>;
Expand Down Expand Up @@ -7239,6 +7250,32 @@ export function useRemoveAccountManagerMutation(baseOptions?: Apollo.MutationHoo
export type RemoveAccountManagerMutationHookResult = ReturnType<typeof useRemoveAccountManagerMutation>;
export type RemoveAccountManagerMutationResult = Apollo.MutationResult<RemoveAccountManagerMutation>;
export type RemoveAccountManagerMutationOptions = Apollo.BaseMutationOptions<RemoveAccountManagerMutation, RemoveAccountManagerMutationVariables>;
export const RemoveSignlessDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"RemoveSignless"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"removeSignless"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SelfFundedTransactionRequest"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SelfFundedTransactionRequestFields"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SponsoredTransactionRequest"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SponsoredTransactionRequestFields"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"TransactionWillFail"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"reason"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SelfFundedTransactionRequestFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SelfFundedTransactionRequest"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"reason"}},{"kind":"Field","name":{"kind":"Name","value":"raw"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chainId"}},{"kind":"Field","name":{"kind":"Name","value":"data"}},{"kind":"Field","name":{"kind":"Name","value":"from"}},{"kind":"Field","name":{"kind":"Name","value":"gasLimit"}},{"kind":"Field","name":{"kind":"Name","value":"maxFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"maxPriorityFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"nonce"}},{"kind":"Field","name":{"kind":"Name","value":"to"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"value"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SponsoredTransactionRequestFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"SponsoredTransactionRequest"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"reason"}},{"kind":"Field","name":{"kind":"Name","value":"raw"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chainId"}},{"kind":"Field","name":{"kind":"Name","value":"data"}},{"kind":"Field","name":{"kind":"Name","value":"from"}},{"kind":"Field","name":{"kind":"Name","value":"gasLimit"}},{"kind":"Field","name":{"kind":"Name","value":"maxFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"maxPriorityFeePerGas"}},{"kind":"Field","name":{"kind":"Name","value":"nonce"}},{"kind":"Field","name":{"kind":"Name","value":"to"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"value"}},{"kind":"Field","name":{"kind":"Name","value":"customData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"customSignature"}},{"kind":"Field","name":{"kind":"Name","value":"factoryDeps"}},{"kind":"Field","name":{"kind":"Name","value":"gasPerPubdata"}},{"kind":"Field","name":{"kind":"Name","value":"paymasterParams"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"paymaster"}},{"kind":"Field","name":{"kind":"Name","value":"paymasterInput"}}]}}]}}]}}]}}]} as unknown as DocumentNode;
export type RemoveSignlessMutationFn = Apollo.MutationFunction<RemoveSignlessMutation, RemoveSignlessMutationVariables>;

/**
* __useRemoveSignlessMutation__
*
* To run a mutation, you first call `useRemoveSignlessMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useRemoveSignlessMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [removeSignlessMutation, { data, loading, error }] = useRemoveSignlessMutation({
* variables: {
* },
* });
*/
export function useRemoveSignlessMutation(baseOptions?: Apollo.MutationHookOptions<RemoveSignlessMutation, RemoveSignlessMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<RemoveSignlessMutation, RemoveSignlessMutationVariables>(RemoveSignlessDocument, options);
}
export type RemoveSignlessMutationHookResult = ReturnType<typeof useRemoveSignlessMutation>;
export type RemoveSignlessMutationResult = Apollo.MutationResult<RemoveSignlessMutation>;
export type RemoveSignlessMutationOptions = Apollo.BaseMutationOptions<RemoveSignlessMutation, RemoveSignlessMutationVariables>;
export const ReportAccountDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"ReportAccount"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"request"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ReportAccountRequest"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"reportAccount"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"request"},"value":{"kind":"Variable","name":{"kind":"Name","value":"request"}}}]}]}}]} as unknown as DocumentNode;
export type ReportAccountMutationFn = Apollo.MutationFunction<ReportAccountMutation, ReportAccountMutationVariables>;

Expand Down

0 comments on commit ff56266

Please sign in to comment.