Skip to content

Commit

Permalink
Parse passphrase and xdr in new provider (instead of NetworkSelector)
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Aug 29, 2024
1 parent fbf670e commit 8f219d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { LayoutMain } from "@/components/layout/LayoutMain";
import { QueryProvider } from "@/query/QueryProvider";
import { StoreProvider } from "@/store/StoreProvider";

import { NetworkByPasswordProvider } from "@/components/NetworkByPasswordProvider";
import "@/styles/globals.scss";
import "@stellar/design-system/build/styles.min.css";
import { NetworkByPasswordProvider } from "@/components/NetworkByPasswordProvider";

// Needed for CSP
export const dynamic = "force-dynamic";
Expand Down
34 changes: 24 additions & 10 deletions src/components/NetworkByPasswordProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,39 @@

import { NetworkOptions } from "@/constants/settings";
import { useStore } from "@/store/useStore";
import { useSearchParams } from "next/navigation";
import { useEffect } from "react";

// Component to set network if only password is given in query string
export const NetworkByPasswordProvider = ({ children }: { children: React.ReactNode }) => {
const { network, updateIsDynamicNetworkSelect, selectNetwork } = useStore();
// Component to set Network and Xdr if only password is given in query string
export const NetworkByPasswordProvider = ({
children,
}: {
children: React.ReactNode;
}) => {
const { updateIsDynamicNetworkSelect, transaction, selectNetwork } = useStore();

const searchParams = useSearchParams();

const getNetworkByPassphrase = (passphrase: string) => {
return NetworkOptions.find((network) => network.passphrase === passphrase);
};

useEffect(() => {
if (network?.passphrase) {
const tx_network = getNetworkByPassphrase(network.passphrase);
if (tx_network) {
updateIsDynamicNetworkSelect(true);
selectNetwork(tx_network);
}
let networkPassphrase = searchParams.get("networkPassphrase");
if (networkPassphrase) {
let network = getNetworkByPassphrase(networkPassphrase);
if (network) {
updateIsDynamicNetworkSelect(true);
selectNetwork(network);
}
}, [network.passphrase, selectNetwork, updateIsDynamicNetworkSelect]);
}

let xdr = searchParams.get("xdr");
if (xdr) {
transaction.updateSignActiveView("overview");
transaction.updateSignImportXdr(xdr);
}
}, [searchParams, selectNetwork, updateIsDynamicNetworkSelect, transaction]);

return children;
};

0 comments on commit 8f219d1

Please sign in to comment.