Skip to content

Commit

Permalink
Merge pull request #4 from fmiras/add-eth
Browse files Browse the repository at this point in the history
Add ETH as new currency
  • Loading branch information
fmiras authored Aug 1, 2018
2 parents 88400eb + 8292b44 commit cc1946a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ Open the [decentraland marketplace](https://market.decentraland.org), then click

### Available Currencies

- USD / US Dollar
- MANA / Decentraland MANA
- ETH / Ethereum
- BTC / Bitcoin
- MANA / Decentraland MANA
- USD / US Dollar

### Contributing

Expand Down
7 changes: 4 additions & 3 deletions src/components/CurrencyDropdown/CurrencyDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import PropTypes from 'prop-types'
import {
getAvailableCurrencies,
getDefaultCurrency,
getCurrencyFromLocalstorage,
setLocalStorageCurrency
getCurrencyFromLocalstorage
} from '../../modules/currency/utils'

import './CurrencyDropdown.css'
Expand All @@ -31,7 +30,9 @@ export default class CurrencyDropdown extends React.PureComponent {
<form>
<select value={this.state.value} onChange={this.handleChange}>
{getAvailableCurrencies().map(currency => (
<option value={currency.label}>{currency.description}</option>
<option key={currency.label} value={currency.label}>
{currency.description}
</option>
))}
</select>
</form>
Expand Down
2 changes: 1 addition & 1 deletion src/components/StarButton/StarButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class StarButton extends React.PureComponent {
<iframe
title="Github Button"
src="https://ghbtns.com/github-btn.html?user=fmiras&repo=decentraland-currency-changer&type=star&count=true"
frameborder="0"
frameBorder="0"
scrolling="0"
width="72px"
height="30px"
Expand Down
17 changes: 14 additions & 3 deletions src/modules/currency/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global chrome */

/* global localStorage */
import { mana } from '../mana'

export const COINMARKET_MANA = 'https://api.coinmarketcap.com/v2/ticker/1966'
export const COINMARKET_BTC = 'https://api.coinmarketcap.com/v2/ticker/1'
export const COINMARKET_ETH = 'https://api.coinmarketcap.com/v2/ticker/1027'

function formatPrice(value, decimals = 2) {
return value.toFixed(decimals).replace(/\d(?=(\d{3})+\.)/g, '$&,')
Expand All @@ -20,6 +20,9 @@ export function formatValue(currency, value) {
case 'BTC': {
return `฿${formatPrice(value)}`
}
case 'ETH': {
return ${formatPrice(value)}`
}
default: {
return formatPrice(value)
}
Expand All @@ -28,7 +31,8 @@ export function formatValue(currency, value) {

export function getAvailableCurrencies() {
return [
{ label: 'BTC', description: 'Bitcoin', default: true },
{ label: 'ETH', description: 'Ethereum', default: true },
{ label: 'BTC', description: 'Bitcoin' },
{ label: 'MANA', description: 'Decentraland MANA' },
{ label: 'USD', description: 'US Dollar' }
]
Expand Down Expand Up @@ -56,12 +60,18 @@ export async function getManaPrice(currency) {
const bitcoinUsdPrice = await getPriceFromUrl(COINMARKET_BTC)
return manaUsdPrice / bitcoinUsdPrice
}
case 'ETH': {
const manaUsdPrice = await getPriceFromUrl(COINMARKET_MANA)
const etherUsdPrice = await getPriceFromUrl(COINMARKET_ETH)
return manaUsdPrice / etherUsdPrice
}
default:
return currency
}
}

export function getCurrencyFromLocalstorage() {
// TODO add chrome storage as feature
// return new Promise(resolve => {
// chrome.storage.sync.get('currency', currency => {
// resolve(currency)
Expand All @@ -71,6 +81,7 @@ export function getCurrencyFromLocalstorage() {
}

export function setLocalStorageCurrency(currency) {
// TODO add chrome storage as feature
// chrome.storage.sync.set({ currency })
localStorage['currency'] = currency
}
Expand Down
7 changes: 7 additions & 0 deletions src/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const localStorageMock = {
getItem: jest.fn(),
setItem: jest.fn(),
clear: jest.fn()
}

global.localStorage = localStorageMock

0 comments on commit cc1946a

Please sign in to comment.