1 import { useCallback, useEffect } from 'react';
3 import { createSelector } from '@reduxjs/toolkit';
5 import { type WasmApiWalletBitcoinAddress } from '@proton/andromeda';
6 import { baseUseSelector } from '@proton/react-redux-store';
7 import { CacheType, createHooks } from '@proton/redux-utilities';
9 import { bitcoinAddressPoolThunk, selectBitcoinAddressPool } from '../slices';
11 const hooks = createHooks(bitcoinAddressPoolThunk, selectBitcoinAddressPool);
13 export const useGetBitcoinAddressPool = () => {
14 const get = hooks.useGet();
17 async (walletId: string, walletAccountId: string) => {
18 const results = await get({ thunkArg: [walletId, walletAccountId], cache: CacheType.None });
19 return results[walletAccountId] ?? [];
25 export const useBitcoinAddressPool = (walletId: string, walletAccountId: string) => {
26 const getBitcoinAddressPool = useGetBitcoinAddressPool();
27 const [, loading] = hooks.useValue();
29 const bitcoinAddressPoolSelector = createSelector(
30 selectBitcoinAddressPool,
31 (result): [WasmApiWalletBitcoinAddress[] | undefined, boolean] => {
32 const { value } = result;
34 const addresses = value?.[walletAccountId];
36 return [addresses, loading];
41 void getBitcoinAddressPool(walletId, walletAccountId);
42 }, [walletId, walletAccountId]);
44 return baseUseSelector(bitcoinAddressPoolSelector);