Skip to content

Commit

Permalink
Merge pull request #1771 from synonymdev/ldkseed-v3
Browse files Browse the repository at this point in the history
feat: ldk seed version 3 using bip39Passphrase
  • Loading branch information
Jasonvdb authored May 3, 2024
2 parents 3c150a6 + 5dab5f6 commit c664cfd
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 432 deletions.
12 changes: 0 additions & 12 deletions src/components/Balances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ import { useBalance } from '../hooks/wallet';
import { useAppSelector } from '../hooks/redux';
import { RootNavigationProp } from '../navigation/types';
import { isGeoBlockedSelector } from '../store/reselect/user';
import { accountVersionSelector } from '../store/reselect/lightning';
import { showToast } from '../utils/notifications';

const Balances = (): ReactElement => {
const { t } = useTranslation('wallet');
const navigation = useNavigation<RootNavigationProp>();
const isGeoBlocked = useAppSelector(isGeoBlockedSelector);
const accountVersion = useAppSelector(accountVersionSelector);
const {
onchainBalance,
lightningBalance,
Expand All @@ -40,15 +37,6 @@ const Balances = (): ReactElement => {
};

const onTransfer = (): void => {
if (accountVersion < 2) {
showToast({
type: 'warning',
title: t('migrating_ldk_title'),
description: t('migrating_ldk_description'),
});
return;
}

if (canTransfer) {
navigation.navigate('LightningRoot', { screen: 'QuickSetup' });
}
Expand Down
13 changes: 0 additions & 13 deletions src/screens/Lightning/Introduction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { Trans, useTranslation } from 'react-i18next';

import { Display } from '../../styles/text';
import OnboardingScreen from '../../components/OnboardingScreen';
import { useAppSelector } from '../../hooks/redux';
import { showToast } from '../../utils/notifications';
import { accountVersionSelector } from '../../store/reselect/lightning';
import type { LightningScreenProps } from '../../navigation/types';

const imageSrc = require('../../assets/illustrations/lightning.png');
Expand All @@ -14,18 +11,8 @@ const Introduction = ({
navigation,
}: LightningScreenProps<'Introduction'>): ReactElement => {
const { t } = useTranslation('lightning');
const accountVersion = useAppSelector(accountVersionSelector);

const onContinue = (): void => {
if (accountVersion < 2) {
showToast({
type: 'warning',
title: t('migrating_ldk_title'),
description: t('migrating_ldk_description'),
});
return;
}

navigation.navigate('Funding');
};

Expand Down
58 changes: 1 addition & 57 deletions src/screens/Settings/DevSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@ import { resetUserState } from '../../../store/slices/user';
import { resetActivityState } from '../../../store/slices/activity';
import { resetBlocktankState } from '../../../store/slices/blocktank';
import { resetFeesState } from '../../../store/slices/fees';
import {
updateLdkAccountVersion,
resetLightningState,
} from '../../../store/slices/lightning';
import { resetLightningState } from '../../../store/slices/lightning';
import { resetMetadataState } from '../../../store/slices/metadata';
import { resetSettingsState } from '../../../store/slices/settings';
import { resetSlashtagsState } from '../../../store/slices/slashtags';
import { resetWidgetsState } from '../../../store/slices/widgets';
import { updateLightningNodeIdThunk } from '../../../store/utils/lightning';
import { resetTodosState } from '../../../store/slices/todos';
import { wipeApp } from '../../../store/utils/settings';
import { getStore, getWalletStore } from '../../../store/helpers';
import { warningsSelector } from '../../../store/reselect/checks';
import { accountVersionSelector } from '../../../store/reselect/lightning';
import {
addressTypeSelector,
selectedNetworkSelector,
Expand All @@ -45,7 +40,6 @@ import { zipLogs } from '../../../utils/lightning/logs';
import { runChecks } from '../../../utils/wallet/checks';
import { showToast } from '../../../utils/notifications';
import { getFakeTransaction } from '../../../utils/wallet/testing';
import { createDefaultLdkAccount, setupLdk } from '../../../utils/lightning';
import Dialog from '../../../components/Dialog';
import { resetBackupState } from '../../../store/slices/backup';
import { updateUi } from '../../../store/slices/ui';
Expand All @@ -60,7 +54,6 @@ const DevSettings = ({
const selectedWallet = useAppSelector(selectedWalletSelector);
const selectedNetwork = useAppSelector(selectedNetworkSelector);
const addressType = useAppSelector(addressTypeSelector);
const accountVersion = useAppSelector(accountVersionSelector);
const isProfiling = useAppSelector((state) => state.ui.isProfiling);
const warnings = useAppSelector((state) => {
return warningsSelector(state, selectedWallet, selectedNetwork);
Expand Down Expand Up @@ -247,55 +240,6 @@ const DevSettings = ({
},
],
},
{
title: 'LDK Account Migration',
data: [
{
title: `LDK Account Version: ${accountVersion}`,
type: EItemType.textButton,
value: '',
testID: 'LDKAccountVersion',
},
{
title: 'Force LDK V2 Account Migration',
type: EItemType.button,
testID: 'ForceV2Migration',
onPress: async (): Promise<void> => {
dispatch(updateLdkAccountVersion(2));
await createDefaultLdkAccount({
version: 2,
selectedWallet,
selectedNetwork,
});
await setupLdk({
selectedWallet,
selectedNetwork,
shouldRefreshLdk: true,
});
await updateLightningNodeIdThunk();
},
},
{
title: 'Revert to LDK V1 Account',
type: EItemType.button,
testID: 'RevertToLDKV1',
onPress: async (): Promise<void> => {
dispatch(updateLdkAccountVersion(1));
await createDefaultLdkAccount({
version: 1,
selectedWallet,
selectedNetwork,
});
await setupLdk({
selectedWallet,
selectedNetwork,
shouldRefreshLdk: true,
});
await updateLightningNodeIdThunk();
},
},
],
},
{
title: 'App Cache',
data: [
Expand Down
12 changes: 1 addition & 11 deletions src/screens/Settings/Lightning/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import {
} from '../../../store/reselect/wallet';
import {
closedChannelsSelector,
accountVersionSelector,
openChannelsSelector,
pendingChannelsSelector,
} from '../../../store/reselect/lightning';
Expand Down Expand Up @@ -234,7 +233,6 @@ const Channels = ({
const selectedWallet = useAppSelector(selectedWalletSelector);
const selectedNetwork = useAppSelector(selectedNetworkSelector);
const enableDevOptions = useAppSelector(enableDevOptionsSelector);
const accountVersion = useAppSelector(accountVersionSelector);

const blocktankOrders = useAppSelector(blocktankOrdersSelector);
const paidOrders = useAppSelector(blocktankPaidOrdersSelector);
Expand All @@ -254,22 +252,14 @@ const Channels = ({
const pendingConnections = [...pendingOrders, ...pendingChannels];

const handleAdd = useCallback((): void => {
if (accountVersion < 2) {
showToast({
type: 'warning',
title: t('migrating_ldk_title'),
description: t('migrating_ldk_description'),
});
return;
}
navigation.navigate('LightningRoot', {
screen: 'CustomSetup',
params: { spending: true },
});

// TODO: Update this view once we enable creating channels with nodes other than Blocktank.
// navigation.navigate('LightningAddConnection');
}, [accountVersion, navigation, t]);
}, [navigation]);

const handleExportLogs = useCallback(async (): Promise<void> => {
const result = await zipLogs();
Expand Down
6 changes: 1 addition & 5 deletions src/screens/Wallets/Receive/ReceiveDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { createCJitEntry } from '../../../utils/blocktank';
import { blocktankInfoSelector } from '../../../store/reselect/blocktank';
import { isGeoBlockedSelector } from '../../../store/reselect/user';
import { useLightningBalance } from '../../../hooks/lightning';
import { accountVersionSelector } from '../../../store/reselect/lightning';
import {
denominationSelector,
nextUnitSelector,
Expand Down Expand Up @@ -65,7 +64,6 @@ const ReceiveDetails = ({
const blocktank = useAppSelector(blocktankInfoSelector);
const lightningBalance = useLightningBalance(false);
const isGeoBlocked = useAppSelector(isGeoBlockedSelector);
const accountVersion = useAppSelector(accountVersionSelector);

const { maxChannelSizeSat } = blocktank.options;
const minChannelSize = Math.round(2.5 * invoice.amount);
Expand All @@ -84,8 +82,7 @@ const ReceiveDetails = ({
if (
!enableInstant ||
isGeoBlocked ||
lightningBalance.remoteBalance >= invoice.amount ||
accountVersion < 2
lightningBalance.remoteBalance >= invoice.amount
) {
return;
}
Expand Down Expand Up @@ -115,7 +112,6 @@ const ReceiveDetails = ({
invoice.amount,
invoice.message,
isGeoBlocked,
accountVersion,
lightningBalance.remoteBalance,
navigation,
dispatch,
Expand Down
10 changes: 2 additions & 8 deletions src/screens/Wallets/Receive/ReceiveQR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import {
import { receiveSelector } from '../../../store/reselect/receive';
import { ReceiveScreenProps } from '../../../navigation/types';
import { isGeoBlockedSelector } from '../../../store/reselect/user';
import { accountVersionSelector } from '../../../store/reselect/lightning';
import { getWalletStore } from '../../../store/helpers';

type Slide = () => ReactElement;
Expand All @@ -89,7 +88,6 @@ const ReceiveQR = ({
const selectedAddressType = useAppSelector(addressTypeSelector);
const addressType = useAppSelector(addressTypeSelector);
const isGeoBlocked = useAppSelector(isGeoBlockedSelector);
const accountVersion = useAppSelector(accountVersionSelector);
const { id, amount, message, tags, jitOrder } =
useAppSelector(receiveSelector);
const lightningBalance = useLightningBalance(false);
Expand Down Expand Up @@ -118,8 +116,7 @@ const ReceiveQR = ({
if (
!receiveNavigationIsOpen ||
!lightningBalance.remoteBalance ||
lightningBalance.remoteBalance < amount ||
accountVersion < 2
lightningBalance.remoteBalance < amount
) {
return;
}
Expand Down Expand Up @@ -337,11 +334,8 @@ const ReceiveQR = ({
const qrSize = Math.min(qrMaxWidth, qrMaxHeight);

const displayReceiveInstantlySwitch = useMemo((): boolean => {
if (accountVersion < 2) {
return false;
}
return !(isGeoBlocked && !lightningBalance.remoteBalance);
}, [isGeoBlocked, accountVersion, lightningBalance.remoteBalance]);
}, [isGeoBlocked, lightningBalance.remoteBalance]);

const QrIcon = useCallback((): ReactElement => {
return (
Expand Down
5 changes: 0 additions & 5 deletions src/store/reselect/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export const lightningState = (state: RootState): TLightningState => {
};
export const nodesState = (state: RootState): TNodes => state.lightning.nodes;

export const accountVersionSelector = createSelector(
lightningState,
(lightning) => lightning.accountVersion,
);

export const pendingPaymentsSelector = createSelector(
lightningState,
(lightning) => lightning.pendingPayments,
Expand Down
2 changes: 1 addition & 1 deletion src/store/shapes/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const defaultLightningShape: TNode = {
};

export const initialLightningState: TLightningState = {
accountVersion: 1,
accountVersion: 3,
version: {
ldk: '',
c_bindings: '',
Expand Down
8 changes: 0 additions & 8 deletions src/store/slices/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { TWalletName } from '../types/wallet';
import {
EChannelStatus,
TChannels,
TLdkAccountVersion,
TLightningNodeVersion,
TPendingPayment,
} from '../types/lightning';
Expand Down Expand Up @@ -137,12 +136,6 @@ export const lightningSlice = createSlice({
const { backup, selectedWallet, selectedNetwork } = action.payload;
state.nodes[selectedWallet].backup[selectedNetwork] = backup;
},
updateLdkAccountVersion: (
state,
action: PayloadAction<TLdkAccountVersion>,
) => {
state.accountVersion = action.payload;
},
addPendingPayment: (state, action: PayloadAction<TPendingPayment>) => {
state.pendingPayments.push(action.payload);
},
Expand All @@ -166,7 +159,6 @@ export const {
removeLightningPeer,
updateClaimableBalances,
updateBackupState,
updateLdkAccountVersion,
addPendingPayment,
removePendingPayment,
resetLightningState,
Expand Down
2 changes: 1 addition & 1 deletion src/store/types/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type TCreateLightningInvoice = TCreatePaymentReq & {
selectedWallet?: TWalletName;
};

export type TLdkAccountVersion = 1 | 2;
export type TLdkAccountVersion = 1 | 2 | 3;

export enum EChannelStatus {
open = 'open',
Expand Down
7 changes: 2 additions & 5 deletions src/store/utils/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import { bytesToString } from '../../utils/converters';
import { isObjPartialMatch } from '../../utils/helpers';
import {
checkAccountVersion,
getLdkAccount,
setAccount,
setLdkStoragePath,
Expand Down Expand Up @@ -76,8 +75,7 @@ export const performLdkRestore = async ({
return err(storageRes.error);
}

const version = await checkAccountVersion();
const lightningAccount = await getLdkAccount({ selectedNetwork, version });
const lightningAccount = await getLdkAccount({ selectedNetwork });
if (lightningAccount.isErr()) {
return err(lightningAccount.error);
}
Expand Down Expand Up @@ -233,8 +231,7 @@ export const performFullRestoreFromLatestBackup = async (
network = ENetworks.regtest;
break;
}
const version = await checkAccountVersion();
const lightningAccount = await getLdkAccount({ selectedNetwork, version });
const lightningAccount = await getLdkAccount({ selectedNetwork });
if (lightningAccount.isErr()) {
return err(lightningAccount.error);
}
Expand Down
Loading

0 comments on commit c664cfd

Please sign in to comment.