diff --git a/src/utils/libp2p/libp2p.js b/src/utils/libp2p/libp2p.js index 07ca8c6..f5695ec 100644 --- a/src/utils/libp2p/libp2p.js +++ b/src/utils/libp2p/libp2p.js @@ -1,12 +1,12 @@ import { noise } from "@chainsafe/libp2p-noise"; +import { circuitRelayTransport } from "@libp2p/circuit-relay-v2"; +import { identify } from "@libp2p/identify"; import { mplex } from "@libp2p/mplex"; import { webRTC } from "@libp2p/webrtc"; import { webSockets } from "@libp2p/websockets"; import * as filters from "@libp2p/websockets/filters"; import { multiaddr } from "@multiformats/multiaddr"; import { createLibp2p } from "libp2p"; -import { circuitRelayTransport } from "@libp2p/circuit-relay-v2"; -import { identify } from "@libp2p/identify"; import { createHa } from "./ha"; export async function createNode() { @@ -68,6 +68,7 @@ export async function start() { console.log("disconected", event.detail.remoteAddr.toString()); updateConnectionsList(); if ( + connection && event.detail.remoteAddr.toString() === connection.remoteAddr.toString() ) { reconnect(connection.remoteAddr.toString()); diff --git a/src/views/telemetry/common.js b/src/views/telemetry/common.js index 8abcf91..f2d0046 100644 --- a/src/views/telemetry/common.js +++ b/src/views/telemetry/common.js @@ -157,7 +157,6 @@ export const useLastDatalog = () => { }; export const useConfig = () => { - const cid = ref(null); const config = ref(null); const store = useStore(); @@ -167,6 +166,16 @@ export const useConfig = () => { (async () => { if (controller.value) { + const haconfig = localStorage.getItem( + `haconfig:${controller.value.address}` + ); + if (haconfig) { + try { + config.value = JSON.parse(haconfig); + } catch (error) { + console.log(error); + } + } notify(store, "Find twin id"); const datalog = await getLastDatalog( robonomics, @@ -184,18 +193,24 @@ export const useConfig = () => { notify(store, `Twin id #${twin_id}`); notify(store, `Start load config`); - cid.value = await getConfigCid( + const cid = await getConfigCid( robonomics, controller.value.address, twin_id ); config.value = await catFileController( - cid.value, + cid, controller.value, store, ipfs ); + + localStorage.setItem( + `haconfig:${controller.value.address}`, + JSON.stringify(config.value) + ); + notify(store, `Config loaded`); } else { notify(store, "Error: not found twin id"); @@ -203,5 +218,5 @@ export const useConfig = () => { } })(); - return { config, cid }; + return { config }; };