Skip to content

Commit

Permalink
Network selector: setup for custom headers (#1101)
Browse files Browse the repository at this point in the history
* Network Selector UI updated

* Update network requests

* Fix tests

* Comment out custom headers for now

* Replace SorobanRpc with StellarRpc
  • Loading branch information
quietbits authored Nov 6, 2024
1 parent 51f9410 commit 586af2b
Show file tree
Hide file tree
Showing 24 changed files with 379 additions and 227 deletions.
2 changes: 2 additions & 0 deletions src/app/(sidebar)/account/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useFriendBot } from "@/query/useFriendBot";
import { useQueryClient } from "@tanstack/react-query";

import { useIsTestingNetwork } from "@/hooks/useIsTestingNetwork";
import { getNetworkHeaders } from "@/helpers/getNetworkHeaders";

import { GenerateKeypair } from "@/components/GenerateKeypair";
import { ExpandBox } from "@/components/ExpandBox";
Expand Down Expand Up @@ -49,6 +50,7 @@ export default function CreateAccount() {
network,
publicKey: account.publicKey!,
key: { type: "create" },
headers: getNetworkHeaders(network, "horizon"),
});

useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/app/(sidebar)/account/fund/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useQueryClient } from "@tanstack/react-query";

import { useFriendBot } from "@/query/useFriendBot";
import { useStore } from "@/store/useStore";
import { getNetworkHeaders } from "@/helpers/getNetworkHeaders";

import { validate } from "@/validate";

Expand Down Expand Up @@ -38,6 +39,7 @@ export default function FundAccount() {
network,
publicKey: generatedPublicKey,
key: { type: "fund" },
headers: getNetworkHeaders(network, "horizon"),
});

const queryClient = useQueryClient();
Expand Down
10 changes: 5 additions & 5 deletions src/app/(sidebar)/endpoints/[[...pages]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { arrayItem } from "@/helpers/arrayItem";
import { delayedAction } from "@/helpers/delayedAction";
import { buildEndpointHref } from "@/helpers/buildEndpointHref";
import { shareableUrl } from "@/helpers/shareableUrl";
import { getNetworkHeaders } from "@/helpers/getNetworkHeaders";

import { Routes } from "@/constants/routes";
import {
Expand Down Expand Up @@ -278,12 +279,11 @@ export default function Endpoints() {
refetch,
isSuccess,
isError,
} = useEndpoint(
} = useEndpoint({
requestUrl,
// There is only one endpoint request for POST, using params directly for
// simplicity.
pageData?.requestMethod === "POST" ? getPostPayload() : undefined,
);
postData: pageData?.requestMethod === "POST" ? getPostPayload() : undefined,
headers: getNetworkHeaders(network, isRpcEndpoint ? "rpc" : "horizon"),
});

const responseEl = useRef<HTMLDivElement | null>(null);

Expand Down
2 changes: 2 additions & 0 deletions src/app/(sidebar)/transaction/build/components/Params.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useStore } from "@/store/useStore";
import { useAccountSequenceNumber } from "@/query/useAccountSequenceNumber";
import { validate } from "@/validate";
import { EmptyObj, KeysOfUnion } from "@/types/types";
import { getNetworkHeaders } from "@/helpers/getNetworkHeaders";

export const Params = () => {
const requiredParams = ["source_account", "seq_num", "fee"] as const;
Expand Down Expand Up @@ -63,6 +64,7 @@ export const Params = () => {
} = useAccountSequenceNumber({
publicKey: txnParams.source_account,
horizonUrl: network.horizonUrl,
headers: getNetworkHeaders(network, "horizon"),
});

// Preserve values and validate inputs when components mounts
Expand Down
2 changes: 2 additions & 0 deletions src/app/(sidebar)/transaction/simulate/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PrettyJson } from "@/components/PrettyJson";
import { useStore } from "@/store/useStore";
import { useSimulateTx } from "@/query/useSimulateTx";
import { delayedAction } from "@/helpers/delayedAction";
import { getNetworkHeaders } from "@/helpers/getNetworkHeaders";
import { validate } from "@/validate";

