Skip to content

Commit

Permalink
POS Square integration
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Jan 14, 2023
1 parent b2f0cda commit 321e02b
Show file tree
Hide file tree
Showing 21 changed files with 1,951 additions and 446 deletions.
1 change: 1 addition & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class App extends React.PureComponent {
UTXOsStore={Stores.utxosStore}
MessageSignStore={Stores.messageSignStore}
ActivityStore={Stores.activityStore}
PosStore={Stores.posStore}
>
<AppContainer>
<Navigation />
Expand Down
10 changes: 10 additions & 0 deletions Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import Sponsors from './views/Settings/Sponsors';
import Olympians from './views/Settings/Olympians';
import Gods from './views/Settings/Gods';
import Mortals from './views/Settings/Mortals';
import PointOfSale from './views/Settings/PointOfSale';

// Routing
import Routing from './views/Routing/Routing';
Expand All @@ -63,6 +64,9 @@ import Accounts from './views/Accounts/Accounts';
import ImportAccount from './views/Accounts/ImportAccount';
import ImportAccountQRScanner from './views/Accounts/ImportAccountQRScanner';

// POS
import Order from './views/Order';

import Intro from './views/Intro';
import IntroSplash from './views/IntroSplash';

Expand Down Expand Up @@ -239,6 +243,12 @@ const AppScenes = {
},
SparkQRScanner: {
screen: SparkQRScanner
},
Order: {
screen: Order
},
PointOfSaleSettings: {
screen: PointOfSale
}
};

