diff --git a/contexts/ShopSettingsContext.js b/contexts/ShopSettingsContext.js index 8e69abb..057b38e 100644 --- a/contexts/ShopSettingsContext.js +++ b/contexts/ShopSettingsContext.js @@ -17,6 +17,7 @@ const ShopSettingsProvider = ({children}) => { const [preferredFiatCurrency, _setPreferredFiatCurrency] = useState( FiatUnit.USD, ); + const [defaultUnit, setDefaultUnit] = useState('sats'); const getPreferredCurrency = async () => { const item = await currency.getPreferredCurrency(); @@ -42,6 +43,7 @@ const ShopSettingsProvider = ({children}) => { setLndhubUser(settings.lndhubUser ? settings.lndhubUser : 'blank'); setLndhub(settings.lndhub ? settings.lndhub : 'blank'); setPrinter(settings.printer ? settings.printer : 'bitcoinize'); + setDefaultUnit(settings.defaultUnit ? settings.defaultUnit : 'sats'); console.log('loaded settings...', settings); } else { console.log('using default settings...'); @@ -50,6 +52,7 @@ const ShopSettingsProvider = ({children}) => { setLndhubUser('blank'); setLndhub('blank'); setPrinter('bitcoinize'); + setDefaultUnit('sats'); } } catch (error) { console.error('Failed to get shop name from storage:', error); @@ -69,6 +72,7 @@ const ShopSettingsProvider = ({children}) => { lndhubUser: lndhubUser?.toString(), lndhub: lndhub?.toString(), printer: printer?.toString(), + defaultUnit: defaultUnit?.toString(), }), ); currency.getPreferredCurrency().then(async preferred => { @@ -83,7 +87,7 @@ const ShopSettingsProvider = ({children}) => { } } saveShopSettings(); - }, [shopName, lndhub, lndhubUser, printer]); + }, [shopName, lndhub, lndhubUser, printer, defaultUnit]); useEffect(() => { async function initWallet() { @@ -134,6 +138,8 @@ const ShopSettingsProvider = ({children}) => { setShopWallet, printer, setPrinter, + defaultUnit, + setDefaultUnit }}> {children} diff --git a/screens/Home.tsx b/screens/Home.tsx index fa56bae..393b8cd 100644 --- a/screens/Home.tsx +++ b/screens/Home.tsx @@ -93,7 +93,7 @@ function Home({navigation}): React.FC { const [lndWallet, setLndWallet] = useState(); //shop settings - const {shopName, lndhub, lndhubUser, printer} = + const {shopName, lndhub, lndhubUser, printer, defaultUnit, setDefaultUnit} = useContext(ShopSettingsContext); //PIN @@ -672,6 +672,10 @@ function Home({navigation}): React.FC { } }, [inputAmount, selectedUnit, totalAmount]); + useEffect(() => { + setSelectedUnit(defaultUnit); + }, [ defaultUnit ]); + useEffect(() => { console.log('***** useEffect [pinCode]'); if (pinCode && pinCode.length == 4) { @@ -821,7 +825,10 @@ function Home({navigation}): React.FC { value={selectedUnit} items={currencyItems} setOpen={setOpen} - setValue={setSelectedUnit} + setValue={(value) => { + setSelectedUnit(value); + if(value) setDefaultUnit(value); + }} // setItems={setItems} theme={isDarkMode ? 'DARK' : 'LIGHT'} multiple={false}