From e33b6847a914b0141eafae13ecca6e44c5d9e88b Mon Sep 17 00:00:00 2001 From: Ivan Vershigora Date: Thu, 14 Nov 2024 12:02:36 +0000 Subject: [PATCH 1/2] fix: migrate to Blocktank client v2 --- __tests__/todos.ts | 3 +-- package.json | 2 +- src/screens/Settings/Lightning/ChannelDetails.tsx | 4 ++-- src/screens/Settings/Lightning/ChannelStatus.tsx | 4 ++-- src/screens/Settings/Lightning/Channels.tsx | 3 +-- src/store/reselect/blocktank.ts | 7 +++++-- src/store/utils/blocktank.ts | 10 +++++----- src/utils/blocktank/index.ts | 13 +++++-------- yarn.lock | 10 +++++----- 9 files changed, 27 insertions(+), 29 deletions(-) diff --git a/__tests__/todos.ts b/__tests__/todos.ts index da14bba0f..6a2e899be 100644 --- a/__tests__/todos.ts +++ b/__tests__/todos.ts @@ -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'; diff --git a/package.json b/package.json index 045ac27ab..94b6c7909 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/screens/Settings/Lightning/ChannelDetails.tsx b/src/screens/Settings/Lightning/ChannelDetails.tsx index 68873734a..9f1f93e12 100644 --- a/src/screens/Settings/Lightning/ChannelDetails.tsx +++ b/src/screens/Settings/Lightning/ChannelDetails.tsx @@ -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 { diff --git a/src/screens/Settings/Lightning/ChannelStatus.tsx b/src/screens/Settings/Lightning/ChannelStatus.tsx index 2b109118b..9c5d03d52 100644 --- a/src/screens/Settings/Lightning/ChannelStatus.tsx +++ b/src/screens/Settings/Lightning/ChannelStatus.tsx @@ -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'; diff --git a/src/screens/Settings/Lightning/Channels.tsx b/src/screens/Settings/Lightning/Channels.tsx index 8aadbf606..1c8a7afdb 100644 --- a/src/screens/Settings/Lightning/Channels.tsx +++ b/src/screens/Settings/Lightning/Channels.tsx @@ -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'; diff --git a/src/store/reselect/blocktank.ts b/src/store/reselect/blocktank.ts index 68fef05c6..51fca6830 100644 --- a/src/store/reselect/blocktank.ts +++ b/src/store/reselect/blocktank.ts @@ -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; diff --git a/src/store/utils/blocktank.ts b/src/store/utils/blocktank.ts index cc3766fe5..3ebe57a4d 100644 --- a/src/store/utils/blocktank.ts +++ b/src/store/utils/blocktank.ts @@ -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'; @@ -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'), diff --git a/src/utils/blocktank/index.ts b/src/utils/blocktank/index.ts index 3975b9942..e422e9b9c 100644 --- a/src/utils/blocktank/index.ts +++ b/src/utils/blocktank/index.ts @@ -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'; @@ -102,6 +102,7 @@ export const createOrder = async ({ nodeId, source: options?.source ?? 'bitkit', zeroReserve: true, + announceChannel: false, }); if (buyRes?.id) { await refreshOrder(buyRes.id); @@ -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(); diff --git a/yarn.lock b/yarn.lock index 1e19befa4..61359833c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -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 From 1101a26552c5a901742d6e42efd24a8eef7b79fe Mon Sep 17 00:00:00 2001 From: Ivan Vershigora Date: Thu, 14 Nov 2024 12:37:14 +0000 Subject: [PATCH 2/2] fix: calculations in ReceiveConnect --- src/screens/Wallets/Receive/ReceiveConnect.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/screens/Wallets/Receive/ReceiveConnect.tsx b/src/screens/Wallets/Receive/ReceiveConnect.tsx index 7a06a3bfa..0bb7b5ac0 100644 --- a/src/screens/Wallets/Receive/ReceiveConnect.tsx +++ b/src/screens/Wallets/Receive/ReceiveConnect.tsx @@ -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); const lspBalance = channelSize - amount; const payAmount = amount - feeEstimate; const displayFee = useDisplayValues(feeEstimate); @@ -76,7 +76,7 @@ const ReceiveConnect = ({ const onContinue = async (): Promise => { setIsLoading(true); const cJitEntryResponse = await createCJitEntry({ - channelSize: channelSize, + channelSize, invoiceAmount: amount, invoiceDescription: message, }); @@ -86,6 +86,7 @@ const ReceiveConnect = ({ title: t('receive_cjit_error'), description: cJitEntryResponse.error.message, }); + setIsLoading(false); return; } const order = cJitEntryResponse.value;