Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
polish demo code
Browse files Browse the repository at this point in the history
  • Loading branch information
gre committed Jul 4, 2019
1 parent 4e3525f commit bc30e3b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
10 changes: 10 additions & 0 deletions demo/src/demos/countervalues/components/CounterValuesAPIDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Table, {
TableHead,
TableRow
} from "material-ui/Table";
import TextField from "material-ui/TextField";
import { withStyles } from "material-ui/styles";
import AppBar from "material-ui/AppBar";
import Toolbar from "material-ui/Toolbar";
Expand Down Expand Up @@ -66,9 +67,13 @@ class App extends Component<{
addMarket: *,
setMarket: *
}> {
onChangeCVAPI = e => {
window.LEDGER_CV_API = e.target.value;
};
render() {
const { classes, markets, setMarket, addMarket } = this.props;
const CounterValues = getCountervalues();

return (
<div className={classes.root}>
<AppBar position="static">
Expand All @@ -82,6 +87,11 @@ class App extends Component<{
>
CounterValues API demo
</Typography>
<TextField
defaultValue={window.LEDGER_CV_API}
onChange={this.onChangeCVAPI}
style={{ width: 400 }}
/>
<Button onClick={polling.wipe} color="inherit">
Wipe
</Button>
Expand Down
34 changes: 32 additions & 2 deletions demo/src/live-common-setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { Observable } from "rxjs";
import { implementCountervalues } from "@ledgerhq/live-common/lib/countervalues";
import { setSupportedCurrencies } from "@ledgerhq/live-common/lib/data/cryptocurrencies";
import { map } from "rxjs/operators";
import TransportWebUSB from "@ledgerhq/hw-transport-webusb";
import TransportWebBLE from "@ledgerhq/hw-transport-web-ble";
Expand All @@ -18,6 +19,36 @@ setEnv("FORCE_PROVIDER", 4);

setNetwork(axios);

setSupportedCurrencies([
"bitcoin",
"ethereum",
"ripple",
"bitcoin_cash",
"litecoin",
"dash",
"ethereum_classic",
"qtum",
"zcash",
"bitcoin_gold",
"stratis",
"dogecoin",
"digibyte",
"hcash",
"komodo",
"pivx",
"zencash",
"vertcoin",
"peercoin",
"viacoin",
"stakenet",
"stealthcoin",
"poswallet",
"clubcoin",
"decred",
"bitcoin_testnet",
"ethereum_ropsten"
]);

const webusbDevices = {};

// Still a big WIP. not sure how this should work in web paradigm...
Expand Down Expand Up @@ -113,6 +144,5 @@ implementCountervalues({
storeSelector: state => state.countervalues,
pairsSelector,
setExchangePairsAction,
addExtraPollingHooks,
maximumDays: 1 // we don't actually need history
addExtraPollingHooks
});
32 changes: 6 additions & 26 deletions demo/src/reducers/markets.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @flow
import {
getCryptoCurrencyById,
getFiatCurrencyByTicker,
listCryptoCurrencies
listSupportedCurrencies,
getFiatCurrencyByTicker
} from "@ledgerhq/live-common/lib/currencies";
import type { Currency } from "@ledgerhq/live-common/lib/types";
import { createSelector } from "reselect";
Expand All @@ -15,30 +15,10 @@ export type State = Array<{

const bitcoin = getCryptoCurrencyById("bitcoin");

const initialState: State = [
{
from: bitcoin,
to: getFiatCurrencyByTicker("USD"),
exchange: "KRAKEN"
},
{
from: bitcoin,
to: getFiatCurrencyByTicker("EUR"),
exchange: null
},
{
from: getCryptoCurrencyById("ripple"),
to: getCryptoCurrencyById("ethereum"),
exchange: null
},
{
from: getCryptoCurrencyById("litecoin"),
to: getCryptoCurrencyById("bitcoin"),
exchange: null
},
...listCryptoCurrencies().map(from => ({
const getInitialState = () => [
...listSupportedCurrencies().map(from => ({
from,
to: bitcoin,
to: from === bitcoin ? getFiatCurrencyByTicker("USD") : bitcoin,
exchange: null
}))
];
Expand All @@ -65,7 +45,7 @@ const reducers = {
})
};

export default (state: State = initialState, action: *) => {
export default (state: State = getInitialState(), action: *) => {
const reducer = reducers[action.type];
return (reducer && reducer(state, action)) || state;
};
Expand Down

0 comments on commit bc30e3b

Please sign in to comment.