Skip to content

Commit

Permalink
Merge pull request #411 from oasisprotocol/xz/fix-proxy-in-provider
Browse files Browse the repository at this point in the history
clients: Support Brave wallet default
  • Loading branch information
aefhm authored Oct 31, 2024
2 parents be334e2 + 3cc95f8 commit 88143e1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion clients/js/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,17 @@ 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
const propWritable =
Object.getOwnPropertyDescriptor(upstream, prop)?.writable !== false;

if (typeof value === 'function' && propWritable) {
return value.bind(upstream);
}
return value;
},
});
}

0 comments on commit 88143e1

Please sign in to comment.