Skip to content

Commit

Permalink
create currency dropdown and communicate via chrome message sender
Browse files Browse the repository at this point in the history
  • Loading branch information
fmiras committed Jun 18, 2018
1 parent 19723c1 commit 5fbf0a5
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"eject": "react-scripts eject"
},
"dependencies": {
"prop-types": "15.6.1",
"react": "16.4.1",
"react-dom": "16.4.1"
},
Expand Down
22 changes: 17 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import React, { Component } from 'react'
import React from 'react'
import CurrencyDropdown from './components/CurrencyDropdown'

import logo from './logo.svg'
import './App.css'

class App extends Component {
class App extends React.PureComponent {
constructor(props) {
super(props)
this.state = { currency: 'USD' }
}

handleChange(currency) {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
chrome.tabs.sendMessage(tabs[0].id, { currency })
})
}

render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<p className="App-intro">Marketplace currency:</p>
<CurrencyDropdown onChange={this.handleChange} />
</div>
)
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/CurrencyDropdown/CurrencyDropdown.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
form {
padding: 10px;
}
39 changes: 39 additions & 0 deletions src/components/CurrencyDropdown/CurrencyDropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react'
import PropTypes from 'prop-types'
import { getAvailableCurrencies } from '../../modules/currency/utils'

import './CurrencyDropdown.css'

export default class CurrencyDropdown extends React.PureComponent {
static propTypes = { onChange: PropTypes.func.isRequired }

constructor(props) {
super(props)
this.state = { value: 'USD' }
}

handleChange = e => {
this.setState({ value: e.target.value })
this.props.onChange(e.target.value)
}

getOptions() {
return getAvailableCurrencies().map(currency => ({
text: currency.label,
value: currency.label,
description: currency.text
}))
}

render() {
return (
<form>
<select value={this.state.value} onChange={this.handleChange}>
<option value="USD">USD</option>
<option value="MANA">MANA</option>
<option value="BTC">BTC</option>
</select>
</form>
)
}
}
3 changes: 3 additions & 0 deletions src/components/CurrencyDropdown/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CurrencyDropdown from './CurrencyDropdown'

export default CurrencyDropdown
8 changes: 6 additions & 2 deletions src/registerManaConversion.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { CurrencyLoader } from './modules/currency'

window.loader = new CurrencyLoader()
const loader = new CurrencyLoader()
chrome.runtime.onMessage.addListener(message => {
loader.setCurrency(message.currency)
})

export const registerManaConversion = () => {
window.loader.reload()
loader.reload()
setTimeout(registerManaConversion, 1000)
}

Expand Down

0 comments on commit 5fbf0a5

Please sign in to comment.