mirror of
https://github.com/kremalicious/blowfish.git
synced 2024-12-29 16:17:52 +01:00
preferences styling
This commit is contained in:
parent
bfe2a76ad6
commit
67997fe12a
@ -23,6 +23,7 @@
|
|||||||
"@reach/router": "^1.2.1",
|
"@reach/router": "^1.2.1",
|
||||||
"ms": "^2.1.1",
|
"ms": "^2.1.1",
|
||||||
"react": "^16.8.6",
|
"react": "^16.8.6",
|
||||||
|
"react-blockies": "^1.4.1",
|
||||||
"react-dom": "^16.8.6"
|
"react-dom": "^16.8.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Consumer } from '../store/createContext'
|
import { AppContext } from '../store/createContext'
|
||||||
import { locale } from '../util/moneyFormatter'
|
import { locale } from '../util/moneyFormatter'
|
||||||
import { formatCurrency } from '@coingecko/cryptoformat'
|
import { formatCurrency } from '@coingecko/cryptoformat'
|
||||||
|
|
||||||
const Balance = ({ balance }) => (
|
const Balance = ({ balance }) => (
|
||||||
<h1 className="number">
|
<h1 className="number">
|
||||||
<Consumer>
|
<AppContext.Consumer>
|
||||||
{({ currency }) =>
|
{({ currency }) =>
|
||||||
formatCurrency(balance[currency], currency.toUpperCase(), locale)
|
formatCurrency(balance[currency], currency.toUpperCase(), locale)
|
||||||
.replace(/BTC/, 'Ƀ')
|
.replace(/BTC/, 'Ƀ')
|
||||||
.replace(/ETH/, 'Ξ')
|
.replace(/ETH/, 'Ξ')
|
||||||
.replace(/OCEAN/, 'Ọ')
|
.replace(/OCEAN/, 'Ọ')
|
||||||
}
|
}
|
||||||
</Consumer>
|
</AppContext.Consumer>
|
||||||
</h1>
|
</h1>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import { Consumer } from '../store/createContext'
|
import { AppContext } from '../store/createContext'
|
||||||
import { locale } from '../util/moneyFormatter'
|
import { locale } from '../util/moneyFormatter'
|
||||||
import { formatCurrency } from '@coingecko/cryptoformat'
|
import { formatCurrency } from '@coingecko/cryptoformat'
|
||||||
import './Ticker.css'
|
import './Ticker.css'
|
||||||
@ -8,7 +8,7 @@ export default class Ticker extends PureComponent {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<footer className="number-unit-wrap ticker" {...this.props}>
|
<footer className="number-unit-wrap ticker" {...this.props}>
|
||||||
<Consumer>
|
<AppContext.Consumer>
|
||||||
{({ toggleCurrencies, currency, prices }) => (
|
{({ toggleCurrencies, currency, prices }) => (
|
||||||
<>
|
<>
|
||||||
{Object.keys(prices).map((key, i) => (
|
{Object.keys(prices).map((key, i) => (
|
||||||
@ -27,7 +27,7 @@ export default class Ticker extends PureComponent {
|
|||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Consumer>
|
</AppContext.Consumer>
|
||||||
</footer>
|
</footer>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Consumer } from '../store/createContext'
|
import { AppContext } from '../store/createContext'
|
||||||
import Balance from './Balance'
|
import Balance from './Balance'
|
||||||
import { prices } from '../../config'
|
import { prices } from '../../config'
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ const calculateTotalBalance = (accounts, currency) => {
|
|||||||
|
|
||||||
const Total = () => (
|
const Total = () => (
|
||||||
<div className="number-unit number-unit--main">
|
<div className="number-unit number-unit--main">
|
||||||
<Consumer>
|
<AppContext.Consumer>
|
||||||
{({ accounts }) => {
|
{({ accounts }) => {
|
||||||
const conversions = Object.assign(
|
const conversions = Object.assign(
|
||||||
...prices.map(key => ({
|
...prices.map(key => ({
|
||||||
@ -36,7 +36,7 @@ const Total = () => (
|
|||||||
|
|
||||||
return <Balance balance={balanceNew} />
|
return <Balance balance={balanceNew} />
|
||||||
}}
|
}}
|
||||||
</Consumer>
|
</AppContext.Consumer>
|
||||||
<span className="label">Total Balance</span>
|
<span className="label">Total Balance</span>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import { Link } from '@reach/router'
|
import { Link } from '@reach/router'
|
||||||
import { Consumer } from '../store/createContext'
|
import { AppContext } from '../store/createContext'
|
||||||
import Total from '../components/Total'
|
import Total from '../components/Total'
|
||||||
import Account from '../components/Account'
|
import Account from '../components/Account'
|
||||||
import Ticker from '../components/Ticker'
|
import Ticker from '../components/Ticker'
|
||||||
@ -8,34 +8,34 @@ import Spinner from '../components/Spinner'
|
|||||||
import './Home.css'
|
import './Home.css'
|
||||||
|
|
||||||
export default class Home extends PureComponent {
|
export default class Home extends PureComponent {
|
||||||
|
static contextType = AppContext
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { isLoading, accounts, needsConfig } = this.context
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Consumer>
|
<>
|
||||||
{({ isLoading, accounts, needsConfig }) => (
|
<Link to="preferences">Preferences</Link>
|
||||||
<>
|
<main className="main">
|
||||||
<Link to="preferences">Settings</Link>
|
{needsConfig ? (
|
||||||
<main className="main">
|
'Needs config'
|
||||||
{needsConfig ? (
|
) : isLoading ? (
|
||||||
'Needs config'
|
<Spinner />
|
||||||
) : isLoading ? (
|
) : (
|
||||||
<Spinner />
|
<>
|
||||||
) : (
|
<Total />
|
||||||
<>
|
|
||||||
<Total />
|
|
||||||
|
|
||||||
<div className="number-unit-wrap number-unit-wrap--accounts">
|
<div className="number-unit-wrap number-unit-wrap--accounts">
|
||||||
{accounts.map((account, i) => (
|
{accounts.map((account, i) => (
|
||||||
<Account key={i} account={account} />
|
<Account key={i} account={account} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<Ticker style={isLoading ? { opacity: 0 } : null} />
|
<Ticker style={isLoading ? { opacity: 0 } : null} />
|
||||||
</>
|
</>
|
||||||
)}
|
|
||||||
</Consumer>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,3 +2,88 @@
|
|||||||
text-align: left;
|
text-align: left;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.preferences__title {
|
||||||
|
font-size: 3rem;
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preference__list {
|
||||||
|
padding: 0;
|
||||||
|
border-top: 1px solid #e2e2e2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark .preference__list {
|
||||||
|
border-top-color: #303030;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preference__list li {
|
||||||
|
list-style: none;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
border-bottom: 1px solid #e2e2e2;
|
||||||
|
padding-top: .3rem;
|
||||||
|
padding-bottom: .25rem;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark .preference__list li {
|
||||||
|
border-bottom-color: #303030;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preferences button {
|
||||||
|
background: none;
|
||||||
|
border: 0;
|
||||||
|
box-shadow: none;
|
||||||
|
margin: 0;
|
||||||
|
outline: 0;
|
||||||
|
color: #f6388a;
|
||||||
|
font-size: 1rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.delete {
|
||||||
|
font-size: 2rem;
|
||||||
|
color: #8b98a9;
|
||||||
|
transition: color .5s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.delete:hover {
|
||||||
|
color: #f6388a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preference {
|
||||||
|
-webkit-app-region: none;
|
||||||
|
-webkit-user-select: text;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preference__title {
|
||||||
|
font-size: 1.2rem;
|
||||||
|
color: #8b98a9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preference .identicon {
|
||||||
|
width: 1.5rem !important;
|
||||||
|
height: 1.5rem !important;
|
||||||
|
border-radius: 50%;
|
||||||
|
vertical-align: middle;
|
||||||
|
margin-top: -.2rem;
|
||||||
|
margin-right: .5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preference__input {
|
||||||
|
font-size: 1rem;
|
||||||
|
outline: 0;
|
||||||
|
background: none;
|
||||||
|
border: 0;
|
||||||
|
width: 80%;
|
||||||
|
color: #303030;
|
||||||
|
margin-top: .75rem;
|
||||||
|
margin-bottom: .75rem;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark .preference__input {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import { Link } from '@reach/router'
|
import { Link } from '@reach/router'
|
||||||
import Store from 'electron-store'
|
import Store from 'electron-store'
|
||||||
|
import Blockies from 'react-blockies'
|
||||||
import './Preferences.css'
|
import './Preferences.css'
|
||||||
|
import { AppContext } from '../store/createContext'
|
||||||
|
|
||||||
export default class Preferences extends PureComponent {
|
export default class Preferences extends PureComponent {
|
||||||
|
static contextType = AppContext
|
||||||
|
|
||||||
store = new Store()
|
store = new Store()
|
||||||
|
|
||||||
state = { accounts: [], input: '' }
|
state = { accounts: [], input: '' }
|
||||||
@ -26,8 +30,10 @@ export default class Preferences extends PureComponent {
|
|||||||
!this.state.accounts.includes(this.state.input) // duplication check
|
!this.state.accounts.includes(this.state.input) // duplication check
|
||||||
) {
|
) {
|
||||||
const joined = [...this.state.accounts, this.state.input]
|
const joined = [...this.state.accounts, this.state.input]
|
||||||
|
|
||||||
this.store.set('accounts', joined)
|
this.store.set('accounts', joined)
|
||||||
this.setState({ accounts: joined })
|
this.setState({ accounts: joined, input: '' })
|
||||||
|
this.context.setBalances(joined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,32 +50,51 @@ export default class Preferences extends PureComponent {
|
|||||||
|
|
||||||
this.store.set('accounts', array)
|
this.store.set('accounts', array)
|
||||||
this.setState({ accounts: array })
|
this.setState({ accounts: array })
|
||||||
|
this.context.setBalances(array)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="preferences">
|
<div className="preferences">
|
||||||
Hello Preferences <Link to="/">Close</Link>
|
<h1 className="preferences__title">Preferences</h1>{' '}
|
||||||
<div>
|
<Link to="/">Close</Link>
|
||||||
{this.state.accounts &&
|
<div className="preference">
|
||||||
this.state.accounts.map(account => (
|
<h2 className="preference__title">Accounts</h2>
|
||||||
<div key={account}>
|
<ul className="preference__list">
|
||||||
{account}
|
{this.state.accounts &&
|
||||||
<button onClick={e => this.handleDelete(e, account)}>
|
this.state.accounts.map(account => (
|
||||||
×
|
<li key={account}>
|
||||||
</button>
|
<div>
|
||||||
</div>
|
<Blockies seed={account} size={10} scale={3} />
|
||||||
))}
|
{account}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className="delete"
|
||||||
|
onClick={e => this.handleDelete(e, account)}
|
||||||
|
title="Remove account"
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
<li>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="0xxxxxxxx"
|
||||||
|
value={this.state.input}
|
||||||
|
onChange={this.handleInputChange}
|
||||||
|
className="preference__input"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
className="preference__input__add"
|
||||||
|
onClick={e => this.handleSave(e)}
|
||||||
|
>
|
||||||
|
Add
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<form>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="0xxxxxxxx"
|
|
||||||
value={this.state.input}
|
|
||||||
onChange={this.handleInputChange}
|
|
||||||
/>
|
|
||||||
<button onClick={e => this.handleSave(e)}>Add</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import React, { PureComponent } from 'react'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import ms from 'ms'
|
import ms from 'ms'
|
||||||
import Store from 'electron-store'
|
import Store from 'electron-store'
|
||||||
import { Provider } from './createContext'
|
import { AppContext } from './createContext'
|
||||||
import { refreshInterval, prices, oceanTokenContract } from '../../config'
|
import { refreshInterval, prices, oceanTokenContract } from '../../config'
|
||||||
|
|
||||||
export default class AppProvider extends PureComponent {
|
export default class AppProvider extends PureComponent {
|
||||||
@ -18,7 +18,8 @@ export default class AppProvider extends PureComponent {
|
|||||||
currency: 'ocean',
|
currency: 'ocean',
|
||||||
needsConfig: false,
|
needsConfig: false,
|
||||||
prices: Object.assign(...prices.map(key => ({ [key]: 0 }))),
|
prices: Object.assign(...prices.map(key => ({ [key]: 0 }))),
|
||||||
toggleCurrencies: currency => this.setState({ currency })
|
toggleCurrencies: currency => this.setState({ currency }),
|
||||||
|
setBalances: account => this.setBalances(account)
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
@ -30,15 +31,6 @@ export default class AppProvider extends PureComponent {
|
|||||||
await setInterval(this.setBalances, ms(refreshInterval))
|
await setInterval(this.setBalances, ms(refreshInterval))
|
||||||
|
|
||||||
this.setState({ isLoading: false })
|
this.setState({ isLoading: false })
|
||||||
|
|
||||||
// document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
// this.store.onDidChange('accounts', async (newValue, oldValue) => {
|
|
||||||
// const { accounts } = await this.getAccounts()
|
|
||||||
// await this.setBalances(accounts)
|
|
||||||
|
|
||||||
// console.log('hello from setting window', newValue, oldValue)
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@ -138,6 +130,10 @@ export default class AppProvider extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <Provider value={this.state}>{this.props.children}</Provider>
|
return (
|
||||||
|
<AppContext.Provider value={this.state}>
|
||||||
|
{this.props.children}
|
||||||
|
</AppContext.Provider>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createContext } from 'react'
|
import { createContext } from 'react'
|
||||||
|
|
||||||
const { Provider, Consumer } = createContext()
|
const AppContext = createContext({})
|
||||||
|
|
||||||
export { Provider, Consumer }
|
export { AppContext }
|
||||||
|
Loading…
Reference in New Issue
Block a user