Skip to content

Commit

Permalink
Allow localhost network (#1104)
Browse files Browse the repository at this point in the history
* Network Selector UI updated

* Update network requests

* Fix tests

* Allow localhost network

* Update CSP
  • Loading branch information
quietbits authored Nov 6, 2024
1 parent 586af2b commit 684ee3e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export function middleware(request: NextRequest) {
const nonce = Buffer.from(crypto.randomUUID()).toString("base64");

// script-src 'unsafe-eval' is needed for XDR JSON WebAssembly scripts
// connect-src http://localhost:* to allow local network
const cspHeader = `
default-src 'self';
script-src 'self' 'nonce-${nonce}' 'strict-dynamic' https: 'unsafe-inline' 'unsafe-eval';
Expand All @@ -13,7 +14,7 @@ export function middleware(request: NextRequest) {
: `'unsafe-inline'`
};
img-src 'self' https://stellar.creit.tech/wallet-icons/ blob: data:;
connect-src 'self' https:;
connect-src 'self' http://localhost:* https:;
font-src 'self' https://fonts.gstatic.com/;
object-src 'none';
frame-src 'self' https://connect.trezor.io/;
Expand Down
5 changes: 4 additions & 1 deletion src/query/useLatestLedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export const useLatestLedger = ({
const query = useQuery({
queryKey: ["useLatestLedger"],
queryFn: async () => {
const rpcServer = new StellarRpc.Server(rpcUrl, { headers });
const rpcServer = new StellarRpc.Server(rpcUrl, {
headers,
allowHttp: new URL(rpcUrl).hostname === "localhost",
});

try {
const latestLedger = await rpcServer.getLatestLedger();
Expand Down
1 change: 1 addition & 0 deletions src/query/useSubmitHorizonTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const useSubmitHorizonTx = () => {
);
const horizonServer = new Horizon.Server(horizonUrl, {
headers: isEmptyObject(headers) ? undefined : { ...headers },
allowHttp: new URL(horizonUrl).hostname === "localhost",
});
return (await horizonServer.submitTransaction(
transaction,
Expand Down
1 change: 1 addition & 0 deletions src/query/useSubmitRpcTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const useSubmitRpcTx = () => {
);
const rpcServer = new StellarRpc.Server(rpcUrl, {
headers: isEmptyObject(headers) ? undefined : { ...headers },
allowHttp: new URL(rpcUrl).hostname === "localhost",
});
const sentTx = await rpcServer.sendTransaction(transaction);

Expand Down

0 comments on commit 684ee3e

Please sign in to comment.