forked from tahowallet/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground-ui.ts
43 lines (38 loc) · 1.54 KB
/
background-ui.ts
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
// TODO This is meant to do UI notifications, but is incomplete.
/* import { browser, newProxyStore } from "@tallyho/tally-background"
newProxyStore().then((backgroundStore) => {
// undefined if no account has been resolved, string array with the latest
// activity hashes if it has.
let latestActivityHashes: Set<string> | undefined
backgroundStore.subscribe(() => {
const state = backgroundStore.getState()
const {
combinedData: { totalMainCurrencyValue, activity: updatedActivity },
} = state.account
if (updatedActivity) {
// Undefined activity hashes means we're initializing. Otherwise, notify
// for any new activity.
if (typeof latestActivityHashes === "undefined") {
latestActivityHashes = new Set()
} else {
const newActivity = updatedActivity.filter(
({ hash }) => latestActivityHashes?.has(hash) || false
)
browser.notifications.create("balance-update", {
type: "basic",
title: "Balance Update",
message: `<address> has balance ${totalMainCurrencyValue}`,
contextMessage: `${newActivity.length} transactions have updated the balance for <address> to ${totalMainCurrencyValue}`,
})
}
latestActivityHashes = updatedActivity.reduce(
(acc, { hash }) => acc.add(hash),
latestActivityHashes
)
} else {
// Account has been cleared, reset activity hashes so they can be
// reinitialized next time the account is set.
latestActivityHashes = undefined
}
})
}) */