Skip to content

Commit

Permalink
Calculate webauthn fee
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Aug 30, 2024
1 parent c7fce07 commit 4bcf835
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages/keychain/src/components/Execute/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { Policies } from "Policies";
import { Fees } from "./Fees";
import { ExecuteCtx } from "utils/connection";
import { TransferAmountExceedsBalance } from "errors";
import { ETH_MIN_PREFUND } from "utils/token";
import { num } from "starknet";

export const WEBAUTHN_GAS = 3300n;
export const CONTRACT_ETH =
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";

Expand Down Expand Up @@ -87,7 +87,12 @@ export function Execute() {
account
.estimateInvokeFee(calls, ctx.transactionsDetail)
.then((fees) => {
setFees({ base: fees.overall_fee, max: fees.suggestedMaxFee });
let webauthn_fee = WEBAUTHN_GAS * BigInt(fees.gas_price);

setFees({
base: fees.overall_fee + webauthn_fee,
max: fees.suggestedMaxFee + webauthn_fee,
});
})
.catch((e) => {
if (e.message.includes("ERC20: transfer amount exceeds balance")) {
Expand All @@ -112,14 +117,12 @@ export function Execute() {

const execute = useCallback(async () => {
if (!paymaster) {
const maxFee = num.toHex(
ctx.transactionsDetail?.maxFee || ETH_MIN_PREFUND,
);
let { transaction_hash } = await account.execute(calls, { maxFee });

let { transaction_hash } = await account.execute(calls, {
maxFee: num.toHex(fees.max),
});

return transaction_hash;
}

try {
return await account.executeFromOutside(calls, paymaster);
} catch (error) {
Expand Down Expand Up @@ -171,10 +174,8 @@ export function Execute() {
console.warn(
"Paymaster not supported, falling back to regular execution",
);
const maxFee = num.toHex(
ctx.transactionsDetail?.maxFee || ETH_MIN_PREFUND,
);
let { transaction_hash } = await account.execute(calls, { maxFee });
let { transaction_hash } = await account.execute(calls, { maxFee: num.toHex(fees.max) });

return transaction_hash;
} else {
throw error; // Re-throw other errors
Expand All @@ -183,7 +184,7 @@ export function Execute() {
throw error;
}
}
}, [account, calls, paymaster, ctx.transactionsDetail]);
}, [account, calls, paymaster, fees, ctx.transactionsDetail]);

const onSubmit = useCallback(async () => {
setLoading(true);
Expand Down

0 comments on commit 4bcf835

Please sign in to comment.