export default function SimulateTransaction() {
Expand Down Expand Up @@ -75,6 +76,7 @@ export default function SimulateTransaction() {
rpcUrl: network.rpcUrl,
transactionXdr: xdr.blob,
instructionLeeway: simulate.instructionLeeway,
headers: getNetworkHeaders(network, "rpc"),
});

if (simulate.triggerOnLaunch) {
Expand Down
44 changes: 28 additions & 16 deletions src/app/(sidebar)/transaction/submit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as StellarXdr from "@/helpers/StellarXdr";
import { delayedAction } from "@/helpers/delayedAction";
import { openUrl } from "@/helpers/openUrl";
import { getBlockExplorerLink } from "@/helpers/getBlockExplorerLink";
import { getNetworkHeaders } from "@/helpers/getNetworkHeaders";
import { localStorageSubmitMethod } from "@/helpers/localStorageSubmitMethod";
import { buildEndpointHref } from "@/helpers/buildEndpointHref";

Expand Down Expand Up @@ -73,7 +74,9 @@ export default function SubmitTransaction() {
const [isSaveTxnModalVisible, setIsSaveTxnModalVisible] = useState(false);
const [isDropdownActive, setIsDropdownActive] = useState(false);
const [isDropdownVisible, setIsDropdownVisible] = useState(false);
const [submitMethod, setSubmitMethod] = useState("");
const [submitMethod, setSubmitMethod] = useState<"horizon" | "rpc" | string>(
"",
);

const dropdownRef = useRef<HTMLDivElement | null>(null);
const responseSuccessEl = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -178,21 +181,30 @@ export default function SubmitTransaction() {
};

const handleSubmit = () => {
if (submitMethod === "rpc") {
submitRpc({
rpcUrl: network.rpcUrl,
transactionXdr: blob,
networkPassphrase: network.passphrase,
});
} else if (submitMethod === "horizon") {
submitHorizon({
horizonUrl: network.horizonUrl,
transactionXdr: blob,
networkPassphrase: network.passphrase,
});
} else {
// Do nothing
}
resetSubmitState();

delayedAction({
action: () => {
if (submitMethod === "rpc") {
submitRpc({
rpcUrl: network.rpcUrl,
transactionXdr: blob,
networkPassphrase: network.passphrase,
headers: getNetworkHeaders(network, submitMethod),
});
} else if (submitMethod === "horizon") {
submitHorizon({
horizonUrl: network.horizonUrl,
transactionXdr: blob,
networkPassphrase: network.passphrase,
headers: getNetworkHeaders(network, submitMethod),
});
} else {
// Do nothing
}
},
delay: 300,
});
};

const onSimulateTx = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/app/(sidebar)/xdr/view/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { parseToLosslessJson } from "@/helpers/parseToLosslessJson";
import { useIsXdrInit } from "@/hooks/useIsXdrInit";
import { useStore } from "@/store/useStore";
import { delayedAction } from "@/helpers/delayedAction";
import { getNetworkHeaders } from "@/helpers/getNetworkHeaders";

export default function ViewXdr() {
const { xdr, network } = useStore();
Expand All @@ -43,7 +44,7 @@ export default function ViewXdr() {
isFetching: isLatestTxnFetching,
isLoading: isLatestTxnLoading,
refetch: fetchLatestTxn,
} = useLatestTxn(network.horizonUrl);
} = useLatestTxn(network.horizonUrl, getNetworkHeaders(network, "horizon"));

const queryClient = useQueryClient();

Expand Down
2 changes: 2 additions & 0 deletions src/components/FormElements/LedgerSeqPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PositiveIntPicker } from "@/components/FormElements/PositiveIntPicker";
import { useLatestLedger } from "@/query/useLatestLedger";

import { useStore } from "@/store/useStore";
import { getNetworkHeaders } from "@/helpers/getNetworkHeaders";

interface LedgerSeqPickerProps {
id: string;
Expand Down Expand Up @@ -37,6 +38,7 @@ export const LedgerSeqPicker = ({
isLoading,
} = useLatestLedger({
rpcUrl: network.rpcUrl,
headers: getNetworkHeaders(network, "rpc"),
});

useEffect(() => {
Expand Down
Loading

0 comments on commit 586af2b

Please sign in to comment.