Skip to content

Commit

Permalink
Merge main into dev branch 5 (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab authored Aug 16, 2024
2 parents dea6d25 + a69c6be commit 9f5aab4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-staking",
"version": "0.2.32",
"version": "0.2.33",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -102,25 +100,9 @@ export const FinalityProviders: React.FC<FinalityProvidersProps> = ({
return <LoadingView />;
}

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 (
<>
<p>
Select a finality provider or{" "}
<a
href={createFinalityProviderLink}
target="_blank"
rel="noopener noreferrer"
className="sublink text-primary hover:underline"
>
create your own
</a>
.
</p>
<p>Select a finality provider.</p>
<div className="flex gap-3">
<FinalityProviderSearch onSearch={handleSearch} />
</div>
Expand Down
29 changes: 19 additions & 10 deletions src/app/components/Staking/Form/StakingAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const StakingAmount: React.FC<StakingAmountProps> = ({
}) => {
const [value, setValue] = useState("");
const [error, setError] = useState("");

// Track if the input field has been interacted with
const [touched, setTouched] = useState(false);

Expand Down Expand Up @@ -51,16 +52,8 @@ export const StakingAmount: React.FC<StakingAmountProps> = ({
}
};

const handleBlur = (_e: FocusEvent<HTMLInputElement>) => {
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);

Expand Down Expand Up @@ -103,6 +96,22 @@ export const StakingAmount: React.FC<StakingAmountProps> = ({
onStakingAmountSatChange(satoshis);
setValue(maxDecimals(satoshiToBtc(satoshis), 8).toString());
}
}, [
btcWalletBalanceSat,
minStakingAmountSat,
maxStakingAmountSat,
value,
onStakingAmountSatChange,
coinName,
]);

const handleBlur = (_e: FocusEvent<HTMLInputElement>) => {
if (value === "") {
onStakingAmountSatChange(0);
setError(generalErrorMessage);
return;
}
setTouched(true);
};

const minStakeAmount = maxDecimals(satoshiToBtc(minStakingAmountSat), 8);
Expand Down
11 changes: 10 additions & 1 deletion src/app/components/Staking/Staking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,19 @@ export const Staking: React.FC<StakingProps> = ({
);
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(),
},
Expand Down

0 comments on commit 9f5aab4

Please sign in to comment.