Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit d592547

Browse files
committed
Handle fresh install with no stored settings
1 parent 3ba2069 commit d592547

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/action/app-storage.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ class AppStorage {
99
async restore() {
1010
try {
1111
const stateString = await this._AsyncStorage.getItem('settings');
12+
if (!stateString) return;
1213
const state = JSON.parse(stateString);
13-
state &&
14-
Object.keys(state).forEach(key => {
15-
if (typeof this._store.settings[key] !== 'undefined') {
16-
this._store.settings[key] = state[key];
17-
}
18-
});
19-
log.info('Loaded initial state');
20-
this._store.loaded = true;
14+
Object.keys(state).forEach(key => {
15+
if (typeof this._store.settings[key] !== 'undefined') {
16+
this._store.settings[key] = state[key];
17+
}
18+
});
2119
} catch (err) {
2220
log.error('Store load error', err);
21+
} finally {
22+
log.info('Loaded initial state');
2323
this._store.loaded = true;
2424
}
2525
}

test/unit/action/app-storage.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ describe('Action App Storage Unit Tests', () => {
2525
});
2626

2727
describe('restore()', () => {
28+
it('should use default if nothing is saved yet', async () => {
29+
AsyncStorageStub.getItem.resolves(undefined);
30+
await db.restore(AsyncStorageStub);
31+
expect(store.settings.unit, 'to equal', 'btc');
32+
expect(logger.error, 'was not called');
33+
expect(store.loaded, 'to be', true);
34+
});
35+
2836
it('should set supported setting', async () => {
2937
AsyncStorageStub.getItem
3038
.withArgs('settings')

0 commit comments

Comments
 (0)