Skip to content
This repository has been archived by the owner on Feb 27, 2021. It is now read-only.

Commit

Permalink
fix(configuration): add query param configuration for rpc url
Browse files Browse the repository at this point in the history
fixes #56
  • Loading branch information
shanejonas committed Sep 5, 2019
1 parent c9fbf4c commit 530500a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ By default, multi-geth service will run ETC mainnet. Jade Service runner conveni
└── keystore
```

## Configuration

### Configure rpc via url

https://explorer.jade.builders/?rpcUrl=https://services.jade.builders/multi-geth/kotti/1.9.2


### Configure default urls via environment variables

Override eth url
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useMultiGeth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function useMultiGeth(
serviceRunnerUrl: string,
version: string,
env: string,
queryUrlOverride?: string,
): [ERPC, Dispatch<string>] {
const [erpc, setErpc] = React.useState();
const [urlOverride, setUrlOverride] = useState(process.env.REACT_APP_ETH_RPC_URL);
Expand All @@ -24,7 +25,7 @@ function useMultiGeth(
await serviceRunner.startService(serviceName, version, env);
let parsedUrl;
try {
parsedUrl = new URL(urlOverride || `${serviceRunnerUrl}/${serviceName}/${env}/${version}`);
parsedUrl = new URL(queryUrlOverride || urlOverride || `${serviceRunnerUrl}/${serviceName}/${env}/${version}`);
} catch (e) {
return;
}
Expand All @@ -49,7 +50,7 @@ function useMultiGeth(
}
};
runAsync();
}, [serviceRunner, serviceRunnerUrl, version, env, urlOverride]);
}, [serviceRunner, serviceRunnerUrl, version, env, urlOverride, queryUrlOverride]);
return [erpc, setUrlOverride];
}

Expand Down
27 changes: 27 additions & 0 deletions src/hooks/useQueryParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useState } from "react";
import * as qs from "qs";

const useQueryParams = () => {
const parse = () => {
return qs.parse(window.location.search, {
ignoreQueryPrefix: true,
depth: 100,
decoder(str) {
if (/^(\d+|\d*\.\d+)$/.test(str)) {
return parseFloat(str);
}
if (str === "false") {
return false;
}
if (str === "true") {
return true;
}
return decodeURIComponent(str);
},
});
};
const [query] = useState(parse());
return [query];
};

export default useQueryParams;
4 changes: 3 additions & 1 deletion src/stores/useMultiGethStore.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { createStore } from "reusable";
import useMultiGeth from "../hooks/useMultiGeth";
import useServiceRunnerStore from "./useServiceRunnerStore";
import useQueryParams from "../hooks/useQueryParams";

export default createStore(() => {
const [serviceRunner, serviceRunnerUrl] = useServiceRunnerStore();
return useMultiGeth(serviceRunner, serviceRunnerUrl, "1.9.2", "mainnet");
const [queryParams] = useQueryParams();
return useMultiGeth(serviceRunner, serviceRunnerUrl, "1.9.2", "mainnet", queryParams.rpcUrl);
});

0 comments on commit 530500a

Please sign in to comment.