Skip to content

Commit

Permalink
feat: LNRUL-pay comment
Browse files Browse the repository at this point in the history
  • Loading branch information
limpbrains committed Jul 23, 2024
1 parent 8ac93e6 commit 196dcae
Show file tree
Hide file tree
Showing 26 changed files with 477 additions and 334 deletions.
8 changes: 6 additions & 2 deletions e2e/lnurl.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ d('LNURL', () => {
it('Can process lnurl channel, withdraw, pay and login requests', async () => {
// Test plan:
// - connect to LND node`with lnurl-channel
// - test lnurl-channel
// - test lnurl-pay
// - test lnrul-withdraw
// - test lnurl-auth
Expand Down Expand Up @@ -173,25 +174,27 @@ d('LNURL', () => {
.withTimeout(30000);
await element(by.id('LNURLChannelSuccess-button')).tap();

// test lnurl-pay, with min !== max amount
// test lnurl-pay, with min !== max amount and comment
const payRequest1 = await lnurl.generateNewUrl('payRequest', {
minSendable: 100000, // msats
maxSendable: 200000, // msats
metadata: '[["text/plain", "lnurl-node1"]]',
commentAllowed: 12,
});
await element(by.id('Scan')).tap();
await element(by.id('ScanPrompt')).tap();
await element(by.id('QRInput')).replaceText(payRequest1.encoded);
await element(by.id('DialogConfirm')).tap();

await element(by.id('ContinueAmount')).tap();
await element(by.id('CommentInput')).typeText('test comment');
await element(by.id('GRAB')).swipe('right', 'slow', 0.95, 0.5, 0.5); // Swipe to confirm
await waitFor(element(by.id('SendSuccess')))
.toBeVisible()
.withTimeout(10000);
await element(by.id('Close')).tap();

// test lnurl-pay, with min == max amount
// test lnurl-pay, with min == max amount, no comment
const payRequest2 = await lnurl.generateNewUrl('payRequest', {
minSendable: 222000, // msats
maxSendable: 222000, // msats
Expand All @@ -201,6 +204,7 @@ d('LNURL', () => {
await element(by.id('ScanPrompt')).tap();
await element(by.id('QRInput')).replaceText(payRequest2.encoded);
await element(by.id('DialogConfirm')).tap();
await waitFor(element(by.id('CommentInput'))).not.toBeVisible();
await element(by.id('GRAB')).swipe('right', 'slow', 0.95, 0.5, 0.5); // Swipe to confirm
await waitFor(element(by.id('SendSuccess')))
.toBeVisible()
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@synonymdev/feeds": "2.1.1",
"@synonymdev/ledger": "0.0.5",
"@synonymdev/react-native-ldk": "0.0.147",
"@synonymdev/react-native-lnurl": "0.0.9",
"@synonymdev/react-native-lnurl": "0.0.10",
"@synonymdev/result": "0.0.2",
"@synonymdev/slashtags-keychain": "1.0.0",
"@synonymdev/slashtags-profile": "1.0.2",
Expand Down Expand Up @@ -165,7 +165,7 @@
"eslint-plugin-ft-flow": "^3.0.7",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lnurl": "limpbrains/lnurl-node#private",
"lnurl": "0.26.2",
"nano-staged": "^0.8.0",
"node-fetch": "^2.6.7",
"prettier": "^2.8.8",
Expand Down
2 changes: 0 additions & 2 deletions src/navigation/bottom-sheet/BottomSheets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import BackupNavigation from './BackupNavigation';
import BoostPrompt from '../../screens/Wallets/BoostPrompt';
import ConnectionClosed from './ConnectionClosed';
import ForceTransfer from './ForceTransfer';
import LNURLPayNavigation from './LNURLPayNavigation';
import LNURLWithdrawNavigation from './LNURLWithdrawNavigation';
import NewTxPrompt from '../../screens/Wallets/NewTxPrompt';
import OrangeTicket from '../../screens/OrangeTicket';
Expand All @@ -25,7 +24,6 @@ const BottomSheets = (): JSX.Element => {
{views.boostPrompt.isMounted && <BoostPrompt />}
{views.connectionClosed.isMounted && <ConnectionClosed />}
{views.forceTransfer.isMounted && <ForceTransfer />}
{views.lnurlPay.isMounted && <LNURLPayNavigation />}
{views.lnurlWithdraw.isMounted && <LNURLWithdrawNavigation />}
{views.newTxPrompt.isMounted && <NewTxPrompt />}
{views.orangeTicket.isMounted && <OrangeTicket />}
Expand Down
69 changes: 0 additions & 69 deletions src/navigation/bottom-sheet/LNURLPayNavigation.tsx

This file was deleted.

19 changes: 17 additions & 2 deletions src/navigation/bottom-sheet/SendNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { ReactElement, memo } from 'react';
import { useAppSelector } from '../../hooks/redux';
import { createNavigationContainerRef } from '@react-navigation/native';
import {
createNativeStackNavigator,
NativeStackNavigationOptions,
NativeStackNavigationProp,
} from '@react-navigation/native-stack';
import { LNURLPayParams } from 'js-lnurl';

import BottomSheetWrapper from '../../components/BottomSheetWrapper';
import Recipient from '../../screens/Wallets/Send/Recipient';
Expand All @@ -23,6 +23,8 @@ import Contacts from '../../screens/Wallets/Send/Contacts';
import Address from '../../screens/Wallets/Send/Address';
import Scanner from '../../screens/Wallets/Send/Scanner';
import CoinSelection from '../../screens/Wallets/Send/CoinSelection';
import LNURLAmount from '../../screens/Wallets/LNURLPay/Amount';
import LNURLConfirm from '../../screens/Wallets/LNURLPay/Confirm';
import { NavigationContainer } from '../../styles/components';
import { TProcessedData } from '../../utils/scanner';
import { useSnapPoints } from '../../hooks/bottomSheet';
Expand All @@ -35,6 +37,7 @@ import { __E2E__ } from '../../constants/env';
import { EActivityType } from '../../store/types/activity';
import { updateOnchainFeeEstimates } from '../../store/utils/fees';
import { useLightningBalance } from '../../hooks/lightning';
import { useAppSelector } from '../../hooks/redux';
import {
selectedNetworkSelector,
selectedWalletSelector,
Expand All @@ -60,6 +63,8 @@ export type SendStackParamList = {
Pending: { txId: string };
Success: { type: EActivityType; amount: number; txId: string };
Error: { errorMessage: string };
LNURLAmount: { pParams: LNURLPayParams; url: string };
LNURLConfirm: { amount: number; pParams: LNURLPayParams; url: string };
};

const Stack = createNativeStackNavigator<SendStackParamList>();
Expand Down Expand Up @@ -104,7 +109,7 @@ const SendNavigation = (): ReactElement => {
const lightningBalance = useLightningBalance(false);
const selectedWallet = useAppSelector(selectedWalletSelector);
const selectedNetwork = useAppSelector(selectedNetworkSelector);
const { isOpen, screen } = useAppSelector((state) => {
const { isOpen, screen, pParams, amount, url } = useAppSelector((state) => {
return viewControllerSelector(state, 'sendNavigation');
});
const transaction = useAppSelector(transactionSelector);
Expand Down Expand Up @@ -149,6 +154,16 @@ const SendNavigation = (): ReactElement => {
<Stack.Screen name="Pending" component={Pending} />
<Stack.Screen name="Success" component={Success} />
<Stack.Screen name="Error" component={Error} />
<Stack.Screen
name="LNURLAmount"
component={LNURLAmount}
initialParams={{ pParams, url }}
/>
<Stack.Screen
name="LNURLConfirm"
component={LNURLConfirm}
initialParams={{ pParams, url, amount }}
/>
</Stack.Navigator>
</NavigationContainer>
</BottomSheetWrapper>
Expand Down
4 changes: 0 additions & 4 deletions src/navigation/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type { ProfileLinkStackParamList } from '../bottom-sheet/ProfileLinkNavig
import type { ReceiveStackParamList } from '../bottom-sheet/ReceiveNavigation';
import type { SendStackParamList } from '../bottom-sheet/SendNavigation';
import type { LNURLWithdrawStackParamList } from '../bottom-sheet/LNURLWithdrawNavigation';
import type { LNURLPayStackParamList } from '../bottom-sheet/LNURLPayNavigation';
import type { TreasureHuntStackParamList } from '../bottom-sheet/TreasureHuntNavigation';

// TODO: move all navigation related types here
Expand Down Expand Up @@ -104,9 +103,6 @@ export type SendScreenProps<T extends keyof SendStackParamList> =
export type LNURLWithdrawProps<T extends keyof LNURLWithdrawStackParamList> =
NativeStackScreenProps<LNURLWithdrawStackParamList, T>;

export type LNURLPayProps<T extends keyof LNURLPayStackParamList> =
NativeStackScreenProps<LNURLPayStackParamList, T>;

export type TreasureHuntScreenProps<
T extends keyof TreasureHuntStackParamList,
> = NativeStackScreenProps<TreasureHuntStackParamList, T>;
12 changes: 6 additions & 6 deletions src/screens/Wallets/LNURLPay/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ import { useAppSelector } from '../../../hooks/redux';
import { useBalance, useSwitchUnit } from '../../../hooks/wallet';
import { getNumberPadText } from '../../../utils/numberpad';
import { convertToSats } from '../../../utils/conversion';
import type { LNURLPayProps } from '../../../navigation/types';
import type { SendScreenProps } from '../../../navigation/types';

const Amount = ({
const LNURLAmount = ({
navigation,
route,
}: LNURLPayProps<'Amount'>): ReactElement => {
}: SendScreenProps<'LNURLAmount'>): ReactElement => {
const { t } = useTranslation('wallet');
const { pParams } = route.params;
const { pParams, url } = route.params;
const { minSendable, maxSendable } = pParams;
const { spendingBalance } = useBalance();
const switchUnit = useSwitchUnit();
Expand Down Expand Up @@ -154,7 +154,7 @@ const Amount = ({
disabled={!isValid}
testID="ContinueAmount"
onPress={(): void => {
navigation.navigate('Confirm', { amount, pParams });
navigation.navigate('LNURLConfirm', { amount, pParams, url });
}}
/>
</View>
Expand Down Expand Up @@ -211,4 +211,4 @@ const styles = StyleSheet.create({
},
});

export default memo(Amount);
export default memo(LNURLAmount);
Loading

0 comments on commit 196dcae

Please sign in to comment.