@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.
@@ -0,0 +1,53 @@
1
+ import AsyncStorage from '@react-native-async-storage/async-storage'
2
+ import type { PushAdapter } from './types'
3
+
4
+ export const PUSH_REGISTRATION_KEY = 'push_registration_v1'
5
+
6
+ export interface RegisterDeviceClient {
7
+ registerDevice(
8
+ params: { fcmToken: string; platform?: 'ios' | 'android'; deviceId?: string },
9
+ overrideHost?: string
10
+ ): Promise<unknown>
11
+ }
12
+
13
+ export type SyncResult = 'registered' | 'unchanged' | 'skipped' | 'failed'
14
+
15
+ /**
16
+ * Make sure the MessageBox host knows this device's FCM token for this
17
+ * identity. Idempotent: the last successful (host, identity, token) triple is
18
+ * remembered, so the common case is no network call at all. Never throws —
19
+ * push is an enhancement and must not take any caller down with it.
20
+ */
21
+ export async function syncPushRegistration(args: {
22
+ adapter: PushAdapter | undefined
23
+ host: string | undefined
24
+ identityKey: string | undefined
25
+ makeClient: (host: string) => RegisterDeviceClient
26
+ storage?: { getItem(k: string): Promise<string | null>; setItem(k: string, v: string): Promise<void> }
27
+ }): Promise<SyncResult> {
28
+ const { adapter, host, identityKey, makeClient } = args
29
+ const storage = args.storage ?? AsyncStorage
30
+ if (!adapter || !host || !identityKey) return 'skipped'
31
+ let token: string | null | undefined
32
+ try {
33
+ if ((await adapter.getPermission()) !== 'granted') return 'skipped'
34
+ token = await adapter.getToken()
35
+ if (!token) return 'skipped'
36
+ const marker = `${host}|${identityKey}|${token}`
37
+ if ((await storage.getItem(PUSH_REGISTRATION_KEY)) === marker) return 'unchanged'
38
+ await makeClient(host).registerDevice({ fcmToken: token, platform: adapter.platform }, host)
39
+ await storage.setItem(PUSH_REGISTRATION_KEY, marker)
40
+ return 'registered'
41
+ } catch (e) {
42
+ // Only the error's message is logged, so a failure is diagnosable without
43
+ // the log ever carrying the token or the identity key. A message that
44
+ // happens to quote the token, the identity key or the host has them cut out.
45
+ const raw = e instanceof Error ? e.message : String(e)
46
+ const message = [token, identityKey, host].reduce<string>(
47
+ (text, secret) => (secret ? text.split(secret).join('[redacted]') : text),
48
+ raw
49
+ )
50
+ console.warn('[push] registerDevice failed: ' + message)
51
+ return 'failed'
52
+ }
53
+ }
@@ -0,0 +1,31 @@
1
+ export type PushPermission = 'granted' | 'denied' | 'undetermined'
2
+
3
+ export interface PushOpenedEvent {
4
+ /** Data payload from the push (messageId, originator). */
5
+ data: Record<string, string>
6
+ }
7
+
8
+ /**
9
+ * The host's push implementation. This package never imports a push SDK: the
10
+ * host wraps whichever one it ships (e.g. React Native Firebase Messaging) in
11
+ * this shape and hands it over through `configureToolbox({ push })`.
12
+ *
13
+ * New members will be added as optional, so an adapter written against this
14
+ * shape keeps compiling and working when the package is updated.
15
+ */
16
+ export interface PushAdapter {
17
+ readonly platform: 'ios' | 'android'
18
+ getPermission(): Promise<PushPermission>
19
+ /** Shows the OS dialog when undetermined; resolves to the result. */
20
+ requestPermission(): Promise<PushPermission>
21
+ /** FCM registration token, or null when unavailable. */
22
+ getToken(): Promise<string | null>
23
+ onTokenRefresh(cb: (token: string) => void): () => void
24
+ /** Tap while backgrounded. */
25
+ onNotificationOpened(cb: (e: PushOpenedEvent) => void): () => void
26
+ /** Tap that launched the app from killed; null when not launched by a tap. */
27
+ getInitialNotification(): Promise<PushOpenedEvent | null>
28
+ /** Push received while app is foreground. */
29
+ onForegroundMessage(cb: (e: PushOpenedEvent) => void): () => void
30
+ openSettings(): Promise<void>
31
+ }
@@ -1,4 +1,5 @@
1
1
  import type { AppChain } from './config'
