From 1c6e18aa25d24e042bc7c97b6cf465a1aae2cf96 Mon Sep 17 00:00:00 2001 From: wjrjerome Date: Fri, 10 Jan 2025 21:26:07 +1100 Subject: [PATCH 1/2] chore: use gas price from env --- src/app/hooks/client/rpc/mutation/useBbnTransaction.ts | 5 +++-- src/config/index.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/hooks/client/rpc/mutation/useBbnTransaction.ts b/src/app/hooks/client/rpc/mutation/useBbnTransaction.ts index 3a5d8845..66852a2f 100644 --- a/src/app/hooks/client/rpc/mutation/useBbnTransaction.ts +++ b/src/app/hooks/client/rpc/mutation/useBbnTransaction.ts @@ -1,10 +1,11 @@ import { useCallback } from "react"; +import { BBN_GAS_PRICE } from "@/config"; + import { useSigningStargateClient } from "./useSigningStargateClient"; const GAS_MULTIPLIER = 1.5; const GAS_DENOM = "ubbn"; -const GAS_PRICE = 0.002; export interface BbnGasFee { amount: { denom: string; amount: string }[]; @@ -29,7 +30,7 @@ export const useBbnTransaction = () => { const gasWanted = Math.ceil(gasEstimate * GAS_MULTIPLIER); return { amount: [ - { denom: GAS_DENOM, amount: (gasWanted * GAS_PRICE).toFixed(0) }, + { denom: GAS_DENOM, amount: (gasWanted * BBN_GAS_PRICE).toFixed(0) }, ], gas: gasWanted.toString(), }; diff --git a/src/config/index.ts b/src/config/index.ts index 668a435f..300cafcb 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -24,3 +24,11 @@ export const getBtcNetwork = (): Network => { export const IS_FIXED_TERM_FIELD = process.env.NEXT_PUBLIC_FIXED_STAKING_TERM === "true"; + +export const BBN_GAS_PRICE = (() => { + const price = Number(process.env.NEXT_PUBLIC_BBN_GAS_PRICE) || 0.002; + if (isNaN(price) || price <= 0 || price >= 1) { + return 0.002; // fallback to default if invalid + } + return price; +})(); From f0cd8c095fc813df75159851331cc7795aef420e Mon Sep 17 00:00:00 2001 From: wjrjerome Date: Mon, 13 Jan 2025 20:43:34 +1100 Subject: [PATCH 2/2] add DEFAULT_BBN_GAS_PRICE --- src/config/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/config/index.ts b/src/config/index.ts index 300cafcb..59f42135 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -2,6 +2,9 @@ import { Network } from "@/utils/wallet/btc_wallet_provider"; import { network } from "./network/btc"; +// Default gas price for BABY +const DEFAULT_BBN_GAS_PRICE = 0.002; + // shouldDisplayTestingMsg function is used to check if the application is running in testing mode or not. // Default to true if the environment variable is not set. export const shouldDisplayTestingMsg = (): boolean => { @@ -25,10 +28,11 @@ export const getBtcNetwork = (): Network => { export const IS_FIXED_TERM_FIELD = process.env.NEXT_PUBLIC_FIXED_STAKING_TERM === "true"; +// BBN_GAS_PRICE is used to get the gas price for BABY export const BBN_GAS_PRICE = (() => { - const price = Number(process.env.NEXT_PUBLIC_BBN_GAS_PRICE) || 0.002; + const price = parseFloat(process.env.NEXT_PUBLIC_BBN_GAS_PRICE || ""); if (isNaN(price) || price <= 0 || price >= 1) { - return 0.002; // fallback to default if invalid + return DEFAULT_BBN_GAS_PRICE; // fallback to default if invalid } return price; })();