Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show All 12 Lines | import { | ||||
addNewHydratedUtxos, | addNewHydratedUtxos, | ||||
removeConsumedUtxos, | removeConsumedUtxos, | ||||
areAllUtxosIncludedInIncrementallyHydratedUtxos, | areAllUtxosIncludedInIncrementallyHydratedUtxos, | ||||
getHashArrayFromWallet, | getHashArrayFromWallet, | ||||
parseChronikTx, | parseChronikTx, | ||||
checkWalletForTokenInfo, | checkWalletForTokenInfo, | ||||
isActiveWebsocket, | isActiveWebsocket, | ||||
} from 'utils/cashMethods'; | } from 'utils/cashMethods'; | ||||
import { isValidCashtabSettings, isValidContactList } from 'utils/validation'; | import { | ||||
isValidCashtabSettings, | |||||
isValidContactList, | |||||
parseInvalidSettingsForMigration, | |||||
} from 'utils/validation'; | |||||
import localforage from 'localforage'; | import localforage from 'localforage'; | ||||
import { currency } from 'components/Common/Ticker'; | import { currency } from 'components/Common/Ticker'; | ||||
import isEmpty from 'lodash.isempty'; | import isEmpty from 'lodash.isempty'; | ||||
import isEqual from 'lodash.isequal'; | import isEqual from 'lodash.isequal'; | ||||
import { | import { | ||||
xecReceivedNotification, | xecReceivedNotification, | ||||
xecReceivedNotificationWebsocket, | xecReceivedNotificationWebsocket, | ||||
eTokenReceivedNotification, | eTokenReceivedNotification, | ||||
▲ Show 20 Lines • Show All 1,114 Lines • ▼ Show 20 Lines | const loadCashtabSettings = async () => { | ||||
setCashtabSettings(currency.defaultSettings); | setCashtabSettings(currency.defaultSettings); | ||||
return currency.defaultSettings; | return currency.defaultSettings; | ||||
} | } | ||||
// If you found an object in localforage at the settings key, make sure it's valid | // If you found an object in localforage at the settings key, make sure it's valid | ||||
if (isValidCashtabSettings(localSettings)) { | if (isValidCashtabSettings(localSettings)) { | ||||
setCashtabSettings(localSettings); | setCashtabSettings(localSettings); | ||||
return localSettings; | return localSettings; | ||||
} | } | ||||
// If a settings object is present but invalid, parse to find and add missing keys | |||||
let modifiedLocalSettings = | |||||
parseInvalidSettingsForMigration(localSettings); | |||||
if (isValidCashtabSettings(modifiedLocalSettings)) { | |||||
// modifiedLocalSettings placed in local storage | |||||
localforage.setItem('settings', modifiedLocalSettings); | |||||
setCashtabSettings(modifiedLocalSettings); | |||||
// update missing key in local storage without overwriting existing valid settings | |||||
return modifiedLocalSettings; | |||||
} else { | |||||
// if not valid, also set cashtabSettings to default | // if not valid, also set cashtabSettings to default | ||||
setCashtabSettings(currency.defaultSettings); | setCashtabSettings(currency.defaultSettings); | ||||
// localforage not needed as function will continue until localSettings are valid | |||||
bytesofman: Replace comment
```
// Since this is returning default settings based on an error from reading… | |||||
return currency.defaultSettings; | return currency.defaultSettings; | ||||
} | |||||
}; | }; | ||||
const loadContactList = async () => { | const loadContactList = async () => { | ||||
// get contactList object from localforage | // get contactList object from localforage | ||||
let localContactList; | let localContactList; | ||||
try { | try { | ||||
localContactList = await localforage.getItem('contactList'); | localContactList = await localforage.getItem('contactList'); | ||||
// If there is no keyvalue pair in localforage with key 'settings' | // If there is no keyvalue pair in localforage with key 'settings' | ||||
▲ Show 20 Lines • Show All 326 Lines • Show Last 20 Lines |
Replace comment