Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
feat: store assets and base amount in local storage (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Feb 15, 2019
1 parent a6c9597 commit b2fa64c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"Promise": true,
"window": true,
"document": true,
"navigator": true
"navigator": true,
"localStorage": true,
},
"env": {
"es6": true,
Expand Down
25 changes: 20 additions & 5 deletions src/components/swaptab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import DropDown from '../dropdown';
import Controls from '../controls';
import Text, { InfoText } from '../text';
import { decimals } from '../../scripts/utils';
import { MIN, MAX } from '../../constants/fees';

const styles = theme => ({
wrapper: {
Expand Down Expand Up @@ -145,6 +144,16 @@ class SwapTab extends React.Component {
)}/${this.parseBoltSuffix(this.state.quote, false)}`;
};

componentWillMount() {
if (localStorage.length !== 0) {
this.setState({
base: localStorage.getItem('base'),
quote: localStorage.getItem('quote'),
baseAmount: localStorage.getItem('baseAmount'),
});
}
}

componentDidMount = () => {
const symbol = this.getSymbol();
const limits = this.props.limits[symbol];
Expand All @@ -160,6 +169,8 @@ class SwapTab extends React.Component {
};

componentDidUpdate = (_, prevState) => {
const { base, quote, baseAmount } = this.state;

// Update the rate if the request finished or the currencies changed
if (
prevState.base !== this.state.base ||
Expand All @@ -169,7 +180,7 @@ class SwapTab extends React.Component {

// Swapping from chain to chain or from Lightning to Lightning is not supported right now
if (
this.state.base === this.state.quote ||
base === quote ||
(this.baseAsset.isLightning && this.quoteAsset.isLightning)
) {
this.setState({
Expand All @@ -192,8 +203,6 @@ class SwapTab extends React.Component {
const rate = this.props.rates[symbol];
const limits = this.props.limits[symbol];

console.log(this.props);

this.setState(
{
rate,
Expand All @@ -204,10 +213,16 @@ class SwapTab extends React.Component {
() => this.updateQuoteAmount(this.state.baseAmount)
);
}

localStorage.setItem('base', base);
localStorage.setItem('quote', quote);
localStorage.setItem('baseAmount', baseAmount);
};

checkBaseAmount = baseAmount => {
return baseAmount <= MAX && baseAmount >= MIN;
const { minAmount, maxAmount } = this.state;

return baseAmount <= maxAmount && baseAmount >= minAmount;
};

updatePair = (quote, base) => {
Expand Down

0 comments on commit b2fa64c

Please sign in to comment.