Skip to content
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
23 changes: 10 additions & 13 deletions src/components/primitives/toast/specialized-toasts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,19 +445,14 @@ const TransactionToast = memo<TransactionToastProps>(
className="text-foreground animate-spin min-w-6"
/>
) : (
[
<CheckIcon
size="default"
className="text-foreground min-w-6"
/>,
]
<CheckIcon size="default" className="text-foreground min-w-6" />
)}
</div>
<span className="text-foreground text-sm font-normal leading-5 tracking-[0.01em] truncate">
{status === "confirming" ? "Confirming" : "Confirmed"}
</span>
{status === "confirming" && (
<div className="flex items-center px-2 py-1 bg-translucent-dark-100 rounded-[2px] ml-2 flex-shrink-0">
<div className="flex items-center py-1 bg-translucent-dark-100 rounded-[2px] flex-shrink-0">
<div className="w-4 h-4 mr-1 flex items-center justify-center">
<TransactionIcon className="w-[11px] h-[9px] text-achievement" />
</div>
Expand All @@ -481,8 +476,10 @@ const TransactionToast = memo<TransactionToastProps>(
TransactionToast.displayName = "TransactionToast";

// Convenience functions for using with the existing toast system
type ToastPropsToOmit = "safeToClose" | "variant" | "children";

export const showAchievementToast = (
props: Omit<AchievementToastProps, "variant" | "children">,
props: Omit<AchievementToastProps, ToastPropsToOmit>,
) => {
const toastId = props.toastId || `achievement-${Date.now()}`;
return {
Expand All @@ -494,7 +491,7 @@ export const showAchievementToast = (
};

export const showMarketplaceToast = (
props: Omit<MarketplaceToastProps, "variant" | "children">,
props: Omit<MarketplaceToastProps, ToastPropsToOmit>,
) => {
const toastId = props.toastId || `marketplace-${Date.now()}`;
return {
Expand All @@ -506,7 +503,7 @@ export const showMarketplaceToast = (
};

export const showNetworkSwitchToast = (
props: Omit<NetworkSwitchToastProps, "variant" | "children">,
props: Omit<NetworkSwitchToastProps, ToastPropsToOmit>,
) => {
const toastId = props.toastId || `network-${Date.now()}`;
return {
Expand All @@ -520,7 +517,7 @@ export const showNetworkSwitchToast = (
};

export const showErrorToast = (
props: Omit<ErrorToastProps, "variant" | "children">,
props: Omit<ErrorToastProps, ToastPropsToOmit>,
) => {
const toastId = props.toastId || `error-${Date.now()}`;
return {
Expand All @@ -533,7 +530,7 @@ export const showErrorToast = (
};

export const showSuccessToast = (
props: Omit<SuccessToastProps, "variant" | "children">,
props: Omit<SuccessToastProps, ToastPropsToOmit>,
) => {
const toastId = props.toastId || `success-${Date.now()}`;
return {
Expand All @@ -546,7 +543,7 @@ export const showSuccessToast = (
};

export const showTransactionToast = (
props: Omit<TransactionToastProps, "variant" | "children">,
props: Omit<TransactionToastProps, ToastPropsToOmit>,
) => {
const toastId = props.toastId || `transaction-${Date.now()}`;
return {
Expand Down
5 changes: 5 additions & 0 deletions src/components/primitives/toast/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export interface ToastProps
VariantProps<typeof toastVariants> {
showClose?: boolean;
toastId?: string;
// compatibility with controller events
toasterId?: string;
safeToClose?: boolean;
iconUrl?: string;
}

export const Toast = React.forwardRef<HTMLDivElement, ToastProps>(
Expand All @@ -70,6 +73,8 @@ export const Toast = React.forwardRef<HTMLDivElement, ToastProps>(
showClose = true,
toastId,
toasterId,
safeToClose,
iconUrl,
...props
},
ref,
Expand Down
41 changes: 35 additions & 6 deletions src/stories/toast-controller-integration.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function ControllerToasterDemo() {
ControllerNotificationTypes[]
>([]);
const [position, setPosition] = useState<ToastPosition>("bottom-right");
const [txCount, setTxCount] = useState(1);
const [txConfirming, setTxConfirming] = useState(false);

// Debounced toast function to prevent multiple rapid clicks
const showToastWithDebounce = useCallback(
Expand Down Expand Up @@ -109,23 +111,39 @@ function ControllerToasterDemo() {
const options: TransactionToastOptions = {
variant: "transaction",
status: "confirming",
toastId: "0x1234", // transaction hash
toastId: `tx-${txCount}`,
label: "Purchase",
progress: 50,
duration: 5000,
safeToClose: false,
};
emitControllerToast("transactionConfirming", options);
setTxConfirming(true);
};

const showTransactionConfirmed = () => {
const options: TransactionToastOptions = {
variant: "transaction",
status: "confirmed",
toastId: "0x1234", // transaction hash
toastId: `tx-${txCount}`,
progress: 50,
duration: 5000,
};
emitControllerToast("transactionConfirmed", options);
setTxConfirming(false);
setTxCount((prev) => prev + 1);
};

const showTransactionError = () => {
const options: ErrorToastOptions = {
variant: "error",
message: "Transaction execution failed",
toastId: `tx-${txCount}`,
duration: 5000,
};
emitControllerToast("transactionError", options);
setTxConfirming(false);
setTxCount((prev) => prev + 1);
};

const showSwitchToStarknet = () => {
Expand Down Expand Up @@ -202,6 +220,7 @@ function ControllerToasterDemo() {
isDraft: true,
progress: 50,
duration: 5000,
iconUrl: "",
};
emitControllerToast("achievementDraft", options);
};
Expand All @@ -214,6 +233,7 @@ function ControllerToasterDemo() {
xpAmount: 100,
progress: 100,
duration: 5000,
iconUrl: "",
};
emitControllerToast("achievement", options);
};
Expand Down Expand Up @@ -286,20 +306,29 @@ function ControllerToasterDemo() {
<Button
onClick={showTransactionConfirming}
className="w-full"
disabled={isLoading.transactionConfirming}
disabled={isLoading.transactionConfirming || txConfirming}
>
{isLoading.transactionConfirming
? "Loading..."
: "Transaction Confirming"}
: `Confirm TX${txCount}...`}
</Button>
<Button
onClick={showTransactionConfirmed}
className="w-full"
disabled={isLoading.transactionConfirmed}
disabled={isLoading.transactionConfirmed || !txConfirming}
>
{isLoading.transactionConfirmed
? "Loading..."
: "Transaction Confirmed"}
: `...TX${txCount} confirmed`}
</Button>
<Button
onClick={showTransactionError}
className="w-full"
disabled={isLoading.transactionError || !txConfirming}
>
{isLoading.transactionError
? "Loading..."
: `...TX${txCount} error`}
</Button>
<Button
onClick={showSwitchToStarknet}
Expand Down
Loading