Expand Down
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ android {
applicationId "app.zeusln.zeus"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 55
versionCode 56
versionName "0.7.1"
multiDexEnabled true
missingDimensionStrategy 'react-native-camera', 'general'
Expand Down
1 change: 1 addition & 0 deletions assets/images/SVG/POS.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 35 additions & 17 deletions components/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface TextInputProps {
suffix?: string;
toggleUnits?: any;
onPressIn?: any;
right?: number;
}

export default function TextInput(props: TextInputProps) {
Expand All @@ -46,7 +47,8 @@ export default function TextInput(props: TextInputProps) {
prefix,
suffix,
toggleUnits,
onPressIn
onPressIn,
right
} = props;

const defaultStyle = numberOfLines
Expand All @@ -67,15 +69,23 @@ export default function TextInput(props: TextInputProps) {
}}
>
{prefix && (
<TouchableOpacity onPress={() => toggleUnits()}>
<TouchableOpacity onPress={() => toggleUnits && toggleUnits()}>
<Text
style={{
...styles.unit,
marginRight: 5,
color: themeColor('text'),
backgroundColor: themeColor('background')
}}
onPress={() => toggleUnits()}
style={
toggleUnits
? {
...styles.unit,
marginRight: 5,
color: themeColor('text'),
backgroundColor: themeColor('background')
}
: {
...styles.unit,
marginRight: 5,
color: themeColor('text')
}
}
onPress={() => toggleUnits && toggleUnits()}
>
{prefix}
</Text>
Expand All @@ -100,15 +110,23 @@ export default function TextInput(props: TextInputProps) {
onPressIn={onPressIn}
/>
{suffix && (
<TouchableOpacity onPress={() => toggleUnits()}>
<TouchableOpacity onPress={() => toggleUnits && toggleUnits()}>
<Text
style={{
...styles.unit,
right: 45,
color: themeColor('text'),
backgroundColor: themeColor('background')
}}
onPress={() => toggleUnits()}
style={
toggleUnits
? {
...styles.unit,
right: right || 45,
color: themeColor('text'),
backgroundColor: themeColor('background')
}
: {
...styles.unit,
right: right || 45,
color: themeColor('text')
}
}
onPress={() => toggleUnits && toggleUnits()}
>
{suffix}
</Text>
Expand Down
76 changes: 71 additions & 5 deletions components/WalletHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Clipboard from '@react-native-clipboard/clipboard';

import SettingsStore from '../stores/SettingsStore';
import NodeInfoStore from '../stores/NodeInfoStore';
import PosStore from '../stores/PosStore';

import LoadingIndicator from '../components/LoadingIndicator';
import NodeIdenticon from '../components/NodeIdenticon';
Expand All @@ -16,6 +17,7 @@ import { themeColor } from '../utils/ThemeUtils';

import ClipboardSVG from '../assets/images/SVG/Clipboard.svg';
import Scan from '../assets/images/SVG/Scan.svg';
import POS from '../assets/images/SVG/POS.svg';

import stores from '../stores/Stores';

Expand All @@ -41,6 +43,32 @@ const OpenChannelButton = ({ navigation }: { navigation: any }) => (
/>
);

const AdminButton = ({ navigation }: { navigation: any }) => (
<Button
title=""
icon={{
name: 'settings',
size: 20,
color: themeColor('text')
}}
buttonStyle={{
backgroundColor: 'transparent',
marginRight: -10,
marginTop: -5
}}
onPress={() => {
const { settings } = stores.settingsStore;
const loginRequired =
settings && (settings.passphrase || settings.pin);
loginRequired
? navigation.navigate('Lockscreen', {
attemptAdminLogin: true
})
: navigation.navigate('Settings');
}}
/>
);

const ScanBadge = ({ navigation }: { navigation: any }) => (
<TouchableOpacity
onPress={() => navigation.navigate('HandleAnythingQRScanner')}
Expand All @@ -63,9 +91,28 @@ const ClipboardBadge = ({
</TouchableOpacity>
);

const POSBadge = ({
setPosStatus,
getOrders
}: {
setPosStatus: (status: string) => void;
getOrders: () => void;
}) => (
<TouchableOpacity
onPress={async () => {
getOrders();
await setPosStatus('active');
}}
style={{ top: -3 }}
>
<POS stroke={themeColor('text')} width="34" height="34" />
</TouchableOpacity>
);

interface WalletHeaderProps {
SettingsStore: SettingsStore;
NodeInfoStore: NodeInfoStore;
PosStore: PosStore;
navigation: any;
loading: boolean;
title: string;
Expand All @@ -76,7 +123,7 @@ interface WalletHeaderState {
clipboard: string;
}

@inject('SettingsStore', 'NodeInfoStore')
@inject('SettingsStore', 'NodeInfoStore', 'PosStore')
@observer
export default class WalletHeader extends React.Component<
WalletHeaderProps,
Expand Down Expand Up @@ -109,9 +156,11 @@ export default class WalletHeader extends React.Component<
title,
channels,
SettingsStore,
NodeInfoStore
NodeInfoStore,
PosStore
} = this.props;
const { settings } = SettingsStore;
const { settings, posStatus, setPosStatus } = SettingsStore;
const { getOrders } = PosStore;
const multipleNodes: boolean =
(settings && settings.nodes && settings.nodes.length > 1) || false;
const selectedNode: any =
Expand All @@ -120,6 +169,9 @@ export default class WalletHeader extends React.Component<
settings.nodes[settings.selectedNode || 0]) ||
null;

const squareEnabled: boolean =
(settings && settings.pos && settings.pos.squareEnabled) || false;

const SettingsButton = () => (
<TouchableOpacity onPress={() => navigation.navigate('Settings')}>
{multipleNodes ? (
Expand Down Expand Up @@ -160,7 +212,11 @@ export default class WalletHeader extends React.Component<

return (
<Header
leftComponent={loading ? undefined : <SettingsButton />}
leftComponent={
loading || posStatus == 'active' ? undefined : (
<SettingsButton />
)
}
centerComponent={
title ? (
<View style={{ top: 5 }}>
Expand All @@ -178,7 +234,9 @@ export default class WalletHeader extends React.Component<
)
}
rightComponent={
channels ? (
posStatus === 'active' ? (
<AdminButton navigation={navigation} />
) : channels ? (
<OpenChannelButton navigation={navigation} />
) : (
<View style={{ flex: 1, flexDirection: 'row' }}>
Expand All @@ -187,6 +245,14 @@ export default class WalletHeader extends React.Component<
.loadingLightningBalance) && (
<LoadingIndicator size={80} />
)}
{squareEnabled && (
<View style={{ marginRight: 20 }}>
<POSBadge
setPosStatus={setPosStatus}
getOrders={getOrders}
/>
</View>
)}
{!!clipboard && (
<View style={{ marginRight: 20 }}>
<ClipboardBadge
Expand Down
22 changes: 21 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
"general.unified": "Unified",
"general.percentage": "percentage",
"general.paste": "Paste from clipboard",
"general.order": "Order",
"general.orders": "Orders",
"general.pos": "Point of Sale",
"general.admin": "Admin",
"general.pay": "Pay",
"general.fiatFetchError": "Error fetching exchange rates",
"components.CollapsedQr.show": "Show QR",
"components.CollapsedQr.hide": "Hide QR",
"components.CollapsedQr.startNfc": "Start NFC broadcast",
Expand Down Expand Up @@ -183,6 +189,7 @@
"views.Wallet.Wallet.startingUp": "Zeus is starting up.",
"views.Wallet.Wallet.connecting": "Zeus is connecting to your node.",
"views.Wallet.restart": "Restart",
"view.Wallet.PosPane.orderNumber": "Order number",
"views.BTCPayConfigQRScanner.text": "Scan a BTCPay Config under Settings > Services > LND Rest",
"views.BTCPayConfigQRScanner.error": "Error fetching BTCPay config",
"views.Channel.baseFee": "Base Fee",
Expand Down Expand Up @@ -455,6 +462,9 @@
"views.Settings.Help.github": "GitHub Issues",
"views.Settings.Help.telegram": "Telegram Group",
"views.Settings.Help.twitter": "Twitter (DMs open)",
"views.Settings.POS.enableSquare": "Enable Square POS integration",
"views.Settings.POS.accessToken": "Square Access token",
"views.Settings.POS.locationId": "Square Location ID",
"views.Transaction.title": "Transaction",
"views.Transaction.totalFees": "Total Fees",
"views.Transaction.transactionHash": "Transaction Hash",
Expand Down Expand Up @@ -510,5 +520,15 @@
"stores.SettingsStore.lndhubError": "Error creating LNDHub account. Please check the host and try again.",
"error.connectionRefused": "Host unreachable. Try restarting your node or its Tor process.",
"error.hostUnreachable": "Host unreachable. Try restarting your node or its Tor process.",
"error.torBootstrap": "Error starting up Tor on your phone. Try restarting Zeus. If the problem persists consider reinstalling the app."
"error.torBootstrap": "Error starting up Tor on your phone. Try restarting Zeus. If the problem persists consider reinstalling the app.",
"pos.views.Wallet.PosPane.noOrders": "No orders open at the moment",
"pos.views.Wallet.PosPane.fetchingRates": "Fetching exchange rates",
"pos.views.Order.tax": "Tax",
"pos.views.Order.totalBeforeTip": "Total before tip",
"pos.views.Order.addTip": "Add Tip",
"pos.views.Order.tip": "Tip",
"pos.views.Order.totalFiat": "Total (Fiat)",
"pos.views.Order.totalBitcoin": "Total (Bitcoin)",
"pos.views.Settings.PointOfSale.authWarning": "Warning: no password or PIN set",
"pos.views.Settings.PointOfSale.currencyError": "Error: currency must be set first"
}
Loading

0 comments on commit 321e02b

Please sign in to comment.