diff --git a/package-lock.json b/package-lock.json index 428e5786..d310daa2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "simple-staking", - "version": "0.2.32", + "version": "0.2.33", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "simple-staking", - "version": "0.2.32", + "version": "0.2.33", "dependencies": { "@bitcoinerlab/secp256k1": "^1.1.1", "@keystonehq/animated-qr": "^0.8.6", @@ -16,7 +16,7 @@ "@tanstack/react-query": "^5.28.14", "@tanstack/react-query-next-experimental": "^5.28.14", "@uidotdev/usehooks": "^2.4.1", - "axios": "^1.6.8", + "axios": "^1.7.4", "bitcoinjs-lib": "^6.1.5", "btc-staking-ts": "^0.2.10", "date-fns": "^3.6.0", @@ -6273,9 +6273,9 @@ } }, "node_modules/axios": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", - "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", + "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", diff --git a/package.json b/package.json index 0794c648..0029140f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-staking", - "version": "0.2.32", + "version": "0.2.33", "private": true, "scripts": { "dev": "next dev", @@ -28,8 +28,8 @@ "@scure/bip32": "^1.4.0", "@tanstack/react-query": "^5.28.14", "@tanstack/react-query-next-experimental": "^5.28.14", + "axios": "^1.7.4", "@uidotdev/usehooks": "^2.4.1", - "axios": "^1.6.8", "bitcoinjs-lib": "^6.1.5", "btc-staking-ts": "^0.2.10", "date-fns": "^3.6.0", diff --git a/src/app/components/Staking/FinalityProviders/FinalityProviders.tsx b/src/app/components/Staking/FinalityProviders/FinalityProviders.tsx index b3b0bcc2..e93cb32c 100644 --- a/src/app/components/Staking/FinalityProviders/FinalityProviders.tsx +++ b/src/app/components/Staking/FinalityProviders/FinalityProviders.tsx @@ -14,8 +14,6 @@ import { useError } from "@/app/context/Error/ErrorContext"; import { useFinalityProvidersData } from "@/app/hooks/finalityProviders/useFinalityProvidersData"; import { ErrorState } from "@/app/types/errors"; import { FinalityProvidersProps } from "@/app/types/finalityProviders"; -import { getNetworkConfig } from "@/config/network.config"; -import { Network } from "@/utils/wallet/wallet_provider"; import { FinalityProvider } from "./FinalityProvider"; import { FinalityProviderSearch } from "./FinalityProviderSearch"; @@ -102,25 +100,9 @@ export const FinalityProviders: React.FC = ({ return ; } - const network = getNetworkConfig().network; - const createFinalityProviderLink = `https://github.com/babylonlabs-io/networks/tree/main/${ - network == Network.MAINNET ? "bbn-1" : "bbn-test-4" - }/finality-providers`; - return ( <> -

- Select a finality provider or{" "} - - create your own - - . -

+

Select a finality provider.

diff --git a/src/app/components/Staking/Form/StakingAmount.tsx b/src/app/components/Staking/Form/StakingAmount.tsx index a680754b..2ce5d531 100644 --- a/src/app/components/Staking/Form/StakingAmount.tsx +++ b/src/app/components/Staking/Form/StakingAmount.tsx @@ -23,6 +23,7 @@ export const StakingAmount: React.FC = ({ }) => { const [value, setValue] = useState(""); const [error, setError] = useState(""); + // Track if the input field has been interacted with const [touched, setTouched] = useState(false); @@ -51,16 +52,8 @@ export const StakingAmount: React.FC = ({ } }; - const handleBlur = (_e: FocusEvent) => { - if (!btcWalletBalanceSat) return; - setTouched(true); - - if (value === "") { - onStakingAmountSatChange(0); - setError(generalErrorMessage); - return; - } - + useEffect(() => { + if (btcWalletBalanceSat === undefined || value === "") return; const numValue = parseFloat(value); const satoshis = btcToSatoshi(numValue); @@ -103,6 +96,22 @@ export const StakingAmount: React.FC = ({ onStakingAmountSatChange(satoshis); setValue(maxDecimals(satoshiToBtc(satoshis), 8).toString()); } + }, [ + btcWalletBalanceSat, + minStakingAmountSat, + maxStakingAmountSat, + value, + onStakingAmountSatChange, + coinName, + ]); + + const handleBlur = (_e: FocusEvent) => { + if (value === "") { + onStakingAmountSatChange(0); + setError(generalErrorMessage); + return; + } + setTouched(true); }; const minStakeAmount = maxDecimals(satoshiToBtc(minStakingAmountSat), 8); diff --git a/src/app/components/Staking/Staking.tsx b/src/app/components/Staking/Staking.tsx index dc2193e8..67544de3 100644 --- a/src/app/components/Staking/Staking.tsx +++ b/src/app/components/Staking/Staking.tsx @@ -363,10 +363,19 @@ export const Staking: React.FC = ({ ); return stakingFeeSat; } catch (error: Error | any) { + let errorMsg = error?.message; + // Turn the error message into a user-friendly message + // The btc-staking-ts lib will be improved to return propert error types + // in the future. For now, we need to handle the errors manually by + // matching the error message. + if (errorMsg.includes("Insufficient funds")) { + errorMsg = + "Not enough balance to cover staking amount and fees, please lower the staking amount"; + } // fees + staking amount can be more than the balance showError({ error: { - message: error.message, + message: errorMsg, errorState: ErrorState.STAKING, errorTime: new Date(), },