Skip to content

Commit a0ebcde

Browse files
authored
Merge pull request #190 from lightninglabs/disable-fund-account
pool+accounts: display warning if node has no channels
2 parents 9a4a22b + f9b982b commit a0ebcde

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

app/src/__tests__/components/pool/AccountSection.spec.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('AccountSection', () => {
2828

2929
beforeEach(async () => {
3030
store = createStore();
31+
await store.channelStore.fetchChannels();
3132
await store.nodeStore.fetchBalances();
3233
await store.accountStore.fetchAccounts();
3334
await store.orderStore.fetchOrders();
@@ -37,6 +38,19 @@ describe('AccountSection', () => {
3738
return renderWithProviders(<AccountSection />, store);
3839
};
3940

41+
it('should display channel notice', () => {
42+
// remove all accounts to display the FundNewAccountForm
43+
runInAction(() => {
44+
store.accountStore.accounts.clear();
45+
store.accountStore.activeTraderKey = '';
46+
store.channelStore.channels.clear();
47+
});
48+
const { getByText } = render();
49+
50+
expect(getByText('Welcome to Pool')).toBeInTheDocument();
51+
expect(getByText(/Your node must already have open channels/)).toBeInTheDocument();
52+
});
53+
4054
it('should validate fund new account form', () => {
4155
// remove all accounts to display the FundNewAccountForm
4256
runInAction(() => {

app/src/components/pool/account/NoAccount.tsx

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { observer } from 'mobx-react-lite';
33
import { usePrefixedTranslation } from 'hooks';
44
import { useStore } from 'store';
5-
import { Button, UserPlus } from 'components/base';
5+
import { AlertTriangle, Button, UserPlus } from 'components/base';
66
import LoaderLines from 'components/common/LoaderLines';
77
import { styled } from 'components/theme';
88

@@ -16,19 +16,34 @@ const Styled = {
1616
Content: styled.div`
1717
font-size: ${props => props.theme.sizes.xs};
1818
text-align: center;
19-
20-
> div {
21-
margin: 20px;
22-
}
2319
`,
2420
UserIcon: styled(UserPlus)`
2521
width: 64px;
2622
height: 64px;
2723
`,
2824
Title: styled.div`
25+
margin: 20px;
2926
font-size: ${props => props.theme.sizes.s};
3027
font-weight: bold;
3128
`,
29+
Message: styled.div`
30+
margin: 20px;
31+
`,
32+
ChannelNotice: styled.div`
33+
display: flex;
34+
margin: 20px 0;
35+
color: ${props => props.theme.colors.gold};
36+
37+
> svg {
38+
width: 70px;
39+
height: 66px;
40+
}
41+
42+
> span {
43+
margin-left: 5px;
44+
text-align: left;
45+
}
46+
`,
3247
Actions: styled.div`
3348
margin: 30px auto;
3449
`,
@@ -38,7 +53,7 @@ const NoAccount: React.FC = () => {
3853
const { l } = usePrefixedTranslation('cmps.pool.account.NoAccount');
3954
const { accountSectionView, accountStore } = useStore();
4055

41-
const { Loading, Content, UserIcon, Title, Actions } = Styled;
56+
const { Loading, Content, UserIcon, Title, Message, ChannelNotice, Actions } = Styled;
4257
if (!accountStore.loaded) {
4358
return (
4459
<Loading>
@@ -53,9 +68,21 @@ const NoAccount: React.FC = () => {
5368
<UserIcon />
5469
</div>
5570
<Title>{l('welcome')}</Title>
56-
<div>{l('message')}</div>
71+
{!accountSectionView.hasChannels ? (
72+
<ChannelNotice>
73+
<AlertTriangle size="large" />
74+
<span>{l('channelNotice')}</span>
75+
</ChannelNotice>
76+
) : (
77+
<Message>{l('message')}</Message>
78+
)}
5779
<Actions>
58-
<Button primary ghost onClick={accountSectionView.showFundNew}>
80+
<Button
81+
primary
82+
ghost
83+
disabled={!accountSectionView.hasChannels}
84+
onClick={accountSectionView.showFundNew}
85+
>
5986
{l('createAccount')}
6087
</Button>
6188
</Actions>

app/src/i18n/locales/en-US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
"cmps.pool.account.FundAccountForm.newBalance": "New Account Balance",
152152
"cmps.pool.account.NoAccount.welcome": "Welcome to Pool",
153153
"cmps.pool.account.NoAccount.message": "To begin buying and selling channels, you will need to deposit funds into a non-custodial account. You will be able to withdraw at any time.",
154+
"cmps.pool.account.NoAccount.channelNotice": "Your node must already have open channels before you can fund your Pool account.",
154155
"cmps.pool.account.NoAccount.createAccount": "Open an Account",
155156
"cmps.pool.batches.BatchRowHeader.batchId": "Batch ID",
156157
"cmps.pool.batches.BatchRowHeader.txId": "Tx ID",

app/src/store/views/accountSectionView.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export default class AccountSectionView {
4949
return this.section;
5050
}
5151

52+
/** indicates if the LND node has any open channels */
53+
get hasChannels() {
54+
return this._store.channelStore.channels.size > 0;
55+
}
56+
5257
//
5358
// Actions
5459
//

0 commit comments

Comments
 (0)