From 4c114518fb4fd314058c83f5d23efa9aaf8f7e2a Mon Sep 17 00:00:00 2001 From: Ivan Vershigora Date: Mon, 2 Dec 2024 14:12:10 +0000 Subject: [PATCH] revert: remove ledger --- package.json | 1 - src/App.tsx | 1 - src/navigation/settings/SettingsNavigator.tsx | 6 - src/screens/Settings/AddressViewer/index.tsx | 5 +- src/screens/Settings/DevSettings/index.tsx | 8 - .../Settings/Ledger/LedgerTransaction.tsx | 233 ------------- src/screens/Settings/Ledger/index.tsx | 330 ------------------ src/store/index.ts | 2 +- src/store/migrations/index.ts | 12 + src/utils/ledger.ts | 281 --------------- src/utils/lightning/index.ts | 8 - src/utils/startup/index.ts | 5 - src/utils/wallet/index.ts | 5 - yarn.lock | 11 - 14 files changed, 14 insertions(+), 894 deletions(-) delete mode 100644 src/screens/Settings/Ledger/LedgerTransaction.tsx delete mode 100644 src/screens/Settings/Ledger/index.tsx delete mode 100644 src/utils/ledger.ts diff --git a/package.json b/package.json index a9f916402..d565f8673 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "@shopify/react-native-skia": "1.3.11", "@synonymdev/blocktank-lsp-http-client": "2.0.0", "@synonymdev/feeds": "3.0.0", - "@synonymdev/ledger": "0.0.5", "@synonymdev/react-native-ldk": "0.0.154", "@synonymdev/react-native-lnurl": "0.0.10", "@synonymdev/react-native-pubky": "^0.3.0", diff --git a/src/App.tsx b/src/App.tsx index acbdd3382..72bfb1ae5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,7 +14,6 @@ import { ThemeProvider } from 'styled-components/native'; import './utils/i18n'; import './utils/quick-actions'; -import './utils/ledger'; import AppOnboarded from './AppOnboarded'; import { SlashtagsProvider } from './components/SlashtagsProvider'; import { toastConfig } from './components/Toast'; diff --git a/src/navigation/settings/SettingsNavigator.tsx b/src/navigation/settings/SettingsNavigator.tsx index e83f8c3c9..ed9a7ea6d 100644 --- a/src/navigation/settings/SettingsNavigator.tsx +++ b/src/navigation/settings/SettingsNavigator.tsx @@ -47,8 +47,6 @@ import ResetAndRestore from '../../screens/Settings/Backup/ResetAndRestore'; import TagsSettings from '../../screens/Settings/Tags'; import FeeSettings from '../../screens/Settings/Fee'; import WebRelay from '../../screens/Settings/WebRelay'; -import Ledger from '../../screens/Settings/Ledger'; -import LedgerTransaction from '../../screens/Settings/Ledger/LedgerTransaction'; import { __E2E__ } from '../../constants/env'; import AppStatus from '../../screens/Settings/AppStatus'; import { TChannel } from '../../store/types/lightning'; @@ -104,8 +102,6 @@ export type SettingsStackParamList = { AddressViewer: undefined; FeeSettings: undefined; WebRelay: undefined; - Ledger: undefined; - LedgerTransaction: { ledgerTxId: number }; }; const Stack = createNativeStackNavigator(); @@ -178,8 +174,6 @@ const SettingsNavigator = (): ReactElement => { - - ); }; diff --git a/src/screens/Settings/AddressViewer/index.tsx b/src/screens/Settings/AddressViewer/index.tsx index 025370463..e1ad5d638 100644 --- a/src/screens/Settings/AddressViewer/index.tsx +++ b/src/screens/Settings/AddressViewer/index.tsx @@ -15,6 +15,7 @@ import { err, ok, Result } from '@synonymdev/result'; import Clipboard from '@react-native-clipboard/clipboard'; import fuzzysort from 'fuzzysort'; import { ldk } from '@synonymdev/react-native-ldk'; +import { EAddressType, IAddress, IUtxo } from 'beignet'; import { TouchableOpacity, @@ -68,8 +69,6 @@ import { setupLdk } from '../../../utils/lightning'; import { startWalletServices } from '../../../utils/startup'; import { updateOnchainFeeEstimates } from '../../../store/utils/fees'; import { viewControllerIsOpenSelector } from '../../../store/reselect/ui'; -import { EAddressType, IAddress, IUtxo } from 'beignet'; -import { setupLedger, syncLedger } from '../../../utils/ledger'; export type TAddressViewerData = { [EAddressType.p2tr]: { @@ -743,7 +742,6 @@ const AddressViewer = ({ if (selectedNetwork !== config.selectedNetwork) { // Wipe existing activity dispatch(resetActivityState()); - setupLedger({ selectedWallet, selectedNetwork }); ldk.stop(); // Switch to new network. dispatch(updateWallet({ selectedNetwork: config.selectedNetwork })); @@ -753,7 +751,6 @@ const AddressViewer = ({ await startWalletServices({ selectedNetwork: config.selectedNetwork }); await updateOnchainFeeEstimates({ forceUpdate: true }); updateActivityList(); - await syncLedger(); } let _utxos: IUtxo[] = []; diff --git a/src/screens/Settings/DevSettings/index.tsx b/src/screens/Settings/DevSettings/index.tsx index 6f8501a94..6861246da 100644 --- a/src/screens/Settings/DevSettings/index.tsx +++ b/src/screens/Settings/DevSettings/index.tsx @@ -128,14 +128,6 @@ const DevSettings = ({ navigation.navigate('FeeSettings'); }, }, - { - title: 'Ledger', - type: EItemType.button, - testID: 'FeeSettings', - onPress: (): void => { - navigation.navigate('Ledger'); - }, - }, { title: t('RBF'), type: EItemType.switch, diff --git a/src/screens/Settings/Ledger/LedgerTransaction.tsx b/src/screens/Settings/Ledger/LedgerTransaction.tsx deleted file mode 100644 index 27c21e3f2..000000000 --- a/src/screens/Settings/Ledger/LedgerTransaction.tsx +++ /dev/null @@ -1,233 +0,0 @@ -import Clipboard from '@react-native-clipboard/clipboard'; -import React, { ReactElement, memo, useMemo } from 'react'; -import { useTranslation } from 'react-i18next'; -import { StyleSheet, TouchableOpacity, View } from 'react-native'; - -import NavigationHeader from '../../../components/NavigationHeader'; -import SafeAreaInset from '../../../components/SafeAreaInset'; -import { SettingsScreenProps } from '../../../navigation/types'; -import { ScrollView, View as ThemedView } from '../../../styles/components'; -import { CaptionB, Caption13Up } from '../../../styles/text'; -import { i18nTime } from '../../../utils/i18n'; -import { bitkitLedger } from '../../../utils/ledger'; -import { showToast } from '../../../utils/notifications'; -import { accToEmoji } from '.'; - -const Section = memo( - ({ - name, - value, - testID, - onPress, - }: { - name: string; - value: ReactElement; - testID?: string; - onPress?: () => void; - }): ReactElement => { - return ( - - - {name} - - - {value} - - - ); - }, -); - -const LedgerTransaction = ({ - navigation, - route, -}: SettingsScreenProps<'LedgerTransaction'>): ReactElement => { - const { ledgerTxId } = route.params; - const { t } = useTranslation(); - const { t: tTime } = useTranslation('intl', { i18n: i18nTime }); - - const tx = useMemo( - () => bitkitLedger?.ledger.getTransaction(ledgerTxId)!, - [ledgerTxId], - ); - const { id, balancesBefore, amount, fromAcc, toAcc, metadata, timestamp } = - tx; - const meta = JSON.stringify(metadata, null, 2); - const fromText = accToEmoji(fromAcc); - const toText = accToEmoji(toAcc); - - return ( - - - navigation.goBack()} - /> - - - - Details - -
- {id} - - } - onPress={(): void => { - Clipboard.setString(String(id)); - showToast({ - type: 'success', - title: t('copied'), - description: String(id), - }); - }} - /> -
- {tTime('dateTime', { - v: new Date(timestamp), - formatParams: { - v: { - year: 'numeric', - month: 'short', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - hour12: false, - }, - }, - })} - - } - /> -
{amount}} /> -
- {fromAcc.wallet} / {fromAcc.account} - - } - /> -
- {toAcc.wallet} / {toAcc.account} - - } - /> - - - - - - - Balance before From - -
- {balancesBefore.fromWallet.available} - - } - /> -
- {balancesBefore.fromWallet.hold} - - } - /> - - - - Balance before To - -
- {balancesBefore.toWallet.available} - - } - /> -
- {balancesBefore.toWallet.hold} - - } - /> - - - - - - - Metadata - - - {`${meta}`} - - - - - - ); -}; - -const styles = StyleSheet.create({ - root: { - flex: 1, - justifyContent: 'space-between', - }, - content: { - paddingHorizontal: 16, - flexGrow: 1, - }, - section: { - marginTop: 16, - }, - sectionTitle: { - marginBottom: 8, - flexDirection: 'row', - alignItems: 'center', - }, - sectionRoot: { - height: 50, - flexDirection: 'row', - alignItems: 'center', - justifyContent: 'space-between', - borderBottomWidth: 1, - borderBottomColor: 'rgba(255, 255, 255, 0.1)', - }, - sectionName: { - flex: 1, - }, - sectionValue: { - flex: 1.5, - alignItems: 'flex-end', - justifyContent: 'center', - }, - row: { - flexDirection: 'row', - alignItems: 'center', - justifyContent: 'space-between', - }, - column: { - width: '45%', - }, -}); - -export default memo(LedgerTransaction); diff --git a/src/screens/Settings/Ledger/index.tsx b/src/screens/Settings/Ledger/index.tsx deleted file mode 100644 index 8ced5eb02..000000000 --- a/src/screens/Settings/Ledger/index.tsx +++ /dev/null @@ -1,330 +0,0 @@ -import { TBitkitTransaction, TDestination } from '@synonymdev/ledger'; -import React, { ReactElement, memo, useState } from 'react'; -import { Alert, StyleSheet, View } from 'react-native'; - -import Button from '../../../components/buttons/Button'; -import NavigationHeader from '../../../components/NavigationHeader'; -import SafeAreaInset from '../../../components/SafeAreaInset'; -import { useBalance } from '../../../hooks/wallet'; -import { SettingsScreenProps } from '../../../navigation/types'; -import { - ScrollView, - TouchableOpacity as ThemedTouchableOpacity, - View as ThemedView, -} from '../../../styles/components'; -import { Caption13Up, BodyM } from '../../../styles/text'; -import { - bitkitLedger, - deleteLedger, - syncLedger, - exportLedger, -} from '../../../utils/ledger'; - -export const accToEmoji = (acc: TDestination): string => { - let wallet = ''; - if (acc.wallet === 'onchain') { - wallet = '🏠🔗'; - } else if (acc.wallet === 'lightning') { - wallet = '🏠⚡️'; - } else if (acc.wallet === 'onchain_remote') { - wallet = '🌐🔗'; - } else if (acc.wallet === 'lightning_remote') { - wallet = '🌐⚡️'; - } - - let account = ''; - if (acc.account === 'available') { - account = '💰'; - } else if (acc.account === 'hold') { - account = '🔒'; - } - - return wallet + account; -}; - -const Transaction = ({ - tx, - onPress, -}: { - tx: TBitkitTransaction; - onPress: () => void; -}): ReactElement => { - const { id, amount, fromAcc, toAcc } = tx; - const fromText = accToEmoji(fromAcc); - const toText = accToEmoji(toAcc); - - let color; - if (toAcc.account === 'hold') { - color = 'white16'; - } else if (toAcc.wallet.includes('_remote')) { - color = 'red16'; - } else { - color = 'green16'; - } - - return ( - - - {id} - - - {amount} - - - - {fromText} ⟶ {toText} - - - - ); -}; - -const Ledger = ({ - navigation, -}: SettingsScreenProps<'Ledger'>): ReactElement => { - const [_, setRerender] = useState(0); - const [syncing, setSyncing] = useState(false); - const balance = useBalance(); - - const reRender = (): NodeJS.Timeout => - setTimeout(() => setRerender((prev) => prev + 1), 10); - - const handleSync = async (): Promise => { - setSyncing(true); - const res = await syncLedger(); - Alert.alert('Init', res.isErr() ? res.error.message : 'Success'); - setSyncing(false); - }; - - const handleReset = async (): Promise => { - const res = await deleteLedger(); - Alert.alert('Reset', res.isErr() ? res.error.message : 'Success'); - reRender(); - }; - - const handleExport = async (): Promise => { - const res = await exportLedger(); - Alert.alert('Export', res.isErr() ? res.error.message : 'Success'); - }; - - const handleTransaction = (id: number): void => { - navigation.navigate('LedgerTransaction', { ledgerTxId: id }); - }; - - return ( - - - navigation.goBack()} - /> - - {!bitkitLedger ? ( - <> - Ledger is not initialized yet - - ) : ( - <> - -