Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lightning): Upgrade To Blocktank v2 API #1216

Merged
merged 37 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
de96a1c
chore(lightning): Upgrade To Blocktank v2 API
coreyphillips Aug 22, 2023
39a156d
fix(lightning): Add min0ConfTxFee to channelOpenCost
coreyphillips Aug 22, 2023
55f2cc3
fix(wallet): Fix id in QuickConfirm
coreyphillips Aug 22, 2023
5b45f2a
fix(lightning): fix channel open cost, refresh order
pwltr Aug 22, 2023
cc753ff
fix(wallet): Update getFees method in lm.start
coreyphillips Aug 22, 2023
0b7601d
fix(wallet): Set announce channel to false
coreyphillips Aug 22, 2023
bb51d96
fix(lightning): fix refresh order
pwltr Aug 23, 2023
7d30a49
fix(wallet): Update Channel State Conditions
coreyphillips Aug 23, 2023
e8f82c4
Merge branch 'master' into blocktank-v2
coreyphillips Aug 24, 2023
572ca23
fix(wallet): Fix blocktankNodeUris
coreyphillips Aug 24, 2023
ca43c6a
fix(wallet): Update Lightning Setup Steps
coreyphillips Aug 24, 2023
8d713aa
fix(backup): Update defaultOrderResponse dates
coreyphillips Aug 24, 2023
e80c5f5
fix(lightning): Update QuickSetupReserveNote condition
coreyphillips Aug 24, 2023
384871c
fix(lightning): Update channels test
coreyphillips Aug 24, 2023
71b4f29
fix(lightning): channels test
limpbrains Aug 25, 2023
259615c
fix(lightning): channels test
limpbrains Aug 25, 2023
21ab801
fix(lightning): Update maxChannelSizeFiat in CustomSetup.tsx
coreyphillips Aug 25, 2023
a08ea7d
fix(lightning): Update maxChannelSizeFiat in Custom and Quick Setup
coreyphillips Aug 25, 2023
d4552e2
fix(lightning): Fix min/max ChannelSizeSat values
coreyphillips Aug 25, 2023
82119cd
fix(lightning): Update QuickSetupBlocktankNote condition
coreyphillips Aug 25, 2023
9e4730e
fix(lightning): Update btSpendingLimit in QuickSetup.tsx
coreyphillips Aug 26, 2023
0c58170
fix(wallet): Fix Onboarding Status
coreyphillips Aug 29, 2023
349a97f
fix(lightning): Update ChannelDetail status orders
coreyphillips Aug 30, 2023
fddf66e
fix(lightning): Add channel open notification back
coreyphillips Aug 30, 2023
208f3c9
fix(lightning): Update handleOrderStateChange
coreyphillips Aug 31, 2023
90437ab
fix(lightning): Update lightningConnecting condition
coreyphillips Aug 31, 2023
4ba7b8c
fix(lightning): Remove old TODO
coreyphillips Aug 31, 2023
0eeed2f
fix(lightning): Fix Custom Channel Open Flow Calculations
coreyphillips Aug 31, 2023
0cd61f5
fix(lightning): Fix Custom Channel Open Flow Calculations
coreyphillips Aug 31, 2023
ef142ca
fix(lightning): Update channel fee value
coreyphillips Sep 1, 2023
65d9307
fix(lightning): Update PACKAGES_RECEIVING array
coreyphillips Sep 1, 2023
180143c
fix(lightning): Adjust packageFiatAmount condition
coreyphillips Sep 1, 2023
95f67ec
fix(lightning): Add v1 to v2 order migration
coreyphillips Sep 1, 2023
885566f
fix(lightning): Add minUsableLspBalance to QuickSetup for 0-sat clien…
coreyphillips Sep 3, 2023
438bf5b
chore(lightning): Remove console logs
coreyphillips Sep 4, 2023
8f05e63
chore(lightning): Add setDefaultClientBalance
coreyphillips Sep 4, 2023
e852886
chore(lightning): Clean up comments/unnecessary awaits
coreyphillips Sep 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions e2e/channels.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import jestExpect from 'expect';

