Skip to content

Commit 0dda455

Browse files
authored
Merge pull request #52 from lightninglabs/ui-fixes
Additional UI fixes
2 parents e0bea6c + bb805e5 commit 0dda455

29 files changed

+216
-93
lines changed

app/src/__stories__/HistoryPage.stories.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { SwapState, SwapType } from 'types/generated/loop_pb';
33
import { useStore } from 'store';
4+
import { Swap } from 'store/models';
45
import HistoryPage from 'components/history/HistoryPage';
56
import { Layout } from 'components/layout';
67

@@ -10,24 +11,28 @@ export default {
1011
parameters: { contained: true },
1112
};
1213

14+
const updateSwapsStatus = (swaps: Swap[]) => {
15+
swaps.forEach((s, i) => {
16+
if (s.typeName === 'Unknown') s.type = SwapType.LOOP_IN;
17+
if (i === 0) s.state = SwapState.INITIATED;
18+
if (i === 1) s.state = SwapState.PREIMAGE_REVEALED;
19+
if (i === 2) s.state = SwapState.HTLC_PUBLISHED;
20+
if (i === 3) s.state = SwapState.INVOICE_SETTLED;
21+
});
22+
};
23+
1324
export const Default = () => {
1425
const store = useStore();
1526
store.swapStore.stopAutoPolling();
16-
store.swapStore.sortedSwaps.forEach((s, i) => {
17-
if (s.typeName === 'Unknown') s.type = SwapType.LOOP_IN;
18-
if (i === 0) s.state = SwapState.INVOICE_SETTLED;
19-
});
27+
updateSwapsStatus(store.swapStore.sortedSwaps);
2028
return <HistoryPage />;
2129
};
2230

