Skip to content

Commit

Permalink
bitshares#1331 Store last expiration on localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbsfromncis committed Mar 25, 2018
1 parent d31e298 commit 15cb07f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/actions/SettingsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class SettingsActions {
updateLatencies(latencies) {
return latencies;
}

setExchangeLastExpiration(value) {
return value;
}
}

export default alt.createActions(SettingsActions);
13 changes: 11 additions & 2 deletions app/components/Exchange/Exchange.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class Exchange extends React.Component {
this.state = {
...this._initialState(props),
expirationType: {
bid: "YEAR",
ask: "YEAR"
bid: props.exchange.getIn(["lastExpiration", "bid"]) || "YEAR",
ask: props.exchange.getIn(["lastExpiration", "ask"]) || "YEAR"
},
expirationCustomTime: {
bid: moment().add(1, "day"),
Expand All @@ -85,6 +85,15 @@ class Exchange extends React.Component {
[type]: e.target.value
};

if (e.target.value !== "SPECIFIC") {
SettingsActions.setExchangeLastExpiration({
...((this.props.exchange.has("lastExpiration") &&
this.props.exchange.get("lastExpiration").toJS()) ||
{}),
[type]: e.target.value
});
}

this.setState({
expirationType: expirationType
});
Expand Down
3 changes: 3 additions & 0 deletions app/components/Exchange/ExchangeContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class ExchangeContainer extends React.Component {
settings: () => {
return SettingsStore.getState().settings;
},
exchange: () => {
return SettingsStore.getState().exchange;
},
starredMarkets: () => {
return SettingsStore.getState().starredMarkets;
},
Expand Down
24 changes: 23 additions & 1 deletion app/stores/SettingsStore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import alt from "alt-instance";
import SettingsActions from "actions/SettingsActions";
import IntlActions from "actions/IntlActions";
import Immutable from "immutable";
import Immutable, {fromJS} from "immutable";
import {merge} from "lodash";
import ls from "common/localStorage";
import {Apis} from "bitsharesjs-ws";
Expand All @@ -22,6 +22,8 @@ class SettingsStore {
});

this.bindListeners({
onSetExchangeLastExpiration:
SettingsActions.setExchangeLastExpiration,
onChangeSetting: SettingsActions.changeSetting,
onChangeViewSetting: SettingsActions.changeViewSetting,
onChangeMarketDirection: SettingsActions.changeMarketDirection,
Expand Down Expand Up @@ -163,6 +165,8 @@ class SettingsStore {
"testnet_faucet",
settingsAPIs.TESTNET_FAUCET
);

this.exchange = fromJS(ss.get("exchange", {}));
}

init() {
Expand Down Expand Up @@ -475,6 +479,24 @@ class SettingsStore {
setLastBudgetObject(value) {
ss.set(this._getChainKey("lastBudgetObject"), value);
}

setExchangeSettings(key, value) {
this.exchange = this.exchange.set(key, value);

ss.set("exchange", this.exchange.toJS());
}

getExchangeSettings(key) {
return this.exchange.get(key);
}

onSetExchangeLastExpiration(value) {
this.setExchangeSettings("lastExpiration", fromJS(value));
}

getExhchangeLastExpiration() {
return this.getExchangeSettings("lastExpiration");
}
}

export default alt.createStore(SettingsStore, "SettingsStore");

0 comments on commit 15cb07f

Please sign in to comment.