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

WIP: Add ability to donate some amount for ZEUS #2815

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@
"views.PaymentRequest.isRelaysSigValid": "Relays signature",
"views.PaymentRequest.notAllowedToSend": "This wallet is not allowed to send funds!",
"views.PaymentRequest.slideToPay": "Slide to Pay",
"views.PaymentRequest.supportZeus": "Support ZEUS 💜",
"views.PaymentRequest.enableDonations": "Enable donations",
"views.Receive.title": "Receive",
"views.Receive.successCreate": "Successfully created invoice",
"views.Receive.warningLndHub": "Please note that LNDHub has a fixed on-chain address",
Expand Down
4 changes: 3 additions & 1 deletion stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface PrivacySettings {
clipboard?: boolean;
lurkerMode?: boolean;
enableMempoolRates?: boolean;
enableDonations?: boolean;
}

interface DisplaySettings {
Expand Down Expand Up @@ -1112,7 +1113,8 @@ export default class SettingsStore {
customBlockExplorer: '',
clipboard: false,
lurkerMode: false,
enableMempoolRates: true
enableMempoolRates: true,
enableDonations: false
},
display: {
theme: DEFAULT_THEME,
Expand Down
111 changes: 108 additions & 3 deletions views/PaymentRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
TouchableOpacity
} from 'react-native';
import { inject, observer } from 'mobx-react';
import Slider from '@react-native-community/slider';

import { StackNavigationProp } from '@react-navigation/stack';

import Amount from '../components/Amount';
Expand Down Expand Up @@ -84,6 +86,9 @@ interface InvoiceState {
zaplockerToggle: boolean;
lightningReadyToSend: boolean;
slideToPayThreshold: number;
enableDonation: boolean;
donationPercentage: any;
donationAmount: any;
}

@inject(
Expand Down Expand Up @@ -119,7 +124,10 @@ export default class PaymentRequest extends React.Component<
settingsToggle: false,
zaplockerToggle: false,
lightningReadyToSend: false,
slideToPayThreshold: 10000
slideToPayThreshold: 10000,
enableDonation: false,
donationPercentage: 0,
donationAmount: 0
};

async UNSAFE_componentWillMount() {
Expand Down Expand Up @@ -352,7 +360,9 @@ export default class PaymentRequest extends React.Component<
settingsToggle,
timeoutSeconds,
lightningReadyToSend,
slideToPayThreshold
slideToPayThreshold,
donationAmount,
donationPercentage
} = this.state;
const {
pay_req,
Expand Down Expand Up @@ -404,7 +414,9 @@ export default class PaymentRequest extends React.Component<

const date = new Date(Number(timestamp) * 1000).toString();

const { enableTor, implementation } = SettingsStore;
const { enableTor, implementation, settings } = SettingsStore;

const enableDonations = settings?.privacy?.enableDonations;

const isLnd: boolean = BackendUtils.isLNDBased();
const isCLightning: boolean =
Expand Down Expand Up @@ -1075,6 +1087,99 @@ export default class PaymentRequest extends React.Component<
/>
</>
)}

{enableDonations && (
<>
<Row justify="center">
<Text
style={{
...styles.label,
color: themeColor(
'text'
)
}}
>
{localeString(
'views.PaymentRequest.supportZeus'
)}
</Text>
</Row>
<Slider
style={{
width: '100%',
height: 40
}}
minimumValue={0}
maximumValue={100}
step={1}
value={donationPercentage}
onValueChange={(
value: any
) =>
this.setState({
donationPercentage:
value,
donationAmount:
Math.round(
((requestAmount ||
0) *
value) /
100
)
})
}
minimumTrackTintColor={themeColor(
'highlight'
)}
maximumTrackTintColor={themeColor(
'secondaryText'
)}
/>
<Row justify="flex-end">
<Text
style={{
color: themeColor(
'secondaryText'
)
}}
>
{`${donationPercentage}% `}
</Text>
</Row>
<Row justify="flex-end">
<Text
style={{
color: themeColor(
'highlight'
)
}}
>
{donationAmount +
` ${localeString(
'general.sats'
)}`}
</Text>
</Row>
<Row justify="center">
<Text
style={{
...styles.labelSecondary,
color: themeColor(
'text'
)
}}
>
{`${
requestAmount || 0
} + ` +
donationAmount +
` ${localeString(
'general.sats'
)} `}
</Text>
</Row>
</>
)}
</>
)}
</View>
Expand Down
44 changes: 41 additions & 3 deletions views/Settings/PaymentsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface PaymentsSettingsState {
preferredMempoolRate: string;
slideToPayThreshold: string;
mounted?: boolean;
enableDonations: boolean;
}

@inject('SettingsStore')
Expand All @@ -47,7 +48,8 @@ export default class PaymentsSettings extends React.Component<
enableMempoolRates: false,
preferredMempoolRate: 'fastestFee',
slideToPayThreshold: '10000',
mounted: false
mounted: false,
enableDonations: false
};

async UNSAFE_componentWillMount() {
Expand All @@ -65,7 +67,8 @@ export default class PaymentsSettings extends React.Component<
settings?.payments?.preferredMempoolRate || 'fastestFee',
slideToPayThreshold:
settings?.payments?.slideToPayThreshold?.toString() || '10000',
mounted: true
mounted: true,
enableDonations: settings?.privacy?.enableDonations || false
});
}

Expand All @@ -86,7 +89,8 @@ export default class PaymentsSettings extends React.Component<
enableMempoolRates,
timeoutSeconds,
preferredMempoolRate,
slideToPayThreshold
slideToPayThreshold,
enableDonations
} = this.state;
const { SettingsStore } = this.props;
const { updateSettings, settings, implementation } = SettingsStore;
Expand Down Expand Up @@ -336,6 +340,40 @@ export default class PaymentsSettings extends React.Component<
/>
</>
)}
<View
style={{
flexDirection: 'row',
marginTop: 10
}}
>
<Text
style={{
fontFamily: 'PPNeueMontreal-Book',
color: themeColor('secondaryText'),
flex: 1
}}
>
{localeString(
'views.PaymentRequest.enableDonations'
)}
</Text>
<View>
<Switch
value={enableDonations}
onValueChange={async () => {
this.setState({
enableDonations: !enableDonations
});
await updateSettings({
privacy: {
...settings.privacy,
enableDonations: !enableDonations
}
});
}}
/>
</View>
</View>
<View
style={{
flexDirection: 'row',
Expand Down