@@ -11,14 +11,16 @@ import InputGroup from '../../../components/input-group';
11
11
import Heading from '../../../components/heading' ;
12
12
import { TooltipProps } from '../../../components/tooltip' ;
13
13
import ErrorPage from '../error' ;
14
+ import Error from '../../../components/inline-error' ;
15
+ import { numberWithSpaces } from '../../../utils/helpers' ;
14
16
15
17
export type IFormErrors = {
16
18
[ key : string ] : string ;
17
19
} ;
18
20
19
21
const inboundTip : TooltipProps = {
20
- title : 'Inbound capacity' ,
21
- body : 'This is the amount of sats you will be able to receive in payments. The amount must be at least double the amount of your ‘spending balance’. The maximum amount of inbound capacity is 50, 000, 000 sats.'
22
+ title : 'My receiving capacity' ,
23
+ body : 'This is the amount of sats you will be able to receive in payments. The amount must be at least double that of your \\ ‘spending balance\\ ’. Maximum receiving capacity is 50 000 000 sats.'
22
24
} ;
23
25
24
26
const spendingTip : TooltipProps = {
@@ -38,10 +40,11 @@ function ConfigurePage(): JSX.Element {
38
40
const [ isLoading , setIsLoading ] = useState ( true ) ;
39
41
const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
40
42
const [ product , setProduct ] = useState < IService | undefined > ( undefined ) ;
41
- const [ channelExpiry , setChannelExpiry ] = useState < string > ( '1 ' ) ;
42
- const [ localBalance , setLocalBalance ] = useState < string > ( '0 ' ) ;
43
+ const [ channelExpiry , setChannelExpiry ] = useState < string > ( '' ) ;
44
+ const [ localBalance , setLocalBalance ] = useState < string > ( '' ) ;
43
45
const [ remoteBalance , setRemoteBalance ] = useState < string > ( '0' ) ;
44
46
const [ formErrors , setFormErrors ] = useState < IFormErrors > ( { } ) ;
47
+ const [ generalError , setGeneralError ] = useState ( '' ) ;
45
48
46
49
useEffect ( ( ) => {
47
50
if ( services . length > 0 ) {
@@ -57,16 +60,12 @@ function ConfigurePage(): JSX.Element {
57
60
if ( localBalance === '0' ) {
58
61
// setLocalBalance(`${service.min_channel_size}`);
59
62
}
60
-
61
- if ( channelExpiry === '1' ) {
62
- setChannelExpiry ( `${ service . max_chan_expiry } ` ) ;
63
- }
64
63
}
65
64
} , [ services ] ) ;
66
65
67
66
useEffect ( ( ) => {
68
67
dispatch ( refreshInfo ( ) )
69
- . catch ( ( e ) => alert ( e ) )
68
+ . catch ( ( e ) => setGeneralError ( e . toString ( ) ) )
70
69
. finally ( ( ) => setIsLoading ( false ) ) ;
71
70
} , [ ] ) ;
72
71
@@ -83,11 +82,13 @@ function ConfigurePage(): JSX.Element {
83
82
84
83
setIsSubmitting ( true ) ;
85
84
85
+ const { max_chan_expiry } = product ;
86
+
86
87
const req : IBuyChannelRequest = {
87
88
product_id : product . product_id ,
88
- channel_expiry : Number ( channelExpiry ) ,
89
+ channel_expiry : channelExpiry ? Number ( channelExpiry ) : max_chan_expiry ,
89
90
local_balance : Number ( remoteBalance ) , // Switched around for context
90
- remote_balance : Number ( localBalance )
91
+ remote_balance : localBalance ? Number ( localBalance ) : 0
91
92
} ;
92
93
93
94
try {
@@ -101,7 +102,7 @@ function ConfigurePage(): JSX.Element {
101
102
if ( error . toString ( ) . indexOf ( 'GEO_BLOCKED' ) > - 1 ) {
102
103
dispatch ( navigate ( { page : 'geoblocked' } ) ) ;
103
104
} else {
104
- alert ( error ) ;
105
+ setGeneralError ( error . toString ( ) ) ;
105
106
}
106
107
}
107
108
} ;
@@ -117,7 +118,7 @@ function ConfigurePage(): JSX.Element {
117
118
118
119
// TODO check channel balance
119
120
120
- if ( Number ( channelExpiry ) < 1 ) {
121
+ if ( channelExpiry !== '' && Number ( channelExpiry ) < 1 ) {
121
122
errors . channelExpiry = `Minimum channel expiry is ${ product . min_chan_expiry } week${
122
123
product . min_chan_expiry !== 1 ? 's' : ''
123
124
} `;
@@ -126,13 +127,17 @@ function ConfigurePage(): JSX.Element {
126
127
}
127
128
128
129
if ( Number ( remoteBalance ) > product . max_channel_size ) {
129
- errors . remoteBalance = `Max channel size must be smaller than ${ product . max_channel_size } ` ;
130
+ errors . remoteBalance = `Max receiving capacity is ${ numberWithSpaces ( product . max_channel_size ) } sats ` ;
130
131
} else if ( Number ( remoteBalance ) < product . min_channel_size ) {
131
- errors . remoteBalance = `Min channel size must be greater than ${ product . min_channel_size } ` ;
132
+ errors . remoteBalance = `Minimum receiving capacity is ${ numberWithSpaces ( product . min_channel_size ) } sats ` ;
132
133
}
133
134
134
135
if ( Number ( localBalance ) !== 0 && Number ( localBalance ) < product . min_channel_size ) {
135
- errors . localBalance = `Local balance needs to be greater than ${ product . min_channel_size } ` ;
136
+ errors . localBalance = `Minimum spending balance is ${ numberWithSpaces ( product . min_channel_size ) } sats` ;
137
+ }
138
+
139
+ if ( Number ( localBalance ) !== 0 && Number ( localBalance ) > product . max_channel_size ) {
140
+ errors . localBalance = `Max spending balance is ${ numberWithSpaces ( product . max_channel_size ) } sats` ;
136
141
}
137
142
138
143
setFormErrors ( errors ) ;
@@ -171,7 +176,7 @@ function ConfigurePage(): JSX.Element {
171
176
return < div /> ;
172
177
}
173
178
174
- const { available } = product ;
179
+ const { available, max_chan_expiry } = product ;
175
180
176
181
if ( ! available ) {
177
182
return < ErrorPage type = { 'unavailable' } /> ;
@@ -191,14 +196,14 @@ function ConfigurePage(): JSX.Element {
191
196
>
192
197
< Form className = { 'form-content' } >
193
198
< div className = { 'form-fields' } >
194
- < Heading > Configure </ Heading >
199
+ < Heading > My channel </ Heading >
195
200
196
201
< InputGroup
197
202
type = 'number'
198
203
value = { remoteBalance }
199
204
onChange = { ( str ) => onSetInput ( str , setRemoteBalance ) }
200
205
id = { 'remote-balance' }
201
- label = { 'My inbound capacity' }
206
+ label = { 'My receiving capacity' }
202
207
append = { 'sats' }
203
208
showFiatFromSatsValue
204
209
error = { formErrors . remoteBalance }
@@ -209,6 +214,7 @@ function ConfigurePage(): JSX.Element {
209
214
< InputGroup
210
215
type = 'number'
211
216
value = { localBalance }
217
+ placeholder = { '0' }
212
218
onChange = { ( str ) => onSetInput ( str , setLocalBalance ) }
213
219
id = { 'local-balance' }
214
220
label = { 'My spending balance' }
@@ -222,6 +228,7 @@ function ConfigurePage(): JSX.Element {
222
228
< InputGroup
223
229
type = 'number'
224
230
value = { channelExpiry }
231
+ placeholder = { `${ max_chan_expiry } ` }
225
232
onChange = { ( str ) => onSetInput ( str , setChannelExpiry ) }
226
233
id = { 'channel-expiry' }
227
234
label = { 'Keep my channel open for at least' }
@@ -230,6 +237,8 @@ function ConfigurePage(): JSX.Element {
230
237
onBlur = { onBlur }
231
238
tooltip = { durationTip }
232
239
/>
240
+
241
+ < Error > { generalError } </ Error >
233
242
</ div >
234
243
235
244
< div className = { 'button-container' } >
0 commit comments