Skip to content

Commit

Permalink
chore: avoid substr in favour of modern js
Browse files Browse the repository at this point in the history
  • Loading branch information
2color committed Jul 29, 2024
1 parent 65ee5cb commit 1e4c48d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ <h2 class="f4">What does it mean if I get an error?</h2>
function formatOutput (formData, respObj) {
const ma = formData.get('multiaddr')
const peerIDStartIndex = ma.lastIndexOf("/p2p/")
const peerID = ma.substr(peerIDStartIndex + 5, ma.length)
const addrPart = ma.substr(0, peerIDStartIndex)
const peerID = ma.slice(peerIDStartIndex + 5);
const addrPart = ma.slice(0, peerIDStartIndex);
let outText = ""

if (respObj.ConnectionError !== "") {
Expand All @@ -174,6 +174,7 @@ <h2 class="f4">What does it mean if I get an error?</h2>
}

if (ma.indexOf("/p2p/") === 0 && ma.lastIndexOf("/") === 4) {
// only peer id passed with /p2p/PeerID
if (Object.keys(respObj.PeerFoundInDHT).length === 0) {
outText += "❌ Could not find any multiaddrs in the dht\n"
} else {
Expand All @@ -183,6 +184,7 @@ <h2 class="f4">What does it mean if I get an error?</h2>
}
}
} else {
// a proper maddr with an IP was passed
let foundAddr = false
for (const key in respObj.PeerFoundInDHT) {
if (key === addrPart) {
Expand Down

0 comments on commit 1e4c48d

Please sign in to comment.