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

feat(mfi-v2-ui): improved toasts throughout the app #377

Closed
Closed
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InputAdornment, TextField } from "@mui/material";
import { FC, MouseEventHandler, useCallback } from "react";
import { NumberFormatValues, NumericFormat } from "react-number-format";
import { toast } from "react-toastify";
import { showErrorToast } from "~/utils/toastUtils";

interface AssetRowInputBox {
value: number;
Expand All @@ -28,7 +28,7 @@ const AssetRowInputBox: FC<AssetRowInputBox> = ({
if (maxValue !== undefined) {
setValue(maxValue);
} else {
toast.error("Not implemented");
showErrorToast("Not implemented");
}
}, [maxValue, setValue]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { SwapMode, useJupiter } from "@jup-ag/react-hook";
import JSBI from "jsbi";
import { StakeData, usePrevious } from "~/utils";
import { createJupiterApiClient } from "@jup-ag/api";
import { toast } from "react-toastify";
import { SettingsModal } from "./SettingsModal";
import { SettingsIcon } from "./SettingsIcon";
import { LST_MINT, TokenData, TokenDataMap } from "~/store/lstStore";
Expand All @@ -46,6 +45,7 @@ import { IconLoader } from "~/components/ui/icons";
import BN from "bn.js";
import debounce from "lodash.debounce";
import { Desktop, Mobile } from "~/mediaQueries";
import { MultiStepToastHandle, showErrorToast } from "~/utils/toastUtils";

const QUOTE_EXPIRY_MS = 30_000;
const DEFAULT_DEPOSIT_OPTION: DepositOption = { type: "native", amount: new BN(0), maxAmount: new BN(0) };
Expand Down Expand Up @@ -182,7 +182,7 @@ export const StakingCard: FC = () => {
[depositOption, refresh, lastRefreshTimestamp]
);

const showErrotToast = useRef(debounce(() => toast.error("Failed to find route"), 250));
const showErrotToast = useRef(debounce(() => showErrorToast("Failed to find route"), 250));

const prevError = usePrevious(error);
useEffect(() => {
Expand Down Expand Up @@ -267,6 +267,9 @@ export const StakingCard: FC = () => {

setOngoingAction("minting");

const multiStepToast = new MultiStepToastHandle("Stake", [{ label: "Minting LST" }]);
multiStepToast.start();

try {
if (depositOption.type === "stake") {
const { instructions, signers } = await makeDepositStakeToStakePoolIx(
Expand All @@ -293,6 +296,7 @@ export const StakingCard: FC = () => {
} else if (depositOption.type === "token") {
const quote = quoteResponseMeta?.original;
if (!quote) {
multiStepToast.setFailed("Route not calculated yet");
console.error("Route not calculated yet");
return;
}
Expand Down Expand Up @@ -346,10 +350,10 @@ export const StakingCard: FC = () => {
"confirmed"
);
} else {
throw new Error("Invalid deposit option");
multiStepToast.setFailed("Invalid deposit option");
}

toast.success("Minting complete");
multiStepToast.setSuccessAndNext();
} catch (error: any) {
if (error.logs) {
console.log("------ Logs 👇 ------");
Expand All @@ -360,7 +364,7 @@ export const StakingCard: FC = () => {
if (errorMsg) {
errorMsg = errorMsg ? errorMsg : "Transaction failed!";
}
toast.error(errorMsg);
multiStepToast.setFailed(errorMsg);
} finally {
await Promise.all([refresh(), fetchLstState()]);
setDepositOption((currentDepositOption) =>
Expand Down
Loading