Handle migration to new zap settings

This commit is contained in:
Bojan Mojsilovic 2024-01-23 12:49:01 +01:00
parent 75aff15861
commit f79328b896

View File

@ -392,8 +392,23 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
} = JSON.parse(content?.content);
theme && setThemeByName(theme, true);
zapDefault && setDefaultZapAmount(zapDefault, true);
zapConfig && updateStore('availableZapOptions', () => zapConfig);
// If new setting is missing, merge with the old setting
if (zapDefault) {
setDefaultZapAmount(zapDefault, true);
}
else {
setDefaultZapAmount({ ...defaultZap, amount: defaultZapAmount }, true);
}
// If new setting is missing, merge with the old setting
if (zapConfig) {
updateStore('availableZapOptions', () => [...zapConfig]);
}
else {
const newConfig = defaultZapOptions.map((o, i) => ({ ...o, amount: zapOptions[i]}));
updateStore('availableZapOptions', () => [...newConfig]);
}
updateStore('defaultZapAmountOld' , () => defaultZapAmount);
updateStore('zapOptionsOld', () => zapOptions);