Skip to content

Commit

Permalink
POS: add confirmation preference
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Jan 15, 2023
1 parent 3a96c9a commit eab74cc
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 33 deletions.
10 changes: 9 additions & 1 deletion stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface PosSettings {
squareEnabled?: boolean;
squareAccessToken?: string;
squareLocationId?: string;
confirmationPreference?: string;
}

interface Settings {
Expand Down Expand Up @@ -176,6 +177,12 @@ export const DEFAULT_THEME = 'dark';
export const DEFAULT_FIAT = 'Disabled';
export const DEFAULT_LOCALE = 'English';

export const POS_CONF_PREF_KEYS = [
{ key: '0 conf', value: '0conf' },
{ key: '1 conf', value: '1conf' },
{ key: 'LN only', value: 'lnOnly' }
];

const STORAGE_KEY = 'zeus-settings';

export default class SettingsStore {
Expand All @@ -195,7 +202,8 @@ export default class SettingsStore {
pos: {
squareEnabled: false,
squareAccessToken: '',
squareLocationId: ''
squareLocationId: '',
confirmationPreference: 'lnOnly'
},
scramblePin: true,
loginBackground: false,
Expand Down
2 changes: 2 additions & 0 deletions views/Channels/ChannelsPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { localeString } from '../../utils/LocaleUtils';
import { Spacer } from '../../components/layout/Spacer';

import ChannelsStore from '../../stores/ChannelsStore';
import SettingsStore from '../../stores/SettingsStore';

// TODO: does this belong in the model? Or can it be computed from the model?
export enum Status {
Expand All @@ -24,6 +25,7 @@ export enum Status {
interface ChannelsProps {
navigation: any;
ChannelsStore: ChannelsStore;
SettingsStore: SettingsStore;
}

@inject('ChannelsStore', 'SettingsStore')
Expand Down
70 changes: 46 additions & 24 deletions views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ export default class Receive extends React.Component<
};

componentDidMount() {
const { navigation, InvoicesStore } = this.props;
const { navigation, InvoicesStore, SettingsStore } = this.props;
const { reset } = InvoicesStore;
const { settings } = SettingsStore;
const lnOnly =
settings &&
settings.pos &&
settings.pos.confirmationPreference &&
settings.pos.confirmationPreference === 'lnOnly';

reset();
const lnurl: LNURLWithdrawParams | undefined =
Expand Down Expand Up @@ -124,6 +130,12 @@ export default class Receive extends React.Component<
});
}

if (lnOnly) {
this.setState({
selectedIndex: 1
});
}

if (autoGenerate)
this.autoGenerateInvoice(this.getSatAmount(amount), memo);
}
Expand Down Expand Up @@ -278,10 +290,16 @@ export default class Receive extends React.Component<
clearUnified,
reset
} = InvoicesStore;
const { implementation, posStatus } = SettingsStore;
const { implementation, posStatus, settings } = SettingsStore;
const loading = SettingsStore.loading || InvoicesStore.loading;
const address = onChainAddress;

const lnOnly =
settings &&
settings.pos &&
settings.pos.confirmationPreference &&
settings.pos.confirmationPreference === 'lnOnly';

const satAmount = this.getSatAmount();

