Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Commit

Permalink
Redirect navigation flow for 0 value invocies.
Browse files Browse the repository at this point in the history
Detecting a zero amount invoice in checkType we redirect to a seperate view.
Currently only title is changed in the view.
  • Loading branch information
emiljoha committed Jan 12, 2020
1 parent 35e7871 commit 09d5baa
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 1 deletion.
10 changes: 10 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2017",
"allowSyntheticDefaultImports": true,
"noEmit": true,
"checkJs": true,
"jsx": "react",
"lib": [ "dom", "es2017" ]
}
}
4 changes: 4 additions & 0 deletions src/action/nav-mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ class NavAction {
this._navigate('Pay');
}

goPayLightningSupplyAmount() {
this._navigate('PayLightningSupplyAmount');
}

goPayLightningConfirm() {
this._navigate('PayLightningConfirm');
}
Expand Down
4 changes: 4 additions & 0 deletions src/action/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class NavAction {
this._store.route = 'Pay';
}

goPayLightningSupplyAmount() {
this._store.route = 'PayLightningSupplyAmount';
}

goPayLightningConfirm() {
this._store.route = 'PayLightningConfirm';
}
Expand Down
9 changes: 8 additions & 1 deletion src/action/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ class PaymentAction {
return this._notification.display({ msg: 'Enter an invoice or address' });
}
if (await this.decodeInvoice({ invoice: this._store.payment.address })) {
this._nav.goPayLightningConfirm();
if (
this._store.payment.amount === '0' ||
this._store.payment.amount === 0
) {
this._nav.goPayLightningSupplyAmount();
} else {
this._nav.goPayLightningConfirm();
}
} else if (isAddress(this._store.payment.address)) {
this._nav.goPayBitcoin();
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/view/main-mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import SettingUnitView from './setting-unit';
import SettingFiatView from './setting-fiat';
import CLIView from './cli';
import PaymentView from './payment-mobile';
import PayLightningSupplyAmountView from './pay-lightning-supply-amount-mobile';
import PayLightningConfirmView from './pay-lightning-confirm-mobile';
import PayLightningDoneView from './pay-lightning-done-mobile';
import PaymentFailedView from './payment-failed-mobile';
Expand Down Expand Up @@ -171,6 +172,10 @@ const InvoiceQR = () => (

const Pay = () => <PaymentView store={store} payment={payment} nav={nav} />;

const PayLightningSupplyAmount = () => (
<PayLightningSupplyAmountView store={store} payment={payment} nav={nav} />
);

const PayLightningConfirm = () => (
<PayLightningConfirmView store={store} payment={payment} nav={nav} />
);
Expand Down Expand Up @@ -236,6 +241,7 @@ const InvoiceStack = createStackNavigator(
const PayStack = createStackNavigator(
{
Pay,
PayLightningSupplyAmount,
PayLightningConfirm,
Wait,
PayLightningDone,
Expand Down
4 changes: 4 additions & 0 deletions src/view/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import LoaderSyncing from './loader-syncing';
import Wait from './wait';
import Home from './home';
import Payment from './payment';
import PayLightningSupplyAmount from './pay-lightning-supply-amount';
import PayLightningConfirm from './pay-lightning-confirm';
import PayLightningDone from './pay-lightning-done';
import PaymentFailed from './payment-failed';
Expand Down Expand Up @@ -130,6 +131,9 @@ class MainView extends Component {
{route === 'Pay' && (
<Payment store={store} payment={payment} nav={nav} />
)}
{route === 'PayLightningSupplyAmount' && (
<PayLightningSupplyAmount store={store} payment={payment} nav={nav} />
)}
{route === 'PayLightningConfirm' && (
<PayLightningConfirm store={store} payment={payment} nav={nav} />
)}
Expand Down
88 changes: 88 additions & 0 deletions src/view/pay-lightning-supply-amount-mobile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from 'react';
import { StyleSheet } from 'react-native';
import { observer } from 'mobx-react';
import PropTypes from 'prop-types';
import Background from '../component/background';
import MainContent from '../component/main-content';
import { NamedField } from '../component/field';
import { Header, Title } from '../component/header';
import { CancelButton, BackButton, SmallGlasButton } from '../component/button';
import Card from '../component/card';
import LightningBoltIcon from '../asset/icon/lightning-bolt';
import { FormStretcher } from '../component/form';
import {
BalanceLabel,
BalanceLabelNumeral,
BalanceLabelUnit,
} from '../component/label';
import { color } from '../component/style';

const styles = StyleSheet.create({
balance: {
marginBottom: 10,
},
numeral: {
color: color.blackText,
},
unit: {
color: color.blackText,
},
totalLbl: {
marginTop: 5,
},
note: {
marginTop: 5,
borderBottomWidth: 0,
},
confirmBtn: {
marginTop: 20,
},
});

const PayLightningSupplyAmountView = ({ store, nav, payment }) => (
<Background color={color.purple}>
<Header color={color.purple}>
<BackButton onPress={() => nav.goPay()} />
<Title title="Supply Lightning Payment Amount">
<LightningBoltIcon height={12} width={6.1} />
</Title>
<CancelButton onPress={() => nav.goHome()} />
</Header>
<MainContent>
<Card>
<FormStretcher>
<BalanceLabel style={styles.balance}>
<BalanceLabelNumeral style={styles.numeral}>
{store.paymentAmountLabel}
</BalanceLabelNumeral>
<BalanceLabelUnit style={styles.unit}>
{store.unitLabel}
</BalanceLabelUnit>
</BalanceLabel>
<NamedField name="Fee">
{store.paymentFeeLabel} {store.unitLabel}
</NamedField>
<NamedField name="Total" style={styles.totalLbl}>
{store.paymentTotalLabel} {store.unitLabel}
</NamedField>
{store.payment.note ? (
<NamedField name="Note" style={styles.note}>
{store.payment.note}
</NamedField>
) : null}
</FormStretcher>
</Card>
</MainContent>
<SmallGlasButton onPress={() => payment.payLightning()}>
Confirm
</SmallGlasButton>
</Background>
);

PayLightningSupplyAmountView.propTypes = {
store: PropTypes.object.isRequired,
nav: PropTypes.object.isRequired,
payment: PropTypes.object.isRequired,
};

export default observer(PayLightningSupplyAmountView);
91 changes: 91 additions & 0 deletions src/view/pay-lightning-supply-amount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from 'react';
import { StyleSheet } from 'react-native';
import { observer } from 'mobx-react';
import PropTypes from 'prop-types';
import Background from '../component/background';
import MainContent from '../component/main-content';
import { NamedField } from '../component/field';
import { Header, Title } from '../component/header';
import { CancelButton, BackButton, PillButton } from '../component/button';
import Card from '../component/card';
import LightningBoltIcon from '../asset/icon/lightning-bolt';
import { FormStretcher } from '../component/form';
import {
BalanceLabel,
BalanceLabelNumeral,
BalanceLabelUnit,
} from '../component/label';
import { color } from '../component/style';

const styles = StyleSheet.create({
balance: {
marginBottom: 10,
},
numeral: {
color: color.blackText,
},
unit: {
color: color.blackText,
},
totalLbl: {
marginTop: 5,
},
note: {
marginTop: 5,
borderBottomWidth: 0,
},
confirmBtn: {
marginTop: 20,
},
});

const PayLightningSupplyAmountView = ({ store, nav, payment }) => (
<Background image="purple-gradient-bg">
<Header shadow color={color.purple}>
<BackButton onPress={() => nav.goPay()} />
<Title title="Supply Lightning Amount">
<LightningBoltIcon height={12} width={6.1} />
</Title>
<CancelButton onPress={() => nav.goHome()} />
</Header>
<MainContent>
<Card>
<FormStretcher>
<BalanceLabel style={styles.balance}>
<BalanceLabelNumeral style={styles.numeral}>
{store.paymentAmountLabel}
</BalanceLabelNumeral>
<BalanceLabelUnit style={styles.unit}>
{store.unitLabel}
</BalanceLabelUnit>
</BalanceLabel>
<NamedField name="Fee">
{store.paymentFeeLabel} {store.unitLabel}
</NamedField>
<NamedField name="Total" style={styles.totalLbl}>
{store.paymentTotalLabel} {store.unitLabel}
</NamedField>
{store.payment.note ? (
<NamedField name="Note" style={styles.note}>
{store.payment.note}
</NamedField>
) : null}
</FormStretcher>
<PillButton
style={styles.confirmBtn}
onPress={() => payment.payLightning()}
>
Confirm
</PillButton>
</Card>
</MainContent>
</Background>
);

PayLightningSupplyAmountView.propTypes = {
store: PropTypes.object.isRequired,
nav: PropTypes.object.isRequired,
payment: PropTypes.object.isRequired,
};

export default observer(PayLightningSupplyAmountView);

0 comments on commit 09d5baa

Please sign in to comment.