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

Commit

Permalink
feat: Lightning Joule integration
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Feb 6, 2019
1 parent 4c030d6 commit b4adfed
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 78 deletions.
70 changes: 40 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"react-scripts": "^2.1.3",
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0"
"redux-thunk": "^2.3.0",
"webln": "^0.1.0"
},
"devDependencies": {
"@babel/plugin-syntax-decorators": "^7.2.0",
Expand Down
3 changes: 3 additions & 0 deletions src/components/inputarea/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const InputArea = ({
height,
width,
onChange,
value,
placeholder,
}) => (
<textarea
autoFocus={autoFocus}
value={value}
placeholder={placeholder}
className={classes.wrapper}
rows={height}
Expand All @@ -41,6 +43,7 @@ InputArea.propTypes = {
onChange: PropTypes.func.isRequired,
error: PropTypes.bool.isRequired,
autoFocus: PropTypes.bool,
value: PropTypes.string,
placeholder: PropTypes.string,
};

Expand Down
55 changes: 26 additions & 29 deletions src/components/swaptab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,45 +148,42 @@ class SwapTab extends React.Component {
const rate = this.getRate();

// Swapping from chain to chain or from Lightning to Lightning is not supported right now
if (this.baseAsset.isLightning !== this.quoteAsset.isLightning) {
this.setState(
{
rate,
error: false,
},
() => this.updateQuoteAmount(this.state.baseAmount)
);
} else {
if (
this.state.base === this.state.quote ||
(this.baseAsset.isLightning && this.quoteAsset.isLightning)
) {
this.setState({
rate: undefined,
error: true,
errorMessage: 'Choose a different asset',
});
return;
}

if (!this.baseAsset.isLightning && !this.quoteAsset.isLightning) {
this.setState({
rate: undefined,
error: true,
errorMessage: 'Coming soon',
});
return;
}

this.setState(
{
rate,
error: false,
},
() => this.updateQuoteAmount(this.state.baseAmount)
);
}
};

checkBaseAmount = baseAmount => {
return baseAmount <= MAX && baseAmount >= MIN;
};

checkValidPair = (quote, base) => {
if (quote === base) {
this.setState({
error: true,
errorMessage: 'Choose a different asset',
});
return;
}

const pair = `${quote}/${base}`;
if (pair === 'BTC/LTC' || pair === 'LTC/BTC') {
this.setState({
error: true,
errorMessage: 'Coming soon',
});
return;
}

updatePair = (quote, base) => {
this.setState({ base, quote, error: false, errorMessage: '' });
};

Expand Down Expand Up @@ -274,7 +271,7 @@ class SwapTab extends React.Component {
<DropDown
defaultValue={base}
fields={currencies}
onChange={e => this.checkValidPair(quote, e)}
onChange={e => this.updatePair(quote, e)}
/>
</View>
<View className={classes.select}>
Expand All @@ -290,7 +287,7 @@ class SwapTab extends React.Component {
<DropDown
defaultValue={quote}
fields={currencies}
onChange={e => this.checkValidPair(e, base)}
onChange={e => this.updatePair(e, base)}
/>
</View>
</View>
Expand Down
11 changes: 11 additions & 0 deletions src/views/landingpage/landingpage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import injectSheet from 'react-jss';
import { requestProvider } from 'webln';
import BackGround from '../../components/background';
import View from '../../components/view';
import { LinkButton } from '../../components/button';
Expand Down Expand Up @@ -57,6 +58,14 @@ class LandingPage extends React.Component {
this.props.getPairs(() => {
this.forceUpdate();
});

try {
requestProvider().then(provider => {
this.webln = provider;
});
} catch (error) {
console.log(`Could not enable webln: ${error}`);
}
}

render() {
Expand Down Expand Up @@ -111,13 +120,15 @@ class LandingPage extends React.Component {
initReverseSwap({
...state,
keys,
webln: this.webln,
});

goReverseSwap();
} else {
initSwap({
...state,
keys,
webln: this.webln,
});

goSwap();
Expand Down
1 change: 1 addition & 0 deletions src/views/reverse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { nav } from '../../action/index';
import ReverseSwap from './reverse';

const mapStateToProps = state => ({
webln: state.reverseSwapReducer.webln,
inSwapMode: state.reverseSwapReducer.inSwapMode,
isFetching: state.reverseSwapReducer.isFetching,
swapInfo: state.reverseSwapReducer.swapInfo,
Expand Down
3 changes: 3 additions & 0 deletions src/views/reverse/reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const ReverseSwap = ({
startReverseSwap,
completeSwap,
goHome,
webln,
nextStage,
swapInfo,
swapResponse,
Expand Down Expand Up @@ -60,6 +61,7 @@ const ReverseSwap = ({
<PayInvoice
asset={swapInfo.base}
invoice={swapResponse.invoice}
webln={webln}
/>
)}
/>
Expand Down Expand Up @@ -111,6 +113,7 @@ ReverseSwap.propTypes = {
history: PropTypes.object.isRequired,
isFetching: PropTypes.bool.isRequired,
goHome: PropTypes.func.isRequired,
webln: PropTypes.object,
swapInfo: PropTypes.object,
swapResponse: PropTypes.object,
completeSwap: PropTypes.func,
Expand Down
1 change: 1 addition & 0 deletions src/views/reverse/reverseActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { toSatoshi, getHexBuffer, getNetwork } from '../../scripts/utils';
export const initReverseSwap = state => ({
type: actionTypes.INIT_REVERSE_SWAP,
payload: {
webln: state.webln,
base: state.base,
quote: state.quote,
baseAmount: state.baseAmount,
Expand Down
Loading

0 comments on commit b4adfed

Please sign in to comment.