diff options
author | Fabio Berger <me@fabioberger.com> | 2018-07-04 04:58:17 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-07-04 04:58:17 +0800 |
commit | d528ce757c7d07e7d2e6f2f65ad48efc85ec4e50 (patch) | |
tree | 7c6d7b933ee46fd0a7d492b9ce65ce83fb7ac177 /packages | |
parent | 9b864517e2402d766b285098040787c62dfcd99d (diff) | |
download | dexon-sol-tools-d528ce757c7d07e7d2e6f2f65ad48efc85ec4e50.tar dexon-sol-tools-d528ce757c7d07e7d2e6f2f65ad48efc85ec4e50.tar.gz dexon-sol-tools-d528ce757c7d07e7d2e6f2f65ad48efc85ec4e50.tar.bz2 dexon-sol-tools-d528ce757c7d07e7d2e6f2f65ad48efc85ec4e50.tar.lz dexon-sol-tools-d528ce757c7d07e7d2e6f2f65ad48efc85ec4e50.tar.xz dexon-sol-tools-d528ce757c7d07e7d2e6f2f65ad48efc85ec4e50.tar.zst dexon-sol-tools-d528ce757c7d07e7d2e6f2f65ad48efc85ec4e50.zip |
Replace use of web3 w/ web3wrapper in subproviders and rename injectedWeb3 to signer subprovider for clarity
Diffstat (limited to 'packages')
-rw-r--r-- | packages/subproviders/package.json | 2 | ||||
-rw-r--r-- | packages/subproviders/src/index.ts | 2 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/signer.ts (renamed from packages/subproviders/src/subproviders/injected_web3.ts) | 45 | ||||
-rw-r--r-- | packages/website/ts/containers/subproviders_documentation.ts | 3 |
4 files changed, 36 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; diff --git a/packages/website/ts/containers/subproviders_documentation.ts b/packages/website/ts/containers/subproviders_documentation.ts index 6d4230e53..567f6a37e 100644 --- a/packages/website/ts/containers/subproviders_documentation.ts +++ b/packages/website/ts/containers/subproviders_documentation.ts @@ -25,6 +25,7 @@ const docSections = { emptyWalletSubprovider: 'emptyWalletSubprovider', fakeGasEstimateSubprovider: 'fakeGasEstimateSubprovider', injectedWeb3Subprovider: 'injectedWeb3Subprovider', + signerSubprovider: 'signerSubprovider', redundantRPCSubprovider: 'redundantRPCSubprovider', ganacheSubprovider: 'ganacheSubprovider', nonceTrackerSubprovider: 'nonceTrackerSubprovider', @@ -50,6 +51,7 @@ const docsInfoConfig: DocsInfoConfig = { ['emptyWallet-subprovider']: [docSections.emptyWalletSubprovider], ['fakeGasEstimate-subprovider']: [docSections.fakeGasEstimateSubprovider], ['injectedWeb3-subprovider']: [docSections.injectedWeb3Subprovider], + ['signer-subprovider']: [docSections.signerSubprovider], ['redundantRPC-subprovider']: [docSections.redundantRPCSubprovider], ['ganache-subprovider']: [docSections.ganacheSubprovider], ['nonceTracker-subprovider']: [docSections.nonceTrackerSubprovider], @@ -69,6 +71,7 @@ const docsInfoConfig: DocsInfoConfig = { [docSections.emptyWalletSubprovider]: ['"subproviders/src/subproviders/empty_wallet_subprovider"'], [docSections.fakeGasEstimateSubprovider]: ['"subproviders/src/subproviders/fake_gas_estimate_subprovider"'], [docSections.injectedWeb3Subprovider]: ['"subproviders/src/subproviders/injected_web3"'], + [docSections.signerSubprovider]: ['"subproviders/src/subproviders/signer"'], [docSections.redundantRPCSubprovider]: ['"subproviders/src/subproviders/redundant_rpc"'], [docSections.ganacheSubprovider]: ['"subproviders/src/subproviders/ganache"'], [docSections.nonceTrackerSubprovider]: ['"subproviders/src/subproviders/nonce_tracker"'], |