mirror of
https://github.com/kremalicious/blowfish.git
synced 2024-12-30 16:47:52 +01:00
output btc & eth calculations
This commit is contained in:
parent
6ae353d5da
commit
79e1ad5042
16
README.md
16
README.md
@ -5,12 +5,21 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
- [Features](#features)
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
- [Build packages](#build-packages)
|
- [Build packages](#build-packages)
|
||||||
- [Data Sources](#data-sources)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- show Ocean Token balances from a list of Ethereum account addresses
|
||||||
|
- show a total balance of all account balances
|
||||||
|
- convert those balances against multiple currencies
|
||||||
|
- re-fetches everything automatically every minute
|
||||||
|
- balances are fetched via etherscan.io API
|
||||||
|
- spot prices are fetched from coingecko.com API
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Clone, add adresses, and run:
|
Clone, add adresses, and run:
|
||||||
@ -42,8 +51,3 @@ On a Mac and Linux machine, packaging requires [`wine`](https://www.winehq.org)
|
|||||||
```bash
|
```bash
|
||||||
brew install wine
|
brew install wine
|
||||||
```
|
```
|
||||||
|
|
||||||
## Data Sources
|
|
||||||
|
|
||||||
- balances are checked via etherscan.io API
|
|
||||||
- spot prices are fetched from coingecko.com API
|
|
||||||
|
27
src/App.css
27
src/App.css
@ -115,12 +115,25 @@ button {
|
|||||||
padding-right: 2%;
|
padding-right: 2%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
color: #8b98a9;
|
||||||
|
font-size: .85rem;
|
||||||
|
display: block;
|
||||||
|
white-space: nowrap;
|
||||||
|
margin-top: .3rem;
|
||||||
|
transition: color .2s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.number-unit:hover .label {
|
||||||
|
color: #f6388a;
|
||||||
|
}
|
||||||
|
|
||||||
.number {
|
.number {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
transition: .15s ease-out;
|
transition: .15s ease-out;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
-webkit-app-region: no-drag;
|
-webkit-app-region: no-drag;
|
||||||
-webkit-user-select: auto;
|
-webkit-user-select: text;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0 .3rem;
|
padding: 0 .3rem;
|
||||||
@ -132,14 +145,6 @@ button {
|
|||||||
animation: updated .5s ease-out forwards;
|
animation: updated .5s ease-out forwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
.label {
|
|
||||||
color: #8b98a9;
|
|
||||||
font-size: .85rem;
|
|
||||||
display: block;
|
|
||||||
white-space: nowrap;
|
|
||||||
margin-top: .3rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.number-unit-wrap--accounts {
|
.number-unit-wrap--accounts {
|
||||||
min-height: 55px;
|
min-height: 55px;
|
||||||
}
|
}
|
||||||
@ -149,6 +154,10 @@ button {
|
|||||||
border-bottom: 1px solid #e2e2e2;
|
border-bottom: 1px solid #e2e2e2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.number-unit--main:hover .label {
|
||||||
|
color: #8b98a9;
|
||||||
|
}
|
||||||
|
|
||||||
.dark .number-unit--main {
|
.dark .number-unit--main {
|
||||||
border-bottom-color: #303030;
|
border-bottom-color: #303030;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ export default class App extends PureComponent {
|
|||||||
<Titlebar />
|
<Titlebar />
|
||||||
<div className="app__content">
|
<div className="app__content">
|
||||||
<main className="main">
|
<main className="main">
|
||||||
<Actions />
|
|
||||||
<Total />
|
<Total />
|
||||||
|
|
||||||
<div className="number-unit-wrap number-unit-wrap--accounts">
|
<div className="number-unit-wrap number-unit-wrap--accounts">
|
||||||
@ -33,6 +32,8 @@ export default class App extends PureComponent {
|
|||||||
}
|
}
|
||||||
</Consumer>
|
</Consumer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Actions />
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</AppProvider>
|
</AppProvider>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
|
import { openUrl } from '../util/openUrl'
|
||||||
import Balance from './Balance'
|
import Balance from './Balance'
|
||||||
|
|
||||||
export default class Account extends PureComponent {
|
export default class Account extends PureComponent {
|
||||||
@ -19,12 +20,16 @@ export default class Account extends PureComponent {
|
|||||||
const { balance, address } = account
|
const { balance, address } = account
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="number-unit">
|
<a
|
||||||
|
onClick={() =>
|
||||||
|
openUrl(`https://etherscan.io/address/${address}#tokentxns`)
|
||||||
|
}
|
||||||
|
title="Click to view on Etherscan"
|
||||||
|
className="number-unit"
|
||||||
|
>
|
||||||
<Balance balance={balance} />
|
<Balance balance={balance} />
|
||||||
<span className="label" title={address}>
|
<span className="label">{address.substring(0, 12)}...</span>
|
||||||
{address.substring(0, 12)}...
|
</a>
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,17 @@ export default class Actions extends PureComponent {
|
|||||||
return (
|
return (
|
||||||
<div className="actions">
|
<div className="actions">
|
||||||
<Consumer>
|
<Consumer>
|
||||||
{({ toggleCurrencies }) => (
|
{({ toggleCurrencies, accounts }) => (
|
||||||
<>
|
<>
|
||||||
<button onClick={() => toggleCurrencies('ocean')}>OCEAN</button>
|
{accounts.length > 0 &&
|
||||||
<button onClick={() => toggleCurrencies('eur')}>EUR</button>
|
Object.keys(accounts[0].balance).map(currency => (
|
||||||
<button onClick={() => toggleCurrencies('usd')}>USD</button>
|
<button
|
||||||
|
key={currency}
|
||||||
|
onClick={() => toggleCurrencies(currency)}
|
||||||
|
>
|
||||||
|
{currency}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Consumer>
|
</Consumer>
|
||||||
|
@ -4,16 +4,18 @@ import { Consumer } from '../store/createContext'
|
|||||||
import { numberFormatter, fiatFormatter } from '../util/moneyFormatter'
|
import { numberFormatter, fiatFormatter } from '../util/moneyFormatter'
|
||||||
|
|
||||||
const Balance = ({ balance }) => {
|
const Balance = ({ balance }) => {
|
||||||
const { ocean, eur, usd } = balance
|
const { ocean, btc, eth, eur, usd } = balance
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<h1 className="number">
|
<h1 className="number">
|
||||||
<Consumer>
|
<Consumer>
|
||||||
{({ currency }) =>
|
{({ currency }) =>
|
||||||
currency === 'ocean' ? (
|
currency === 'ocean' ? (
|
||||||
<span className="balance" title={numberFormatter(ocean)}>
|
<span className="balance">Ọ {numberFormatter(ocean) || 0}</span>
|
||||||
Ọ {numberFormatter(ocean) || 0}
|
) : currency === 'btc' ? (
|
||||||
</span>
|
<span className="balance">₿ {numberFormatter(btc) || 0}</span>
|
||||||
|
) : currency === 'eth' ? (
|
||||||
|
<span className="balance">Ξ {numberFormatter(eth) || 0}</span>
|
||||||
) : currency === 'eur' ? (
|
) : currency === 'eur' ? (
|
||||||
<span className="balance">{fiatFormatter('EUR', eur)}</span>
|
<span className="balance">{fiatFormatter('EUR', eur)}</span>
|
||||||
) : (
|
) : (
|
||||||
@ -28,6 +30,8 @@ const Balance = ({ balance }) => {
|
|||||||
Balance.propTypes = {
|
Balance.propTypes = {
|
||||||
balance: PropTypes.shape({
|
balance: PropTypes.shape({
|
||||||
ocean: PropTypes.number.isRequired,
|
ocean: PropTypes.number.isRequired,
|
||||||
|
btc: PropTypes.number.isRequired,
|
||||||
|
eth: PropTypes.number.isRequired,
|
||||||
eur: PropTypes.number.isRequired,
|
eur: PropTypes.number.isRequired,
|
||||||
usd: PropTypes.number.isRequired
|
usd: PropTypes.number.isRequired
|
||||||
})
|
})
|
||||||
|
@ -23,11 +23,15 @@ const Total = () => (
|
|||||||
<Consumer>
|
<Consumer>
|
||||||
{({ accounts }) => {
|
{({ accounts }) => {
|
||||||
const totalOcean = calculateTotalBalance(accounts, 'ocean')
|
const totalOcean = calculateTotalBalance(accounts, 'ocean')
|
||||||
|
const totalBtc = calculateTotalBalance(accounts, 'btc')
|
||||||
|
const totalEth = calculateTotalBalance(accounts, 'eth')
|
||||||
const totalEur = calculateTotalBalance(accounts, 'eur')
|
const totalEur = calculateTotalBalance(accounts, 'eur')
|
||||||
const totalUsd = calculateTotalBalance(accounts, 'usd')
|
const totalUsd = calculateTotalBalance(accounts, 'usd')
|
||||||
|
|
||||||
const balance = {
|
const balance = {
|
||||||
ocean: totalOcean,
|
ocean: totalOcean,
|
||||||
|
btc: totalBtc,
|
||||||
|
eth: totalEth,
|
||||||
eur: totalEur,
|
eur: totalEur,
|
||||||
usd: totalUsd
|
usd: totalUsd
|
||||||
}
|
}
|
||||||
|
13
src/main.js
13
src/main.js
@ -18,7 +18,7 @@ const height = 380
|
|||||||
|
|
||||||
const isDarkMode = systemPreferences.isDarkMode()
|
const isDarkMode = systemPreferences.isDarkMode()
|
||||||
|
|
||||||
const createWindow = () => {
|
const createWindow = async () => {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
@ -47,13 +47,12 @@ const createWindow = () => {
|
|||||||
REACT_DEVELOPER_TOOLS
|
REACT_DEVELOPER_TOOLS
|
||||||
} = require('electron-devtools-installer')
|
} = require('electron-devtools-installer')
|
||||||
|
|
||||||
installExtension(REACT_DEVELOPER_TOOLS)
|
try {
|
||||||
.then(name => {
|
const name = await installExtension(REACT_DEVELOPER_TOOLS)
|
||||||
console.log(`Added Extension: ${name}`) // eslint-disable-line no-console
|
console.log(`Added Extension: ${name}`) // eslint-disable-line no-console
|
||||||
})
|
} catch (error) {
|
||||||
.catch(err => {
|
console.log('An error occurred: ', error) // eslint-disable-line no-console
|
||||||
console.log('An error occurred: ', err) // eslint-disable-line no-console
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.once('ready-to-show', () => {
|
mainWindow.once('ready-to-show', () => {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const { app, Menu } = require('electron')
|
const { app, Menu } = require('electron')
|
||||||
|
const { openUrl } = require('./util/openUrl')
|
||||||
|
|
||||||
const template = [
|
const template = [
|
||||||
{
|
{
|
||||||
@ -70,7 +71,7 @@ const template = [
|
|||||||
{
|
{
|
||||||
label: 'Learn More',
|
label: 'Learn More',
|
||||||
click() {
|
click() {
|
||||||
require('electron').shell.openExternal('https://electron.atom.io')
|
openUrl('https://electron.atom.io')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -56,11 +56,11 @@ export default class AppProvider extends PureComponent {
|
|||||||
|
|
||||||
fetchPrice = async () => {
|
fetchPrice = async () => {
|
||||||
const json = await this.fetch(
|
const json = await this.fetch(
|
||||||
'https://api.coingecko.com/api/v3/simple/price?ids=ocean-protocol&vs_currencies=usd,eur'
|
'https://api.coingecko.com/api/v3/simple/price?ids=ocean-protocol&vs_currencies=btc,eth,usd,eur'
|
||||||
)
|
)
|
||||||
|
|
||||||
const { usd, eur } = json['ocean-protocol']
|
const { btc, eth, usd, eur } = json['ocean-protocol']
|
||||||
return { usd, eur }
|
return { btc, eth, usd, eur }
|
||||||
}
|
}
|
||||||
|
|
||||||
setBalances = async () => {
|
setBalances = async () => {
|
||||||
@ -68,7 +68,7 @@ export default class AppProvider extends PureComponent {
|
|||||||
// when they are changed instead of resetting all to 0 here
|
// when they are changed instead of resetting all to 0 here
|
||||||
this.clearAccounts()
|
this.clearAccounts()
|
||||||
|
|
||||||
const { usd, eur } = await this.fetchPrice()
|
const { btc, eth, usd, eur } = await this.fetchPrice()
|
||||||
|
|
||||||
accounts.map(async account => {
|
accounts.map(async account => {
|
||||||
const oceanBalance = await this.fetchBalance(account)
|
const oceanBalance = await this.fetchBalance(account)
|
||||||
@ -77,6 +77,8 @@ export default class AppProvider extends PureComponent {
|
|||||||
address: account,
|
address: account,
|
||||||
balance: {
|
balance: {
|
||||||
ocean: oceanBalance || 0,
|
ocean: oceanBalance || 0,
|
||||||
|
btc: oceanBalance * btc || 0,
|
||||||
|
eth: oceanBalance * eth || 0,
|
||||||
eur: oceanBalance * eur || 0,
|
eur: oceanBalance * eur || 0,
|
||||||
usd: oceanBalance * usd || 0
|
usd: oceanBalance * usd || 0
|
||||||
}
|
}
|
||||||
|
7
src/util/openUrl.js
Normal file
7
src/util/openUrl.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
const { shell } = require('electron')
|
||||||
|
|
||||||
|
const openUrl = url => {
|
||||||
|
shell.openExternal(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { openUrl }
|
Loading…
Reference in New Issue
Block a user