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

Metamask provider not wrapped in MetamaskSubprovider error - EIP712 #1223

Closed
MarcZenn opened this issue Nov 7, 2018 · 6 comments
Closed

Comments

@MarcZenn
Copy link
Contributor

MarcZenn commented Nov 7, 2018

Expected Behavior

Per the examples provider here - #1169, I've setup the following MetamaskSubprovider implementation:

import { MetamaskSubprovider, RPCSubprovider, SignerSubprovider,  Web3ProviderEngine } from '@0x/subproviders';

const engine = new Web3ProviderEngine();
const signer = new MetamaskSubprovider(web.currentProvider);
const rpcProvider = new RPCSubprovider(nodeUrl);

// Add the signer first, all account based requests are handled by the signer
engine.addProvider(signer);

// Add the data provider, all logs, data fetching are handled by the rpcProvider
engine.addProvider(rpcProvider);

const web3Wrapper = new Web3Wrapper(engine);
const contractWrappers = new ContractWrappers(engine, { networkId });

This should display order data in the Metamask signing prompt when an order is signed via the following 0x.js signature utils method:

import { signatureUtils } from '0x.js';

try {
     await signatureUtils.ecSignTypedDataOrderAsync(engine, order, makerAddress);
 } catch (error) {
     console.log(error);
}

Current Behavior

At the moment that method when invoked is producing an error that when logged outputs Error: MetaMask provider must be wrapped in a MetamaskSubprovider (from the '@0x/subproviders' package) in order to work with this method. to the console.

This is accompanied by MetaMask - RPC Error: TypeError: e.toLowerCase is not a function chrome-at L extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js type error.

Possible Solution

Unsure of a solution but passing MetamaskSuprovider directly to ecSignTypedDataOrderAsync i.e.
signatureUtils.ecSignTypedDataOrderAsync(new MetamaskSuprovider(web.currentProvider, order, makerAddress) works as expected.

Steps to Reproduce (for bugs)

I will post up a minimal repo as soon as I can.

Environment

0x.js 2.0.0
@0x/subproviders 2.1.0
@0x/web3-wrapper 3.1.0
metamask plugin 5.0.0
node 8.9.0

@dekz
Copy link
Member

dekz commented Nov 7, 2018

hey @MarcZenn

MetaMask - RPC Error: TypeError: e.toLowerCase is not a function might be an indication to an underlying problem.

I've quickly forked the codesandbox to use provider engine. It should popup a signing window on load. Which I've just tested locally on Metamask 5.0.0.

Can you confirm whether you see the same errors in this code sandbox, or if the signing window appears?

@MarcZenn
Copy link
Contributor Author

MarcZenn commented Nov 7, 2018

Hmm the signing window appears in the codesandbox and works as expected.

@dekz
Copy link
Member

dekz commented Nov 7, 2018

Can you JSON stringify the order and signerAddress/makerAddress you are using in your example?

@MarcZenn
Copy link
Contributor Author

MarcZenn commented Nov 7, 2018

JSON stringifying results in a type error Error: Expected order to conform to schema /orderSchema when passed due to function signature param types. I'll attempt to step through signature_utils and metamask_suprovider and see what I come across.

@MarcZenn
Copy link
Contributor Author

MarcZenn commented Nov 8, 2018

I've found the cause of my issue!

There was a method in my code overriding the MetamaskSubprovider wrapped provider with the injected web3 provider...hence the error. my bad.

@dekz want me to close the issue?

@dekz
Copy link
Member

dekz commented Nov 8, 2018

@MarcZenn ah that would do it. Let me know if you run into any other issues.

@dekz dekz closed this as completed Nov 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants