Skip to content

Commit

Permalink
[Fix] Network add in portfolio swap (#1153)
Browse files Browse the repository at this point in the history
* fix network add in portfolio swap

* run prettier
  • Loading branch information
BrettCleary authored Nov 16, 2024
1 parent 7a9c4f7 commit 9b20356
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/backend/proxy/providerPreload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,33 @@ const listenToRendererCalls = (
})
}

function extractJSONAfterError(input: string): object | null {
try {
// Match the pattern where "error=" precedes a JSON string
const errorPattern = /error=(\{[^{}]*\})/

const match = input.match(errorPattern)

if (match && match[1]) {
// Parse the JSON string captured by the regex
return JSON.parse(match[1])
}

// Return null if no valid JSON is found
return null
} catch (error) {
console.error('Error parsing JSON:', error)
return null
}
}

const provRequest = async (args: RequestArguments) => {
const x = await ipcRenderer.invoke('providerRequest', args)
const jsonErrorInString = extractJSONAfterError(`${x}`)
if (jsonErrorInString !== null) {
throw jsonErrorInString
}

if (
x !== null &&
x !== 'undefined' &&
Expand Down

0 comments on commit 9b20356

Please sign in to comment.