Skip to content
This repository has been archived by the owner on Nov 9, 2024. It is now read-only.

Commit

Permalink
Fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
necipsagiro committed Mar 1, 2024
1 parent c6aabe1 commit e9a40c7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 41 deletions.
5 changes: 3 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,16 +938,17 @@ fn edit_validator(
--security-contact={contact} \
--identity={keybase_id} \
--commission-rate={com_rate} \
--details={details}'",
--details={details} 2>&1'",
password = my_boxed_session.walletpassword,
operation = match exception.as_str() {
"babylon" => "checkpointing",
"babylon" => "staking",
_ => "staking",
},
))
.map_err(|e| e.to_string())?;
channel.read_to_string(&mut s).map_err(|e| e.to_string())?;
channel.close().map_err(|e| e.to_string())?;
println!("{}", s);
Ok(s)
}

Expand Down
99 changes: 60 additions & 39 deletions src/node-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ tevent.listen("check_logs", (event) => {
}
});

function getJsonFromText(text) {
const startIndex = text.indexOf('{');
const endIndex = text.lastIndexOf('}') + 1;

const json = text.substring(startIndex, endIndex);

return JSON.parse(json);
};

const loadNodePage = async (start) => {
const eachSidebarTag = document.querySelectorAll(".each-sidebar-tag");
eachSidebarTag[0].setAttribute("class", "each-sidebar-tag sidebar-active-tag");
Expand Down Expand Up @@ -501,26 +510,33 @@ const addValidatorSetup = () => {
details: document.querySelectorAll(".each-input-field")[8].value,
exception: exception
}).then(async (res) => {
console.log(res);
res = res.slice(res.indexOf('{'));
res = JSON.parse(res);
if (res.raw_log.length == 2) {
createMessage("Tx Hash", res.txhash);
await tauri.invoke("show_wallets", { exception: exception }).then(async (list) => {
list = JSON.parse(list);
currentIp.validator_addr = list.filter((item) => item.name == document.querySelectorAll(".each-input-field")[1].value)[0].address;
}).catch((err) => {
console.log(err);
showErrorMessage(err);
});
await tauri.invoke("set_main_wallet", { walletname: document.querySelectorAll(".each-input-field")[1].value, address: currentIp.validator_addr, exception: exception }).catch((err) => {
console.log(err);
showErrorMessage(err);
});
localStorage.setItem("ipaddresses", JSON.stringify(ipAddresses));
await updateSidebar();
} else {
showErrorMessage(res.raw_log);
if (res.includes('validator already exist'))
showErrorMessage("Validator already exists");
else if (res.includes('insufficient funds'))
showErrorMessage("Insufficient funds");
else if (res.includes('not found: key not found'))
showErrorMessage("Please send tokens to the wallet first");
else {
res = getJsonFromText(res);
console.log(res);
if (res.raw_log.length == 2 || res.raw_log.length == 0) {
createMessage("Tx Hash", res.txhash);
await tauri.invoke("show_wallets", { exception: exception }).then(async (list) => {
list = JSON.parse(list);
currentIp.validator_addr = list.filter((item) => item.name == document.querySelectorAll(".each-input-field")[1].value)[0].address;
}).catch((err) => {
console.log(err);
showErrorMessage(err);
});
await tauri.invoke("set_main_wallet", { walletname: document.querySelectorAll(".each-input-field")[1].value, address: currentIp.validator_addr, exception: exception }).catch((err) => {
console.log(err);
showErrorMessage(err);
});
localStorage.setItem("ipaddresses", JSON.stringify(ipAddresses));
await updateSidebar();
} else {
showErrorMessage(res.raw_log);
};
};
}).catch(async (err) => { await handleTimeOut(err); showErrorMessage(err); });
hideLoadingAnimation();
Expand All @@ -537,17 +553,16 @@ const editValidatorSetup = () => {
hideErrorMessage();
await tauri.invoke("edit_validator", {
walletName: document.querySelectorAll(".each-input-field")[0].value,
website: document.querySelectorAll(".each-input-field")[1].value,
comRate: document.querySelectorAll(".each-input-field")[2].value,
contact: document.querySelectorAll(".each-input-field")[3].value,
keybaseId: document.querySelectorAll(".each-input-field")[4].value,
comRate: document.querySelectorAll(".each-input-field")[1].value,
website: document.querySelectorAll(".each-input-field")[2].value,
keybaseId: document.querySelectorAll(".each-input-field")[3].value,
contact: document.querySelectorAll(".each-input-field")[4].value,
details: document.querySelectorAll(".each-input-field")[5].value,
exception: exception
}).then((res) => {
res = res.slice(res.indexOf('{'));
console.log(res);
res = JSON.parse(res);
if (res.raw_log.length == 2) {
res = getJsonFromText(res);
if (res.raw_log.length == 2 || res.raw_log.length == 0) {
createMessage("Tx Hash", res.txhash);
} else {
showErrorMessage(res.raw_log);
Expand All @@ -569,8 +584,9 @@ const withdrawRewardsSetup = () => {
fees: document.querySelectorAll(".each-input-field")[1].value,
exception: exception
}).then((res) => {
res = JSON.parse(res);
if (res.raw_log.length == 2) {
res = getJsonFromText(res);
console.log(res);
if (res.raw_log.length == 2 || res.raw_log.length == 0) {
createMessage("Tx Hash", res.txhash);
} else {
showErrorMessage(res.raw_log);
Expand All @@ -592,9 +608,9 @@ const delegateSetup = (valoper) => {
amount: document.querySelectorAll(".each-input-field")[3].value,
exception: exception
}).then((res) => {
res = getJsonFromText(res);
console.log(res);
res = JSON.parse(res);
if (res.raw_log.length == 2) {
if (res.raw_log.length == 2 || res.raw_log.length == 0) {
createMessage("Tx Hash", res.txhash);
} else {
showErrorMessage(res.raw_log);
Expand All @@ -616,8 +632,9 @@ const redelegateSetup = () => {
amount: document.querySelectorAll(".each-input-field")[4].value,
exception: exception
}).then((res) => {
res = JSON.parse(res);
if (res.raw_log.length == 2) {
res = getJsonFromText(res);
console.log(res);
if (res.raw_log.length == 2 || res.raw_log.length == 0) {
createMessage("Tx Hash", res.txhash);
} else {
showErrorMessage(res.raw_log);
Expand All @@ -637,8 +654,9 @@ const voteSetup = () => {
selectedOption: document.querySelector(".each-input-radio-option:checked").nextElementSibling.textContent.toLowerCase(),
exception: exception
}).then((res) => {
res = JSON.parse(res);
if (res.raw_log.length == 2) {
res = getJsonFromText(res);
console.log(res);
if (res.raw_log.length == 2 || res.raw_log.length == 0) {
createMessage("Tx Hash", res.txhash);
} else {
showErrorMessage(res.raw_log);
Expand All @@ -657,8 +675,9 @@ const unjailSetup = () => {
fees: document.querySelectorAll(".each-input-field")[1].value,
exception: exception
}).then((res) => {
res = JSON.parse(res);
if (res.raw_log.length == 2) {
res = getJsonFromText(res);
console.log(res);
if (res.raw_log.length == 2 || res.raw_log.length == 0) {
createMessage("Tx Hash", res.txhash);
} else {
showErrorMessage(res.raw_log);
Expand All @@ -679,8 +698,9 @@ const sendTokenSetup = () => {
fees: document.querySelectorAll(".each-input-field")[3].value,
exception: exception
}).then((res) => {
res = JSON.parse(res);
if (res.raw_log.length == 2) {
res = getJsonFromText(res);
console.log(res);
if (res.raw_log.length == 2 || res.raw_log.length == 0) {
createMessage("Tx Hash", res.txhash);
} else {
showErrorMessage(res.raw_log);
Expand All @@ -695,6 +715,7 @@ const createBLSKeySetup = () => {
showLoadingAnimation();
hideErrorMessage();
await tauri.invoke("create_bls_key", { walletName: document.querySelectorAll(".each-input-field")[0].value }).then((res) => {
res = getJsonFromText(res);
console.log(res);
if (res.includes("Error")) {
showErrorMessage("Wrong wallet name!");
Expand Down

0 comments on commit e9a40c7

Please sign in to comment.