Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
reassign error.data
Browse files Browse the repository at this point in the history
  • Loading branch information
Velenir committed Nov 12, 2020
1 parent a472504 commit f66eb4d
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/api/wallet/composeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ import {
removeTxPendingApproval,
} from 'components/OuterModal'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const sanitizeErrorData = (jsonRpcError?: JsonRpcError<any>): void => {
if (!jsonRpcError) return

if (jsonRpcError.data?.originalError) {
jsonRpcError.data = jsonRpcError.data.originalError.data
}
}

// custom providerAsMiddleware
function providerAsMiddleware(provider: Provider): JsonRpcMiddleware {
// WalletConnectProvider.sendAsync is web3-provider-engine.sendAsync
Expand All @@ -46,10 +55,17 @@ function providerAsMiddleware(provider: Provider): JsonRpcMiddleware {
return
}

provider.request(req).then((providerRes) => {
Object.assign(res, providerRes)
end()
}, end)
provider.request(req).then(
(providerRes) => {
Object.assign(res, providerRes)
sanitizeErrorData(res.error)
end()
},
(error) => {
sanitizeErrorData(error)
end(error)
},
)
}
}

Expand All @@ -62,7 +78,11 @@ function providerAsMiddleware(provider: Provider): JsonRpcMiddleware {

provider[sendFName](req, (err: JsonRpcError<unknown>, providerRes: JsonRpcResponse<unknown>) => {
// forward any error
if (err) return end(err)
if (err) {
sanitizeErrorData(err)
return end(err)
}
sanitizeErrorData(providerRes.error)
// copy provider response onto original response
Object.assign(res, providerRes)
end()
Expand Down

0 comments on commit f66eb4d

Please sign in to comment.