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

fix: migrate to Blocktank client v2 #2350

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions __tests__/todos.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import assert from 'node:assert';
import cloneDeep from 'lodash/cloneDeep';
import { IBtOrder } from '@synonymdev/blocktank-lsp-http-client';
import { BtOrderState2 } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtOrderState2';
import { IBtOrder, BtOrderState2 } from '@synonymdev/blocktank-lsp-http-client';

import '../src/utils/i18n';
import { todosFullSelector } from '../src/store/reselect/todos';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@react-navigation/native-stack": "6.10.1",
"@reduxjs/toolkit": "2.2.6",
"@shopify/react-native-skia": "1.3.11",
"@synonymdev/blocktank-lsp-http-client": "1.5.0",
"@synonymdev/blocktank-lsp-http-client": "2.0.0",
"@synonymdev/feeds": "3.0.0",
"@synonymdev/ledger": "0.0.5",
"@synonymdev/react-native-keychain": "9.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Settings/Lightning/ChannelDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Clipboard from '@react-native-clipboard/clipboard';
import {
BtOpenChannelState,
BtOrderState2,
BtPaymentState2,
IBtOrder,
ICJitEntry,
} from '@synonymdev/blocktank-lsp-http-client';
import { BtOrderState2 } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtOrderState2';
import { BtPaymentState2 } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtPaymentState2';
import React, { ReactElement, memo, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Settings/Lightning/ChannelStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { StyleSheet, View } from 'react-native';
import { useTranslation } from 'react-i18next';
import {
BtOpenChannelState,
BtOrderState2,
BtPaymentState2,
IBtOrder,
} from '@synonymdev/blocktank-lsp-http-client';
import { BtOrderState2 } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtOrderState2';
import { BtPaymentState2 } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtPaymentState2';

import { EChannelStatus } from '../../../store/types/lightning';
import { View as ThemedView } from '../../../styles/components';
Expand Down
3 changes: 1 addition & 2 deletions src/screens/Settings/Lightning/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
import Share from 'react-native-share';
import { FadeIn, FadeOut } from 'react-native-reanimated';
import { useTranslation } from 'react-i18next';
import { IBtOrder } from '@synonymdev/blocktank-lsp-http-client';
import { BtOrderState2 } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtOrderState2';
import { IBtOrder, BtOrderState2 } from '@synonymdev/blocktank-lsp-http-client';

import { AnimatedView, View as ThemedView } from '../../../styles/components';
import { Caption13Up, BodyMSB } from '../../../styles/text';
Expand Down
5 changes: 3 additions & 2 deletions src/screens/Wallets/Receive/ReceiveConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const ReceiveConnect = ({
const { maxChannelSizeSat } = blocktank.options;
const minChannelSize = Math.round(amount * 2.5);
const maxChannelSize = Math.round(maxChannelSizeSat / 2);
const channelSize = Math.max(minChannelSize, maxChannelSize);
const channelSize = Math.min(minChannelSize, maxChannelSize);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a mistake here. minChannelSize = amount * 2.5 and it can be bigger than maxChannelSize
Looks like it was changed at 2a6b1fb by mistake

Copy link
Collaborator Author

@limpbrains limpbrains Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should be ?

const channelSize = min(max(amount * 2.5, maxChannelSizeSat / 2), maxChannelSizeSat);

const lspBalance = channelSize - amount;
const payAmount = amount - feeEstimate;
const displayFee = useDisplayValues(feeEstimate);
Expand Down Expand Up @@ -76,7 +76,7 @@ const ReceiveConnect = ({
const onContinue = async (): Promise<void> => {
setIsLoading(true);
const cJitEntryResponse = await createCJitEntry({
channelSize: channelSize,
channelSize,
invoiceAmount: amount,
invoiceDescription: message,
});
Expand All @@ -86,6 +86,7 @@ const ReceiveConnect = ({
title: t('receive_cjit_error'),
description: cJitEntryResponse.error.message,
});
setIsLoading(false);
return;
}
const order = cJitEntryResponse.value;
Expand Down
7 changes: 5 additions & 2 deletions src/store/reselect/blocktank.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { createSelector } from '@reduxjs/toolkit';
import { RootState } from '..';
import { IBlocktank, TPaidBlocktankOrders } from '../types/blocktank';
import { IBtInfo, IBtOrder } from '@synonymdev/blocktank-lsp-http-client';
import { BtOrderState2 } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtOrderState2';
import {
BtOrderState2,
IBtInfo,
IBtOrder,
} from '@synonymdev/blocktank-lsp-http-client';

const blocktankState = (state: RootState): IBlocktank => state.blocktank;

Expand Down
10 changes: 5 additions & 5 deletions src/store/utils/blocktank.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { err, ok, Result } from '@synonymdev/result';
import { CJitStateEnum } from '@synonymdev/blocktank-lsp-http-client/dist/shared/CJitStateEnum';
import {
BtBolt11PaymentState,
BtBolt11InvoiceState,
BtOpenChannelState,
BtOrderState2,
BtPaymentState2,
CJitStateEnum,
IBtOrder,
ICJitEntry,
} from '@synonymdev/blocktank-lsp-http-client';
import { BtOrderState2 } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtOrderState2';
import { BtPaymentState2 } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtPaymentState2';
import notifee, { TimestampTrigger, TriggerType } from '@notifee/react-native';

import { __E2E__ } from '../../constants/env';
Expand Down Expand Up @@ -384,7 +384,7 @@ const handleOrderStateChange = (order: IBtOrder): void => {
}

// given up
if (order.payment.bolt11Invoice.state === BtBolt11PaymentState.FAILED) {
if (order.payment.bolt11Invoice.state === BtBolt11InvoiceState.CANCELED) {
showToast({
type: 'warning',
title: i18n.t('lightning:order_given_up_title'),
Expand Down
13 changes: 5 additions & 8 deletions src/utils/blocktank/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
BlocktankClient,
BtOrderState2,
CJitStateEnum,
IBt0ConfMinTxFeeWindow,
IBtInfo,
IBtOrder,
ICJitEntry,
} from '@synonymdev/blocktank-lsp-http-client';
import { err, ok, Result } from '@synonymdev/result';
import { CJitStateEnum } from '@synonymdev/blocktank-lsp-http-client/dist/shared/CJitStateEnum';
import { IBt0ConfMinTxFeeWindow } from '@synonymdev/blocktank-lsp-http-client/dist/shared/IBt0ConfMinTxFeeWindow';
import { BtOrderState2 } from '@synonymdev/blocktank-lsp-http-client/dist/shared/BtOrderState2';

import { EAvailableNetwork } from '../networks';
import { addPeers, getNodeId, refreshLdk } from '../lightning';
Expand Down Expand Up @@ -102,6 +102,7 @@ export const createOrder = async ({
nodeId,
source: options?.source ?? 'bitkit',
zeroReserve: true,
announceChannel: false,
});
if (buyRes?.id) {
await refreshOrder(buyRes.id);
Expand Down Expand Up @@ -246,11 +247,7 @@ export const openChannel = async (
}
//Attempt to sync and re-add peers prior to channel open.
await refreshLdk();
const finalizeChannelResponse = await bt.openChannel(
orderId,
nodeId.value,
false,
);
const finalizeChannelResponse = await bt.openChannel(orderId, nodeId.value);
if (finalizeChannelResponse) {
// Once finalized, refresh on-chain & lightning.
await refreshWallet();
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4894,12 +4894,12 @@ __metadata:
languageName: node
linkType: hard

"@synonymdev/blocktank-lsp-http-client@npm:1.5.0":
version: 1.5.0
resolution: "@synonymdev/blocktank-lsp-http-client@npm:1.5.0"
"@synonymdev/blocktank-lsp-http-client@npm:2.0.0":
version: 2.0.0
resolution: "@synonymdev/blocktank-lsp-http-client@npm:2.0.0"
dependencies:
axios: ^1.4.0
checksum: d2aa8b8d12a5b6e118056b054658b69c482b2c9dcee18248d61abc229ff652a042cf4f126078d638aacbea1da80f384aedbe26eba5d6473f672f919df8fe63ee
checksum: 05befc91b212ac5dc5f6478b376245b46af3aca0e8950aadf69e4f99eb45026ba0130ed058b4d6aa894bdc615778fa00f1835b3a4bf5aef3fc31c5af0c6ab4ef
languageName: node
linkType: hard

Expand Down Expand Up @@ -6602,7 +6602,7 @@ __metadata:
"@react-navigation/native-stack": 6.10.1
"@reduxjs/toolkit": 2.2.6
"@shopify/react-native-skia": 1.3.11
"@synonymdev/blocktank-lsp-http-client": 1.5.0
"@synonymdev/blocktank-lsp-http-client": 2.0.0
"@synonymdev/feeds": 3.0.0
"@synonymdev/ledger": 0.0.5
"@synonymdev/react-native-keychain": 9.1.1
Expand Down