-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/app/common/monitor-confirmations/monitor-confirmations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { PendingConfirmation } from '@app/common/monitor-confirmations/monitor-confirmations'; | ||
|
||
async function monitorTransactions() { | ||
const alarm = await chrome.alarms.get('transaction-monitor'); | ||
|
||
if (!alarm) { | ||
await chrome.alarms.create('transaction-monitor', { | ||
periodInMinutes: 0.05, | ||
}); | ||
} | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
monitorTransactions().catch(error => console.error(error)); | ||
|
||
const MONITORED_TXNS_KEY = 'monitoredTransactions'; | ||
|
||
interface PendingConfirmationStore { | ||
pendingConfirmations: PendingConfirmation[]; | ||
} | ||
|
||
export async function readTransactionStore() { | ||
const { pendingConfirmations = [] } = chrome.storage.local.get( | ||
MONITORED_TXNS_KEY | ||
) as unknown as PendingConfirmationStore; | ||
|
||
return pendingConfirmations; | ||
} | ||
|
||
export async function writeTransaction(pendingConfirmation: PendingConfirmation) { | ||
const exisitingPendingConfirmations = await readTransactionStore(); | ||
return await chrome.storage.local.set({ | ||
[MONITORED_TXNS_KEY]: [pendingConfirmation, ...exisitingPendingConfirmations], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters