-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.js
More file actions
29 lines (24 loc) · 813 Bytes
/
sample.js
File metadata and controls
29 lines (24 loc) · 813 Bytes
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
// Get the existing data
const existing = localStorage.getItem(`account:${val.receiverAddress}`);
// if existing data, update value
if(existing) {
const data = JSON.parse(existing);
const lastTime = data.time;
if (((new Date()).getTime() - lastTime) > 1000 * 60 * 60 * 24) {
window.localStorage.removeItem(`account:${val.receiverAddress}`);
}
const Object = {
address: val.receiverAddress,
value: val.amount,
time: (new Date()).getTime()
}
window.localStorage.setItem(`account:${val.receiverAddress}`, JSON.stringify(Object));
} else {
// if !existing data, add new data
const Object = {
address: val.receiverAddress,
value: val.amount,
time: (new Date()).getTime()
}
window.localStorage.setItem(`account:${val.receiverAddress}`, JSON.stringify(Object));
}