diff --git a/package-lock.json b/package-lock.json index e3228569..c7bb927a 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", @@ -15,7 +15,7 @@ "@scure/bip32": "^1.4.0", "@tanstack/react-query": "^5.28.14", "@tanstack/react-query-next-experimental": "^5.28.14", - "axios": "^1.6.8", + "axios": "^1.7.4", "bitcoinjs-lib": "^6.1.5", "btc-staking-ts": "^0.2.8", "date-fns": "^3.6.0", @@ -5673,9 +5673,10 @@ } }, "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", "form-data": "^4.0.0", diff --git a/package.json b/package.json index 1657ae19..a3564de8 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,7 +28,7 @@ "@scure/bip32": "^1.4.0", "@tanstack/react-query": "^5.28.14", "@tanstack/react-query-next-experimental": "^5.28.14", - "axios": "^1.6.8", + "axios": "^1.7.4", "bitcoinjs-lib": "^6.1.5", "btc-staking-ts": "^0.2.8", "date-fns": "^3.6.0", 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 85cbcc0b..18230b71 100644 --- a/src/app/components/Staking/Staking.tsx +++ b/src/app/components/Staking/Staking.tsx @@ -366,10 +366,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(), },