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

Edit channel fees: fix showing feedback after fees have been set #1738

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
312 changes: 155 additions & 157 deletions components/SetFeesForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { StyleSheet, Text, View, ScrollView } from 'react-native';
import { StyleSheet, Text, View } from 'react-native';
import { inject, observer } from 'mobx-react';

import Button from './../components/Button';
Expand All @@ -19,16 +19,17 @@ import FeeStore from './../stores/FeeStore';
import SettingsStore from './../stores/SettingsStore';

interface SetFeesFormProps {
FeeStore: FeeStore;
ChannelsStore: ChannelsStore;
SettingsStore: SettingsStore;
FeeStore?: FeeStore;
ChannelsStore?: ChannelsStore;
SettingsStore?: SettingsStore;
baseFee?: string;
feeRate?: string;
timeLockDelta?: string;
channelPoint?: string;
channelId?: string;
minHtlc?: string;
maxHtlc?: string;
setFeesCompleted: () => void;
}

interface SetFeesFormState {
Expand Down Expand Up @@ -78,166 +79,145 @@ export default class SetFeesForm extends React.Component<
channelPoint,
channelId,
minHTLC,
maxHTLC
maxHTLC,
setFeesCompleted
} = this.props;
const {
setFees,
loading,
setFeesError,
setFeesErrorMsg,
setFeesSuccess
} = FeeStore;
const { implementation } = SettingsStore;
} = FeeStore!;
const { implementation } = SettingsStore!;

