@bsv/expo-wallet-toolbox 0.11.7 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -0
- package/core/config.tsx +1 -1
- package/core/context/WalletContext.tsx +171 -19
- package/core/i18n/translations.tsx +120 -12
- package/core/index.ts +2 -0
- package/core/pay/beefRepair.ts +8 -3
- package/core/pay/rails/address.ts +43 -3
- package/core/pay/rails/handle.ts +1 -1
- package/core/pay/sweeper.ts +39 -4
- package/core/push/events.ts +142 -0
- package/core/push/pushAdvisory.ts +33 -0
- package/core/push/registration.ts +53 -0
- package/core/push/types.ts +31 -0
- package/core/toolboxConfig.ts +24 -1
- package/package.json +1 -1
- package/ui/components/pay/HandleReceive.tsx +141 -16
- package/ui/components/pay/NotificationAdvisoryModal.tsx +124 -0
- package/ui/components/ui/PermissionSheet.tsx +53 -8
- package/ui/index.ts +1 -0
- package/ui/screens/PayScreen.tsx +53 -0
- package/ui/screens/SettingsScreen.tsx +72 -2
package/ui/screens/PayScreen.tsx
CHANGED
|
@@ -46,6 +46,9 @@ import { useAssetStatus, useMandala } from '../hooks/useMandala'
|
|
|
46
46
|
import { formatTokenAmountWithUnit } from '../tokenFormat'
|
|
47
47
|
import { nearbyAdvisory } from '../../core/localpay/nearbyAdvisory'
|
|
48
48
|
import { NearbyAdvisoryModal } from '../components/pay/NearbyAdvisoryModal'
|
|
49
|
+
import { pushAdvisory } from '../../core/push/pushAdvisory'
|
|
50
|
+
import { getPushAdapter } from '../../core/toolboxConfig'
|
|
51
|
+
import { NotificationAdvisoryModal, shouldShowNotificationAdvisory } from '../components/pay/NotificationAdvisoryModal'
|
|
49
52
|
import type { DismissTarget } from '../dismissTarget'
|
|
50
53
|
|
|
51
54
|
/**
|
|
@@ -298,6 +301,35 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
298
301
|
}, [])
|
|
299
302
|
const isNearbyCell = (direction === 'pay' && nearbySession !== null) || method === 'get-nearby'
|
|
300
303
|
|
|
304
|
+
// ── notification advisory ───────────────────────────────────────────
|
|
305
|
+
/**
|
|
306
|
+
* The first time the user picks "Share remote link", the OS will be asked to
|
|
307
|
+
* allow notifications (so a payment can reach them while the app is in the
|
|
308
|
+
* background). The advisory goes first, over the link flow — which keeps
|
|
309
|
+
* mounting underneath and never waits on the answer. null = not loaded yet
|
|
310
|
+
* (show nothing rather than flash it at a returning user); both stay null
|
|
311
|
+
* until the user first lands on the remote-link method.
|
|
312
|
+
*/
|
|
313
|
+
const [pushAdvisorySeen, setPushAdvisorySeen] = useState<boolean | null>(null)
|
|
314
|
+
const [pushPermission, setPushPermission] = useState<'granted' | 'denied' | 'undetermined' | null>(null)
|
|
315
|
+
useEffect(() => {
|
|
316
|
+
if (method !== 'get-handle' || pushAdvisorySeen !== null) return
|
|
317
|
+
let cancelled = false
|
|
318
|
+
const adapter = getPushAdapter()
|
|
319
|
+
void Promise.all([pushAdvisory.get(), adapter ? adapter.getPermission() : Promise.resolve(null)])
|
|
320
|
+
.then(([seen, perm]) => {
|
|
321
|
+
if (cancelled) return
|
|
322
|
+
setPushAdvisorySeen(seen)
|
|
323
|
+
setPushPermission(perm)
|
|
324
|
+
})
|
|
325
|
+
.catch(() => {
|
|
326
|
+
// Advisory only: a host adapter that cannot report its permission just means no modal.
|
|
327
|
+
})
|
|
328
|
+
return () => {
|
|
329
|
+
cancelled = true
|
|
330
|
+
}
|
|
331
|
+
}, [method, pushAdvisorySeen])
|
|
332
|
+
|
|
301
333
|
// Refreshed whenever the wallet finishes building, connectivity changes, or
|
|
302
334
|
// the user enters/leaves a method or a nearby session: the queue only moves
|
|
303
335
|
// when the network state does or when one of those just queued a row (e.g.
|
|
@@ -595,6 +627,27 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
595
627
|
setNearbyAdvisorySeen(true)
|
|
596
628
|
}}
|
|
597
629
|
/>
|
|
630
|
+
<NotificationAdvisoryModal
|
|
631
|
+
visible={shouldShowNotificationAdvisory({
|
|
632
|
+
method,
|
|
633
|
+
advisorySeen: pushAdvisorySeen,
|
|
634
|
+
permission: pushPermission
|
|
635
|
+
})}
|
|
636
|
+
onNotNow={() => {
|
|
637
|
+
void pushAdvisory.set()
|
|
638
|
+
setPushAdvisorySeen(true)
|
|
639
|
+
}}
|
|
640
|
+
onContinue={() => {
|
|
641
|
+
void pushAdvisory.set()
|
|
642
|
+
setPushAdvisorySeen(true)
|
|
643
|
+
void getPushAdapter()
|
|
644
|
+
?.requestPermission()
|
|
645
|
+
.then(setPushPermission)
|
|
646
|
+
.catch(() => {
|
|
647
|
+
// The link flow does not depend on the answer; Task 7's sync reads the permission itself.
|
|
648
|
+
})
|
|
649
|
+
}}
|
|
650
|
+
/>
|
|
598
651
|
</View>
|
|
599
652
|
)
|
|
600
653
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState, useEffect, useCallback } from 'react'
|
|
2
|
-
import { View, Text, ScrollView, StyleSheet } from 'react-native'
|
|
2
|
+
import { View, Text, ScrollView, StyleSheet, AppState } from 'react-native'
|
|
3
3
|
import { useTranslation } from 'react-i18next'
|
|
4
4
|
import { useTheme, spacing, typography, useWallet, isVaultAvailable, useVault } from '@bsv/expo-wallet-toolbox'
|
|
5
5
|
import { GroupedSection } from '../components/ui/GroupedList'
|
|
@@ -7,6 +7,9 @@ import { ListRow } from '../components/ui/ListRow'
|
|
|
7
7
|
import AmountDisplay from '../components/wallet/AmountDisplay'
|
|
8
8
|
import { sdk } from '@bsv/wallet-toolbox-mobile'
|
|
9
9
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
10
|
+
import { pushAdvisory } from '../../core/push/pushAdvisory'
|
|
11
|
+
import type { PushPermission } from '../../core/push/types'
|
|
12
|
+
import { getPushAdapter } from '../../core/toolboxConfig'
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* expo-router is required lazily rather than imported at module scope: this
|
|
@@ -31,7 +34,9 @@ const CACHE_DURATION = 30000
|
|
|
31
34
|
export function SettingsScreen() {
|
|
32
35
|
const { t } = useTranslation()
|
|
33
36
|
const { colors } = useTheme()
|
|
34
|
-
|
|
37
|
+
// `useFocusEffect` is a hook, but calling it through the lazy loader is
|
|
38
|
+
// equivalent to a direct import (same as WalletHomeScreen/PayScreen).
|
|
39
|
+
const { router, useFocusEffect } = loadExpoRouter()
|
|
35
40
|
const { managers, adminOriginator, selectedNetwork, txStatusVersion } = useWallet()
|
|
36
41
|
|
|
37
42
|
// Read during render, from the reactive network, so the row disappears on a
|
|
@@ -110,6 +115,57 @@ export function SettingsScreen() {
|
|
|
110
115
|
refreshBalance()
|
|
111
116
|
}, [txStatusVersion, refreshBalance])
|
|
112
117
|
|
|
118
|
+
// Payment notifications. The row exists only when the host wired a push
|
|
119
|
+
// adapter, and it is the one place besides the "Share remote link" advisory
|
|
120
|
+
// that can trigger the OS permission prompt.
|
|
121
|
+
const pushAdapter = getPushAdapter()
|
|
122
|
+
const [pushPermission, setPushPermission] = useState<PushPermission | null>(null)
|
|
123
|
+
const refreshPushPermission = useCallback(async () => {
|
|
124
|
+
if (!pushAdapter) return
|
|
125
|
+
try {
|
|
126
|
+
const next = await pushAdapter.getPermission()
|
|
127
|
+
// A re-read never walks 'denied' back to 'undetermined'. Android reports
|
|
128
|
+
// every not-granted state as 'undetermined', and the OS dialog's own
|
|
129
|
+
// dismissal brings the app back to 'active' right after a denial, so an
|
|
130
|
+
// unguarded read would erase the denial and leave the next press
|
|
131
|
+
// re-requesting (a silent no-op once the OS stops prompting) instead of
|
|
132
|
+
// opening the OS settings. A later 'granted' still replaces 'denied'.
|
|
133
|
+
setPushPermission(prev => (prev === 'denied' && next === 'undetermined' ? prev : next))
|
|
134
|
+
} catch {
|
|
135
|
+
// Leave the last known state; the row stays usable.
|
|
136
|
+
}
|
|
137
|
+
}, [pushAdapter])
|
|
138
|
+
useFocusEffect(
|
|
139
|
+
useCallback(() => {
|
|
140
|
+
void refreshPushPermission()
|
|
141
|
+
}, [refreshPushPermission])
|
|
142
|
+
)
|
|
143
|
+
// Coming back from the OS notification settings does not refocus this
|
|
144
|
+
// screen, so re-read when the app returns to the foreground.
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (!pushAdapter) return
|
|
147
|
+
const subscription = AppState.addEventListener('change', state => {
|
|
148
|
+
if (state === 'active') void refreshPushPermission()
|
|
149
|
+
})
|
|
150
|
+
return () => subscription.remove()
|
|
151
|
+
}, [pushAdapter, refreshPushPermission])
|
|
152
|
+
|
|
153
|
+
const onPushPress = useCallback(async () => {
|
|
154
|
+
if (!pushAdapter) return
|
|
155
|
+
try {
|
|
156
|
+
if (pushPermission === 'undetermined') {
|
|
157
|
+
await pushAdvisory.set()
|
|
158
|
+
// Take the answer as given rather than re-reading it (see the guard
|
|
159
|
+
// in refreshPushPermission for why a denial must stick).
|
|
160
|
+
setPushPermission(await pushAdapter.requestPermission())
|
|
161
|
+
} else {
|
|
162
|
+
await pushAdapter.openSettings()
|
|
163
|
+
}
|
|
164
|
+
} catch {
|
|
165
|
+
// The adapter is host code; a failed call leaves the row as it was.
|
|
166
|
+
}
|
|
167
|
+
}, [pushAdapter, pushPermission])
|
|
168
|
+
|
|
113
169
|
return (
|
|
114
170
|
<View style={{ backgroundColor: colors.backgroundSecondary }}>
|
|
115
171
|
<ScrollView contentContainerStyle={{ paddingBottom: spacing.xxxl }}>
|
|
@@ -158,6 +214,20 @@ export function SettingsScreen() {
|
|
|
158
214
|
)}
|
|
159
215
|
</GroupedSection>
|
|
160
216
|
|
|
217
|
+
{/* ── Notifications ── */}
|
|
218
|
+
{pushAdapter && (
|
|
219
|
+
<GroupedSection header={t('notifications')}>
|
|
220
|
+
<ListRow
|
|
221
|
+
label={t('push_settings_row')}
|
|
222
|
+
icon="notifications-outline"
|
|
223
|
+
iconColor={colors.accent}
|
|
224
|
+
value={pushPermission === 'granted' ? t('push_settings_on') : t('push_settings_off')}
|
|
225
|
+
onPress={onPushPress}
|
|
226
|
+
isLast
|
|
227
|
+
/>
|
|
228
|
+
</GroupedSection>
|
|
229
|
+
)}
|
|
230
|
+
|
|
161
231
|
{/* ── Settings drill-down ── */}
|
|
162
232
|
<GroupedSection>
|
|
163
233
|
<ListRow
|