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: adding txh display in toast notification #728

Closed
wants to merge 1 commit into from
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
7 changes: 7 additions & 0 deletions apps/namada-interface/src/App/Toast/toast.components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ export const Message = styled.div`
text-overflow: ellipsis;
`;

export const LinkExplorer = styled.a`
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-decoration: underline;
`;

export const CloseToastButton = styled.div`
cursor: pointer;
display: flex;
Expand Down
28 changes: 27 additions & 1 deletion apps/namada-interface/src/App/Toast/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,24 @@ import {
CloseToastButton,
Container,
Content,
LinkExplorer,
Message,
Title,
Wrapper,
} from "./toast.components";

const convertToHiddenString = (
str: string,
visibleLength: number = 16
): string => {
if (str.length <= visibleLength) {
return str;
}
const head = str.slice(0, visibleLength / 2);
const tail = str.slice(-visibleLength / 2);
return `${head}...${tail}`;
};

export const Toasts = (): JSX.Element => {
const dispatch = useAppDispatch();

Expand Down Expand Up @@ -69,6 +82,10 @@ export const Toast = ({
}, timeout.value);
}, [timeout.kind]);

// Input the original URL explorer here. Currently, it's a explorer url from SE contest
const baseExplorerUrl = "https://namada.valopers.com/transactions/";
const successMessage =
"Hash: " + convertToHiddenString(toast.innerTxHash ?? "");
return (
<Wrapper
className={toast.type}
Expand All @@ -79,7 +96,16 @@ export const Toast = ({
>
<Content>
<Title title={toast.title}>{toast.title}</Title>
<Message title={toast.message}>{toast.message}</Message>
{toast.type === "success" ? (
<LinkExplorer
target="_blank"
href={baseExplorerUrl + toast.innerTxHash}
>
{successMessage}
</LinkExplorer>
) : (
<Message title={toast.message}>{toast.message}</Message>
)}
</Content>
<CloseToastButton onClick={() => onClose(id)}>
<Icon name="ChevronRight" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export const NamadaTxCompletedHandler =
id: msgId,
txTypeLabel: TxTypeLabel[txType as TxType],
success,
error: payload || "",
error: !success ? payload : "",
innerTxHash: success ? payload : undefined,
})
);
refreshPublicKeys();
Expand Down
4 changes: 3 additions & 1 deletion apps/namada-interface/src/slices/notifications/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ export const reducers = {
txTypeLabel: TxLabel;
success: boolean;
error: string;
innerTxHash: string;
}>
) {
const { error, id, success, txTypeLabel } = action.payload;
const { error, id, success, txTypeLabel, innerTxHash } = action.payload;
state.toasts = {
...state.toasts,
[id]: {
title: `${txTypeLabel} ${success ? "confirmed" : "rejected"}`,
message: success ? "Transaction completed!" : error,
type: success ? "success" : "error",
timeout: ToastTimeout.Default(),
innerTxHash,
},
};
},
Expand Down
1 change: 1 addition & 0 deletions apps/namada-interface/src/slices/notifications/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type Toast = {
message: string;
type: ToastType;
timeout: Timeout;
innerTxHash?: string;
};

export type NotificationsState = {
Expand Down