-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
Settings: Payments: allow the user to change their default fee limit #1256
Merged
kaloudis
merged 12 commits into
ZeusLN:master
from
setlife-network:or/issue-1106/change-default-fee-limit
Jan 18, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e0cbc68
Create new strings
Ovifer13 b76e1e2
Add payments option to settings
Ovifer13 6dbe337
Add PaymentSettings
Ovifer13 cab42cb
PaymentsSettings view
Ovifer13 7d8728a
Navigation to PaymentsSettings
Ovifer13 0a2b1eb
Merge branch 'master' into or/issue-1106/change-default-fee-limit
Ovifer13 17d7a6e
delete (sats) from string
Ovifer13 c98a8ef
Change from number to string
Ovifer13 bdf1558
Add field for sats and percentage and change types from number to str…
Ovifer13 9e14378
Add function to update fees based on user settings
Ovifer13 202b11f
delete console log
Ovifer13 9d10b4d
Fix lint issues
Ovifer13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
import * as React from 'react'; | ||
import { Text, View } from 'react-native'; | ||
import { Header, Icon } from 'react-native-elements'; | ||
import { inject, observer } from 'mobx-react'; | ||
import SettingsStore from '../../stores/SettingsStore'; | ||
import { localeString } from '../../utils/LocaleUtils'; | ||
import { themeColor } from '../../utils/ThemeUtils'; | ||
|
||
import LoadingIndicator from '../../components/LoadingIndicator'; | ||
import TextInput from '../../components/TextInput'; | ||
|
||
interface PaymentsSettingsProps { | ||
navigation: any; | ||
SettingsStore: SettingsStore; | ||
} | ||
|
||
interface PaymentsSettingsState { | ||
feeLimitMethod: string; | ||
feeLimit: string; | ||
feePercentage: string; | ||
} | ||
|
||
@inject('SettingsStore') | ||
@observer | ||
export default class PaymentsSettings extends React.Component< | ||
PaymentsSettingsProps, | ||
PaymentsSettingsState | ||
> { | ||
state = { | ||
feeLimitMethod: 'fixed', | ||
feeLimit: '100', | ||
feePercentage: '0.5' | ||
}; | ||
|
||
async UNSAFE_componentWillMount() { | ||
const { SettingsStore } = this.props; | ||
const { getSettings } = SettingsStore; | ||
const settings = await getSettings(); | ||
|
||
this.setState({ | ||
feeLimitMethod: settings.payments.defaultFeeMethod || 'fixed', | ||
feeLimit: settings.payments.defaultFeeFixed || '100', | ||
feePercentage: settings.payments.defaultFeePercentage || '0.5' | ||
}); | ||
} | ||
|
||
handleSave = async () => { | ||
const { feeLimitMethod, feeLimit, feePercentage } = this.state; | ||
const { SettingsStore } = this.props; | ||
const { updateSettings } = SettingsStore; | ||
await updateSettings({ | ||
payments: { | ||
defaultFeeMethod: feeLimitMethod, | ||
defaultFeePercentage: feePercentage, | ||
defaultFeeFixed: feeLimit | ||
} | ||
}); | ||
}; | ||
|
||
renderSeparator = () => ( | ||
<View | ||
style={{ | ||
height: 1, | ||
backgroundColor: themeColor('separator') | ||
}} | ||
/> | ||
); | ||
|
||
render() { | ||
const { navigation, SettingsStore } = this.props; | ||
const { feeLimit, feeLimitMethod, feePercentage } = this.state; | ||
const { loading }: any = SettingsStore; | ||
|
||
const BackButton = () => ( | ||
<Icon | ||
name="arrow-back" | ||
onPress={() => { | ||
this.handleSave(); | ||
navigation.navigate('Settings', { | ||
refresh: true | ||
}); | ||
}} | ||
color={themeColor('text')} | ||
underlayColor="transparent" | ||
/> | ||
); | ||
|
||
return ( | ||
<View | ||
style={{ | ||
flex: 1, | ||
backgroundColor: themeColor('background') | ||
}} | ||
> | ||
<Header | ||
leftComponent={<BackButton />} | ||
centerComponent={{ | ||
text: localeString('views.Settings.Payments.title'), | ||
style: { | ||
color: themeColor('text'), | ||
fontFamily: 'Lato-Regular' | ||
} | ||
}} | ||
backgroundColor={themeColor('background')} | ||
containerStyle={{ | ||
borderBottomWidth: 0 | ||
}} | ||
/> | ||
{loading ? ( | ||
<LoadingIndicator /> | ||
) : ( | ||
<View | ||
style={{ | ||
padding: 20 | ||
}} | ||
> | ||
<Text | ||
style={{ | ||
fontFamily: 'Lato-Regular', | ||
paddingTop: 5, | ||
color: themeColor('text') | ||
}} | ||
> | ||
{`${localeString( | ||
'views.Settings.Payments.defaultFeeLimit' | ||
)}`} | ||
</Text> | ||
<View | ||
style={{ | ||
flex: 1, | ||
flexWrap: 'wrap', | ||
flexDirection: 'row', | ||
justifyContent: 'flex-end', | ||
opacity: feeLimitMethod == 'percent' ? 1 : 0.25 | ||
}} | ||
></View> | ||
<View | ||
style={{ | ||
flexDirection: 'row', | ||
width: '95%' | ||
}} | ||
> | ||
<TextInput | ||
style={{ | ||
width: '50%', | ||
opacity: | ||
feeLimitMethod == 'fixed' ? 1 : 0.25 | ||
}} | ||
keyboardType="numeric" | ||
value={feeLimit} | ||
onChangeText={(text: string) => | ||
this.setState({ | ||
feeLimit: text | ||
}) | ||
} | ||
onPressIn={() => | ||
this.setState({ | ||
feeLimitMethod: 'fixed' | ||
}) | ||
} | ||
/> | ||
<Text | ||
style={{ | ||
fontFamily: 'Lato-Regular', | ||
paddingTop: 5, | ||
color: themeColor('text'), | ||
top: 28, | ||
right: 30, | ||
opacity: | ||
feeLimitMethod == 'fixed' ? 1 : 0.25 | ||
}} | ||
> | ||
{`${localeString('general.sats')}`} | ||
</Text> | ||
<TextInput | ||
style={{ | ||
width: '50%', | ||
opacity: | ||
feeLimitMethod == 'percent' ? 1 : 0.25 | ||
}} | ||
keyboardType="numeric" | ||
value={feePercentage} | ||
onChangeText={(text: string) => | ||
this.setState({ | ||
feePercentage: text | ||
}) | ||
} | ||
onPressIn={() => | ||
this.setState({ | ||
feeLimitMethod: 'percent' | ||
}) | ||
} | ||
/> | ||
<Text | ||
style={{ | ||
fontFamily: 'Lato-Regular', | ||
paddingTop: 5, | ||
color: themeColor('text'), | ||
top: 28, | ||
right: 18, | ||
opacity: | ||
feeLimitMethod == 'percent' ? 1 : 0.25 | ||
}} | ||
> | ||
{'%'} | ||
</Text> | ||
</View> | ||
</View> | ||
)} | ||
</View> | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For improved type-safety, maybe we should use an enum for this and update the InvoiceState and PaymentSettings interfaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with this. Spoke with Ovidio and agreed to tackle enums more broadly - throughout the app - in another issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking here: #1262