Skip to content

Commit

Permalink
rpc parachain get from url parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
vol4tim committed Oct 7, 2024
1 parent 421bcb7 commit 8bff777
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/hooks/useDevices.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ export const useDevices = (initialOwner = null) => {
const devices = ref([]);

const getDevices = async (owner) => {
const endpoint =
localStorage.getItem("rpc-parachain") ||
"wss://kusama.rpc.robonomics.network/";
const lsKey = `hadevices:${endpoint}:${owner}`;

if (!isReady.value) {
const data = localStorage.getItem(`hadevices:${owner}`);
const data = localStorage.getItem(lsKey);
if (data) {
try {
const parsedData = JSON.parse(data);
Expand All @@ -28,7 +33,7 @@ export const useDevices = (initialOwner = null) => {
return item.toHuman();
});
localStorage.setItem(
`hadevices:${owner}`,
lsKey,
JSON.stringify({ time: Date.now(), value: list })
);
console.log("getDevices chain");
Expand Down
9 changes: 7 additions & 2 deletions src/hooks/useSubscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ export const useSubscription = (initialOwner = null) => {
};

const getLedger = async (owner) => {
const endpoint =
localStorage.getItem("rpc-parachain") ||
"wss://kusama.rpc.robonomics.network/";
const lsKey = `hasubscription:${endpoint}:${owner}`;

if (!isReady.value) {
const data = localStorage.getItem(`hasubscription:${owner}`);
const data = localStorage.getItem(lsKey);
if (data) {
try {
const parsedData = JSON.parse(data);
Expand All @@ -73,7 +78,7 @@ export const useSubscription = (initialOwner = null) => {
const res = await getInstance().rws.getLedger(owner);
if (!res.isEmpty) {
localStorage.setItem(
`hasubscription:${owner}`,
lsKey,
JSON.stringify({ time: Date.now(), value: res.value.toJSON() })
);
console.log("getLedger chain");
Expand Down
5 changes: 1 addition & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ app
.use(router)
.use(store)
.use(filters)
.use(robonomics, {
// endpoint: "ws://127.0.0.1:9944"
endpoint: "wss://kusama.rpc.robonomics.network/"
})
.use(robonomics)
.use(ipfs, {
api: { gateway: "https://ipfs.url.today" },
gateways: [
Expand Down
20 changes: 18 additions & 2 deletions src/plugins/robonomics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ref, shallowRef } from "vue";
import AccountManager from "./robonomicsAccountManager";

export default {
install: async (app, params) => {
install: async (app, params = {}) => {
const isReady = ref(false);
const instance = shallowRef();
const accountManager = new AccountManager(keyring);
Expand All @@ -13,7 +13,23 @@ export default {
instance,
accountManager
});
instance.value = await Robonomics.createInstance(params);

const urlParams = new URLSearchParams(window.location.search);
let endpoint = urlParams.get("rpc");

if (!endpoint) {
endpoint =
localStorage.getItem("rpc-parachain") ||
"wss://kusama.rpc.robonomics.network/";
}
localStorage.setItem("rpc-parachain", endpoint);
const config = {
// endpoint: "ws://127.0.0.1:9944"
// endpoint: "wss://kusama.rpc.robonomics.network/"
endpoint
};

instance.value = await Robonomics.createInstance({ ...config, ...params });
instance.value.setAccountManager(accountManager);
isReady.value = true;
}
Expand Down
9 changes: 7 additions & 2 deletions src/views/telemetry/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,13 @@ export const useConfig = () => {
const { controller } = useSetup();

const getConfig = async (controller) => {
const endpoint =
localStorage.getItem("rpc-parachain") ||
"wss://kusama.rpc.robonomics.network/";
const lsKey = `haconfig:${endpoint}:${controller}`;

if (!isReady.value) {
const data = localStorage.getItem(`haconfig:${controller}`);
const data = localStorage.getItem(lsKey);
if (data) {
try {
const parsedData = JSON.parse(data);
Expand Down Expand Up @@ -217,7 +222,7 @@ export const useConfig = () => {
);

localStorage.setItem(
`haconfig:${controller}`,
lsKey,
JSON.stringify({ time: Date.now(), value: config })
);
console.log("getConfig chain");
Expand Down

0 comments on commit 8bff777

Please sign in to comment.