Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cb724a7
feat(wallet): add notifications permission to manifest
jinhojang6 Apr 7, 2026
73085df
feat(wallet): add Chrome notifications helper
jinhojang6 Apr 7, 2026
e4bed24
fix(wallet): await chrome.notifications.create and fix vi.mock ordering
jinhojang6 Apr 7, 2026
1e58673
feat(wallet): add background transaction monitor
jinhojang6 Apr 7, 2026
c3e7f74
feat(wallet): register tx-monitor alarm in background service worker
jinhojang6 Apr 7, 2026
f1172e4
fix(wallet): cast storage mock through unknown for TypeScript
jinhojang6 Apr 7, 2026
83989a6
feat(wallet): notify user when transaction is sent
jinhojang6 Apr 7, 2026
b4a74f3
feat(wallet): add settings page with notification toggle
jinhojang6 Apr 7, 2026
aad359f
feat(wallet): add settings navigation and route guard
jinhojang6 Apr 7, 2026
2a74301
fix(wallet): notify confirmation from popup cleanup hook to handle po…
jinhojang6 Apr 7, 2026
1afee5e
fix(wallet): notification quality fixes (precision, disable, dedup, e…
jinhojang6 Apr 7, 2026
d0af15f
chore(wallet): regenerate onboarding route token after settings route…
jinhojang6 Apr 7, 2026
9776c18
fix(wallet): update pending transaction handling to use async/await f…
jinhojang6 Apr 8, 2026
583fff4
chore: add changeset for browser notifications for wallet transactions
jinhojang6 Apr 8, 2026
8489c3e
refactor(wallet): streamline pending transactions handling and improv…
jinhojang6 Apr 9, 2026
50ec9f0
refactor(wallet): enhance settings page layout and add back navigation
jinhojang6 Apr 9, 2026
3a34085
fix(wallet): improve error handling for notifications and transaction…
jinhojang6 Apr 9, 2026
f0d18bd
fix(wallet): add hasPendingTransactions check before processing pendi…
jinhojang6 Apr 13, 2026
b9e3add
refactor(wallet): optimize pending transactions handling and receipt …
jinhojang6 Apr 13, 2026
cc88d85
refactor(wallet): consolidate transaction hash extraction logic into …
jinhojang6 Apr 13, 2026
fe50c3a
refactor(notifications): unify notification creation logic and simpli…
jinhojang6 Apr 13, 2026
69f43be
feat(wallet): dynamic tx monitor alarm - start on pending, clear when…
jinhojang6 Apr 13, 2026
710a580
test(wallet): remove outdated tx-monitor tests
jinhojang6 Apr 13, 2026
33eda97
Merge branch 'main' into wallet-notifications
jinhojang6 Apr 13, 2026
effa64c
Merge branch 'main' into wallet-notifications
jinhojang6 Apr 14, 2026
6a1b96e
refactor(tx-monitor): extract interval constant for alarm creation
jinhojang6 Apr 14, 2026
1458916
fix: pass network parameter to fetchNetworkNonce in getNonceHex function
jinhojang6 Apr 15, 2026
54acb45
feat(notifications): implement notification permission check and stor…
jinhojang6 Apr 15, 2026
3c0dac0
fix(settings): add gap between notification toggle and description
jinhojang6 Apr 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/amber-tulips-sprint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wallet': patch
---

add browser notifications for wallet transactions
19 changes: 19 additions & 0 deletions apps/wallet/src/entrypoints/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../../.wxt/wxt.d.ts" />

import { storage } from '@wxt-dev/storage'
import { Buffer } from 'buffer'
import { defineBackground } from 'wxt/sandbox'

Expand All @@ -14,6 +15,12 @@ import { INACTIVITY_ALARM_NAME, lock } from '../data/session'
import { getWalletCore } from '../data/wallet'
import { RpcMessage } from '../lib/messages'
import { handleRpcRequest } from '../lib/rpc-handler'
import { PENDING_TXS_KEY } from '../lib/storage-keys'
import {
checkPendingTransactions,
startTxMonitor,
TX_MONITOR_ALARM,
} from '../lib/tx-monitor'

export default defineBackground({
type: 'module',
Expand Down Expand Up @@ -41,6 +48,18 @@ export default defineBackground({

chrome.alarms.onAlarm.addListener(alarm => {
if (alarm.name === INACTIVITY_ALARM_NAME) lock()
if (alarm.name === TX_MONITOR_ALARM) {
void checkPendingTransactions().catch(error => {
console.error('Failed to check pending transactions', error)
})
}
})

// Start tx monitor alarm when pending transactions are added
storage.watch<unknown[]>(PENDING_TXS_KEY, pendingTxs => {
if (pendingTxs && pendingTxs.length > 0) {
void startTxMonitor()
}
})

chrome.runtime.onInstalled.addListener(() => {
Expand Down
22 changes: 22 additions & 0 deletions apps/wallet/src/hooks/use-notification-permission-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect } from 'react'

import { useToast } from '@status-im/components'
import { storage } from '@wxt-dev/storage'

import { NOTIFICATION_PROMPTED_KEY } from '../lib/storage-keys'

export function useNotificationPermissionCheck() {
const toast = useToast()

useEffect(() => {
storage.getItem<boolean>(NOTIFICATION_PROMPTED_KEY).then(prompted => {
if (prompted) return

storage.setItem(NOTIFICATION_PROMPTED_KEY, true)
toast.positive(
'To receive transaction alerts, make sure notifications are enabled for this browser in System Settings.',
)
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
}
58 changes: 58 additions & 0 deletions apps/wallet/src/lib/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { storage } from '@wxt-dev/storage'

import { NOTIFICATIONS_ENABLED_KEY } from './storage-keys'

async function isEnabled(): Promise<boolean> {
try {
return (await storage.getItem<boolean>(NOTIFICATIONS_ENABLED_KEY)) ?? true
} catch (error) {
console.warn('Failed to read notification setting', error)
return true
}
}

async function createNotification(
title: string,
message: string,
): Promise<boolean> {
try {
Comment thread
jinhojang6 marked this conversation as resolved.
if (!(await isEnabled())) return false
chrome.notifications.create({
type: 'basic',
iconUrl: chrome.runtime.getURL('icons/128.png'),
title,
message,
})
return true
} catch (error) {
console.warn('Failed to create notification', error)
return false
}
}

export async function notifyTransactionSent(
amount: string,
asset: string,
): Promise<boolean> {
return createNotification('Transaction Sent', `Sending ${amount} ${asset}…`)
}

export async function notifyTransactionConfirmed(
amount: string,
asset: string,
): Promise<boolean> {
return createNotification(
'Transaction Confirmed',
`${amount} ${asset} sent successfully`,
)
}

export async function notifyTransactionFailed(
amount: string,
asset: string,
): Promise<boolean> {
return createNotification(
'Transaction Failed',
`${amount} ${asset} transaction failed`,
)
}
5 changes: 5 additions & 0 deletions apps/wallet/src/lib/storage-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const NOTIFICATIONS_ENABLED_KEY = 'local:notifications:enabled' as const
export const TX_NOTIFIED_KEY = 'local:tx-monitor:notified' as const
export const PENDING_TXS_KEY =
'local:pending-transactions:transactions' as const
export const NOTIFICATION_PROMPTED_KEY = 'local:notifications:prompted' as const
13 changes: 13 additions & 0 deletions apps/wallet/src/lib/tx-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function extractTxHash(hash: unknown): string | null {
if (typeof hash === 'string') return hash
if (hash && typeof hash === 'object') {
const obj = hash as Record<string, unknown>
if ('result' in obj && typeof obj.result === 'string') return obj.result
if ('txid' in obj && typeof obj.txid === 'string') return obj.txid
}
return null
}

export function truncateAddress(address: string, chars = 5): string {
return `${address.slice(0, chars)}...${address.slice(-chars)}`
}
126 changes: 126 additions & 0 deletions apps/wallet/src/lib/tx-monitor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { storage } from '@wxt-dev/storage'

import {
notifyTransactionConfirmed,
notifyTransactionFailed,
} from './notifications'
import { PENDING_TXS_KEY, TX_NOTIFIED_KEY } from './storage-keys'
import { extractTxHash } from './tx-helpers'

type PendingTx = {
hash: unknown
value: number
asset: string
displayAmount?: string
}

async function fetchReceipt(
txHash: string,
): Promise<{ status: string } | null> {
try {
const url = `${import.meta.env.WXT_STATUS_API_URL}/api/trpc/rpc.proxy`
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
json: {
method: 'eth_getTransactionReceipt',
params: [txHash],
id: 1,
chainId: 1,
},
}),
})
const body = (await res.json()) as {
result: { data: { json: { result: { status: string } | null } } }
}
return body.result.data.json.result
} catch {
return null
}
}

export const TX_MONITOR_ALARM = 'tx-monitor'
// 0.5 minutes = 30 seconds, minimum allowed by Chrome MV3
const TX_MONITOR_INTERVAL_MINUTES = 0.5

export async function startTxMonitor(): Promise<void> {
const existing = await chrome.alarms.get(TX_MONITOR_ALARM)
if (!existing) {
chrome.alarms.create(TX_MONITOR_ALARM, {
periodInMinutes: TX_MONITOR_INTERVAL_MINUTES,
})
}
}

export async function checkPendingTransactions(): Promise<void> {
const pendingTxs = (await storage.getItem<PendingTx[]>(PENDING_TXS_KEY)) ?? []

if (pendingTxs.length === 0) {
await chrome.alarms.clear(TX_MONITOR_ALARM)
const notified = await storage.getItem<string[]>(TX_NOTIFIED_KEY)
if (Array.isArray(notified) && notified.length > 0) {
await storage.setItem(TX_NOTIFIED_KEY, [])
}
return
}

const notified = (await storage.getItem<string[]>(TX_NOTIFIED_KEY)) ?? []
const notifiedSet = new Set(notified)
const newlyNotified: string[] = []
const settledHashes = new Set<string>()

const receipts = await Promise.all(
pendingTxs.map(tx => {
const txHash = extractTxHash(tx.hash)
return txHash
? fetchReceipt(txHash).then(r => ({ tx, txHash, receipt: r }))
: null
}),
)

for (const entry of receipts) {
if (!entry || !entry.receipt) continue

const { tx, txHash, receipt } = entry
const alreadyNotified = notifiedSet.has(txHash)
const amount = tx.displayAmount ?? String(tx.value)
const asset = tx.asset ?? 'ETH'

if (receipt.status === '0x1') {
if (!alreadyNotified) {
const fired = await notifyTransactionConfirmed(amount, asset)
if (fired) {
newlyNotified.push(txHash)
notifiedSet.add(txHash)
}
}
settledHashes.add(txHash)
} else if (receipt.status === '0x0') {
if (!alreadyNotified) {
const fired = await notifyTransactionFailed(amount, asset)
if (fired) {
newlyNotified.push(txHash)
notifiedSet.add(txHash)
}
}
settledHashes.add(txHash)
}
}

if (settledHashes.size > 0) {
const remaining = pendingTxs.filter(tx => {
const txHash = extractTxHash(tx.hash)
return !txHash || !settledHashes.has(txHash)
})
await storage.setItem(PENDING_TXS_KEY, remaining)

if (remaining.length === 0) {
await chrome.alarms.clear(TX_MONITOR_ALARM)
}
}

if (newlyNotified.length > 0) {
await storage.setItem(TX_NOTIFIED_KEY, [...notified, ...newlyNotified])
}
}
11 changes: 6 additions & 5 deletions apps/wallet/src/providers/pending-transactions-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Activity = ApiOutput['activities']['activities']['activities'][0]
type PendingTransaction = Activity & {
status: 'pending'
uniqueId: string
displayAmount?: string
}

type PendingTransactionsContext = {
Expand Down Expand Up @@ -68,11 +69,11 @@ export function PendingTransactionsProvider({
}, [storage])

useEffect(() => {
if (!isLoading) {
storage.set({ transactions: pendingTransactions }).catch(error => {
console.error('Failed to save pending transactions:', error)
})
}
if (isLoading) return

storage.set({ transactions: pendingTransactions }).catch(error => {
console.error('Failed to save pending transactions:', error)
})
}, [pendingTransactions, storage, isLoading])

const addPendingTransaction = (
Expand Down
18 changes: 2 additions & 16 deletions apps/wallet/src/providers/signer-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { type Address, createPublicClient, type Hex, http } from 'viem'
import { mainnet } from 'viem/chains'
import { formatEther } from 'viem/utils'

import { extractTxHash } from '@/lib/tx-helpers'

import { apiClient } from './api-client'
import { usePassword } from './password-context'
import { useWallet } from './wallet-context'
Expand Down Expand Up @@ -190,22 +192,6 @@ export function SignerProvider({ children }: { children: React.ReactNode }) {
}
}

const extractTxHash = (id: unknown): string | undefined => {
if (typeof id === 'string') {
return id
}
if (id && typeof id === 'object') {
const obj = id as Record<string, unknown>
if ('result' in obj && typeof obj.result === 'string') {
return obj.result
}
if ('txid' in obj) {
return obj.txid as string
}
}
return undefined
}

if (tx.data) {
const ERC20_TRANSFER_SIGNATURE = '0xa9059cbb'
const isErc20Transfer = tx.data
Expand Down
Loading
Loading