2
+ import type { PushAdapter } from './push/types'
2
3
 
3
4
  /**
4
5
  * Service endpoints and API keys for one chain.
@@ -108,6 +109,14 @@ export interface ToolboxConfig {
108
109
  * never read from process.env here.
109
110
  */
110
111
  vaultEnabled?: boolean
112
+ /**
113
+ * The host's push implementation. Optional: a host that ships no push SDK
114
+ * omits it and every push feature stays off. The package never imports a
115
+ * push SDK itself — the SDK's native module would have to be linked by every
116
+ * host that merely installs this package — so the host wraps its own and
117
+ * states it here, like the URLs above.
118
+ */
119
+ push?: PushAdapter
111
120
  }
112
121
 
113
122
  interface ResolvedConfig {
@@ -116,6 +125,7 @@ interface ResolvedConfig {
116
125
  mandala: Partial<Record<AppChain, MandalaEndpointConfig>>
117
126
  handleRegistry: Partial<Record<AppChain, HandleRegistryConfig>>
118
127
  vaultEnabled: boolean
128
+ push: PushAdapter | undefined
119
129
  }
120
130
 
121
131
  let current: ResolvedConfig | null = null
@@ -193,7 +203,8 @@ export function configureToolbox(config: ToolboxConfig): void {
193
203
  services: config.services ?? {},
194
204
  mandala: config.mandala ?? {},
195
205
  handleRegistry: config.handleRegistry ?? {},
196
- vaultEnabled: config.vaultEnabled === true
206
+ vaultEnabled: config.vaultEnabled === true,
207
+ push: config.push
197
208
  }
198
209
  }
199
210
 
@@ -318,6 +329,18 @@ export function isVaultEnabled(): boolean {
318
329
  return current?.vaultEnabled ?? false
319
330
  }
320
331
 
332
+ /**
333
+ * The host's push implementation, if it wired one. The package never imports a
334
+ * push SDK itself.
335
+ *
336
+ * Deliberately NOT throwing when unconfigured, like `isVaultEnabled`: push
337
+ * listeners are set up while rendering, and "unconfigured" must look like
338
+ * "no push" rather than crash a wallet that never wanted notifications.
339
+ */
340
+ export function getPushAdapter(): PushAdapter | undefined {
341
+ return current?.push
342
+ }
343
+
321
344
  /**
322
345
  * Whether the vault may be used on this network.
323
346
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/expo-wallet-toolbox",
3
- "version": "0.11.7",
3
+ "version": "0.12.0",
4
4
  "private": false,
5
5
  "description": "Wallet screens and P2P local-payment backend for Expo/React Native apps, extracted from BSV Wallet.",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -158,6 +158,13 @@ function loadQRCode(): QRCodeComponent {
158
158
  */
159
159
  const INBOX_POLL_MS = 5000
160
160
 
161
+ /**
162
+ * While the live socket is up the satoshi inbox is only re-read on every Nth
163
+ * poll tick: the socket tells us the moment something lands, so the poll is the
164
+ * safety net for a missed event, not the delivery path.
165
+ */
166
+ const LIVE_SATOSHI_POLL_EVERY = 3
167
+
161
168
  // ── Needs attention ──────────────────────────────────────────────────────────
162
169
  //
163
170
  // Replaces the old accept list. An arriving payment is credited automatically
