1- import React , { memo , ReactElement , useMemo } from 'react' ;
1+ import React , { memo , ReactElement , useCallback , useMemo } from 'react' ;
22import { useTranslation } from 'react-i18next' ;
33import { useAppDispatch , useAppSelector } from '../../../hooks/redux' ;
44
5+ import { ECoinSelectPreference } from 'beignet' ;
56import { EItemType , IListData } from '../../../components/List' ;
6- import { coinSelectAutoSelector } from '../../../store/reselect/settings' ;
7+ import {
8+ coinSelectAutoSelector ,
9+ coinSelectPreferenceSelector ,
10+ } from '../../../store/reselect/settings' ;
711import { updateSettings } from '../../../store/slices/settings' ;
12+ import { updateCoinSelectPreference } from '../../../utils/settings' ;
13+ import { getOnChainWalletAsync } from '../../../utils/wallet' ;
814import SettingsView from '../SettingsView' ;
915
1016const CoinSelectSettings = ( ) : ReactElement => {
1117 const { t } = useTranslation ( 'settings' ) ;
1218 const dispatch = useAppDispatch ( ) ;
1319 const selectedAutoPilot = useAppSelector ( coinSelectAutoSelector ) ;
14- // const coinSelectPreference = useAppSelector(coinSelectPreferenceSelector);
20+ const coinSelectPreference = useAppSelector ( coinSelectPreferenceSelector ) ;
1521
1622 const settingsListData : IListData [ ] = useMemo (
1723 ( ) => [
@@ -22,73 +28,88 @@ const CoinSelectSettings = (): ReactElement => {
2228 title : t ( 'adv.cs_manual' ) ,
2329 value : ! selectedAutoPilot ,
2430 type : EItemType . button ,
25- onPress : ( ) : void => {
31+ onPress : async ( ) : Promise < void > => {
32+ // Update the coin selection preference in beignet.
33+ const wallet = await getOnChainWalletAsync ( ) ;
34+ // Set beignet to consolidate if manual coin control is enabled in Bitkit.
35+ wallet . updateCoinSelectPreference (
36+ ECoinSelectPreference . consolidate ,
37+ ) ;
2638 dispatch ( updateSettings ( { coinSelectAuto : false } ) ) ;
2739 } ,
2840 } ,
2941 {
3042 title : t ( 'adv.cs_auto' ) ,
3143 value : selectedAutoPilot ,
3244 type : EItemType . button ,
33- onPress : ( ) : void => {
45+ onPress : async ( ) : Promise < void > => {
46+ // Update the coin selection preference in beignet.
47+ const wallet = await getOnChainWalletAsync ( ) ;
48+ wallet . updateCoinSelectPreference ( coinSelectPreference ) ;
3449 dispatch ( updateSettings ( { coinSelectAuto : true } ) ) ;
3550 } ,
3651 } ,
3752 ] ,
3853 } ,
39- /*{
40- // TODO: Re-Add and enable this feature once thoroughly tested in Beignet.
41- title: selectedAutoPilot ? t('adv.cs_auto_mode') : '',
42- data: [
43- {
44- title: t('adv.cs_max'),
45- description: t('adv.cs_max_description'),
46- value: coinSelectPreference === 'large',
47- type: EItemType.button,
48- hide: !selectedAutoPilot,
49- onPress: (): void => {
50- dispatch(
51- updateSettings({
52- coinSelectAuto: true,
53- coinSelectPreference: 'large',
54- }),
55- );
54+ {
55+ title : selectedAutoPilot ? t ( 'adv.cs_auto_mode' ) : '' ,
56+ data : [
57+ {
58+ title : t ( 'adv.cs_max' ) ,
59+ description : t ( 'adv.cs_max_description' ) ,
60+ value : coinSelectPreference === ECoinSelectPreference . small ,
61+ type : EItemType . button ,
62+ hide : ! selectedAutoPilot ,
63+ onPress : ( ) : void => {
64+ updateCoinSelectPreference ( ECoinSelectPreference . small ) ;
65+ } ,
66+ } ,
67+ {
68+ title : t ( 'adv.cs_min' ) ,
69+ description : t ( 'adv.cs_min_description' ) ,
70+ value : coinSelectPreference === ECoinSelectPreference . large ,
71+ type : EItemType . button ,
72+ hide : ! selectedAutoPilot ,
73+ onPress : ( ) : void => {
74+ updateCoinSelectPreference ( ECoinSelectPreference . large ) ;
75+ } ,
76+ } ,
77+ {
78+ title : t ( 'adv.cs_consolidate' ) ,
79+ description : t ( 'adv.cs_consolidate_description' ) ,
80+ value : coinSelectPreference === ECoinSelectPreference . consolidate ,
81+ type : EItemType . button ,
82+ hide : ! selectedAutoPilot ,
83+ onPress : ( ) : void => {
84+ updateCoinSelectPreference ( ECoinSelectPreference . consolidate ) ;
85+ } ,
5686 } ,
57- },
58- {
59- title: t('adv.cs_min'),
60- description: t('adv.cs_min_description'),
61- value: coinSelectPreference === 'small',
62- type: EItemType.button,
63- hide: !selectedAutoPilot,
64- onPress: (): void => {
65- dispatch(
66- updateSettings({
67- coinSelectAuto: true,
68- coinSelectPreference: 'small',
69- }),
70- );
87+ {
88+ title : t ( 'adv.cs_first_in_first_out' ) ,
89+ description : t ( 'adv.cs_first_in_first_out_description' ) ,
90+ value :
91+ coinSelectPreference === ECoinSelectPreference . firstInFirstOut ,
92+ type : EItemType . button ,
93+ hide : ! selectedAutoPilot ,
94+ onPress : ( ) : void => {
95+ updateCoinSelectPreference ( ECoinSelectPreference . firstInFirstOut ) ;
96+ } ,
7197 } ,
72- },
73- {
74- title: t('adv.cs_consolidate'),
75- description: t('adv.cs_consolidate_description'),
76- value: coinSelectPreference === 'consolidate',
77- type: EItemType.button,
78- hide: !selectedAutoPilot,
79- onPress: (): void => {
80- dispatch(
81- updateSettings({
82- coinSelectAuto: true,
83- coinSelectPreference: 'consolidate',
84- }),
85- );
98+ {
99+ title : t ( 'adv.cs_last_in_last_out' ) ,
100+ description : t ( 'adv.cs_last_in_last_out_description' ) ,
101+ value :
102+ coinSelectPreference === ECoinSelectPreference . lastInFirstOut ,
103+ type : EItemType . button ,
104+ hide : ! selectedAutoPilot ,
105+ onPress : ( ) : void => {
106+ updateCoinSelectPreference ( ECoinSelectPreference . lastInFirstOut ) ;
107+ } ,
86108 } ,
87- },
88- ],
89- },*/
109+ ] ,
110+ } ,
90111 ] ,
91- [ selectedAutoPilot , t , dispatch ] ,
112+ [ selectedAutoPilot , coinSelectPreference , t , dispatch ] ,
92113 ) ;
93114
94115 return (
0 commit comments