Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(widget): suppress console errors #2594

Merged
merged 10 commits into from
May 9, 2024
6 changes: 6 additions & 0 deletions packages/widget/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as BRIDGEABLE from '@/constants/bridgeable'
import { CHAINS_ARRAY } from '@/constants/chains'
import { BackgroundListenerProvider } from '@/providers/BackgroundListenerProvider'
import { useBridgeSelectionData } from '@/hooks/useBridgeSelectionData'
import { suppressSynapseConsoleErrors } from '@/utils/suppressSynapseConsoleErrors'

export const Bridge = ({
web3Provider,
Expand All @@ -20,11 +21,16 @@ export const Bridge = ({
targetChainIds,
targetTokens,
protocolName,
hideConsoleErrors,
}: BridgeProps) => {
if (!web3Provider) {
return null
}

if (hideConsoleErrors) {
suppressSynapseConsoleErrors()
}

return (
<Web3Provider config={web3Provider}>
<SynapseProvider chains={CHAINS_ARRAY} customRpcs={customRpcs}>
Expand Down
3 changes: 3 additions & 0 deletions packages/widget/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export interface BridgeProps {

/* Custom name prop for consumer protocol */
protocolName?: string

/* Supress Consumer browser console errors */
hideConsoleErrors?: boolean
}

export interface Chain {
Expand Down
27 changes: 27 additions & 0 deletions packages/widget/src/utils/suppressSynapseConsoleErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
enum SynapseErrorPrefix {
SDK = 'SynapseSDK',
WIDGET = 'Synapse Widget',
}

export const suppressSynapseConsoleErrors = () => {
console.log('Supressing Synapse console errors.')

// Store the original console.error function
const originalConsoleError = console.error

// Redefine console.error to filter out specific messages
console.error = (...args) => {
const message = args.join(' ')

// Suppress Synapse console.error messages
if (
message.includes(SynapseErrorPrefix.SDK) ||
message.includes(SynapseErrorPrefix.WIDGET)
) {
return
}

// Call the original console.error for other messages
originalConsoleError(...args)
}
}
bigboydiamonds marked this conversation as resolved.
Show resolved Hide resolved
Loading