import initWaitForElectrumToSync from '../__tests__/utils/wait-for-electrum';
import {
sleep,
checkComplete,
markComplete,
launchAndWait,
Expand All @@ -12,7 +11,7 @@ import {
bitcoinURL,
} from './helpers';

d = checkComplete('channels-1') ? describe.skip : describe;
const d = checkComplete('channels-1') ? describe.skip : describe;

d('LN Channel Onboarding', () => {
let waitForElectrum;
Expand Down Expand Up @@ -67,7 +66,6 @@ d('LN Channel Onboarding', () => {
// receive BTC
await element(by.id('Receive')).tap();
await element(by.id('UnderstoodButton')).tap();
await sleep(1000); // animation
// get address from qrcode
let { label: wAddress } = await element(by.id('QRCode')).getAttributes();
wAddress = wAddress.replace('bitcoin:', '');
Expand All @@ -80,24 +78,22 @@ d('LN Channel Onboarding', () => {
.toBeVisible()
.withTimeout(10000);
await element(by.id('NewTxPrompt')).swipe('down'); // close Receive screen
await sleep(1000); // animation

await element(by.id('Suggestion-lightning')).tap();
await element(by.id('QuickSetupButton')).tap();
// set spending balance to zero
await element(by.id('SliderHandle')).swipe('left');
await sleep(2000); // wait for weird slider behavior
const button = element(by.id('QuickSetupContinue'));
const buttonEnabled = await isButtonEnabled(button);
jestExpect(buttonEnabled).toBe(false);

// should show 80% limit note
await element(by.id('SliderHandle')).swipe('right', 'slow', NaN, 0.8);
await expect(element(by.id('QuickSetupReserveNote'))).toBeVisible();
await expect(element(by.id('QuickSetupBlocktankNote'))).toBeVisible();
await element(by.id('QuickSetupCustomAmount')).tap();
await element(by.id('NumberPadButtonsMax')).tap();
await element(by.id('NumberPadButtonsDone')).tap();
await expect(element(by.id('QuickSetupReserveNote'))).toBeVisible();
await expect(element(by.id('QuickSetupBlocktankNote'))).toBeVisible();
// await expect(element(by.text('80%'))).toBeVisible();

// get more BTC
Expand All @@ -108,7 +104,6 @@ d('LN Channel Onboarding', () => {
.toBeVisible()
.withTimeout(10000);
await element(by.id('NewTxPrompt')).swipe('down'); // close Receive screen
await sleep(1000); // animation

// should show Blocktank limit note
await element(by.id('SliderHandle')).swipe('right', 'slow', NaN, 0.8);
Expand All @@ -130,14 +125,15 @@ 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 sleep(1000); // animation
await expect(element(by.id('LightningSettingUp'))).toBeVisible();
await waitFor(element(by.id('LightningSettingUp')))
.toBeVisible()
.withTimeout(10000);

// CustomSetup
await launchAndWait();
await expect(
element(by.id('Suggestion-lightningSettingUp')),
).toBeVisible();
await waitFor(element(by.id('Suggestion-lightningSettingUp')))
.toBeVisible()
.withTimeout(10000);
await element(by.id('BitcoinAsset')).tap();
await element(by.id('TransferButton')).tap();
await element(by.id('CustomSetupButton')).tap();
Expand All @@ -153,18 +149,22 @@ d('LN Channel Onboarding', () => {

// Receive Amount
await element(by.id('CustomSetupContinue')).tap();
await sleep(1000); // animation
const button2 = element(by.id('Barrel-medium'));
const buttonEnabled2 = await isButtonEnabled(button2);
jestExpect(buttonEnabled2).toBe(false);

// go back and change to 2nd card
await element(by.id('NavigationBack')).atIndex(1).tap();
await element(by.id('Barrel-medium')).tap();
await element(by.id('CustomSetupContinue')).tap();
await element(by.id('Barrel-medium')).tap();

// go to confirmation screen
await element(by.id('CustomSetupContinue')).tap();
await sleep(1000); // animation

// check that the amounts are correct
await expect(element(by.text('100.00'))).toBeVisible();
await expect(element(by.text('500.00'))).toBeVisible();
await expect(element(by.text('999.00'))).toBeVisible();

// TODO: testID on Text not working yet
// // set channel duration
Expand All @@ -177,8 +177,9 @@ 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 sleep(1000); // animation
await expect(element(by.id('LightningSettingUp'))).toBeVisible();
await waitFor(element(by.id('LightningSettingUp')))
.toBeVisible()
.withTimeout(10000);

markComplete('channels-1');
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@reduxjs/toolkit": "^1.9.3",
"@sayem314/react-native-keep-awake": "^1.2.0",
"@shopify/react-native-skia": "0.1.182",
"@synonymdev/blocktank-client": "0.0.50",
"@synonymdev/blocktank-lsp-http-client": "^0.2.4",
"@synonymdev/react-native-ldk": "0.0.105",
"@synonymdev/react-native-lnurl": "0.0.5",
"@synonymdev/result": "0.0.2",
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/blocktank.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { useSelector } from 'react-redux';
import { IGetOrderResponse } from '@synonymdev/blocktank-client';
import {
blocktankOrdersSelector,
blocktankPaidOrdersSelector,
} from '../store/reselect/blocktank';
import { IBtOrder } from '@synonymdev/blocktank-lsp-http-client';

/**
* Returns the list of blocktank orders that have been paid.
* @returns {IGetOrderResponse[]} paid Blocktank orders
* @returns {IBtOrder[]} paid Blocktank orders
*/
export const usePaidBlocktankOrders = (): IGetOrderResponse[] => {
export const usePaidBlocktankOrders = (): IBtOrder[] => {
const orders = useSelector(blocktankOrdersSelector);
const paidOrders = useSelector(blocktankPaidOrdersSelector);

const paidBlocktankOrders = orders.filter((order) => {
return Object.keys(paidOrders).find((orderId) => orderId === order._id);
return Object.keys(paidOrders).find((orderId) => orderId === order.id);
});

return paidBlocktankOrders;
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/lightning.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { TChannel } from '@synonymdev/react-native-ldk';
import { IGetOrderResponse } from '@synonymdev/blocktank-client';

import { ellipsis } from '../utils/helpers';
import Store from '../store/types';
Expand All @@ -16,6 +15,7 @@ import {
openChannelIdsSelector,
} from '../store/reselect/lightning';
import { usePaidBlocktankOrders } from './blocktank';
import { IBtOrder } from '@synonymdev/blocktank-lsp-http-client';

/**
* Returns the lightning balance of all known open channels.
Expand Down Expand Up @@ -111,18 +111,18 @@ export const useLightningChannelBalance = (
/**
* Returns the name of a channel.
* @param {TChannel} channel
* @param {IGetOrderResponse} blocktankOrder
* @param {IBtOrder} blocktankOrder
* @returns {string}
*/
export const useLightningChannelName = (
channel: TChannel,
blocktankOrder?: IGetOrderResponse,
blocktankOrder?: IBtOrder,
): string => {
const paidBlocktankOrders = usePaidBlocktankOrders();

if (blocktankOrder) {
const index = paidBlocktankOrders.findIndex(
(order) => order._id === blocktankOrder._id,
(order) => order.id === blocktankOrder.id,
);
return `Connection ${index + 1}`;
} else {
Expand Down
36 changes: 17 additions & 19 deletions src/screens/Lightning/CustomConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ import {
} from '../../store/actions/blocktank';
import { showToast } from '../../utils/notifications';
import { addTodo } from '../../store/actions/todos';
import { setLightningSettingUpStep } from '../../store/actions/user';
import {
selectedNetworkSelector,
selectedWalletSelector,
transactionFeeSelector,
} from '../../store/reselect/wallet';
import {
blocktankOrderSelector,
blocktankServiceSelector,
} from '../../store/reselect/blocktank';
import { blocktankOrderSelector } from '../../store/reselect/blocktank';

export const DEFAULT_CHANNEL_DURATION = 6;

Expand All @@ -48,22 +44,26 @@ const CustomConfirm = ({
const [showNumberPad, setShowNumberPad] = useState(false);
const selectedWallet = useSelector(selectedWalletSelector);
const selectedNetwork = useSelector(selectedNetworkSelector);
const blocktankService = useSelector(blocktankServiceSelector);
const order = useSelector((state: Store) => {
return blocktankOrderSelector(state, orderId);
});

const blocktankPurchaseFee = useDisplayValues(order?.price ?? 0);
const blocktankPurchaseFee = useDisplayValues(order?.feeSat ?? 0);
const transactionFee = useSelector(transactionFeeSelector);
const fiatTransactionFee = useDisplayValues(transactionFee);
const clientBalance = useDisplayValues(order?.clientBalanceSat ?? 0);

const channelOpenCost = useMemo(() => {
const fee = blocktankPurchaseFee.fiatValue + fiatTransactionFee.fiatValue;
return fee.toFixed(2);

// avoid flashing different price after confirmation
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [orderId]);
return (
blocktankPurchaseFee.fiatValue -
clientBalance.fiatValue +
fiatTransactionFee.fiatValue
).toFixed(2);
}, [
fiatTransactionFee.fiatValue,
clientBalance.fiatValue,
blocktankPurchaseFee.fiatValue,
]);

const handleConfirm = async (): Promise<void> => {
setLoading(true);
Expand All @@ -73,16 +73,14 @@ const CustomConfirm = ({
setLoading(false);
return;
}
setLightningSettingUpStep(0);
addTodo('lightningSettingUp');
navigation.navigate('SettingUp');
};

const updateOrderExpiration = async (): Promise<void> => {
const purchaseResponse = await startChannelPurchase({
productId: blocktankService.product_id,
remoteBalance: order.remote_balance,
localBalance: order.local_balance,
remoteBalance: order.clientBalanceSat,
localBalance: order.lspBalanceSat,
channelExpiry: Math.max(weeks, 1),
selectedWallet,
selectedNetwork,
Expand All @@ -95,7 +93,7 @@ const CustomConfirm = ({
});
return;
}
setOrderId(purchaseResponse.value.orderId);
setOrderId(purchaseResponse.value.order.id);
};

return (
Expand Down Expand Up @@ -202,7 +200,7 @@ const CustomConfirm = ({
weeks={weeks}
onChange={setWeeks}
onDone={(): void => {
if (order.channel_expiry !== weeks) {
if (order.channelExpiryWeeks !== weeks) {
updateOrderExpiration().then();
}
setShowNumberPad(false);
Expand Down
Loading
Loading