Skip to content

Commit

Permalink
fix not found setup
Browse files Browse the repository at this point in the history
  • Loading branch information
vol4tim committed Mar 12, 2024
1 parent c616c26 commit 59cee6d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 61 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"ipfs-http-client": "^60.0.0",
"libp2p": "^1.2.4",
"robonomics-interface": "^0.3.2",
"robonomics-ui-vue": "^0.2.9",
"robonomics-ui-vue": "^0.3.0",
"uuid": "^9.0.1",
"vue": "^3.4.15",
"vue-router": "^4.2.5",
Expand Down
112 changes: 60 additions & 52 deletions src/views/telemetry/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,22 @@ export const catFileController = async (cid, controller, store, ipfs) => {
};

const loadSetup = (store) => {
if (!store.state.robonomicsUIvue.rws.active) {
return;
}
const setupRaw = store.state.robonomicsUIvue.rws.list.find(
(item) => item.owner === store.state.robonomicsUIvue.rws.active
);
if (setupRaw) {
try {
return {
controller: encryptor(createPair(setupRaw.scontroller)),
owner: setupRaw.owner
};
} catch (error) {
console.log(error);
if (store.state.robonomicsUIvue.rws.active) {
const setupRaw = store.state.robonomicsUIvue.rws.list.find(
(item) => item.owner === store.state.robonomicsUIvue.rws.active
);
if (setupRaw) {
try {
return {
controller: encryptor(createPair(setupRaw.scontroller)),
owner: setupRaw.owner
};
} catch (error) {
console.log(error);
}
}
}
return {
controller: null,
owner: null
};
return false;
};

export const useSetup = () => {
Expand All @@ -104,8 +100,10 @@ export const useSetup = () => {
() => store.state.robonomicsUIvue.rws.active,
() => {
const setup = loadSetup(store);
controller.value = setup.controller;
owner.value = setup.owner;
if (setup) {
controller.value = setup.controller;
owner.value = setup.owner;
}
},
{ immediate: true }
);
Expand Down Expand Up @@ -139,15 +137,20 @@ export const useLastDatalog = () => {
const { controller } = useSetup();

(async () => {
const datalog = await getLastDatalog(robonomics, controller.value.address);
cid.value = datalog.cid;
updateTime.value = datalog.timestamp;
data.value = await catFileController(
cid.value,
controller.value,
store,
ipfs
);
if (controller.value) {
const datalog = await getLastDatalog(
robonomics,
controller.value.address
);
cid.value = datalog.cid;
updateTime.value = datalog.timestamp;
data.value = await catFileController(
cid.value,
controller.value,
store,
ipfs
);
}
})();

return { cid, updateTime, data };
Expand All @@ -163,35 +166,40 @@ export const useConfig = () => {
const { controller } = useSetup();

(async () => {
notify(store, "Find twin id");
const datalog = await getLastDatalog(robonomics, controller.value.address);
const result = await catFileController(
datalog.cid,
controller.value,
store,
ipfs
);

if (result) {
const twin_id = result.twin_id;
notify(store, `Twin id #${twin_id}`);

notify(store, `Start load config`);
cid.value = await getConfigCid(
if (controller.value) {
notify(store, "Find twin id");
const datalog = await getLastDatalog(
robonomics,
controller.value.address,
twin_id
controller.value.address
);

config.value = await catFileController(
cid.value,
const result = await catFileController(
datalog.cid,
controller.value,
store,
ipfs
);
notify(store, `Config loaded`);
} else {
notify(store, "Error: not found twin id");

if (result) {
const twin_id = result.twin_id;
notify(store, `Twin id #${twin_id}`);

notify(store, `Start load config`);
cid.value = await getConfigCid(
robonomics,
controller.value.address,
twin_id
);

config.value = await catFileController(
cid.value,
controller.value,
store,
ipfs
);
notify(store, `Config loaded`);
} else {
notify(store, "Error: not found twin id");
}
}
})();

Expand Down
15 changes: 11 additions & 4 deletions src/views/telemetry/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export const useData = () => {
(results) => {
const r = results.filter((item) => {
return (
item.success && item.data[0].toHuman() === controller.value.address
item.success &&
controller.value &&
item.data[0].toHuman() === controller.value.address
);
});
for (const item of r) {
Expand All @@ -68,9 +70,14 @@ export const useData = () => {
});

const run = async () => {
const datalog = await getLastDatalog(robonomics, controller.value.address);
cid.value = datalog.cid;
updateTime.value = datalog.timestamp;
if (controller.value) {
const datalog = await getLastDatalog(
robonomics,
controller.value.address
);
cid.value = datalog.cid;
updateTime.value = datalog.timestamp;
}
watchDatalog();
};

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7688,10 +7688,10 @@ robonomics-interface@^0.3.2:
cids "^1.1.9"
multihashing-async "^2.1.4"

robonomics-ui-vue@^0.2.9:
version "0.2.9"
resolved "https://registry.yarnpkg.com/robonomics-ui-vue/-/robonomics-ui-vue-0.2.9.tgz#bd59a6def3bec35ab35393d227775df715d52791"
integrity sha512-nr4q2owm548QSRVmvUZPZqNTSiP4PT1PEC7eOUhHM1YNMf+C+s6JGLzD1aOwmcuOcxZNHNobtVY8mlwGanNHgw==
robonomics-ui-vue@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/robonomics-ui-vue/-/robonomics-ui-vue-0.3.0.tgz#3324250a845bdff50a1723318a54812ef59183d8"
integrity sha512-0GNYkNXuyRixqagKwbOcNP3m83u2pjtLIMmWr/kFwdDGvGNyWCB8v+tDas4iQaO5DD49JpR7C+NbFfYaun7uRQ==
dependencies:
"@polkadot/ui-keyring" "^3.6.4"
"@polkadot/util-crypto" "^12.6.2"
Expand Down

0 comments on commit 59cee6d

Please sign in to comment.