From a0a01194f626006a8d9f487449570f2bf7e1b8de Mon Sep 17 00:00:00 2001 From: broody Date: Wed, 21 Aug 2024 20:12:04 -0700 Subject: [PATCH 1/2] test webauthn steps --- .../components/providers/StarknetProvider.tsx | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx b/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx index 913f10ec1..d2610f0f0 100644 --- a/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx +++ b/examples/starknet-react-next/src/components/providers/StarknetProvider.tsx @@ -4,7 +4,7 @@ import { Chain, mainnet, sepolia } from "@starknet-react/chains"; import { StarknetConfig, starkscan } from "@starknet-react/core"; import { PropsWithChildren } from "react"; import CartridgeConnector from "@cartridge/connector"; -import { RpcProvider, shortString } from "starknet"; +import { RpcProvider } from "starknet"; export function StarknetProvider({ children }: PropsWithChildren) { return ( @@ -50,20 +50,11 @@ const cartridge = new CartridgeConnector({ method: "allowance", }, ], - url: - !process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL || - process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL.split(".")[0] === - "cartridge-starknet-react-next" - ? process.env.XFRAME_URL - : "https://" + - (process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ?? "").replace( - "cartridge-starknet-react-next", - "keychain", - ), + url: "https://x.cartridge.gg", rpc: process.env.NEXT_PUBLIC_RPC_SEPOLIA, - paymaster: { - caller: shortString.encodeShortString("ANY_CALLER"), - }, + // paymaster: { + // caller: shortString.encodeShortString("ANY_CALLER"), + // }, // theme: "dope-wars", // colorMode: "light" // prefunds: [ From a4d29d1ed7c6536a9f1fb9ee74d047f65879a8a6 Mon Sep 17 00:00:00 2001 From: broody Date: Fri, 30 Aug 2024 09:56:30 -1000 Subject: [PATCH 2/2] calculate webauth gas --- packages/keychain/src/components/Execute/index.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/keychain/src/components/Execute/index.tsx b/packages/keychain/src/components/Execute/index.tsx index 457a1101f..3f2b65fa2 100644 --- a/packages/keychain/src/components/Execute/index.tsx +++ b/packages/keychain/src/components/Execute/index.tsx @@ -19,6 +19,7 @@ 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"; @@ -112,9 +113,16 @@ export function Execute() { const execute = useCallback(async () => { if (!paymaster) { - const maxFee = num.toHex( - ctx.transactionsDetail?.maxFee || ETH_MIN_PREFUND, - ); + let maxFee; + if (ctx.transactionsDetail?.maxFee) { + maxFee = BigInt(ctx.transactionsDetail.maxFee); + } else { + const pending_block = await account.getBlock(); + const gas_price = pending_block.l1_gas_price.price_in_wei; + const est_webauthn_fee = WEBAUTHN_GAS * BigInt(gas_price); + maxFee = num.toHex(est_webauthn_fee + fees.max); + } + let { transaction_hash } = await account.execute(calls, { maxFee }); return transaction_hash;