Skip to content

Commit

Permalink
clients: Support Brave wallet default
Browse files Browse the repository at this point in the history
  • Loading branch information
aefhm committed Sep 24, 2024
1 parent 42c1a69 commit de0f2ec
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion clients/js/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export function fillOptions(
const SAPPHIRE_WRAPPED_ETHEREUMPROVIDER =
'#SAPPHIRE_WRAPPED_ETHEREUMPROVIDER' as const;

const BRAVE_READ_ONLY_PROPERTIES = [ 'on', 'emit', 'removeListener', 'removeAllListeners'];

export function isWrappedEthereumProvider<P extends EIP2696_EthereumProvider>(
p: P,
): p is P & { [SAPPHIRE_WRAPPED_ETHEREUMPROVIDER]: SapphireWrapOptions } {
Expand Down Expand Up @@ -208,7 +210,13 @@ export function makeTaggedProxyObject<T extends object>(
if (prop === propname) return options;
if (hooks && prop in hooks) return Reflect.get(hooks, prop);
const value = Reflect.get(upstream, prop);
return typeof value === 'function' ? value.bind(upstream) : value;
// Brave wallet web3provider properties are read only and throw typeerror
// https://github.com/brave/brave-core/blob/74bf470a0291ea3719f1a75af066ee10b7057dbd/components/brave_wallet/resources/ethereum_provider.js#L13-L27
// https://github.com/wevm/wagmi/blob/86c42248c2f34260a52ee85183c607315ae63ce8/packages/core/src/connectors/injected.ts#L327-L335
if (typeof value === 'function' && !BRAVE_READ_ONLY_PROPERTIES.includes(prop as string)) {
return value.bind(upstream);
}
return value;
},
});
}

0 comments on commit de0f2ec

Please sign in to comment.