const lnurl: LNURLWithdrawParams | undefined =
Expand Down Expand Up @@ -623,28 +641,32 @@ export default class Receive extends React.Component<
textBottom
/>
)}
{!belowDustLimit && haveUnifiedInvoice && (
<ButtonGroup
onPress={this.updateIndex}
selectedIndex={selectedIndex}
buttons={buttons}
selectedButtonStyle={{
backgroundColor:
themeColor('highlight'),
borderRadius: 12
}}
containerStyle={{
backgroundColor:
themeColor('secondary'),
borderRadius: 12,
borderColor:
themeColor('secondary')
}}
innerBorderStyle={{
color: themeColor('secondary')
}}
/>
)}
{!belowDustLimit &&
haveUnifiedInvoice &&
!lnOnly && (
<ButtonGroup
onPress={this.updateIndex}
selectedIndex={selectedIndex}
buttons={buttons}
selectedButtonStyle={{
backgroundColor:
themeColor('highlight'),
borderRadius: 12
}}
containerStyle={{
backgroundColor:
themeColor('secondary'),
borderRadius: 12,
borderColor:
themeColor('secondary')
}}
innerBorderStyle={{
color: themeColor(
'secondary'
)
}}
/>
)}
</View>
)}
{!loading && !haveInvoice && (
Expand Down
52 changes: 44 additions & 8 deletions views/Settings/PointOfSale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import { inject, observer } from 'mobx-react';
import { localeString } from './../../utils/LocaleUtils';
import { themeColor } from './../../utils/ThemeUtils';

import DropdownSetting from './../../components/DropdownSetting';
import {
ErrorMessage,
WarningMessage
} from './../../components/SuccessErrorMessage';
import Switch from './../../components/Switch';
import TextInput from './../../components/TextInput';

import SettingsStore, { DEFAULT_FIAT } from './../../stores/SettingsStore';
import SettingsStore, {
DEFAULT_FIAT,
POS_CONF_PREF_KEYS
} from './../../stores/SettingsStore';

interface PointOfSaleProps {
navigation: any;
Expand All @@ -23,6 +27,7 @@ interface PointOfSaleState {
squareEnabled: boolean;
squareAccessToken: string;
squareLocationId: string;
confirmationPreference: string;
}

@inject('SettingsStore')
Expand All @@ -34,7 +39,8 @@ export default class PointOfSale extends React.Component<
state = {
squareEnabled: false,
squareAccessToken: '',
squareLocationId: ''
squareLocationId: '',
confirmationPreference: 'lnOnly'
};

async UNSAFE_componentWillMount() {
Expand All @@ -48,7 +54,9 @@ export default class PointOfSale extends React.Component<
squareAccessToken:
(settings.pos && settings.pos.squareAccessToken) || '',
squareLocationId:
(settings.pos && settings.pos.squareLocationId) || ''
(settings.pos && settings.pos.squareLocationId) || '',
confirmationPreference:
(settings.pos && settings.pos.confirmationPreference) || 'lnOnly'
});
}

Expand All @@ -63,8 +71,12 @@ export default class PointOfSale extends React.Component<

render() {
const { navigation, SettingsStore } = this.props;
const { squareEnabled, squareAccessToken, squareLocationId } =
this.state;
const {
squareEnabled,
squareAccessToken,
squareLocationId,
confirmationPreference
} = this.state;
const { updateSettings, settings }: any = SettingsStore;
const { passphrase, pin, fiat } = settings;

Expand Down Expand Up @@ -153,7 +165,8 @@ export default class PointOfSale extends React.Component<
pos: {
squareAccessToken,
squareLocationId,
squareEnabled: !squareEnabled
squareEnabled: !squareEnabled,
confirmationPreference
}
});
}}
Expand Down Expand Up @@ -184,7 +197,8 @@ export default class PointOfSale extends React.Component<
pos: {
squareEnabled,
squareAccessToken: text,
squareLocationId
squareLocationId,
confirmationPreference
}
});
}}
Expand All @@ -211,10 +225,32 @@ export default class PointOfSale extends React.Component<
pos: {
squareEnabled,
squareAccessToken,
squareLocationId: text
squareLocationId: text,
confirmationPreference
}
});
}}
/>

<DropdownSetting
title={localeString(
'views.Settings.Display.defaultView'
)}
selectedValue={confirmationPreference}
onValueChange={async (value: string) => {
this.setState({
confirmationPreference: value
});
await updateSettings({
pos: {
squareEnabled,
squareAccessToken,
squareLocationId,
confirmationPreference: value
}
});
}}
values={POS_CONF_PREF_KEYS}
/>
</>
)}
Expand Down

0 comments on commit eab74cc

Please sign in to comment.