Skip to content

Commit

Permalink
refactor(wallet): Update Types & Remove Methods
Browse files Browse the repository at this point in the history
Updates/Removes most types that have been migrated to Beignet.
Updates/Removes most methods that have been migrated to Beignet.
Added TODO's to several methods types that still need to be migrated into Beignet.
  • Loading branch information
coreyphillips committed Feb 16, 2024
1 parent c52543d commit 6a55626
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 1,452 deletions.
2 changes: 1 addition & 1 deletion src/screens/Activity/ActivityDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import useColors from '../../hooks/colors';
import { useAppDispatch, useAppSelector } from '../../hooks/redux';

import { showBottomSheet } from '../../store/utils/ui';
import { EPaymentType, EBoostType } from '../../store/types/wallet';
import {
activityItemSelector,
activityItemsSelector,
Expand Down Expand Up @@ -96,6 +95,7 @@ import type {
import { i18nTime } from '../../utils/i18n';
import { useSwitchUnit } from '../../hooks/wallet';
import { contactsSelector } from '../../store/reselect/slashtags';
import { EBoostType, EPaymentType } from 'beignet';

const Section = memo(
({ title, value }: { title: string; value: ReactNode }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Activity/ActivityFiltered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import useColors from '../../hooks/colors';
import { useAppDispatch } from '../../hooks/redux';
import { closeSheet } from '../../store/slices/ui';
import { showBottomSheet } from '../../store/utils/ui';
import { EPaymentType } from '../../store/types/wallet';
import DetectSwipe from '../../components/DetectSwipe';
import type { WalletScreenProps } from '../../navigation/types';
import TimeRangePrompt from './TimeRangePrompt';
import TagsPrompt from './TagsPrompt';
import { TActivityFilter } from '../../utils/activity';
import { EPaymentType } from 'beignet';

type TTab = {
id: string;
Expand Down
3 changes: 2 additions & 1 deletion src/screens/Activity/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import {
import { useAppSelector } from '../../hooks/redux';
import { useProfile2 } from '../../hooks/slashtags2';
import { useFeeText } from '../../hooks/fees';
import { EPaymentType, TTransferToSavings } from '../../store/types/wallet';
import { TTransferToSavings } from '../../store/types/wallet';
import { slashTagsUrlSelector } from '../../store/reselect/metadata';
import { truncate } from '../../utils/helpers';
import { getActivityItemDate } from '../../utils/activity';
import { transferSelector } from '../../store/reselect/wallet';
import { EPaymentType } from 'beignet';

export const ListItem = ({
title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { ReactElement } from 'react';
import { StyleSheet, TextInputProps, View } from 'react-native';
import { IAddress } from '../../../store/types/wallet';
import { TouchableOpacity } from '../../../styles/components';
import { Subtitle, Text01M } from '../../../styles/text';
import { Checkmark } from '../../../styles/icons';
import { IThemeColors } from '../../../styles/themes';
import { IAddress } from 'beignet';

type ListItemProps = TextInputProps & {
item: IAddress;
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Settings/AddressViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
selectedNetworkSelector,
selectedWalletSelector,
} from '../../../store/reselect/wallet';
import { IAddress, IUtxo, TWalletName } from '../../../store/types/wallet';
import { TWalletName } from '../../../store/types/wallet';
import Button from '../../../components/Button';
import {
defaultAddressContent,
Expand Down Expand Up @@ -69,7 +69,7 @@ import { setupLdk } from '../../../utils/lightning';
import { startWalletServices } from '../../../utils/startup';
import { updateOnchainFeeEstimates } from '../../../store/utils/fees';
import { viewControllerIsOpenSelector } from '../../../store/reselect/ui';
import { EAddressType } from 'beignet';
import { EAddressType, IAddress, IUtxo } from 'beignet';

export type TAddressViewerData = {
[EAddressType.p2tr]: {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Wallets/Send/CoinSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import {
getTransactionOutputValue,
} from '../../../utils/wallet/transactions';
import { addTxInput, removeTxInput } from '../../../store/actions/wallet';
import { IUtxo } from '../../../store/types/wallet';
import type { SendScreenProps } from '../../../navigation/types';
import {
transactionSelector,
utxosSelector,
} from '../../../store/reselect/wallet';
import { coinSelectPreferenceSelector } from '../../../store/reselect/settings';
import { TRANSACTION_DEFAULTS } from '../../../utils/wallet/constants';
import { IUtxo } from 'beignet';

/**
* Some UTXO's may contain the same tx_hash.
Expand Down
12 changes: 6 additions & 6 deletions src/store/actions/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ import { err, ok, Result } from '@synonymdev/result';

import actions from './actions';
import {
EBoostType,
ETransferStatus,
ETransferType,
IAddress,
ICreateWallet,
IFormattedTransactions,
IKeyDerivationPath,
IUtxo,
IWallets,
IWalletStore,
TTransfer,
Expand Down Expand Up @@ -43,13 +38,18 @@ import { updateActivityList } from '../utils/activity';
import {
EAddressType,
EAvailableNetworks,
EBoostType,
EFeeId,
getDefaultWalletData,
getStorageKeyValues,
IAddress,
IBoostedTransaction,
IFormattedTransactions,
IKeyDerivationPath,
IOnchainFees,
IOutput,
ISendTransaction,
IUtxo,
IWalletData,
TSetupTransactionResponse,
} from 'beignet';
Expand Down Expand Up @@ -246,7 +246,7 @@ export const addUnconfirmedTransactions = ({
* FOR TESTING PURPOSES ONLY. DO NOT USE.
* Injects a fake transaction into the store for testing.
* @param {string} [id]
* @param {IFormattedTransaction} [fakeTx]
* @param {IFormattedTransactions} [fakeTx]
* @param {boolean} [shouldRefreshWallet]
* @param {TWalletName} [selectedWallet]
* @param {EAvailableNetwork} [selectedNetwork]
Expand Down
17 changes: 8 additions & 9 deletions src/store/reselect/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { EAddressType, IFormattedTransaction, ISendTransaction } from 'beignet';
import { createSelector } from '@reduxjs/toolkit';

import { RootState } from '..';
import {
IWalletStore,
IWallets,
IWallet,
TWalletName,
EAddressType,
IBoostedTransactions,
IFormattedTransaction,
IFormattedTransactions,
ISendTransaction,
IUtxo,
} from '../types/wallet';
} from 'beignet';
import { createSelector } from '@reduxjs/toolkit';

import { RootState } from '..';
import { IWalletStore, IWallets, IWallet, TWalletName } from '../types/wallet';
import { defaultSendTransaction } from '../shapes/wallet';
import { EAvailableNetwork } from '../../utils/networks';
import { IExchangeRates } from '../../utils/exchange-rate';
Expand Down
34 changes: 9 additions & 25 deletions src/store/shapes/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import { __WALLET_DEFAULT_SELECTED_NETWORK__ } from '../../constants/env';
import { IHeader } from '../../utils/types/electrum';
import { EAvailableNetwork } from '../../utils/networks';
import { objectKeys } from '../../utils/objectKeys';
import { IWalletItem, IWallet, IWalletStore } from '../types/wallet';
import {
IWalletItem,
IWallet,
IWalletStore,
IKeyDerivationPath,
IAddressTypes,
IAddresses,
IAddress,
EAddressType,
EBoostType,
} from '../types/wallet';
import { EAddressType, EFeeId, ISendTransaction } from 'beignet';
EFeeId,
IAddress,
IAddresses,
ISendTransaction,
TAddressTypes,
} from 'beignet';

export const addressTypes: Readonly<IAddressTypes> = {
export const addressTypes: Readonly<TAddressTypes> = {
[EAddressType.p2tr]: {
type: EAddressType.p2tr,
path: "m/86'/0'/0'/0/0",
Expand Down Expand Up @@ -79,13 +78,6 @@ export type IAddressTypeContent<T> = {
[key in EAddressType]: T;
};

export type TAddressIndexInfo = {
addressIndex: IAddress;
changeAddressIndex: IAddress;
lastUsedAddressIndex: IAddress;
lastUsedChangeAddressIndex: IAddress;
};

export const getAddressIndexShape = (): IWalletItem<
IAddressTypeContent<IAddress>
> => {
Expand Down Expand Up @@ -140,14 +132,6 @@ export const defaultAddressContent: Readonly<IAddress> = {
publicKey: '',
};

export const defaultKeyDerivationPath: Readonly<IKeyDerivationPath> = {
purpose: '84',
coinType: '0',
account: '0',
change: '0',
addressIndex: '0',
};

export const defaultHeader: Readonly<IHeader> = {
height: 0,
hash: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
Expand Down
2 changes: 1 addition & 1 deletion src/store/types/activity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EPaymentType } from './wallet';
import { EPaymentType } from 'beignet';

export enum EActivityType {
onchain = 'onchain',
Expand Down
4 changes: 2 additions & 2 deletions src/store/types/checks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IAddress, IWalletItem, TWalletName } from './wallet';
import { IWalletItem, TWalletName } from './wallet';
import { EAvailableNetwork } from '../../utils/networks';
import { TChannel } from '@synonymdev/react-native-ldk';
import { EAddressType } from 'beignet';
import { EAddressType, IAddress } from 'beignet';

export enum EWarningIds {
'storageCheck' = 888,
Expand Down
131 changes: 5 additions & 126 deletions src/store/types/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@ import { IAddressTypeContent } from '../shapes/wallet';
import { IHeader } from '../../utils/types/electrum';
import {
EAddressType,
IFormattedTransaction,
IAddress,
IAddresses,
IBoostedTransactions,
IFormattedTransactions,
ISendTransaction,
IUtxo,
TServer,
} from 'beignet';

export enum EPaymentType {
sent = 'sent',
received = 'received',
}

export type TKeyDerivationAccountType = 'onchain';
export type TKeyDerivationPurpose = '86' | '84' | '49' | '44'; //"p2tr" | "p2wpkh" | "p2sh" | "p2pkh";
export type TKeyDerivationCoinType = '0' | '1'; //"mainnet" | "testnet";
export type TKeyDerivationAccount = '0'; //"On-Chain Wallet";
export type TKeyDerivationChange = '0' | '1'; //"Receiving Address" | "Change Address";
export type TKeyDerivationAddressIndex = string;
export type TAssetType = 'bitcoin' | 'tether';

export enum EConversionUnit {
Expand All @@ -38,77 +32,6 @@ export enum EDenomination {
classic = 'classic',
}

export type TGetByteCountInput =
| `MULTISIG-P2SH:${number}-${number}`
| `MULTISIG-P2WSH:${number}-${number}`
| `MULTISIG-P2SH-P2WSH:${number}-${number}`
| 'P2SH-P2WPKH'
| 'P2PKH'
| 'p2pkh'
| 'P2WPKH'
| 'p2wpkh'
| 'P2SH'
| 'p2sh'
| 'P2TR'
| 'p2tr';

export type TGetByteCountOutput =
| 'P2SH'
| 'P2PKH'
| 'P2WPKH'
| 'P2WSH'
| 'p2wpkh'
| 'p2sh'
| 'p2pkh'
| 'P2TR'
| 'p2tr';

export type TGetByteCountInputs = {
[key in TGetByteCountInput]?: number;
};

export type TGetByteCountOutputs = {
[key in TGetByteCountOutput]?: number;
};

export enum EBoostType {
rbf = 'rbf',
cpfp = 'cpfp',
}

export interface IAddressTypeData {
type: EAddressType;
path: string;
name: string;
shortName: string;
description: string;
example: string;
}

export type IAddressTypes = {
[key in EAddressType]: Readonly<IAddressTypeData>;
};

// m / purpose' / coin_type' / account' / change / address_index
export interface IKeyDerivationPath {
purpose: TKeyDerivationPurpose;
coinType: TKeyDerivationCoinType;
account: TKeyDerivationAccount;
change: TKeyDerivationChange;
addressIndex: TKeyDerivationAddressIndex;
}

export interface IKeyDerivationPathData {
pathString: string;
pathObject: IKeyDerivationPath;
}

export type TProcessUnconfirmedTransactions = {
unconfirmedTxs: IFormattedTransactions; // zero-conf transactions
outdatedTxs: IUtxo[]; // Transactions that are no longer confirmed.
ghostTxs: string[]; // Transactions that have been removed from the mempool.
};

export type TWalletName = `wallet${number}`;

export interface IWalletStore {
Expand All @@ -128,18 +51,6 @@ export interface IWalletItem<T> {
timestamp?: number | null;
}

export interface IAddress {
index: number;
path: string;
address: string;
scriptHash: string;
publicKey: string;
}

export interface IAddresses {
[scriptHash: string]: IAddress;
}

export interface ICreateWallet {
walletName?: TWalletName;
mnemonic: string;
Expand All @@ -152,38 +63,6 @@ export interface ICreateWallet {
servers?: TServer | TServer[];
}

export interface IUtxo {
address: string;
index: number;
path: string;
scriptHash: string;
height: number;
tx_hash: string;
tx_pos: number;
value: number;
}

export interface IOutput {
address: string; // Address to send to.
value: number; // Amount denominated in sats.
index: number; // Used to specify which output to update or edit when using updateSendTransaction.
}

export interface IFormattedTransactions {
[txId: string]: IFormattedTransaction;
}

export interface IBoostedTransaction {
parentTransactions: string[]; // Array of parent txids to the currently boosted transaction.
childTransaction: string; // Child txid of the currently boosted transaction.
type: EBoostType;
fee: number;
}

export interface IBoostedTransactions {
[txId: string]: IBoostedTransaction;
}

export type TTransfer = TTransferToSpending | TTransferToSavings;

export enum ETransferType {
Expand Down
Loading

0 comments on commit 6a55626

Please sign in to comment.