Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: paymaster #907

Merged
merged 9 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 38 additions & 31 deletions hooks/paymaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useAccount,
useConnect,
useSendTransaction,
useSignTypedData,
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved
} from "@starknet-react/core";
import {
AccountInterface,
Expand Down Expand Up @@ -57,6 +58,7 @@ const usePaymaster = (
const [deploymentTypedData, setDeploymentTypedData] = useState<TypedData>();
const [invalidTx, setInvalidTx] = useState<boolean>(false);
const [txError, setTxError] = useState<ErrorMessage>();
const { signTypedDataAsync, error: signError } = useSignTypedData({});

const argentWallet = useMemo(
() => connector?.id === "argentX" /*|| connector?.id === "argentMobile"*/,
Expand Down Expand Up @@ -169,6 +171,11 @@ const usePaymaster = (
loadingDeploymentData
)
return;
console.log({
userAddress: account.address,
calls: callData,
accountClassHash: deploymentData.class_hash,
});
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved
fetch(`${gaslessOptions.baseUrl}/gasless/v1/build-typed-data`, {
method: "POST",
headers: {
Expand Down Expand Up @@ -198,41 +205,41 @@ const usePaymaster = (
loadingDeploymentData,
]);

console.log("signError", signError);

const handleRegister = () => {
if (!account) return;
if (argentWallet && (connector?.id !== "argentMobile" || isDeployed)) {
if (argentWallet || isDeployed) {
if (deploymentData && deploymentTypedData) {
account
.signMessage(
deploymentTypedData,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
{ skipDeploy: true }
)
.then((signature: Signature) => {
fetch(`${gaslessOptions.baseUrl}/gasless/v1/execute`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
userAddress: account.address,
typedData: JSON.stringify(deploymentTypedData),
signature: (signature as string[]).map(decimalToHex),
deploymentData,
}),
signTypedDataAsync(
deploymentTypedData,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
{ skipDeploy: true }
).then((signature: Signature) => {
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved
fetch(`${gaslessOptions.baseUrl}/gasless/v1/execute`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
userAddress: account.address,
typedData: JSON.stringify(deploymentTypedData),
signature: (signature as string[]).map(decimalToHex),
deploymentData,
}),
})
.then((res) => res.json())
.then((data) => {
return then(data.transactionHash);
})
.then((res) => res.json())
.then((data) => {
return then(data.transactionHash);
})
.catch((error) => {
console.error(
"Error when executing (including deployment) with Paymaster:",
error
);
});
});
.catch((error) => {
console.error(
"Error when executing (including deployment) with Paymaster:",
error
);
});
});
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved
} else
executeCalls(
account,
Expand Down
Loading