Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop integration (revised) #231

Open
wants to merge 39 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6456078
added loop out terms
Jul 1, 2019
e7eb770
removed unused ui files
Jul 1, 2019
455c28b
fixed loop out actions
Jul 1, 2019
f47647a
made changes to temporarily resolve broken travis ci build
Jul 1, 2019
8d0b945
ran yarn tsc locally to resolve build issues
Jul 1, 2019
34e0e89
refactored loop url initialization/add loop out quote
Jul 7, 2019
7068c69
added success message
Jul 7, 2019
573883c
removed unused imports
Jul 7, 2019
7e1fd54
removed package-lock.json
Jul 7, 2019
39a97f8
started working on default swap out
Jul 9, 2019
514a748
initiated loop out from joule - buggy
Jul 10, 2019
78b32c2
updated ComponentDidUpdate to debug Loop Out
Jul 15, 2019
3128df5
started on advanced loop form
Jul 15, 2019
6140fc4
added advanced fields
Jul 16, 2019
adc06b7
add password before loop out
Jul 16, 2019
4c02904
fixed incorrect password bug
Jul 17, 2019
40aa55b
modified loop quote form
Jul 18, 2019
1ef07df
fixed loop url bug
Jul 19, 2019
af93605
fixed interface typo
Jul 21, 2019
b26b4bc
updated conf_target for loop 2.2
Aug 3, 2019
78d927c
updated sweep confirmation handling
Aug 3, 2019
f579667
added loop in support
Aug 5, 2019
1865979
fixed build
Aug 5, 2019
c47a1e8
added deep equality check
Aug 5, 2019
20bcadc
fixed loop terms bug
Aug 6, 2019
5b945fc
added channel selection logic
Aug 7, 2019
6600113
fixed variable shadowing lint error
Aug 7, 2019
8d35edf
Merge remote-tracking branch 'upstream/develop' into loop
Aug 7, 2019
4bb3957
updated channel selector for Loop In
Aug 7, 2019
7bca5e3
removed unncessary fields from loop in
Aug 8, 2019
e7af691
refactored for review
Aug 18, 2019
5528097
set loop with terms asynchronously
Aug 18, 2019
40c830c
fixed typo and minor clean up
Aug 18, 2019
4fa2d81
updated constant
Aug 18, 2019
0ebeb7f
Reorganize loop components. Add some information when setting a Loop …
wbobeirne Aug 19, 2019
fc967fe
Rejigger the loop reducer and components to reduce a lot of code and …
wbobeirne Sep 5, 2019
da3cd5c
Rework the loop form to reduce foot-gun fields, improve explanations,…
wbobeirne Sep 7, 2019
97f4f5f
UI things.
wbobeirne Sep 9, 2019
ecafa96
Fix tsc errors
wbobeirne Sep 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"rimraf": "2.6.2",
"string-hash": "1.1.3",
"webextension-polyfill-ts": "0.8.9",
"webpack-bundle-analyzer": "3.0.3",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-dev-server": "3.2.1",
"write-file-webpack-plugin": "^4.5.0"
}
Expand Down
12 changes: 12 additions & 0 deletions src/app/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import HomePage from 'pages/home';
import OnboardingPage from 'pages/onboarding';
import SettingsPage from 'pages/settings';
import BalancesPage from 'pages/balances';
import LoopPage from 'pages/loop';
import FourOhFourPage from 'pages/fourohfour';
import Template, { Props as TemplateProps } from 'components/Template';

Expand Down Expand Up @@ -74,6 +75,17 @@ const routeConfigs: RouteConfig[] = [
showBack: true,
},
},
{
// Loop
route: {
path: '/loop',
component: LoopPage,
},
template: {
title: 'Lightning Loop',
showBack: true,
},
},
{
// 404
route: {
Expand Down
20 changes: 16 additions & 4 deletions src/app/components/AmountField/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
z-index: 1;
opacity: 0.7;
color: #a0a0a0;

&:hover {
color: #7642FF;
border-color: #7642FF;
color: #7642ff;
border-color: #7642ff;
opacity: 1;
}
}
Expand All @@ -37,6 +37,18 @@
&-fiat {
max-width: 115px;
width: 100%;

.ant-input {
padding-right: 4px;
}
}

&-constraint {
margin-right: 0.5rem;

&:last-child {
margin-right: 0;
}
}

// Ant overrides, use px values
Expand Down Expand Up @@ -64,4 +76,4 @@
right: 6px;
margin-top: -5px;
}
}
}
38 changes: 33 additions & 5 deletions src/app/components/AmountField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ interface OwnProps {
warn?: React.ReactNode;
required?: boolean;
showFiat?: boolean;
minimumSats?: string;
maximumSats?: string;
minimumSats?: string | number;
maximumSats?: string | number;
showMax?: boolean;
showConstraints?: boolean;
onChangeAmount(amount: string): void;
}

