Skip to content

Commit

Permalink
View XDR: add Signatures Checked message (#1061)
Browse files Browse the repository at this point in the history
* View XDR: add Signatures Checked message

* Improve fetch latest XDR sign check

* Clear old data when fetching new tx
  • Loading branch information
quietbits committed Sep 26, 2024
1 parent e7eb0eb commit 245afd5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/app/(sidebar)/xdr/view/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
Icon,
CopyText,
} from "@stellar/design-system";
import { useQueryClient } from "@tanstack/react-query";
import { stringify } from "lossless-json";

import { useLatestTxn } from "@/query/useLatestTxn";
import { stringify } from "lossless-json";
import * as StellarXdr from "@/helpers/StellarXdr";
import { XDR_TYPE_TRANSACTION_ENVELOPE } from "@/constants/settings";

Expand All @@ -26,6 +27,7 @@ import { PrettyJsonTransaction } from "@/components/PrettyJsonTransaction";
import { parseToLosslessJson } from "@/helpers/parseToLosslessJson";
import { useIsXdrInit } from "@/hooks/useIsXdrInit";
import { useStore } from "@/store/useStore";
import { delayedAction } from "@/helpers/delayedAction";

export default function ViewXdr() {
const { xdr, network } = useStore();
Expand All @@ -42,6 +44,8 @@ export default function ViewXdr() {
refetch: fetchLatestTxn,
} = useLatestTxn(network.horizonUrl);

const queryClient = useQueryClient();

useEffect(() => {
if (isLatestTxnSuccess && latestTxn) {
updateXdrBlob(latestTxn);
Expand Down Expand Up @@ -102,7 +106,21 @@ export default function ViewXdr() {
Input a base-64 encoded XDR blob,{" "}
<Link
onClick={() => {
fetchLatestTxn();
if (latestTxn) {
// Reset query to clear old data
queryClient.resetQueries({
queryKey: ["xdr", "latestTxn"],
exact: true,
});
updateXdrBlob("");
}

delayedAction({
action: () => {
fetchLatestTxn();
},
delay: 500,
});
}}
isDisabled={isFetchingLatestTxn}
icon={isFetchingLatestTxn ? <Loader /> : null}
Expand Down
12 changes: 11 additions & 1 deletion src/components/PrettyJson/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type PrettyJsonProps = {
key: string,
parentKey?: string,
) => React.ReactNode | null;
customKeyRenderer?: (item: any, key: string) => React.ReactNode | null;
isLoading?: boolean;
isCollapsible?: boolean;
};
Expand All @@ -39,6 +40,7 @@ export const PrettyJson = ({
json,
customKeyValueLinkMap,
customValueRenderer,
customKeyRenderer,
isLoading,
isCollapsible = true,
}: PrettyJsonProps) => {
Expand All @@ -64,9 +66,16 @@ export const PrettyJson = ({
children: React.ReactNode;
}) => {
const [isExpanded, setIsExpanded] = useState(true);
const customRender =
itemKey && customKeyRenderer
? customKeyRenderer(children, itemKey)
: null;

return (
<div className="PrettyJson__nested">
<div
className="PrettyJson__nested"
{...(customRender ? { "data-is-custom-key": "" } : {})}
>
<div
className={`PrettyJson__inline ${isCollapsible ? "PrettyJson--click" : ""}`}
{...(isCollapsible
Expand All @@ -83,6 +92,7 @@ export const PrettyJson = ({
{itemKey ? <Key>{itemKey}</Key> : null}
<Bracket char={char} isCollapsed={!isExpanded} />
{isCollapsible ? <ItemCount itemList={itemList} /> : null}
{customRender}
</div>
{isExpanded ? (
<div>
Expand Down
19 changes: 19 additions & 0 deletions src/components/PrettyJson/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
&__nested {
padding-left: pxToRem(16px);

// Show "Signatures Checked" message only if signatures are validated
&[data-is-custom-key] {
&:has(.PrettyJson--success),
&:has(.PrettyJson--error) {
.PrettyJson__key__note {
display: block;
}
}
}

&:has(+ .PrettyJson--success) {
.PrettyJson__key {
color: var(--sds-clr-green-11);
Expand Down Expand Up @@ -63,6 +73,15 @@
color: var(--sds-clr-gray-12);
}

&__key {
&__note {
display: none;
font-size: pxToRem(12px);
margin-left: pxToRem(4px);
color: var(--sds-clr-gray-09);
}
}

.Link {
font-family: var(--sds-ff-monospace);
}
Expand Down
9 changes: 9 additions & 0 deletions src/components/PrettyJsonTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,19 @@ export const PrettyJsonTransaction = ({
return null;
};

const customKeyRenderer = (item: any, key: string) => {
if (key === "signatures" && item?.length > 0) {
return <div className="PrettyJson__key__note">· Signatures Checked</div>;
}

return null;
};

return (
<PrettyJson
json={json}
customValueRenderer={customValueRenderer}
customKeyRenderer={customKeyRenderer}
isLoading={isLoading || isFetching}
/>
);
Expand Down

0 comments on commit 245afd5

Please sign in to comment.