Skip to content

Commit

Permalink
save 'defaultUnit' in shop settings
Browse files Browse the repository at this point in the history
  • Loading branch information
chloehjung15 committed Dec 3, 2023
1 parent edbb96a commit d6b4905
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion contexts/ShopSettingsContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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...');
Expand All @@ -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);
Expand All @@ -69,6 +72,7 @@ const ShopSettingsProvider = ({children}) => {
lndhubUser: lndhubUser?.toString(),
lndhub: lndhub?.toString(),
printer: printer?.toString(),
defaultUnit: defaultUnit?.toString(),
}),
);
currency.getPreferredCurrency().then(async preferred => {
Expand All @@ -83,7 +87,7 @@ const ShopSettingsProvider = ({children}) => {
}
}
saveShopSettings();
}, [shopName, lndhub, lndhubUser, printer]);
}, [shopName, lndhub, lndhubUser, printer, defaultUnit]);

useEffect(() => {
async function initWallet() {
Expand Down Expand Up @@ -134,6 +138,8 @@ const ShopSettingsProvider = ({children}) => {
setShopWallet,
printer,
setPrinter,
defaultUnit,
setDefaultUnit
}}>
{children}
</ShopSettingsContext.Provider>
Expand Down
11 changes: 9 additions & 2 deletions screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function Home({navigation}): React.FC<Props> {
const [lndWallet, setLndWallet] = useState<LightningCustodianWallet>();

//shop settings
const {shopName, lndhub, lndhubUser, printer} =
const {shopName, lndhub, lndhubUser, printer, defaultUnit, setDefaultUnit} =
useContext(ShopSettingsContext);

//PIN
Expand Down Expand Up @@ -672,6 +672,10 @@ function Home({navigation}): React.FC<Props> {
}
}, [inputAmount, selectedUnit, totalAmount]);

useEffect(() => {
setSelectedUnit(defaultUnit);
}, [ defaultUnit ]);

useEffect(() => {
console.log('***** useEffect [pinCode]');
if (pinCode && pinCode.length == 4) {
Expand Down Expand Up @@ -821,7 +825,10 @@ function Home({navigation}): React.FC<Props> {
value={selectedUnit}
items={currencyItems}
setOpen={setOpen}
setValue={setSelectedUnit}
setValue={(value) => {
setSelectedUnit(value);
if(value) setDefaultUnit(value);
}}
// setItems={setItems}
theme={isDarkMode ? 'DARK' : 'LIGHT'}
multiple={false}
Expand Down

0 comments on commit d6b4905

Please sign in to comment.