-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sign a tx from link opened via CLI #987
Changes from 7 commits
827fd22
6c8d95d
5ebecaa
9fe349c
17c817b
64bceae
cffba46
c8bcebc
056775a
338ea38
8d0346c
dadf311
a240bf0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use client"; | ||
|
||
import { Routes } from "@/constants/routes"; | ||
import { useStore } from "@/store/useStore"; | ||
import { Loader } from "@stellar/design-system"; | ||
import { useRouter } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
|
||
export default function CliSignTransaction() { | ||
const { network, transaction } = useStore(); | ||
const { sign } = transaction; | ||
const router = useRouter(); | ||
useEffect(() => { | ||
router.push(Routes.SIGN_TRANSACTION); | ||
}, [sign.importXdr, network, router]); | ||
|
||
return <Loader />; | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import React from "react"; | ||
import type { Metadata } from "next"; | ||
import React from "react"; | ||
|
||
import { LayoutMain } from "@/components/layout/LayoutMain"; | ||
import { QueryProvider } from "@/query/QueryProvider"; | ||
import { StoreProvider } from "@/store/StoreProvider"; | ||
|
||
import "@stellar/design-system/build/styles.min.css"; | ||
import { NetworkByPasswordProvider } from "@/components/NetworkByPasswordProvider"; | ||
import "@/styles/globals.scss"; | ||
import "@stellar/design-system/build/styles.min.css"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep the Design System import before the |
||
|
||
// Needed for CSP | ||
export const dynamic = "force-dynamic"; | ||
|
@@ -29,7 +30,9 @@ export default function RootLayout({ | |
<div id="root"> | ||
<StoreProvider> | ||
<QueryProvider> | ||
<LayoutMain>{children}</LayoutMain> | ||
<NetworkByPasswordProvider> | ||
<LayoutMain>{children}</LayoutMain> | ||
</NetworkByPasswordProvider> | ||
</QueryProvider> | ||
</StoreProvider> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use client"; | ||
|
||
import { NetworkOptions } from "@/constants/settings"; | ||
import { useStore } from "@/store/useStore"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
|
||
// Component to set Network and Xdr if only password is given in query string | ||
export const NetworkByPasswordProvider = ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love some feedback/other ideas on the name of this component. |
||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) => { | ||
const { updateIsDynamicNetworkSelect, transaction, selectNetwork } = | ||
useStore(); | ||
|
||
const searchParams = useSearchParams(); | ||
|
||
const getNetworkByPassphrase = (passphrase: string) => { | ||
return NetworkOptions.find((network) => network.passphrase === passphrase); | ||
}; | ||
|
||
useEffect(() => { | ||
const networkPassphrase = searchParams.get("networkPassphrase"); | ||
const xdr = searchParams.get("xdr"); | ||
|
||
if (networkPassphrase) { | ||
const network = getNetworkByPassphrase(networkPassphrase); | ||
if (network) { | ||
updateIsDynamicNetworkSelect(true); | ||
selectNetwork(network); | ||
} | ||
} | ||
|
||
if (xdr) { | ||
transaction.updateSignActiveView("overview"); | ||
transaction.updateSignImportXdr(xdr); | ||
} | ||
}, [searchParams, selectNetwork, updateIsDynamicNetworkSelect, transaction]); | ||
|
||
return children; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea of using the route to do the redirect. 🙌 Do you think we could move
NetworkByPasswordProvider
logic here and remove it completely fromsrc/app/layout.tsx
. That way, everything related to CLI sign transaction would be handled in one place.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, great idea! I'll get an update pushed shortly