From 759a126fb3004366b6331082813e21769d0d9bc4 Mon Sep 17 00:00:00 2001 From: broody Date: Wed, 29 May 2024 06:48:31 -1000 Subject: [PATCH] Revert "Revert "Fix est fee (#314)" (#315)" This reverts commit 2830319fa30bd1b59822cd16d8d81fbf1a5e5cd6. --- .../src/components/StarknetProvider.tsx | 11 ++++++++++- packages/keychain/src/components/Execute/index.tsx | 10 +++------- packages/keychain/src/pages/index.tsx | 2 -- packages/keychain/src/utils/account.ts | 11 +++++++++-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/examples/starknet-react-next/src/components/StarknetProvider.tsx b/examples/starknet-react-next/src/components/StarknetProvider.tsx index 548dc4d35..e46bf33e9 100644 --- a/examples/starknet-react-next/src/components/StarknetProvider.tsx +++ b/examples/starknet-react-next/src/components/StarknetProvider.tsx @@ -25,7 +25,16 @@ export function StarknetProvider({ children }: PropsWithChildren) { ); } -const url = "https://keychain-git-preview-test.preview.cartridge.gg"; +const 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", + ); const connectors = [ new CartridgeConnector( diff --git a/packages/keychain/src/components/Execute/index.tsx b/packages/keychain/src/components/Execute/index.tsx index 01e2a4b4b..c0695900c 100644 --- a/packages/keychain/src/components/Execute/index.tsx +++ b/packages/keychain/src/components/Execute/index.tsx @@ -58,9 +58,6 @@ export function Execute({ const [ethApproved, setEthApproved] = useState(); const [lowEthInfo, setLowEthInfo] = useState(); const [bridging, setBridging] = useState(false); - // temporary boosting max fees - // @ts-expect-error there's no setter field for now - const [multiplier, setMultiplier] = useState(2n); const account = controller.account(chainId); const calls = useMemo(() => { @@ -103,8 +100,8 @@ export function Execute({ if (account.status === Status.DEPLOYED && transactionsDetail.maxFee) { setFees({ - base: BigInt(transactionsDetail.maxFee) * multiplier, - max: BigInt(transactionsDetail.maxFee) * multiplier, + base: BigInt(transactionsDetail.maxFee), + max: BigInt(transactionsDetail.maxFee), }); return; } @@ -126,7 +123,7 @@ export function Execute({ account .estimateInvokeFee(calls, transactionsDetail) .then((fees) => { - setFees({ base: fees.overall_fee * multiplier, max: fees.suggestedMaxFee * multiplier }); + setFees({ base: fees.overall_fee, max: fees.suggestedMaxFee }); }) .catch((e) => { console.error(e); @@ -141,7 +138,6 @@ export function Execute({ calls, chainId, transactionsDetail, - multiplier ]); useEffect(() => { diff --git a/packages/keychain/src/pages/index.tsx b/packages/keychain/src/pages/index.tsx index e139e6009..9d9a485ab 100644 --- a/packages/keychain/src/pages/index.tsx +++ b/packages/keychain/src/pages/index.tsx @@ -192,8 +192,6 @@ const Index: NextPage = () => { nonce: transactionsDetail.nonce, }) ).suggestedMaxFee; - - console.log("execute", { estFee: transactionsDetail.maxFee }); } if ( diff --git a/packages/keychain/src/utils/account.ts b/packages/keychain/src/utils/account.ts index f7690f9b7..d6bb67d8e 100644 --- a/packages/keychain/src/utils/account.ts +++ b/packages/keychain/src/utils/account.ts @@ -28,6 +28,8 @@ import Storage from "./storage"; import { CartridgeAccount } from "@cartridge/account-wasm"; import { Session } from "@cartridge/controller"; +const EST_FEE_MULTIPLIER = 1000n; + export enum Status { COUNTERFACTUAL = "COUNTERFACTUAL", DEPLOYING = "DEPLOYING", @@ -178,7 +180,7 @@ class Account extends BaseAccount { transactionsDetail.nonce ?? (await this.getNonce("pending")); transactionsDetail.maxFee = num.toHex(transactionsDetail.maxFee); - console.log("account", { estFee: transactionsDetail.maxFee }); + console.log({ estFee: transactionsDetail.maxFee }); const res = await this.cartridge .execute(calls as Array, transactionsDetail, session) @@ -217,7 +219,12 @@ class Account extends BaseAccount { details.nonce = details.nonce ?? (await super.getNonce("pending")); - return await super.estimateInvokeFee(calls, details); + let estFee = await super.estimateInvokeFee(calls, details); + console.log("estimated", { suggestedMax: estFee.suggestedMaxFee }); + estFee.suggestedMaxFee *= EST_FEE_MULTIPLIER; + console.log("estimated", { suggestedMax: estFee.suggestedMaxFee }); + + return estFee; } async verifyMessageHash(