Expand Down Expand Up @@ -94,6 +95,7 @@ class AmountField extends React.Component<Props, State> {
showFiat,
maximumSats,
showMax,
showConstraints,
isNoFiat,
fiat,
rates,
Expand All @@ -104,11 +106,12 @@ class AmountField extends React.Component<Props, State> {
} = this.props;
const { value, valueFiat, denomination } = this.state;
const valueError = this.getValueError();
const constraints = !valueError && showConstraints && this.getConstraints();

return (
<Form.Item
label={label}
help={valueError || warn || help}
help={valueError || warn || constraints || help}
validateStatus={value && valueError ? 'error' : warn ? 'warning' : undefined}
className="AmountField"
required={required}
Expand Down Expand Up @@ -186,7 +189,7 @@ class AmountField extends React.Component<Props, State> {
}
if (minimumSats) {
const min = new BN(minimumSats);
if (min.gte(valueBN)) {
if (min.gt(valueBN)) {
const minAmount = `${fromBaseToUnit(min.toString(), denomination)} ${
denominationSymbols[chain][denomination]
}`;
Expand All @@ -198,6 +201,31 @@ class AmountField extends React.Component<Props, State> {
}
};

private getConstraints = () => {
const { minimumSats, maximumSats, chain } = this.props;
const { denomination } = this.state;
const pieces = [];

if (minimumSats) {
pieces.push(
<span key="min" className="AmountField-constraint">
<strong>Min:</strong> {fromBaseToUnit(minimumSats.toString(), denomination)}{' '}
{denominationSymbols[chain][denomination]}
</span>,
);
}
if (maximumSats) {
pieces.push(
<span key="max" className="AmountField-constraint">
<strong>Max:</strong> {fromBaseToUnit(maximumSats.toString(), denomination)}{' '}
{denominationSymbols[chain][denomination]}
</span>,
);
}

return pieces;
};

private handleChangeValue = (ev: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = ev.currentTarget;
this.updateBothValues(name, value);
Expand Down Expand Up @@ -235,7 +263,7 @@ class AmountField extends React.Component<Props, State> {
const { maximumSats } = this.props;
const { denomination } = this.state;
if (maximumSats) {
const value = fromBaseToUnit(maximumSats, denomination);
const value = fromBaseToUnit(maximumSats.toString(), denomination);
this.updateBothValues('value', value);
}
};
Expand Down
6 changes: 5 additions & 1 deletion src/app/components/DetailsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import './DetailsTable.less';
import Help from './Help';

export interface DetailsRow {
label: string;
value: React.ReactNode;
help?: string;
}

const DetailsTable: React.SFC<{ details: DetailsRow[] }> = ({ details }) => {
Expand All @@ -12,7 +14,9 @@ const DetailsTable: React.SFC<{ details: DetailsRow[] }> = ({ details }) => {
<tbody>
{details.map(d => (
<tr className="DetailsTable-row" key={d.label}>
<td className="DetailsTable-row-label">{d.label}</td>
<td className="DetailsTable-row-label">
{d.label} {d.help && <Help>{d.help}</Help>}
</td>
<td className="DetailsTable-row-value">{d.value}</td>
</tr>
))}
Expand Down
14 changes: 14 additions & 0 deletions src/app/components/Loop/InputLoopAddress.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.InputLoopAddress {
width: 100%;
max-width: 440px;
margin: 0 auto;

.ant-form-item,
.ant-alert {
margin-bottom: 1rem;
}

.ant-alert a {
text-decoration: underline;
}
}
96 changes: 96 additions & 0 deletions src/app/components/Loop/InputLoopAddress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React from 'react';
import { browser } from 'webextension-polyfill-ts';
import { Button, Form, Input, message } from 'antd';
import { urlWithoutPort } from 'utils/formatters';
import './InputLoopAddress.less';
import { setLoop } from 'modules/loop/actions';

interface Props {
initialUrl?: string | null;
isCheckingLoop: boolean;
error: Error | null;
setLoop: typeof setLoop;
type: string;
}

interface State {
url: string;
submittedUrl: string;
validation: string;
}

export default class InputLoopAddress extends React.Component<Props, State> {
state: State = {
url: this.props.initialUrl || '',
submittedUrl: this.props.initialUrl || '',
validation: '',
};

componentDidUpdate(nextProps: Props) {
// Handle errors for incorrect URL
const { error } = this.props;
if (error !== null && nextProps.error === null) {
message.error(`Error setting URL!`, 2);
}
}

render() {
const { validation, url } = this.state;
const { isCheckingLoop } = this.props;
const validateStatus = url ? (validation ? 'error' : 'success') : undefined;
return (
<Form className="InputLoopAddress" onSubmit={this.handleSubmit} layout="vertical">
<Form.Item label={`Loop URL`} validateStatus={validateStatus}>
<Input
type="url"
size="small"
value={url}
onChange={this.handleChange}
placeholder="http://localhost:8081"
autoFocus
/>
</Form.Item>

<Button
type="primary"
size="large"
htmlType="submit"
disabled={!url}
loading={isCheckingLoop}
block
>
{`Set Loop URL`}
</Button>
</Form>
);
}

private handleChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
const url = ev.currentTarget.value;
let validation = '';
try {
// tslint:disable-next-line
new URL(url);
} catch (err) {
validation = 'That doesn’t look like a valid url';
}
this.setState({ url, validation });
};

private handleSubmit = (ev: React.FormEvent<HTMLFormElement>) => {
const url = this.state.url.replace(/\/$/, '');
const loop = this.props;
ev.preventDefault();
browser.permissions
.request({
origins: [urlWithoutPort(url)],
})
.then(accepted => {
if (!accepted) {
message.warn('Permission denied, connection may fail');
}
this.setState({ submittedUrl: url });
loop.setLoop(url);
});
};
}
39 changes: 39 additions & 0 deletions src/app/components/Loop/LoopForm.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.LoopForm {
&-type,
&-advancedToggle {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 1rem;
}

&-type {
&-settings.ant-btn {
margin-right: -2rem;
margin-left: 0.5rem;
padding: 0.5rem;
background: none;
border: none;
border-radius: 100%;
}
}

&-actions {
margin-top: 2rem;
display: flex;
align-items: center;

.ant-btn {
margin-left: 0.5rem;

&:first-child {
margin-left: 0;
flex: 1;
}
}
}

.ant-form-item {
margin-bottom: 0.5rem;
}
}
Loading