Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: MIT
import { accountsInfo$ } from '@parity/light.js';
import { action, computed, observable } from 'mobx';
import { map } from 'rxjs/operators';
import store from 'store';
import LS_PREFIX from './utils/lsPrefix';
const LS_KEY = `${LS_PREFIX}::firstRun`;
class OnboardingStore {
@observable hasAccounts; // If the user has at least 1 account or not
@observable isFirstRun; // If it's the 1st time the user is running the app
constructor () {
const isFirstRun = store.get(LS_KEY);
if (isFirstRun === undefined) {
// Set store property to true.
this.setIsFirstRun(true);
} else {
this.setIsFirstRun(isFirstRun);
}
accountsInfo$()
.pipe(map(accounts => Object.keys(accounts).length > 0))
.subscribe(this.setHasAccounts);
}
/**
* We show the onboarding process if:
* - either it's the 1st time the user runs this app
* - or the user has 0 account
*/
@computed
get isOnboarding () {
// If either of the two is undefined, then it means we're still fetching.
// This doesn't count as onboarding.
return this.hasAccounts === undefined || this.isFirstRun === undefined
? false
: !this.hasAccounts || this.isFirstRun;
}
@action
setHasAccounts = hasAccounts => {
this.hasAccounts = hasAccounts;
};
@action
setIsFirstRun = isFirstRun => {
this.isFirstRun = isFirstRun;
this.updateLS();
};
updateLS = () => store.set(LS_KEY, this.isFirstRun);
}
export default new OnboardingStore();