Skip to content

Commit

Permalink
fix(lightning): update transfer to spending flow
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr committed Jan 29, 2024
1 parent 36cd2f5 commit 2800a85
Show file tree
Hide file tree
Showing 14 changed files with 2,160 additions and 78 deletions.
4 changes: 2 additions & 2 deletions e2e/channels.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ d('LN Channel Onboarding', () => {

// Swipe to confirm (set x offset to avoid navigating back)
await element(by.id('GRAB')).swipe('right', 'slow', NaN, 0.8);
await waitFor(element(by.id('LightningSuccess')))
await waitFor(element(by.id('LightningSettingUp')))
.toBeVisible()
.withTimeout(10000);

Expand Down Expand Up @@ -183,7 +183,7 @@ d('LN Channel Onboarding', () => {

// Swipe to confirm (set x offset to avoid navigating back)
await element(by.id('GRAB')).swipe('right', 'slow', NaN, 0.8);
await waitFor(element(by.id('LightningSuccess')))
await waitFor(element(by.id('LightningSettingUp')))
.toBeVisible()
.withTimeout(10000);

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@sayem314/react-native-keep-awake": "1.2.2",
"@shopify/react-native-skia": "0.1.230",
"@synonymdev/blocktank-client": "0.0.50",
"@synonymdev/blocktank-lsp-http-client": "0.9.0",
"@synonymdev/blocktank-lsp-http-client": "0.13.1",
"@synonymdev/feeds": "2.1.1",
"@synonymdev/react-native-ldk": "0.0.127",
"@synonymdev/react-native-lnurl": "0.0.7",
Expand Down Expand Up @@ -174,6 +174,7 @@
"nano-staged": "^0.8.0",
"node-fetch": "^2.6.7",
"prettier": "^2.8.8",
"react-native-bundle-visualizer": "^3.1.3",
"react-native-flipper": "0.212.0",
"react-native-mmkv-flipper-plugin": "^1.0.0",
"react-native-skia-stub": "0.0.1",
Expand Down
5 changes: 2 additions & 3 deletions src/screens/Lightning/CustomConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ const CustomConfirm = ({
setLoading(false);
return;
}
const zeroConf = order.zeroConf && !res.value.useUnconfirmedInputs;
navigation.navigate(zeroConf ? 'SettingUp' : 'Success');
navigation.navigate('SettingUp');
};

const updateOrderExpiration = async (): Promise<void> => {
const purchaseResponse = await startChannelPurchase({
remoteBalance: order.clientBalanceSat,
localBalance: order.lspBalanceSat,
channelExpiry: Math.max(weeks, 1),
turboChannel: order.zeroConf,
zeroConfPayment: order.zeroConf,
selectedWallet,
selectedNetwork,
});
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Lightning/CustomSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ const CustomSetup = ({
remoteBalance: spendingAmount!,
localBalance: amount,
channelExpiry: DEFAULT_CHANNEL_DURATION,
turboChannel:
zeroConfPayment:
spendingAmount! <= blocktankInfo.options.max0ConfClientBalanceSat,
selectedWallet,
selectedNetwork,
Expand Down
3 changes: 1 addition & 2 deletions src/screens/Lightning/QuickConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ const QuickConfirm = ({
setLoading(false);
return;
}
const zeroConf = order?.zeroConf && !res.value.useUnconfirmedInputs;
navigation.navigate(zeroConf ? 'SettingUp' : 'Success');
navigation.navigate('SettingUp');
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Lightning/QuickSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const QuickSetup = ({
localBalance: lspBalance,
channelExpiry: DEFAULT_CHANNEL_DURATION,
lspNodeId: blocktankInfo.nodes[0].pubkey,
turboChannel:
zeroConfPayment:
spendingAmount <= blocktankInfo.options.max0ConfClientBalanceSat,
});

Expand Down
14 changes: 9 additions & 5 deletions src/screens/Lightning/SettingUp.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import React, { ReactElement, memo, useCallback } from 'react';
import { StyleSheet, View } from 'react-native';
import { useAppSelector } from '../../hooks/redux';
import { useTranslation } from 'react-i18next';
import { Trans, useTranslation } from 'react-i18next';
import { useFocusEffect } from '@react-navigation/native';
import {
activateKeepAwake,
deactivateKeepAwake,
} from '@sayem314/react-native-keep-awake';

import { Display, Text01S } from '../../styles/text';
import { Display, Text01B, Text01S } from '../../styles/text';
import SafeAreaInset from '../../components/SafeAreaInset';
import GlowingBackground from '../../components/GlowingBackground';
import NavigationHeader from '../../components/NavigationHeader';
import HourglassSpinner from '../../components/HourglassSpinner';
import ProgressSteps from '../../components/ProgressSteps';
import { useAppSelector } from '../../hooks/redux';
import { lightningSettingUpStepSelector } from '../../store/reselect/user';
import type { LightningScreenProps } from '../../navigation/types';

const TIMEOUT_DELAY = 2 * 60 * 1000; // 2 minutes
const TIMEOUT_DELAY = 10 * 60 * 1000; // 10 minutes

const SettingUp = ({
navigation,
Expand Down Expand Up @@ -63,7 +63,11 @@ const SettingUp = ({
<View style={styles.content} testID="LightningSettingUp">
<Display color="purple">{t('setting_up_header')}</Display>
<Text01S style={styles.text} color="gray1">
{t('setting_up_text')}
<Trans
t={t}
i18nKey="setting_up_text"
components={{ highlight: <Text01B color="white" /> }}
/>
</Text01S>

<HourglassSpinner glowColor="purple" />
Expand Down
11 changes: 2 additions & 9 deletions src/screens/Lightning/Success.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ReactElement, memo } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { Text01B } from '../../styles/text';
import { useTranslation } from 'react-i18next';
import InfoScreen from '../../components/InfoScreen';
import type { LightningScreenProps } from '../../navigation/types';

Expand All @@ -22,13 +21,7 @@ const Success = ({
navTitle={t('add_instant_payments')}
displayBackButton={false}
title={t('result_header')}
description={
<Trans
t={t}
i18nKey="result_text"
components={{ highlight: <Text01B color="white" /> }}
/>
}
description={t('result_text')}
image={imageSrc}
buttonText={t('awesome')}
testID="LightningSuccess"
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Transfer/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const Setup = ({ navigation }: TransferScreenProps<'Setup'>): ReactElement => {
selectedWallet,
remoteBalance,
localBalance,
turboChannel:
zeroConfPayment:
remoteBalance <= blocktankInfo.options.max0ConfClientBalanceSat,
});

Expand Down
10 changes: 10 additions & 0 deletions src/store/shapes/blocktank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export const defaultBlocktankInfoShape: IBtInfo = {
btc: '0.0.0',
ln2: '0.0.0',
},
onchain: {
// @ts-ignore enum not exported from blocktank-lsp-http-client
network: 'mainnet',
feeRates: {
fast: 0,
mid: 0,
slow: 0,
isHigh: false,
},
},
};

export const initialBlocktankState: IBlocktank = {
Expand Down
3 changes: 3 additions & 0 deletions src/store/utils/blocktank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export const startChannelPurchase = async ({
lspNodeId,
couponCode,
turboChannel = true,
zeroConfPayment = false,
selectedWallet,
selectedNetwork,
}: {
Expand All @@ -230,6 +231,7 @@ export const startChannelPurchase = async ({
lspNodeId?: string;
couponCode?: string;
turboChannel?: boolean;
zeroConfPayment?: boolean;
selectedWallet?: TWalletName;
selectedNetwork?: EAvailableNetwork;
}): Promise<
Expand All @@ -255,6 +257,7 @@ export const startChannelPurchase = async ({
lspNodeId,
couponCode,
turboChannel,
zeroConfPayment,
},
});
if (buyChannelResponse.isErr()) {
Expand Down
5 changes: 2 additions & 3 deletions src/utils/blocktank/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { err, ok, Result } from '@synonymdev/result';
import { CJitStateEnum } from '@synonymdev/blocktank-lsp-http-client/dist/shared/CJitStateEnum';
import { BtOpenChannelState } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtOpenChannelState';
import { IBt0ConfMinTxFeeWindow } from '@synonymdev/blocktank-lsp-http-client/dist/shared/IBt0ConfMinTxFeeWindow';

import { EAvailableNetwork } from '../networks';
import { addPeers, getNodeId, refreshLdk } from '../lightning';
Expand Down Expand Up @@ -204,9 +205,7 @@ export const getOrder = async (orderId: string): Promise<Result<IBtOrder>> => {

export const getMin0ConfTxFee = async (
orderId: string,
): Promise<
Result<{ id: string; validityEndsAt: string; satPerVByte: number }>
> => {
): Promise<Result<IBt0ConfMinTxFeeWindow>> => {
try {
const res = await bt.getMin0ConfTxFee(orderId);
return ok(res);
Expand Down
10 changes: 5 additions & 5 deletions src/utils/i18n/locales/en/lightning.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"duration_text": "Choose the minimum number of weeks you want your connection to remain open.",
"duration_week": "{count, plural, one {week} other {weeks}}",
"setting_up_header": "Setting Up.",
"setting_up_text": "Please wait and keep Bitkit open while your Lightning connection is being set up. This process takes about a minute.",
"setting_up_step1": "Awaiting Payment",
"setting_up_text": "Please wait and keep Bitkit open while your Lightning connection is being set up. This process takes about <highlight>±10 minutes.</highlight>",
"setting_up_step1": "Processing Payment",
"setting_up_step2": "Payment Successful",
"setting_up_step3": "Queued For Opening",
"setting_up_step4": "Opening Connection",
"result_header": "Connecting.",
"result_text": "Lightning connection initiated. You will be able to use instant payments in <highlight>±10 minutes.</highlight>",
"result_header": "Connected.",
"result_text": "Your Lightning connection is ready to use.",
"timeout_header": "Please keep Bitkit open.",
"timeout_text": "Bitkit will keep trying to open your Lightning connection in the background. Please keep the app open.",
"awesome": "Awesome!",
Expand Down Expand Up @@ -125,7 +125,7 @@
"order_expired_title": "Instant Payments Setup Failed",
"order_expired_msg": "The setup process expired. Please try again.",
"order_state": {
"awaiting_payment": "Awaiting payment",
"awaiting_payment": "Processing payment",
"paid": "Payment successful",
"refunded": "Payment refunded",
"queued": "Queued for opening",
Expand Down
Loading

0 comments on commit 2800a85

Please sign in to comment.