Skip to content

Commit c3d9fbf

Browse files
authored
Added a link to local lab instance (#94)
* feat: added link to lab * fix: modified access to props * feat: switch lab url depending on network & replace button with link * fix: create a switch for lab prefix * fix: switched default to testnet * fix: adapted url params * fix: removed semi colons in url
1 parent 1e27c74 commit c3d9fbf

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

src/contracts/util.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ export const stellarNetwork =
3232
: env.PUBLIC_STELLAR_NETWORK;
3333
export const networkPassphrase = env.PUBLIC_STELLAR_NETWORK_PASSPHRASE;
3434

35+
const stellarEncode = (str: string) => {
36+
return str.replace(/\//g, "//").replace(/;/g, "/;");
37+
};
38+
39+
export const labPrefix = () => {
40+
switch (stellarNetwork) {
41+
case "LOCAL":
42+
return `http://localhost:8000/lab/transaction-dashboard?$=network$id=custom&label=Custom&horizonUrl=${stellarEncode(horizonUrl)}&rpcUrl=${stellarEncode(rpcUrl)}&passphrase=${stellarEncode(networkPassphrase)};`;
43+
case "PUBLIC":
44+
return `https://lab.stellar.org/transaction-dashboard?$=network$id=mainnet&label=Mainnet&horizonUrl=${stellarEncode(horizonUrl)}&rpcUrl=${stellarEncode(rpcUrl)}&passphrase=${stellarEncode(networkPassphrase)};`;
45+
case "TESTNET":
46+
return `https://lab.stellar.org/transaction-dashboard?$=network$id=testnet&label=Testnet&horizonUrl=${stellarEncode(horizonUrl)}&rpcUrl=${stellarEncode(rpcUrl)}&passphrase=${stellarEncode(networkPassphrase)};`;
47+
case "FUTURENET":
48+
return `https://lab.stellar.org/transaction-dashboard?$=network$id=futurenet&label=Futurenet&horizonUrl=${stellarEncode(horizonUrl)}&rpcUrl=${stellarEncode(rpcUrl)}&passphrase=${stellarEncode(networkPassphrase)};`;
49+
default:
50+
return `https://lab.stellar.org/transaction-dashboard?$=network$id=testnet&label=Testnet&horizonUrl=${stellarEncode(horizonUrl)}&rpcUrl=${stellarEncode(rpcUrl)}&passphrase=${stellarEncode(networkPassphrase)};`;
51+
}
52+
};
53+
3554
// NOTE: needs to be exported for contract files in this directory
3655
export const rpcUrl = env.PUBLIC_STELLAR_RPC_URL;
3756

src/debug/components/ValidationResponseCard.tsx

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Button, Card, Text } from "@stellar/design-system";
1+
import { Button, Card, Link, Text } from "@stellar/design-system";
22
import { Box } from "../../components/layout/Box";
33
import { useState } from "react";
4+
import { labPrefix } from "../../contracts/util";
45

56
type ValidationResponseCard = {
67
variant: "primary" | "success" | "error";
@@ -68,6 +69,15 @@ export const ValidationResponseCard = ({
6869
}: ValidationResponseCard) => {
6970
const [isExpanded, setIsExpanded] = useState(false);
7071

72+
const txHash =
73+
typeof summary === "object" && summary !== null && "_owner" in summary
74+
? ((
75+
summary as {
76+
_owner?: { memoizedProps?: { response?: { hash?: string } } };
77+
}
78+
)._owner?.memoizedProps?.response?.hash ?? "")
79+
: "";
80+
7181
const renderSummary = () => {
7282
if (summary) {
7383
return (
@@ -109,22 +119,30 @@ export const ValidationResponseCard = ({
109119
style={{ display: "flex", flexDirection: "column", gap: "2 rem" }}
110120
>
111121
{renderSummary()}
112-
113-
<Button
114-
title="Expand"
115-
variant="tertiary"
116-
size="sm"
117-
onClick={() => setIsExpanded(!isExpanded)}
118-
style={
119-
{
120-
// ...styles.responsiveButtons,
121-
alignSelf: "flex-end",
122-
marginBottom: "1rem",
123-
} as React.CSSProperties
124-
}
122+
<Box
123+
gap="xs"
124+
direction="row"
125+
style={{ alignSelf: "flex-end", marginBottom: "1rem" }}
125126
>
126-
{isExpanded ? "Hide " : "Show "} Details
127-
</Button>
127+
<Button
128+
title="Expand"
129+
variant="tertiary"
130+
size="sm"
131+
onClick={() => setIsExpanded(!isExpanded)}
132+
>
133+
{isExpanded ? "Hide " : "Show "} Details
134+
</Button>
135+
{txHash ? (
136+
<Link
137+
href={`${labPrefix()}&txDashboard$transactionHash=${txHash}`}
138+
size="xs"
139+
>
140+
See on lab
141+
</Link>
142+
) : (
143+
<></>
144+
)}
145+
</Box>
128146
{isExpanded && (
129147
<Card variant="secondary" noPadding>
130148
<div style={styles.content}>

0 commit comments

Comments
 (0)