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

chore: use gas price from env #619

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions src/app/hooks/client/rpc/mutation/useBbnTransaction.ts
Original file line number Diff line number Diff line change
@@ -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 }[];
Expand All @@ -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(),
};
Expand Down
12 changes: 12 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -24,3 +27,12 @@ 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 = parseFloat(process.env.NEXT_PUBLIC_BBN_GAS_PRICE || "");
if (isNaN(price) || price <= 0 || price >= 1) {
return DEFAULT_BBN_GAS_PRICE; // fallback to default if invalid
}
return price;
})();