@@ -444,6 +451,8 @@ export default function HandleReceive({
444
451
 
445
452
  /** One inbox read at a time — see fetchPayments. */
446
453
  const fetchingRef = useRef(false)
454
+ /** A live payment arrived mid-read: read once more when that read finishes. */
455
+ const rereadRef = useRef(false)
447
456
  /** The live attempt map, for discard copy that must not close over stale state. */
448
457
  const attemptsRef = useRef<Record<string, InboxAttempt>>({})
449
458
  useEffect(() => {
@@ -482,7 +491,7 @@ export default function HandleReceive({
482
491
  }, [identityKey, loadIdentityKey])
483
492
  )
484
493
 
485
- const peerPayClient = useMemo<PeerPayClient | null>(() => {
494
+ const newPeerPayClient = useCallback((): PeerPayClient | null => {
486
495
  if (!isConfigured || !messageBoxUrl || !wallet) return null
487
496
  try {
488
497
  return new PeerPayClient({
@@ -494,6 +503,8 @@ export default function HandleReceive({
494
503
  return null
495
504
  }
496
505
  }, [isConfigured, messageBoxUrl, wallet, adminOriginator])
506
+ /** The client every inbox read, accept and discard goes through. */
507
+ const peerPayClient = useMemo(() => newPeerPayClient(), [newPeerPayClient])
497
508
 
498
509
  // BRC-125 with this app's url extension: the payer learns where to deliver
499
510
  // without an overlay lookup. Omitted when no server is configured, since
@@ -588,13 +599,19 @@ export default function HandleReceive({
588
599
  )
589
600
 
590
601
  const fetchPayments = useCallback(
591
- async (options: { silent?: boolean } = {}) => {
602
+ async (options: { silent?: boolean; queueIfBusy?: boolean } = {}) => {
592
603
  const client = peerPayClient
593
604
  if (!client || !messageBoxUrl || messageBoxUrl === NO_MESSAGE_BOX) return
594
605
  // One read at a time. The poll, the refresh button and every accept all
595
606
  // reach this, and two overlapping reads can land out of order — the older
596
607
  // response winning would resurrect a row that was just internalized.
597
- if (fetchingRef.current) return
608
+ if (fetchingRef.current) {
609
+ // A live payment must not be dropped here: the read in flight may have
610
+ // listed the inbox before it landed, and the poll is slow while the
611
+ // socket is up. Run one more read when this one finishes.
612
+ if (options.queueIfBusy) rereadRef.current = true
613
+ return
614
+ }
598
615
  fetchingRef.current = true
599
616
  try {
600
617
  const outcome = await runCredit()
@@ -614,6 +631,10 @@ export default function HandleReceive({
614
631
  }
615
632
  } finally {
616
633
  fetchingRef.current = false
634
+ if (rereadRef.current) {
635
+ rereadRef.current = false
636
+ void fetchRef.current({ silent: true })
637
+ }
617
638
  }
618
639
  },
619
640
  [peerPayClient, messageBoxUrl, wallet, adminOriginator, t, runCredit]
@@ -668,22 +689,120 @@ export default function HandleReceive({
668
689
  tokenTickRef.current = tokenTick
669
690
  }, [tokenTick])
670
691
 
671
- // ── Poll the inbox ──
692
+ // ── Watch the inbox ──
693
+ //
694
+ // While someone is actually looking at this screen, a MessageBox WebSocket
695
+ // tells us the moment a payment lands, and a poll backs it up. The socket is
696
+ // the fast path; the poll covers a listener that could not start, a socket
697
+ // that dropped without telling us, and everything the socket does not carry
698
+ // (the Mandala token inbox has no live channel). Only the satoshi read
699
+ // slows while the socket is up — the token drain stays on the 5s tick.
672
700
  //
673
- // A payment arrives whenever the sender's wallet delivers it and MessageBox has
674
- // no push channel here, so "it appears on its own" means polling — but only
675
- // while someone is actually looking at this screen. Unmount and blur stop it
676
- // because a poll nobody can see spends battery; a backgrounded app stops it
677
- // for the same reason and because iOS will suspend the timer anyway. The
678
- // shared creditInboxOnce mutex serializes with TaskCreditInbox.
701
+ // Both run only while the screen is focused and the app active. Blur and
702
+ // background disconnect the socket (a backgrounded app cannot hold one, and
703
+ // one that looked alive on return would quietly slow the poll for nothing),
704
+ // and coming back to the foreground re-listens and reads at once. The
705
+ // callback never credits anything itself: it only triggers the same read the
706
+ // poll does, so there is one crediting path and the shared creditInboxOnce
707
+ // mutex still serializes with TaskCreditInbox.
708
+ //
709
+ // Each listening session gets its OWN short-lived client, never the one the
710
+ // reads use. A MessageBoxClient remembers the rooms it joined across a
711
+ // disconnect, so a second listen on the same instance authenticates a fresh
712
+ // socket but never re-joins the room: listenForLivePayments would resolve,
713
+ // the poll would slow, and no push would ever arrive. A new instance starts
714
+ // with no rooms, no half-finished connection attempt and no socket, and
715
+ // throwing it away on stop discards all three.
716
+ //
717
+ // Blur is a ref, not state, so the interval notices it (within one tick)
718
+ // rather than this effect re-running; the effect itself restarts only with
719
+ // the client.
679
720
  useEffect(() => {
680
721
  if (!peerPayClient) return
681
722
  let cancelled = false
723
+ /** A session is starting, up, or has failed and is not to be retried yet. */
724
+ let listening = false
725
+ /** The current session's client, while one is open. */
726
+ let sessionClient: PeerPayClient | null = null
727
+ /** The socket is confirmed up — the only state in which the poll slows. */
728
+ let live = false
729
+ /** Bumped on every stop so a late start result cannot revive a dead session. */
730
+ let generation = 0
731
+ /** Poll ticks since the socket came up, for the slow satoshi cadence. */
732
+ let liveTicks = 0
733
+
734
+ const visible = () => !cancelled && focusedRef.current && AppState.currentState === 'active'
735
+
736
+ const readSatoshiInbox = (queueIfBusy = false) => {
737
+ void fetchRef.current({ silent: true, queueIfBusy })
738
+ }
739
+
740
+ /** Close a session's socket. Safe to repeat and on a session that never connected. */
741
+ const closeSession = (session: PeerPayClient) => {
742
+ void session.disconnectWebSocket().catch(() => {})
743
+ }
744
+
745
+ const startListener = () => {
746
+ if (listening) return
747
+ listening = true
748
+ const mine = ++generation
749
+ const session = newPeerPayClient()
750
+ if (!session) {
751
+ console.warn('[pay] live inbox listener unavailable: client not created')
752
+ return
753
+ }
754
+ sessionClient = session
755
+ void (async () => {
756
+ try {
757
+ // The session client is built with this same MessageBox host, so no
758
+ // overrideHost: the socket goes where the inbox reads go.
759
+ await session.listenForLivePayments({
760
+ onPayment: () => {
761
+ if (mine === generation && visible()) readSatoshiInbox(true)
762
+ }
763
+ })
764
+ if (mine === generation) {
765
+ live = true
766
+ liveTicks = 0
767
+ } else {
768
+ // Stopped while it was still connecting. The stop could not close a
769
+ // socket that did not exist yet, so close it now it does.
770
+ closeSession(session)
771
+ }
772
+ } catch (error: any) {
773
+ // Whatever half-open socket the failed attempt left would otherwise
774
+ // keep retrying in the background.
775
+ closeSession(session)
776
+ if (mine !== generation) return
777
+ live = false
778
+ sessionClient = null
779
+ // `listening` stays set so a failed start is not retried every tick;
780
+ // the next blur or background resets it. Full 5s polling carries on.
781
+ console.warn(`[pay] live inbox listener unavailable: ${error?.message || 'unknown error'}`)
782
+ }
783
+ })()
784
+ }
785
+
786
+ const stopListener = () => {
787
+ if (!listening) return
788
+ listening = false
789
+ live = false
790
+ generation++
791
+ const session = sessionClient
792
+ sessionClient = null
793
+ if (session) closeSession(session)
794
+ }
795
+
796
+ /** Listen exactly while the screen can be seen. */
797
+ const syncListener = () => {
798
+ if (visible()) startListener()
799
+ else stopListener()
800
+ }
682
801
 
683
802
  const tick = () => {
684
- if (cancelled || !focusedRef.current) return
685
- if (AppState.currentState !== 'active') return
686
- void fetchRef.current({ silent: true })
803
+ syncListener()
804
+ if (!visible()) return
805
+ if (!live || ++liveTicks % LIVE_SATOSHI_POLL_EVERY === 0) readSatoshiInbox()
687
806
  // The token inbox is a SIBLING drain, not a widened one: Mandala delivers
688
807
  // to its own message box and the two never meet. Same 5s focused tick,
689
808
  // because a payee standing in front of this screen expects both kinds of
@@ -691,19 +810,25 @@ export default function HandleReceive({
691
810
  void tokenTickRef.current()
692
811
  }
693
812
 
813
+ syncListener()
694
814
  const interval = setInterval(tick, INBOX_POLL_MS)
695
815
  // Returning to the app should show what arrived while it was away, rather
696
- // than waiting out the rest of an interval.
816
+ // than waiting out the rest of an interval — both inboxes, whatever point
817
+ // the slow cadence had reached.
697
818
  const appSubscription = AppState.addEventListener('change', next => {
698
- if (next === 'active') tick()
819
+ syncListener()
820
+ if (next !== 'active' || !visible()) return
821
+ readSatoshiInbox()
822
+ void tokenTickRef.current()
699
823
  })
700
824
 
701
825
  return () => {
702
826
  cancelled = true
703
827
  clearInterval(interval)
704
828
  appSubscription.remove()
829
+ stopListener()
705
830
  }
706
- }, [peerPayClient])
831
+ }, [peerPayClient, newPeerPayClient])
707
832
 
708
833
  /** Retry one row that had given up. Runs the whole pass, forcing this id. */
709
834
  const handleRetry = useCallback(
@@ -0,0 +1,124 @@
1
+ /**
2
+ * One-time heads-up shown the first time the user picks "Share remote link" on
3
+ * "Get paid", before the OS asks to allow notifications. Same rationale as
4
+ * NearbyAdvisoryModal and BiometricAdvisoryModal: never let an OS permission
5
+ * dialog be the user's first signal that something is about to happen — say
6
+ * what it is for, briefly, first.
7
+ *
8
+ * The OS prompt is fired only on Continue. Either button records that the
9
+ * advisory was shown, and neither blocks the link flow underneath.
10
+ */
11
+ import React from 'react'
12
+ import { Modal, Platform, Pressable, StyleSheet, Text, View } from 'react-native'
13
+ import { useTheme, spacing, radii, typography, i18n } from '@bsv/expo-wallet-toolbox'
14
+ import PressableScale from '../ui/PressableScale'
15
+
16
+ const t = (k: string, o?: Record<string, unknown>) => i18n.t(k, o) as string
17
+
18
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
19
+ let ioniconsComponent: IoniconsComponent | undefined
20
+ function loadIonicons(): IoniconsComponent {
21
+ if (!ioniconsComponent) {
22
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
23
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
24
+ }
25
+ return ioniconsComponent
26
+ }
27
+
28
+ /**
29
+ * Whether the advisory should be on screen. Pure so the gating is testable
30
+ * without rendering the screen: only on the remote-link method, only once per
31
+ * device, and only while the OS would still ask (granted/denied are final, and
32
+ * `null` means the state has not loaded yet — show nothing rather than flash).
33
+ */
34
+ export function shouldShowNotificationAdvisory(s: {
35
+ method: string | null
36
+ advisorySeen: boolean | null
37
+ permission: 'granted' | 'denied' | 'undetermined' | null
38
+ }): boolean {
39
+ return s.method === 'get-handle' && s.advisorySeen === false && s.permission === 'undetermined'
40
+ }
41
+
42
+ export const NotificationAdvisoryModal: React.FC<{
43
+ visible: boolean
44
+ onNotNow: () => void
45
+ onContinue: () => void
46
+ }> = ({ visible, onNotNow, onContinue }) => {
47
+ const { colors } = useTheme()
48
+ const Ionicons = loadIonicons()
49
+
50
+ if (!visible) return null
51
+
52
+ return (
53
+ <Modal
54
+ transparent
55
+ visible
56
+ animationType="fade"
57
+ onRequestClose={onNotNow}
58
+ statusBarTranslucent={Platform.OS === 'android'}
59
+ navigationBarTranslucent={Platform.OS === 'android'}
60
+ >
61
+ <View style={[styles.backdrop, { backgroundColor: colors.scrim }]}>
62
+ <Pressable
63
+ style={StyleSheet.absoluteFill}
64
+ onPress={onNotNow}
65
+ accessible={true}
66
+ accessibilityRole="button"
67
+ accessibilityLabel="Close"
68
+ accessibilityHint="Dismisses this advisory"
69
+ />
70
+ <View style={[styles.card, { backgroundColor: colors.sheetBackground, borderColor: colors.separator }]}>
71
+ <View style={[styles.heroIcon, { backgroundColor: colors.fillTertiary }]}>
72
+ <Ionicons name="notifications-outline" size={26} color={colors.accent} />
73
+ </View>
74
+ <Text style={[styles.title, { color: colors.textPrimary }]}>{t('push_advisory_title')}</Text>
75
+ <Text style={[styles.body, { color: colors.textSecondary }]}>{t('push_advisory_body')}</Text>
76
+
77
+ <PressableScale
78
+ haptic="confirm"
79
+ onPress={onContinue}
80
+ style={[styles.primary, { backgroundColor: colors.accent }]}
81
+ >
82
+ <Text style={[styles.primaryLabel, { color: colors.textOnAccent }]}>{t('push_advisory_continue')}</Text>
83
+ </PressableScale>
84
+
85
+ <PressableScale haptic="tap" onPress={onNotNow} style={styles.secondary}>
86
+ <Text style={[styles.secondaryLabel, { color: colors.textSecondary }]}>{t('push_advisory_not_now')}</Text>
87
+ </PressableScale>
88
+ </View>
89
+ </View>
90
+ </Modal>
91
+ )
92
+ }
93
+
94
+ const styles = StyleSheet.create({
95
+ backdrop: { flex: 1, alignItems: 'center', justifyContent: 'center', paddingHorizontal: spacing.xl },
96
+ card: {
97
+ width: '100%',
98
+ maxWidth: 360,
99
+ borderRadius: radii.xl,
100
+ borderWidth: StyleSheet.hairlineWidth,
101
+ padding: spacing.xl,
102
+ alignItems: 'center',
103
+ gap: spacing.md
104
+ },
105
+ heroIcon: {
106
+ width: 56,
107
+ height: 56,
108
+ borderRadius: 28,
109
+ alignItems: 'center',
110
+ justifyContent: 'center',
111
+ marginBottom: spacing.xs
112
+ },
113
+ title: { ...typography.title2, textAlign: 'center' },
114
+ body: { ...typography.subhead, textAlign: 'center', marginBottom: spacing.sm },
115
+ primary: {
116
+ width: '100%',
117
+ borderRadius: radii.md,
118
+ paddingVertical: spacing.lg,
119
+ alignItems: 'center'
120
+ },
121
+ primaryLabel: { ...typography.headline },
122
+ secondary: { paddingVertical: spacing.sm, alignItems: 'center' },
123
+ secondaryLabel: { ...typography.body }
124
+ })
@@ -1,5 +1,6 @@
1
1
  import React, { useContext, useState, useCallback, useMemo, useEffect, useRef } from 'react'
2
2
  import { View, Text, StyleSheet, TouchableOpacity, ScrollView } from 'react-native'
3
+ import type { WalletPermissionsManager } from '@bsv/wallet-toolbox-mobile'
3
4
  import Sheet from './Sheet'
4
5
  import PressableScale from './PressableScale'
5
6
  import { useTranslation } from 'react-i18next'
@@ -70,6 +71,8 @@ interface GroupPermissions {
70
71
  spendingAuthorization?: GroupSpending
71
72
  }
72
73
 
74
+ type GrantedGroupPermissions = Parameters<WalletPermissionsManager['grantGroupedPermission']>[0]['granted']
75
+
73
76
  /** Common shape derived from the four existing modals. */
74
77
  export interface ActivePermission {
75
78
  kind: PermissionKind
@@ -152,6 +155,7 @@ export function deriveActive(
152
155
  basketRequests: any[]
153
156
  certificateRequests: any[]
154
157
  spendingRequests: any[]
158
+ groupRequests?: any[]
155
159
  btmsRequests: any[]
156
160
  mandalaRequests: any[]
157
161
  protocolAccessModalOpen: boolean
@@ -207,6 +211,21 @@ export function deriveActive(
207
211
  }
208
212
  }
209
213
 
214
+ // A site's grouped request (its manifest's metanet.groupPermissions) is the
215
+ // whole set it will use, asked once when it connects.
216
+ if (ctx.groupRequests && ctx.groupRequests.length > 0) {
217
+ const r = ctx.groupRequests[0]
218
+ return {
219
+ kind: 'group',
220
+ requestID: r.requestID,
221
+ originator: r.originator,
222
+ title: 'Permissions',
223
+ description: 'wants these permissions',
224
+ details: [],
225
+ groupPermissions: r.permissions
226
+ }
227
+ }
228
+
210
229
  if (ctx.certificateAccessModalOpen && ctx.certificateRequests.length > 0) {
211
230
  const r = ctx.certificateRequests[0]
212
231
  const certType = r.certificate?.certType ?? r.certificateType
@@ -456,12 +475,14 @@ const PermissionSheet: React.FC = () => {
456
475
  basketRequests,
457
476
  certificateRequests,
458
477
  spendingRequests,
478
+ groupRequests,
459
479
  btmsRequests,
460
480
  mandalaRequests,
461
481
  advanceProtocolQueue,
462
482
  advanceBasketQueue,
463
483
  advanceCertificateQueue,
464
484
  advanceSpendingQueue,
485
+ advanceGroupQueue,
465
486
  advanceBtmsQueue,
466
487
  advanceMandalaQueue,
467
488
  managers,
@@ -516,6 +537,7 @@ const PermissionSheet: React.FC = () => {
516
537
  basketRequests,
517
538
  certificateRequests,
518
539
  spendingRequests,
540
+ groupRequests,
519
541
  btmsRequests,
520
542
  mandalaRequests,
521
543
  protocolAccessModalOpen,
@@ -530,6 +552,7 @@ const PermissionSheet: React.FC = () => {
530
552
  basketRequests,
531
553
  certificateRequests,
532
554
  spendingRequests,
555
+ groupRequests,
533
556
  btmsRequests,
534
557
  mandalaRequests,
535
558
  protocolAccessModalOpen,
@@ -580,6 +603,16 @@ const PermissionSheet: React.FC = () => {
580
603
  } else if (active.kind === 'mandala') {
581
604
  // Mandala uses its own promise-based resolution too — no permissionsManager.denyPermission
582
605
  advanceMandalaQueue(false)
606
+ } else if (active.kind === 'group') {
607
+ // Grant none of the set, but let the site carry on: each permission is
608
+ // then asked for on its own when used. A hard deny would make the
609
+ // site's waitForAuthentication throw.
610
+ try {
611
+ await managers.permissionsManager?.dismissGroupedPermission(active.requestID)
612
+ } catch {
613
+ // Already settled (e.g. the site went away) -- nothing left to answer.
614
+ }
615
+ advanceGroupQueue()
583
616
  } else {
584
617
  try {
585
618
  await managers.permissionsManager?.denyPermission(active.requestID)
@@ -614,6 +647,7 @@ const PermissionSheet: React.FC = () => {
614
647
  advanceBasketQueue,
615
648
  advanceCertificateQueue,
616
649
  advanceSpendingQueue,
650
+ advanceGroupQueue,
617
651
  advanceBtmsQueue,
618
652
  advanceMandalaQueue,
619
653
  setProtocolAccessModalOpen,
@@ -636,6 +670,18 @@ const PermissionSheet: React.FC = () => {
636
670
  advanceBtmsQueue(true)
637
671
  } else if (request.kind === 'mandala') {
638
672
  advanceMandalaQueue(true)
673
+ } else if (request.kind === 'group') {
674
+ // Grants exactly the set shown. The manager mints the permission
675
+ // tokens, then resolves the site's waitForAuthentication; if minting
676
+ // fails it rejects that call itself.
677
+ managers.permissionsManager
678
+ ?.grantGroupedPermission({
679
+ requestID: request.requestID,
680
+ // The manager's own request object, passed back unchanged.
681
+ granted: (request.groupPermissions ?? {}) as GrantedGroupPermissions
682
+ })
683
+ .catch((error: unknown) => console.warn('[permissions] grouped grant failed', error))
684
+ advanceGroupQueue()
639
685
  } else if (request.kind === 'spending') {
640
686
  managers.permissionsManager?.grantPermission({
641
687
  requestID: request.requestID,
@@ -674,6 +720,7 @@ const PermissionSheet: React.FC = () => {
674
720
  advanceBasketQueue,
675
721
  advanceCertificateQueue,
676
722
  advanceSpendingQueue,
723
+ advanceGroupQueue,
677
724
  advanceBtmsQueue,
678
725
  advanceMandalaQueue,
679
726
  setProtocolAccessModalOpen,
@@ -704,10 +751,10 @@ const PermissionSheet: React.FC = () => {
704
751
  }, [active, granted, executeGrant])
705
752
 
706
753
  return (
707
- <Sheet visible={visible} onClose={handleDeny} heightPercent={0.92} fitContent={active?.kind !== 'group'}>
754
+ <Sheet visible={visible} onClose={handleDeny} heightPercent={0.92} fitContent>
708
755
  {active && (
709
- <View style={active.kind === 'group' ? styles.sheetInnerGroup : undefined}>
710
- <View style={[styles.content, active.kind === 'group' && { flex: 1 }]}>
756
+ <View>
757
+ <View style={styles.content}>
711
758
  {/* -------- Originator / domain -------- */}
712
759
  <View style={styles.originatorRow}>
713
760
  <View
@@ -916,10 +963,6 @@ const PermissionSheet: React.FC = () => {
916
963
  // ---------------------------------------------------------------------------
917
964
 
918
965
  const styles = StyleSheet.create({
919
- sheetInnerGroup: {
920
- flex: 1,
921
- justifyContent: 'flex-end'
922
- },
923
966
  content: {
924
967
  paddingHorizontal: spacing.xl,
925
968
  paddingTop: spacing.lg,
@@ -1042,8 +1085,10 @@ const styles = StyleSheet.create({
1042
1085
  },
1043
1086
 
1044
1087
  // Group permissions
1088
+ // Sized to its rows like every other prompt; a long set scrolls instead
1089
+ // of pushing the buttons off screen.
1045
1090
  groupScroll: {
1046
- flex: 1
1091
+ maxHeight: 420
1047
1092
  },
1048
1093
  groupSection: {
1049
1094
  borderTopWidth: StyleSheet.hairlineWidth,
package/ui/index.ts CHANGED
@@ -59,6 +59,7 @@ export { default as HandleReceive } from './components/pay/HandleReceive'
59
59
  export { useMessageBoxConfig, ConfigPanel } from './components/pay/MessageBoxConfig'
60
60
  export { default as NearbyFlow, type NearbyFlowProps } from './components/pay/NearbyFlow'
61
61
  export { NearbyAdvisoryModal } from './components/pay/NearbyAdvisoryModal'
62
+ export { NotificationAdvisoryModal } from './components/pay/NotificationAdvisoryModal'
62
63
  export { default as OfflineNotice, offlineActionDetails, type OfflineNoticeProps } from './components/pay/OfflineNotice'
63
64
  export { default as PayCellRow, type PayCellRowProps } from './components/pay/PayCellRow'
64
65
  export {