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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
import { browser } from "$app/environment";
import { writable, type Writable } from "svelte/store";
export const persistSession = (key, defaultValue = undefined) => {
const s = writable(
browser && sessionStorage.getItem(key) && sessionStorage.getItem(key) !== "undefined"
? JSON.parse(sessionStorage.getItem(key) || "")
: defaultValue,
);
s.subscribe((v) => {
browser && sessionStorage.setItem(key, JSON.stringify(v));
});
return s;
};
export const persistLocal = (key, defaultValue: any = undefined) => {
const s = writable(
browser && localStorage.getItem(key) && localStorage.getItem(key) !== "undefined"
? JSON.parse(localStorage.getItem(key) || "")
: defaultValue,
);
s.subscribe((v) => {
try {
if (browser) {
if (v) {
localStorage.setItem(key, JSON.stringify(v));
} else {
localStorage.removeItem(key);
}
}
} catch (e) {
console.log("problem setting key", v);
console.log(e);
}
});
return s;
};
export const persistLocalValue = (key, defaultValue: any = undefined) => {
const s = writable(
browser && localStorage.getItem(key) && localStorage.getItem(key) !== "undefined"
? JSON.parse(localStorage.getItem(key) || "")
: defaultValue,
);
s.subscribe((v) => {
try {
if (browser) {
if (v === undefined) {
localStorage.removeItem(key);
} else {
localStorage.setItem(key, JSON.stringify(v));
}
}
} catch (e) {
console.log("problem setting key", v);
console.log(e);
}
});
return s;
};
export const account = writable();
export const amountPrompt = persistLocal("amountPrompt");
export const avatar = writable();
export const banner = writable();
export const event = writable();
export const events = writable({});
export const fiat = persistLocalValue("fiat", false);
export const installPrompt: Writable<any> = writable();
export const invoice = writable();
export const last = writable();
export const loginRedirect = writable();
export const decrypted = persistLocal("decrypted", {});
export const ignore = persistLocal("ignore", []);
export const mnemonic = persistSession("mnemonic");
export const newPayment = persistLocal("newPayment");
export const password = writable<string | undefined>();
export const passwordPrompt = writable();
export const eventToSign = writable();
export const pubkey = persistLocal("pubkey");
export const signer = persistLocal("signer");
export const camera = persistLocal("camera");
export const selectSigner = writable();
export const pin = persistLocal("pin");
export const rate = writable();
export const request = writable();
export const requestRedirect = writable();
export const theme = writable("light");
export const token = persistSession("token");
export const ndef = writable();
export const showQr = persistLocal("showQr", true);
export const save = writable();
export const importing = writable(new Set<string>());
export const paymentSignal = writable(0);
export const lastPayment = writable<{ iid: string; amount: number; confirmed: boolean } | null>(
null,
);
export const cachedUser = persistLocal("cachedUser");
export const cachedAccounts = persistLocal("cachedAccounts", []);
export const cachedPayments = persistLocal("cachedPayments", []);
export const cachedRates = persistLocal("cachedRates");
export const offline = writable(false);
export const unreadDMs = writable(0);
|