Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class HttpMetaMaskDataAccess extends HttpDataAccess {

// Creates a local or default provider
this.provider = web3
? new ethers.providers.Web3Provider(web3.currentProvider)
? new ethers.providers.Web3Provider(web3)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: new ethers.providers.JsonRpcProvider({ url: ethereumProviderUrl });
}

Expand Down
3 changes: 0 additions & 3 deletions packages/request-client.js/src/http-request-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default class HttpRequestNetwork extends RequestNetwork {
* @param options.nodeConnectionConfig Configuration options to connect to the node. Follows Axios configuration format.
* @param options.useMockStorage When true, will use a mock storage in memory. Meant to simplify local development and should never be used in production.
* @param options.signatureProvider Module to handle the signature. If not given it will be impossible to create new transaction (it requires to sign).
* @param options.useLocalEthereumBroadcast When true, persisting use the node only for IPFS but persisting on ethereum through local provider (given in ethereumProviderUrl).
* @param options.currencies custom currency list
* @param options.currencyManager custom currency manager (will override `currencies`)
*/
Expand All @@ -43,14 +42,12 @@ export default class HttpRequestNetwork extends RequestNetwork {
nodeConnectionConfig?: AxiosRequestConfig;
signatureProvider?: SignatureProviderTypes.ISignatureProvider;
useMockStorage?: boolean;
useLocalEthereumBroadcast?: boolean;
currencies?: CurrencyInput[];
currencyManager?: ICurrencyManager;
paymentOptions?: PaymentNetworkOptions;
} = {
httpConfig: {},
nodeConnectionConfig: {},
useLocalEthereumBroadcast: false,
useMockStorage: false,
},
) {
Expand Down
11 changes: 10 additions & 1 deletion packages/request-client.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import Request from './api/request';
import Utils from './api/utils';
import { default as RequestNetwork } from './http-request-network';
import { default as RequestNetworkBase } from './api/request-network';
import { default as HttpMetaMaskDataAccess } from './http-metamask-data-access';
import * as Types from './types';

export { PaymentReferenceCalculator, Request, RequestNetwork, RequestNetworkBase, Types, Utils };
export {
PaymentReferenceCalculator,
Request,
RequestNetwork,
RequestNetworkBase,
HttpMetaMaskDataAccess,
Types,
Utils,
};
35 changes: 10 additions & 25 deletions packages/request-client.js/test/index-persist-from-metamask.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>@requestnetwork/request-client.js Test Page</title>
<script src="https://unpkg.com/@metamask/detect-provider/dist/detect-provider.min.js"></script>
<script src="..\..\request-client.js\dist\requestnetwork.min.js"></script>
<script src="..\..\web3-signature\dist\web3-signature.min.js"></script>
</head>
Expand All @@ -13,25 +14,10 @@ <h2>Important</h2>
<p>The dependencies must be built. (yarn build)</p>
<script>
window.addEventListener('load', async () => {
// Modern dapp browsers...
if (window.ethereum) {
window.web3 = new Web3(window.ethereum);
try {
await window.ethereum.enable();
startTestSignatureWithMetamask(window.web3);
} catch (error) {
// User denied account access...
console.log(error);
}
}
// Legacy dapp browsers...
else if (window.web3) {
window.web3 = new Web3(web3.currentProvider);

startTestSignatureWithMetamask(window.web3);
}
// Non-dapp browsers...
else {
const metamaskProvider = await detectEthereumProvider();
if (metamaskProvider) {
startTestSignatureWithMetamask(metamaskProvider);
} else {
console.log('Non-Ethereum browser detected. You should consider trying MetaMask!');
}
});
Expand Down Expand Up @@ -73,19 +59,18 @@ <h2>Important</h2>
};
}

async function startTestSignatureWithMetamask(web3) {
async function startTestSignatureWithMetamask(web3Provider) {
const { contentData, paymentNetwork, requestCreationHash, signatureInfo, topics } =
getMockData();

// Initialize the signature provider
const signatureProvider = new Web3SignatureProvider.Web3SignatureProvider(web3);
const signatureProvider = new Web3SignatureProvider.Web3SignatureProvider(web3Provider);

// Initialize the library in local test mode
const requestNetwork = new RequestNetwork.RequestNetwork({
const dataAccess = new RequestNetwork.HttpMetaMaskDataAccess({ web3: web3Provider });
const requestNetwork = new RequestNetwork.RequestNetworkBase({
dataAccess,
signatureProvider,
// this is a test using the mock storage instead of a real request node
useLocalEthereumBroadcast: true,
web3: window.web3,
});

// Create a request
Expand Down