aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders
diff options
context:
space:
mode:
Diffstat (limited to 'packages/subproviders')
-rw-r--r--packages/subproviders/package.json2
-rw-r--r--packages/subproviders/src/index.ts2
-rw-r--r--packages/subproviders/src/subproviders/signer.ts (renamed from packages/subproviders/src/subproviders/injected_web3.ts)45
3 files changed, 33 insertions, 16 deletions
diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json
index a3ff31f53..2d939f7b4 100644
--- a/packages/subproviders/package.json
+++ b/packages/subproviders/package.json
@@ -42,6 +42,7 @@
"dependencies": {
"@0xproject/assert": "^0.2.12",
"@0xproject/types": "^0.8.1",
+ "@0xproject/web3-wrapper": "^0.7.1",
"@0xproject/typescript-typings": "^0.4.2",
"@0xproject/utils": "^0.7.1",
"@ledgerhq/hw-app-eth": "^4.3.0",
@@ -55,7 +56,6 @@
"hdkey": "^0.7.1",
"lodash": "^4.17.4",
"semaphore-async-await": "^1.5.1",
- "web3": "^0.20.0",
"web3-provider-engine": "14.0.6"
},
"devDependencies": {
diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts
index 9194c1341..8575cd07d 100644
--- a/packages/subproviders/src/index.ts
+++ b/packages/subproviders/src/index.ts
@@ -7,7 +7,7 @@ import { LedgerEthereumClient } from './types';
export { prependSubprovider } from './utils/subprovider_utils';
export { EmptyWalletSubprovider } from './subproviders/empty_wallet_subprovider';
export { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_subprovider';
-export { InjectedWeb3Subprovider } from './subproviders/injected_web3';
+export { SignerSubprovider } from './subproviders/signer';
export { RedundantSubprovider } from './subproviders/redundant_subprovider';
export { LedgerSubprovider } from './subproviders/ledger';
export { GanacheSubprovider } from './subproviders/ganache';
diff --git a/packages/subproviders/src/subproviders/injected_web3.ts b/packages/subproviders/src/subproviders/signer.ts
index 2691dec53..65b1f2635 100644
--- a/packages/subproviders/src/subproviders/injected_web3.ts
+++ b/packages/subproviders/src/subproviders/signer.ts
@@ -1,5 +1,5 @@
+import { Web3Wrapper } from '@0project/web3-wrapper';
import { JSONRPCRequestPayload, Provider } from 'ethereum-types';
-import * as Web3 from 'web3';
import { Callback, ErrorCallback } from '../types';
@@ -7,19 +7,19 @@ import { Subprovider } from './subprovider';
/**
* This class implements the [web3-provider-engine](https://github.com/MetaMask/provider-engine)
- * subprovider interface. It forwards JSON RPC requests involving user accounts (getAccounts,
- * sendTransaction, etc...) to the provider instance supplied at instantiation. All other requests
+ * subprovider interface. It forwards JSON RPC requests involving the domain of a signer (getAccounts,
+ * sendTransaction, signMessage etc...) to the provider instance supplied at instantiation. All other requests
* are passed onwards for subsequent subproviders to handle.
*/
-export class InjectedWeb3Subprovider extends Subprovider {
- private _injectedWeb3: Web3;
+export class SignerSubprovider extends Subprovider {
+ private _SignerWrapper: Web3Wrapper;
/**
- * Instantiates a new InjectedWeb3Subprovider
+ * Instantiates a new SignerSubprovider
* @param provider Web3 provider that should handle all user account related requests
*/
constructor(provider: Provider) {
super();
- this._injectedWeb3 = new Web3(provider);
+ this._SignerWrapper = new Web3Wrapper(provider);
}
/**
* This method conforms to the web3-provider-engine interface.
@@ -33,22 +33,39 @@ export class InjectedWeb3Subprovider extends Subprovider {
public async handleRequest(payload: JSONRPCRequestPayload, next: Callback, end: ErrorCallback): Promise<void> {
switch (payload.method) {
case 'web3_clientVersion':
- this._injectedWeb3.version.getNode(end);
+ try {
+ const nodeVersion = await this._SignerWrapper.getNodeVersionAsync();
+ end(null, nodeVersion);
+ } catch (err) {
+ end(err);
+ }
return;
case 'eth_accounts':
- this._injectedWeb3.eth.getAccounts(end);
+ try {
+ const accounts = await this._SignerWrapper.getAvailableAddressesAsync();
+ end(null, accounts);
+ } catch (err) {
+ end(err);
+ }
return;
-
case 'eth_sendTransaction':
const [txParams] = payload.params;
- this._injectedWeb3.eth.sendTransaction(txParams, end);
+ try {
+ const txHash = await this._SignerWrapper.sendTransactionAsync(txParams);
+ end(null, txHash);
+ } catch (err) {
+ end(err);
+ }
return;
-
case 'eth_sign':
const [address, message] = payload.params;
- this._injectedWeb3.eth.sign(address, message, end);
+ try {
+ const signature = await this._SignerWrapper.signMessageAsync(address, message);
+ end(null, signature);
+ } catch (err) {
+ end(err);
+ }
return;
-
default:
next();
return;