Skip to content

Commit

Permalink
Share transactions (#1084)
Browse files Browse the repository at this point in the history
Co-authored-by: jeesun 지선 <[email protected]>
  • Loading branch information
quietbits and jeesunikim authored Oct 8, 2024
1 parent 02e6ca9 commit 62f2f54
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
10 changes: 4 additions & 6 deletions src/app/(sidebar)/endpoints/[[...pages]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { formComponentTemplateEndpoints } from "@/components/formComponentTempla
import { InputSideElement } from "@/components/InputSideElement";
import { Box } from "@/components/layout/Box";
import { PrettyJsonTextarea } from "@/components/PrettyJsonTextarea";
import { ShareApiExplorerUrlButton } from "@/components/ShareApiExplorerUrlButton";
import { ShareUrlButton } from "@/components/ShareUrlButton";

import { useStore } from "@/store/useStore";
import { isEmptyObject } from "@/helpers/isEmptyObject";
Expand All @@ -33,7 +33,7 @@ import { localStorageSavedEndpointsHorizon } from "@/helpers/localStorageSavedEn
import { arrayItem } from "@/helpers/arrayItem";
import { delayedAction } from "@/helpers/delayedAction";
import { buildEndpointHref } from "@/helpers/buildEndpointHref";
import { apiExplorerShareableUrl } from "@/helpers/apiExplorerShareableUrl";
import { shareableUrl } from "@/helpers/shareableUrl";

import { Routes } from "@/constants/routes";
import {
Expand Down Expand Up @@ -655,9 +655,7 @@ export default function Endpoints() {
Submit
</Button>

<ShareApiExplorerUrlButton
shareableUrl={apiExplorerShareableUrl()}
/>
<ShareUrlButton shareableUrl={shareableUrl("requests")} />

<Button
size="md"
Expand All @@ -674,7 +672,7 @@ export default function Endpoints() {
route: pathname,
params,
network: getSaveItemNetwork(network),
shareableUrl: apiExplorerShareableUrl(),
shareableUrl: shareableUrl("requests"),
}),
);
}}
Expand Down
6 changes: 2 additions & 4 deletions src/app/(sidebar)/endpoints/components/SavedEndpointsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { TabView } from "@/components/TabView";
import { Box } from "@/components/layout/Box";
import { InputSideElement } from "@/components/InputSideElement";
import { NextLink } from "@/components/NextLink";
import { ShareApiExplorerUrlButton } from "@/components/ShareApiExplorerUrlButton";
import { ShareUrlButton } from "@/components/ShareUrlButton";

import { NetworkOptions } from "@/constants/settings";
import { Routes } from "@/constants/routes";
Expand Down Expand Up @@ -153,9 +153,7 @@ export const SavedEndpointsPage = () => {

<>
{e.shareableUrl ? (
<ShareApiExplorerUrlButton
shareableUrl={e.shareableUrl}
/>
<ShareUrlButton shareableUrl={e.shareableUrl} />
) : null}
</>
</Box>
Expand Down
4 changes: 4 additions & 0 deletions src/app/(sidebar)/transaction/build/components/Operations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import { Box } from "@/components/layout/Box";
import { TabbedButtons } from "@/components/TabbedButtons";
import { SdsLink } from "@/components/SdsLink";
import { SaveTransactionModal } from "@/components/SaveTransactionModal";
import { ShareUrlButton } from "@/components/ShareUrlButton";

import { arrayItem } from "@/helpers/arrayItem";
import { isEmptyObject } from "@/helpers/isEmptyObject";
import { sanitizeObject } from "@/helpers/sanitizeObject";
import { shareableUrl } from "@/helpers/shareableUrl";

import { OP_SET_TRUST_LINE_FLAGS } from "@/constants/settings";
import { TRANSACTION_OPERATIONS } from "@/constants/transactionOperations";
Expand Down Expand Up @@ -1167,6 +1169,8 @@ export const Operations = () => {
title="Save transaction"
disabled={!txnXdr}
></Button>

<ShareUrlButton shareableUrl={shareableUrl("transactions")} />
</Box>

<Button
Expand Down
8 changes: 7 additions & 1 deletion src/app/(sidebar)/transaction/saved/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { localStorageSavedTransactions } from "@/helpers/localStorageSavedTransa
import { arrayItem } from "@/helpers/arrayItem";

import { SavedTransaction, SavedTransactionPage } from "@/types/types";
import { ShareUrlButton } from "@/components/ShareUrlButton";

export default function SavedTransactions() {
const { network, transaction, xdr } = useStore();
Expand Down Expand Up @@ -151,7 +152,12 @@ export default function SavedTransactions() {
addlClassName="Endpoints__urlBar__footer"
>
<Box gap="sm" direction="row">
{renderActionButton(txn.timestamp, txn.page)}
<>
{renderActionButton(txn.timestamp, txn.page)}
{txn.shareableUrl ? (
<ShareUrlButton shareableUrl={txn.shareableUrl} />
) : null}
</>
</Box>

<Box gap="sm" direction="row" align="center" justify="end">
Expand Down
2 changes: 2 additions & 0 deletions src/components/SaveTransactionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Button, Input, Modal } from "@stellar/design-system";
import { arrayItem } from "@/helpers/arrayItem";
import { localStorageSavedTransactions } from "@/helpers/localStorageSavedTransactions";
import { getSaveItemNetwork } from "@/helpers/getSaveItemNetwork";
import { shareableUrl } from "@/helpers/shareableUrl";
import { useStore } from "@/store/useStore";
import { SavedTransactionPage } from "@/types/types";

Expand Down Expand Up @@ -129,6 +130,7 @@ export const SaveTransactionModal = ({
name: savedTxnName,
page,
xdr,
shareableUrl: shareableUrl("transactions"),
...(page === "build"
? {
params: transaction.build.params,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Button, CopyText, Icon } from "@stellar/design-system";

export const ShareApiExplorerUrlButton = ({
shareableUrl,
}: {
shareableUrl: string;
}) => {
export const ShareUrlButton = ({ shareableUrl }: { shareableUrl: string }) => {
return (
<CopyText
textToCopy={shareableUrl}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { parse, stringify } from "zustand-querystring";

export const apiExplorerShareableUrl = () => {
export const shareableUrl = (page: "requests" | "transactions") => {
const { origin, pathname, search } = window.location;
const pageParam = page === "requests" ? "endpoints" : "transaction";

// Removing extra chars
const trimmedSearch = search.substring(3);
const searchParams = Object.entries(parse(trimmedSearch) || {}).reduce(
(res, cur) => {
const [key, value] = cur;

// For API Explorer shareable URL we only need to keep network and
// endpoints params
if (["network", "endpoints"].includes(key)) {
// For API Explorer or Transaction shareable URL we only need to keep
// network and endpoints or transaction params
if (["network", pageParam].includes(key)) {
return { ...res, [key]: value };
}

Expand Down
1 change: 1 addition & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export type SavedTransaction = {
xdr: string;
name: string;
page: SavedTransactionPage;
shareableUrl: string | undefined;
};

export type SavedTransactionPage = "build" | "sign" | "simulate" | "submit";
Expand Down

0 comments on commit 62f2f54

Please sign in to comment.