This commit is contained in:
Marcos Rodriguez Velez 2024-07-24 20:53:40 -04:00
parent 6289485ff9
commit ecfd52393e
No known key found for this signature in database
GPG Key ID: 6030B2F48CCE86D7
3 changed files with 18 additions and 22 deletions

4
package-lock.json generated
View File

@ -69,7 +69,7 @@
"react-native-default-preference": "1.4.4",
"react-native-device-info": "11.1.0",
"react-native-document-picker": "https://github.com/BlueWallet/react-native-document-picker#6033c4e1b0dd0a6760b5f5a5a2c3b2e5d07f2ae4",
"react-native-draggable-flatlist": "github:BlueWallet/react-native-draggable-flatlist#ebfddc4",
"react-native-draggable-flatlist": "github:BlueWallet/react-native-draggable-flatlist#3061e30",
"react-native-fs": "2.20.0",
"react-native-gesture-handler": "2.17.1",
"react-native-handoff": "https://github.com/BlueWallet/react-native-handoff#31d005f93d31099d0e564590a3bbd052b8a02b39",
@ -37441,7 +37441,7 @@
},
"react-native-draggable-flatlist": {
"version": "git+ssh://git@github.com/BlueWallet/react-native-draggable-flatlist.git#ebfddc4877e8f65d5391a748db61b9cd030430ba",
"from": "react-native-draggable-flatlist@github:BlueWallet/react-native-draggable-flatlist#ebfddc4",
"from": "react-native-draggable-flatlist@github:BlueWallet/react-native-draggable-flatlist#3061e30",
"requires": {
"@babel/preset-typescript": "^7.17.12"
}

View File

@ -163,7 +163,7 @@
"react-native-default-preference": "1.4.4",
"react-native-device-info": "11.1.0",
"react-native-document-picker": "https://github.com/BlueWallet/react-native-document-picker#6033c4e1b0dd0a6760b5f5a5a2c3b2e5d07f2ae4",
"react-native-draggable-flatlist": "github:BlueWallet/react-native-draggable-flatlist#ebfddc4",
"react-native-draggable-flatlist": "github:BlueWallet/react-native-draggable-flatlist#3061e30",
"react-native-fs": "2.20.0",
"react-native-gesture-handler": "2.17.1",
"react-native-handoff": "https://github.com/BlueWallet/react-native-handoff#31d005f93d31099d0e564590a3bbd052b8a02b39",

View File

@ -12,6 +12,8 @@ import loc from '../../loc';
import { useStorage } from '../../hooks/context/useStorage';
import useDebounce from '../../hooks/useDebounce';
import { Header } from '../../components/Header';
import { TTXMetadata } from '../../class';
import { TWallet } from '../../class/wallets/types';
const SET_SEARCH_QUERY = 'SET_SEARCH_QUERY';
const SET_IS_SEARCH_FOCUSED = 'SET_IS_SEARCH_FOCUSED';
@ -49,8 +51,8 @@ type Action = SetSearchQueryAction | SetIsSearchFocusedAction | SetWalletDataAct
interface State {
searchQuery: string;
isSearchFocused: boolean;
walletData: any[];
txMetadata: { [key: string]: { memo?: string } };
walletData: TWallet[];
txMetadata: TTXMetadata;
order: any[];
}
@ -122,9 +124,10 @@ const ManageWallets: React.FC = () => {
};
useEffect(() => {
const initialOrder = wallets.map(wallet => ({ type: 'wallet', data: wallet }));
dispatch({ type: SET_WALLET_DATA, payload: wallets });
dispatch({ type: SET_TX_METADATA, payload: txMetadata });
dispatch({ type: SET_ORDER, payload: wallets });
dispatch({ type: SET_ORDER, payload: initialOrder });
}, [wallets, txMetadata]);
const handleClose = useCallback(() => {
@ -163,11 +166,18 @@ const ManageWallets: React.FC = () => {
const filteredTxMetadata = Object.entries(txMetadata).filter(([_, tx]) =>
tx.memo?.toLowerCase().includes(debouncedSearchQuery.toLowerCase()),
);
const filteredOrder = [
...filteredWallets.map(wallet => ({ type: 'wallet', data: wallet })),
...Object.entries(filteredTxMetadata).map(([txid, tx]) => ({ type: 'transaction', data: { txid, ...tx } })),
];
dispatch({ type: SET_WALLET_DATA, payload: filteredWallets });
dispatch({ type: SET_TX_METADATA, payload: Object.fromEntries(filteredTxMetadata) });
dispatch({ type: SET_ORDER, payload: filteredOrder });
} else {
const initialOrder = wallets.map(wallet => ({ type: 'wallet', data: wallet }));
dispatch({ type: SET_WALLET_DATA, payload: wallets });
dispatch({ type: SET_TX_METADATA, payload: {} });
dispatch({ type: SET_ORDER, payload: initialOrder });
}
}, [wallets, txMetadata, debouncedSearchQuery]);
@ -273,13 +283,6 @@ const ManageWallets: React.FC = () => {
const _keyExtractor = useCallback((_item: any, index: number) => index.toString(), []);
const data = state.searchQuery
? [
...state.walletData.map(wallet => ({ type: 'wallet', data: wallet })),
...Object.entries(state.txMetadata).map(([txid, tx]) => ({ type: 'transaction', data: { txid, ...tx } })),
]
: state.walletData.map(wallet => ({ type: 'wallet', data: wallet }));
const renderHeader = useMemo(() => {
if (!state.searchQuery) return null;
const hasWallets = state.walletData.length > 0;
@ -289,9 +292,7 @@ const ManageWallets: React.FC = () => {
<>
{hasWallets && <Header leftText={loc.wallets.wallets} isDrawerList />}
{hasTransactions && <Header leftText={loc.addresses.transactions} isDrawerList />}
{!hasWallets && !hasTransactions && (
<Text style={[styles.noResultsText, stylesHook.noResultsText]}>{loc.wallets.no_results_found}</Text>
)}
{!hasWallets && !hasTransactions && <Text style={stylesHook.noResultsText}>{loc.wallets.no_results_found}</Text>}
</>
);
}, [state.searchQuery, state.walletData.length, state.txMetadata, stylesHook.noResultsText]);
@ -302,7 +303,7 @@ const ManageWallets: React.FC = () => {
ref={sortableList}
contentInsetAdjustmentBehavior="automatic"
automaticallyAdjustContentInsets
data={data}
data={state.order}
keyExtractor={_keyExtractor}
renderItem={renderItem}
onChangeOrder={onChangeOrder}
@ -328,11 +329,6 @@ const styles = StyleSheet.create({
button: {
padding: 16,
},
noResultsText: {
fontSize: 18,
textAlign: 'center',
marginTop: 20,
},
});
const iStyles = StyleSheet.create({