2331
export const InsideLayout = () => {
2432
const store = useStore();
2533
store.uiStore.page = 'history';
2634
store.swapStore.stopAutoPolling();
27-
store.swapStore.sortedSwaps.forEach((s, i) => {
28-
if (s.typeName === 'Unknown') s.type = SwapType.LOOP_IN;
29-
if (i === 0) s.state = SwapState.INVOICE_SETTLED;
30-
});
35+
updateSwapsStatus(store.swapStore.sortedSwaps);
3136
return (
3237
<Layout>
3338
<HistoryPage />

app/src/__stories__/Layout.stories.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,27 @@ export default {
88
component: Layout,
99
};
1010

11-
export const Default = () => <Layout />;
11+
export const Default = () => {
12+
const { uiStore } = useStore();
13+
uiStore.goToLoop();
1214

13-
export const WithContent = () => (
14-
<Layout>
15-
<LoopPage />
16-
</Layout>
17-
);
15+
return <Layout />;
16+
};
17+
18+
export const WithContent = () => {
19+
const { uiStore } = useStore();
20+
uiStore.goToLoop();
21+
return (
22+
<Layout>
23+
<LoopPage />
24+
</Layout>
25+
);
26+
};
1827

1928
export const Collapsed = () => {
20-
const store = useStore();
21-
store.settingsStore.sidebarVisible = false;
29+
const { uiStore, settingsStore } = useStore();
30+
uiStore.goToLoop();
31+
settingsStore.sidebarVisible = false;
2232

2333
return (
2434
<Layout>
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react';
1+
import React from 'react';
22
import { useStore } from 'store';
33
import { Layout } from 'components/layout';
44
import LoopPage from 'components/loop/LoopPage';
@@ -11,23 +11,20 @@ export default {
1111

1212
export const Default = () => {
1313
const store = useStore();
14-
useEffect(() => {
15-
// only use a small set of channels
16-
store.channelStore.sortedChannels.splice(10);
17-
18-
// change back to sample data when the component is unmounted
19-
return () => {
20-
store.channelStore.fetchChannels();
21-
};
22-
}, []);
14+
// only use a small set of channels
15+
store.channelStore.sortedChannels.splice(10);
2316

2417
return <LoopPage />;
2518
};
2619

2720
export const ManyChannels = () => <LoopPage />;
2821

29-
export const InsideLayout = () => (
30-
<Layout>
31-
<LoopPage />
32-
</Layout>
33-
);
22+
export const InsideLayout = () => {
23+
const store = useStore();
24+
store.uiStore.goToLoop();
25+
return (
26+
<Layout>
27+
<LoopPage />
28+
</Layout>
29+
);
30+
};

app/src/__stories__/SettingsPage.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export const BalanceMode = () => {
2626
};
2727

2828
export const InsideLayout = () => {
29+
const { uiStore } = useStore();
30+
uiStore.goToSettings();
2931
return (
3032
<Layout>
3133
<SettingsPage />

app/src/__tests__/components/loop/ChannelRow.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import { SwapDirection } from 'types/state';
33
import { fireEvent } from '@testing-library/react';
44
import { formatSats } from 'util/formatters';
5-
import { ellipseInside } from 'util/strings';
65
import { renderWithProviders } from 'util/tests';
76
import { createStore, Store } from 'store';
87
import { Channel } from 'store/models';
@@ -14,6 +13,7 @@ describe('ChannelRow component', () => {
1413

1514
beforeEach(async () => {
1615
store = createStore();
16+
await store.fetchAllData();
1717
channel = new Channel(store, {
1818
chanId: '150633093070848',
1919
remotePubkey: '02ac59099da6d4bd818e6a81098f5d54580b7c3aa8255c707fa0f95ca89b02cb8c',
@@ -51,7 +51,7 @@ describe('ChannelRow component', () => {
5151

5252
it('should display the peer pubkey', () => {
5353
const { getByText } = render();
54-
expect(getByText(ellipseInside(channel.remotePubkey))).toBeInTheDocument();
54+
expect(getByText(channel.ellipsedPubkey)).toBeInTheDocument();
5555
});
5656

5757
it('should display the capacity', () => {

app/src/__tests__/components/loop/LoopPage.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ describe('LoopPage component', () => {
2828
expect(getByText('Lightning Loop')).toBeInTheDocument();
2929
});
3030

31+
it('should display the network badge', () => {
32+
const { getByText, queryByText } = render();
33+
store.nodeStore.network = 'regtest';
34+
expect(getByText('regtest')).toBeInTheDocument();
35+
store.nodeStore.network = 'testnet';
36+
expect(getByText('testnet')).toBeInTheDocument();
37+
store.nodeStore.network = 'mainnet';
38+
expect(queryByText('mainnet')).not.toBeInTheDocument();
39+
});
40+
3141
it('should display the three tiles', () => {
3242
const { getByText } = render();
3343
expect(getByText('Loop History')).toBeInTheDocument();

app/src/__tests__/components/loop/ProcessingSwaps.spec.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import * as LOOP from 'types/generated/loop_pb';
33
import { fireEvent } from '@testing-library/react';
4-
import { ellipseInside } from 'util/strings';
54
import { renderWithProviders } from 'util/tests';
65
import { loopListSwaps } from 'util/tests/sampleData';
76
import { createStore, Store } from 'store';
@@ -49,7 +48,7 @@ describe('ProcessingSwaps component', () => {
4948
const { getByText, getByTitle } = render();
5049
const swap = addSwap(LOOP_IN, INITIATED);
5150
expect(getByText('dot.svg')).toHaveClass('warn');
52-
expect(getByText(ellipseInside(swap.id))).toBeInTheDocument();
51+
expect(getByText(swap.ellipsedId)).toBeInTheDocument();
5352
expect(getByTitle(swap.stateLabel)).toBeInTheDocument();
5453
expect(width(getByTitle(swap.stateLabel))).toBe('25%');
5554
});
@@ -58,7 +57,7 @@ describe('ProcessingSwaps component', () => {
5857
const { getByText, getByTitle } = render();
5958
const swap = addSwap(LOOP_IN, HTLC_PUBLISHED);
6059
expect(getByText('dot.svg')).toHaveClass('warn');
61-
expect(getByText(ellipseInside(swap.id))).toBeInTheDocument();
60+
expect(getByText(swap.ellipsedId)).toBeInTheDocument();
6261
expect(getByTitle(swap.stateLabel)).toBeInTheDocument();
6362
expect(width(getByTitle(swap.stateLabel))).toBe('50%');
6463
});
@@ -67,23 +66,23 @@ describe('ProcessingSwaps component', () => {
6766
const { getByText, getByTitle } = render();
6867
const swap = addSwap(LOOP_IN, INVOICE_SETTLED);
6968
expect(getByText('dot.svg')).toHaveClass('warn');
70-
expect(getByText(ellipseInside(swap.id))).toBeInTheDocument();
69+
expect(getByText(swap.ellipsedId)).toBeInTheDocument();
7170
expect(getByTitle(swap.stateLabel)).toBeInTheDocument();
7271
expect(width(getByTitle(swap.stateLabel))).toBe('75%');
7372
});
7473

7574
it('should display an SUCCESS Loop In', () => {
7675
const { getByText, getByTitle } = render();
7776
const swap = addSwap(LOOP_IN, SUCCESS);
78-
expect(getByText(ellipseInside(swap.id))).toBeInTheDocument();
77+
expect(getByText(swap.ellipsedId)).toBeInTheDocument();
7978
expect(getByTitle(swap.stateLabel)).toBeInTheDocument();
8079
expect(width(getByTitle(swap.stateLabel))).toBe('100%');
8180
});
8281

8382
it('should display an FAILED Loop In', () => {
8483
const { getByText } = render();
8584
const swap = addSwap(LOOP_IN, FAILED);
86-
expect(getByText(ellipseInside(swap.id))).toBeInTheDocument();
85+
expect(getByText(swap.ellipsedId)).toBeInTheDocument();
8786
expect(getByText(swap.stateLabel)).toBeInTheDocument();
8887
expect(getByText('close.svg')).toBeInTheDocument();
8988
});
@@ -92,7 +91,7 @@ describe('ProcessingSwaps component', () => {
9291
const { getByText, getByTitle } = render();
9392
const swap = addSwap(LOOP_OUT, INITIATED);
9493
expect(getByText('dot.svg')).toHaveClass('warn');
95-
expect(getByText(ellipseInside(swap.id))).toBeInTheDocument();
94+
expect(getByText(swap.ellipsedId)).toBeInTheDocument();
9695
expect(getByTitle(swap.stateLabel)).toBeInTheDocument();
9796
expect(width(getByTitle(swap.stateLabel))).toBe('33%');
9897
});
@@ -101,7 +100,7 @@ describe('ProcessingSwaps component', () => {
101100
const { getByText, getByTitle } = render();
102101
const swap = addSwap(LOOP_OUT, PREIMAGE_REVEALED);
103102
expect(getByText('dot.svg')).toHaveClass('warn');
104-
expect(getByText(ellipseInside(swap.id))).toBeInTheDocument();
103+
expect(getByText(swap.ellipsedId)).toBeInTheDocument();
105104
expect(getByTitle(swap.stateLabel)).toBeInTheDocument();
106105
expect(width(getByTitle(swap.stateLabel))).toBe('66%');
107106
});
@@ -110,15 +109,15 @@ describe('ProcessingSwaps component', () => {
110109
const { getByText, getByTitle } = render();
111110
const swap = addSwap(LOOP_OUT, SUCCESS);
112111
expect(getByText('dot.svg')).toHaveClass('success');
113-
expect(getByText(ellipseInside(swap.id))).toBeInTheDocument();
112+
expect(getByText(swap.ellipsedId)).toBeInTheDocument();
114113
expect(getByTitle(swap.stateLabel)).toBeInTheDocument();
115114
expect(width(getByTitle(swap.stateLabel))).toBe('100%');
116115
});
117116

118117
it('should display an FAILED Loop Out', () => {
119118
const { getByText } = render();
120119
const swap = addSwap(LOOP_OUT, FAILED);
121-
expect(getByText(ellipseInside(swap.id))).toBeInTheDocument();
120+
expect(getByText(swap.ellipsedId)).toBeInTheDocument();
122121
expect(getByText(swap.stateLabel)).toBeInTheDocument();
123122
expect(getByText('close.svg')).toBeInTheDocument();
124123
});

app/src/__tests__/components/loop/SwapWizard.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('SwapWizard component', () => {
1212

1313
beforeEach(async () => {
1414
store = createStore();
15-
await store.init();
15+
await store.fetchAllData();
1616

1717
await store.buildSwapStore.startSwap();
1818
store.channelStore.sortedChannels.slice(0, 3).forEach(c => {

app/src/__tests__/store/buildSwapStore.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { values } from 'mobx';
2-
import { SwapDirection } from 'types/state';
2+
import { BuildSwapSteps, SwapDirection } from 'types/state';
33
import { grpc } from '@improbable-eng/grpc-web';
44
import { waitFor } from '@testing-library/react';
55
import Big from 'big.js';
@@ -19,6 +19,15 @@ describe('BuildSwapStore', () => {
1919
store = rootStore.buildSwapStore;
2020
});
2121

22+
it('should not start a swap if there are no channels', async () => {
23+
rootStore.channelStore.channels.clear();
24+
expect(store.currentStep).toBe(BuildSwapSteps.Closed);
25+
expect(rootStore.uiStore.alerts.size).toBe(0);
26+
await store.startSwap();
27+
expect(store.currentStep).toBe(BuildSwapSteps.Closed);
28+
expect(rootStore.uiStore.alerts.size).toBe(1);
29+
});
30+
2231
it('should toggle the selected channels', () => {
2332
expect(store.selectedChanIds).toHaveLength(0);
2433
store.toggleSelectedChannel('test');

app/src/components/base/shared.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ export const Pill = styled.span`
2525
border-radius: 40px;
2626
`;
2727

28+
export const Badge = styled.span`
29+
display: inline-block;
30+
margin-left: 10px;
31+
font-family: ${props => props.theme.fonts.open.light};
32+
font-size: ${props => props.theme.sizes.xxs};
33+
color: ${props => props.theme.colors.orange};
34+
border: 1px solid ${props => props.theme.colors.orange};
35+
border-radius: 4px;
36+
padding: 3px 5px 5px;
37+
text-transform: lowercase;
38+
line-height: 1;
39+
letter-spacing: 1.8px;
40+
`;
41+
2842
//
2943
// Button
3044
//

0 commit comments

Comments
 (0)