aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders
diff options
context:
space:
mode:
Diffstat (limited to 'packages/subproviders')
-rw-r--r--packages/subproviders/package.json3
-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, 34 insertions, 16 deletions
diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json
index 076129636..8eca91dc7 100644
--- a/packages/subproviders/package.json
+++ b/packages/subproviders/package.json
@@ -42,6 +42,8 @@
"dependencies": {
"@0xproject/assert": "^0.2.12",
"@0xproject/types": "^1.0.0",
+ "@0xproject/web3-wrapper": "^0.7.1",
+ "@0xproject/typescript-typings": "^0.4.2",
"@0xproject/utils": "^0.7.1",
"@ledgerhq/hw-app-eth": "^4.3.0",
"@ledgerhq/hw-transport-u2f": "^4.3.0",
@@ -55,7 +57,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 802a27cb1..71d643f14 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..08a9daceb 100644
--- a/packages/subproviders/src/subproviders/injected_web3.ts
+++ b/packages/subproviders/src/subproviders/signer.ts
@@ -1,5 +1,5 @@
+import { Web3Wrapper } from '@0xproject/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 _web3Wrapper: 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._web3Wrapper = 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._web3Wrapper.getNodeVersionAsync();
+ end(null, nodeVersion);
+ } catch (err) {
+ end(err);
+ }
return;
case 'eth_accounts':
- this._injectedWeb3.eth.getAccounts(end);
+ try {
+ const accounts = await this._web3Wrapper.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._web3Wrapper.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._web3Wrapper.signMessageAsync(address, message);
+ end(null, signature);
+ } catch (err) {
+ end(err);
+ }
return;
-
default:
next();
return;