return (
<React.Fragment>
<ScrollView
style={{ paddingTop: 15 }}
keyboardShouldPersistTaps="handled"
<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{loading && <LightningIndicator />}
{feesSubmitted && setFeesSuccess && (
<SuccessMessage
message={localeString(
'components.SetFeesForm.success'
{`${localeString(
'components.SetFeesForm.baseFee'
)} (${localeString('general.sats')})`}
</Text>
<TextInput
keyboardType="numeric"
placeholder={baseFee || '1'}
value={newBaseFee}
onChangeText={(text: string) =>
this.setState({
newBaseFee: text
})
}
autoCapitalize="none"
autoCorrect={false}
/>

<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{`${localeString('components.SetFeesForm.feeRate')} (${
implementation === 'c-lightning-REST'
? localeString(
'components.SetFeesForm.ppmMilliMsat'
)
: localeString('general.percentage')
})`}
</Text>
<TextInput
keyboardType="numeric"
placeholder={
feeRate || implementation === 'c-lightning-REST'
? '1'
: '0.001'
}
value={newFeeRate}
onChangeText={(text: string) =>
this.setState({
newFeeRate: text
})
}
autoCapitalize="none"
autoCorrect={false}
/>

{BackendUtils.isLNDBased() && (
<>
<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{localeString(
'components.SetFeesForm.timeLockDelta'
)}
/>
)}
{feesSubmitted && setFeesError && (
<ErrorMessage
message={
setFeesErrorMsg
? setFeesErrorMsg
: localeString(
'components.SetFeesForm.error'
)
</Text>
<TextInput
keyboardType="numeric"
placeholder={timeLockDelta || '144'}
value={newTimeLockDelta}
onChangeText={(text: string) =>
this.setState({
newTimeLockDelta: text
})
}
autoCapitalize="none"
autoCorrect={false}
/>
)}

<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{`${localeString(
'components.SetFeesForm.baseFee'
)} (${localeString('general.sats')})`}
</Text>
<TextInput
keyboardType="numeric"
placeholder={baseFee || '1'}
value={newBaseFee}
onChangeText={(text: string) =>
this.setState({
newBaseFee: text
})
}
autoCapitalize="none"
autoCorrect={false}
/>

<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{`${localeString('components.SetFeesForm.feeRate')} (${
implementation === 'c-lightning-REST'
? localeString(
'components.SetFeesForm.ppmMilliMsat'
)
: localeString('general.percentage')
})`}
</Text>
<TextInput
keyboardType="numeric"
placeholder={
feeRate || implementation === 'c-lightning-REST'
? '1'
: '0.001'
}
value={newFeeRate}
onChangeText={(text: string) =>
this.setState({
newFeeRate: text
})
}
autoCapitalize="none"
autoCorrect={false}
/>

{BackendUtils.isLNDBased() && (
<>
<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{localeString(
'components.SetFeesForm.timeLockDelta'
)}
</Text>
<TextInput
keyboardType="numeric"
placeholder={timeLockDelta || '144'}
value={newTimeLockDelta}
onChangeText={(text: string) =>
this.setState({
newTimeLockDelta: text
})
}
autoCapitalize="none"
autoCorrect={false}
/>

<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{localeString('components.SetFeesForm.minHtlc')}
</Text>
<TextInput
keyboardType="numeric"
placeholder={minHTLC || '1'}
value={newMinHtlc}
onChangeText={(text: string) =>
this.setState({
newMinHtlc: text
})
}
autoCapitalize="none"
autoCorrect={false}
/>
<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{localeString('components.SetFeesForm.minHtlc')}
</Text>
<TextInput
keyboardType="numeric"
placeholder={minHTLC || '1'}
value={newMinHtlc}
onChangeText={(text: string) =>
this.setState({
newMinHtlc: text
})
}
autoCapitalize="none"
autoCorrect={false}
/>

<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{localeString('components.SetFeesForm.maxHtlc')}
</Text>
<TextInput
keyboardType="numeric"
placeholder={maxHTLC || '250000'}
value={newMaxHtlc}
onChangeText={(text: string) =>
this.setState({
newMaxHtlc: text
})
}
autoCapitalize="none"
autoCorrect={false}
/>
</>
)}
<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{localeString('components.SetFeesForm.maxHtlc')}
</Text>
<TextInput
keyboardType="numeric"
placeholder={maxHTLC || '250000'}
value={newMaxHtlc}
onChangeText={(text: string) =>
this.setState({
newMaxHtlc: text
})
}
autoCapitalize="none"
autoCorrect={false}
/>
</>
)}

{loading && <LightningIndicator />}
{!loading && (
<View style={styles.button}>
<Button
title={localeString(
Expand All @@ -252,21 +232,39 @@ export default class SetFeesForm extends React.Component<
channelId,
newMinHtlc,
newMaxHtlc
).then(() => {
if (
channelId &&
BackendUtils.isLNDBased() &&
!setFeesError
) {
ChannelsStore.getChannelInfo(channelId);
}
});
)
.then(() => {
if (
channelId &&
BackendUtils.isLNDBased() &&
!setFeesError
) {
ChannelsStore!.loadChannelInfo(
channelId
);
}
})
.finally(() => setFeesCompleted());
this.setState({ feesSubmitted: true });
}}
tertiary
/>
</View>
</ScrollView>
)}
{feesSubmitted && setFeesSuccess && (
<SuccessMessage
message={localeString('components.SetFeesForm.success')}
/>
)}
{feesSubmitted && setFeesError && (
<ErrorMessage
message={
setFeesErrorMsg
? setFeesErrorMsg
: localeString('components.SetFeesForm.error')
}
/>
)}
</React.Fragment>
);
}
Expand Down
8 changes: 6 additions & 2 deletions stores/ChannelsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,13 @@ export default class ChannelsStore {
};

@action
public getChannelInfo = (chanId: string) => {
public loadChannelInfo = (chanId: string, deleteBeforeLoading = false) => {
this.loading = true;
if (this.chanInfo[chanId]) delete this.chanInfo[chanId];

if (deleteBeforeLoading) {
if (this.chanInfo[chanId]) delete this.chanInfo[chanId];
}

BackendUtils.getChannelInfo(chanId)
.then((data: any) => {
this.chanInfo[chanId] = new ChannelInfo(data);
Expand Down
Loading