├── .gitignore ├── src ├── index.js ├── CheckIcon.jsx ├── AccountUnavailable.jsx ├── Web3Unavailable.jsx ├── ErrorTemplate.jsx ├── stylesheet.js ├── IconNoWeb3.jsx └── Web3Provider.jsx ├── test ├── helpers │ ├── utils.js │ ├── Component.jsx │ ├── web3.mock.js │ └── web3-v1.mock.js ├── provider-styles.test.js ├── .setup.js └── Web3Provider.test.js ├── webpack.config.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const Web3Provider = require('./Web3Provider'); 2 | const ErrorTemplate = require('./ErrorTemplate'); 3 | 4 | module.exports.Web3Provider = Web3Provider; 5 | module.exports.ErrorTemplate = ErrorTemplate; 6 | 7 | module.exports = { 8 | Web3Provider, 9 | ErrorTemplate 10 | }; 11 | -------------------------------------------------------------------------------- /src/CheckIcon.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | function CheckIcon() { 4 | return ( 5 | 11 | 12 | 13 | 14 | 15 | 16 | ); 17 | } 18 | 19 | export default CheckIcon; 20 | -------------------------------------------------------------------------------- /src/AccountUnavailable.jsx: -------------------------------------------------------------------------------- 1 | const React = require('react'); 2 | const ErrorTemplate = require('./ErrorTemplate'); 3 | 4 | const AccountUnavailable = ErrorTemplate.bind(null, { 5 | title: 'No ETH Account Available', 6 | message: ` 7 | It seems that you don't have an ETH account selected. If using 8 | MetaMask, please make sure that your wallet is unlocked and that 9 | you have at least one account in your accounts list.` 10 | }); 11 | 12 | module.exports = AccountUnavailable; 13 | -------------------------------------------------------------------------------- /test/helpers/utils.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Web3Provider from '../../src/Web3Provider'; 3 | import { shallow, mount } from 'enzyme'; 4 | 5 | export const wait = t => new Promise( 6 | (resolve, reject) => setTimeout(t, resolve) 7 | ); 8 | 9 | export const getWrapper = () => shallow( 10 | 11 |
12 | 13 | ); 14 | export const getMount = () => mount( 15 | 16 |
17 | 18 | ); 19 | -------------------------------------------------------------------------------- /src/Web3Unavailable.jsx: -------------------------------------------------------------------------------- 1 | const React = require('react'); 2 | const ErrorTemplate = require('./ErrorTemplate'); 3 | 4 | const Web3Unavailable = ErrorTemplate.bind(null, { 5 | title: 'Web3 Not Found', 6 | message: ` 7 | It seems that you are using a browser without Web3 capabilities. Please 8 | make sure that you are using a web3-capable browser like mist or parity. 9 | If you are using MetaMask or Parity extension, make sure that it is 10 | enabled. 11 | ` 12 | }); 13 | 14 | module.exports = Web3Unavailable; 15 | -------------------------------------------------------------------------------- /test/helpers/Component.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | class Component extends React.Component { 5 | render() { 6 | const { 7 | web3: { 8 | selectedAccount 9 | } 10 | } = this.context; 11 | 12 | return ( 13 |
14 | {selectedAccount} 15 |
16 | ) 17 | } 18 | } 19 | 20 | Component.contextTypes = { 21 | web3: PropTypes.object 22 | }; 23 | 24 | Component.displayName = 'mock-component'; 25 | 26 | export default Component; 27 | -------------------------------------------------------------------------------- /test/helpers/web3.mock.js: -------------------------------------------------------------------------------- 1 | let defaultAccounts = []; 2 | let defaultNetwork = '1'; 3 | let accounts = defaultAccounts.slice(); 4 | let network = defaultNetwork; 5 | 6 | module.exports = { 7 | eth: { 8 | accounts: accounts, 9 | getAccounts: cb => cb(null, accounts) 10 | }, 11 | version: { 12 | getNetwork: () => network 13 | }, 14 | currentProvider: { 15 | enable: () => { 16 | return Promise.resolve(accounts) 17 | }, 18 | }, 19 | setNetwork: v => network = v, 20 | setAccounts: v => accounts = v, 21 | restore: () => { 22 | accounts = defaultAccounts.slice(); 23 | network = defaultNetwork; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /test/provider-styles.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { expect } from 'chai'; 3 | import { shallow, mount } from 'enzyme'; 4 | import sinon from 'sinon'; 5 | import PropTypes from 'prop-types'; 6 | import Web3Provider from '../src/Web3Provider'; 7 | import Component from './helpers/Component'; 8 | import { wait, getWrapper, getMount } from './helpers/utils'; 9 | 10 | describe('Styles', function () { 11 | 12 | it('should load default stylesheet', () => { 13 | const wrapper = mount( 14 | 15 |
16 | 17 | ); 18 | const html = wrapper.html(); 19 | 20 | expect(html).to.contain(`