This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88ff168
commit a5ca46b
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import LocalStore from 'electron-store'; | ||
import { action, observable } from 'mobx'; | ||
|
||
const localStore = new LocalStore(); | ||
|
||
class AppStore { | ||
@observable depositPublicKey = localStore.get('depositPublicKey', ''); | ||
|
||
@observable screen = 'whatYouNeed'; | ||
|
||
@observable alertType = ''; | ||
|
||
@observable locale = 'en'; | ||
|
||
@observable secretKey = ''; | ||
|
||
@observable gb = [20]; | ||
|
||
@observable state = 'disabled'; | ||
|
||
@action.bound | ||
setScreen(screen) { | ||
this.screen = screen; | ||
} | ||
|
||
@action.bound | ||
showAlert(alertType) { | ||
this.alertType = alertType; | ||
} | ||
|
||
@action.bound | ||
hideAlert() { | ||
this.alertType = null; | ||
} | ||
|
||
@action.bound | ||
setSecretKey(secretKey) { | ||
this.secretKey = secretKey; | ||
} | ||
|
||
@action.bound | ||
setGB(gb) { | ||
this.gb = gb; | ||
} | ||
|
||
@action.bound | ||
setDepositPublicKey(key) { | ||
this.depositPublicKey = key; | ||
} | ||
|
||
@action.bound | ||
setState(state) { | ||
this.state = state; | ||
} | ||
} | ||
|
||
const store = new AppStore(); | ||
|
||
export default store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { configure } from 'mobx'; | ||
|
||
configure({ | ||
enforceActions: 'observed', | ||
}); | ||
|
||
export { default as AppStore } from './app'; | ||
export { default as StatsStore } from './stats'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import LocalStore from 'electron-store'; | ||
import { Connection, PublicKey } from '@solana/web3.js'; | ||
import { action, observable, flow } from 'mobx'; | ||
import url from '../url'; | ||
import Replicator from '../replicator'; | ||
import AppStore from './app'; | ||
|
||
const DEFAULT_LAMPORTS = 10000; | ||
const localStore = new LocalStore(); | ||
|
||
class StatsStore { | ||
constructor() { | ||
this.connection = new Connection(url); | ||
this.replicator = new Replicator(this.connection); | ||
} | ||
|
||
@observable stats = { | ||
transactionCount: 0, | ||
totalMined: localStore.get('totalMined', 0), | ||
newMined: 0, | ||
totalSupply: 0, | ||
depositMinimumLamports: localStore.get( | ||
'depositMinimumLamports', | ||
DEFAULT_LAMPORTS | ||
), | ||
depositPublicKeyBalance: '', | ||
}; | ||
|
||
clusterRestart() { | ||
this.replicator.clusterRestart(); | ||
this.stats.transactionCount = 0; | ||
setTimeout(() => this.updateStats()); | ||
} | ||
|
||
@action.bound | ||
updateStats = flow(function* updateStats() { | ||
const { transactionCount, depositMinimumLamports } = this.stats; | ||
const newTransactionCount = yield this.connection.getTransactionCount(); | ||
|
||
if (newTransactionCount < transactionCount / 2) { | ||
this.clusterRestart(); | ||
return; | ||
} | ||
|
||
this.stats.totalSupply = yield this.connection.getTotalSupply(); | ||
const newMined = yield this.replicator.adjustedReplicatorBalance(); | ||
|
||
if (newMined > depositMinimumLamports) { | ||
const success = yield this.replicator.depositMiningRewards( | ||
new PublicKey(AppStore.depositPublicKey), | ||
newMined | ||
); | ||
if (success) { | ||
this.stats.totalMined += newMined; | ||
localStore.set('totalMined', this.stats.totalMined); | ||
} | ||
} | ||
|
||
const balance = yield this.connection.getBalance( | ||
new PublicKey(AppStore.depositPublicKey) | ||
); | ||
this.stats.depositPublicKeyBalance = `Account Balance: ${balance} lamports`; | ||
this.stats.newMined = newMined; | ||
this.stats.transactionCount = newTransactionCount; | ||
}); | ||
} | ||
|
||
const store = new StatsStore(); | ||
|
||
export default store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7808,6 +7808,16 @@ [email protected], mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: | |
dependencies: | ||
minimist "0.0.8" | ||
|
||
mobx-react-lite@^1.4.1: | ||
version "1.4.1" | ||
resolved "https://registry.yarnpkg.com/mobx-react-lite/-/mobx-react-lite-1.4.1.tgz#7307a45901f97f9a07ebed32b654235507644e1a" | ||
integrity sha512-XmM+gzNv+GyXZYDLZMIGox3DufIiKULYgJsLhQj0U6Wlf+J5jv/h7limrL0aS1bEUtNilG62g9nwTeQ0KHzLFg== | ||
|
||
mobx@^5.13.0: | ||
version "5.13.0" | ||
resolved "https://registry.yarnpkg.com/mobx/-/mobx-5.13.0.tgz#0fd68f10aa5ff2d146a4ed9e145b53337cfbca59" | ||
integrity sha512-eSAntMSMNj0PFL705rgv+aB/z1RjNqDnFEpBe18yQVreXTWiVgIrmBUXzjnJfuba+eo4eAk6zi+/gXQkSUea8A== | ||
|
||
modify-values@^1.0.0: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022" | ||
|