@bsv/expo-wallet-toolbox 0.5.0 → 0.7.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +255 -0
  2. package/README.md +19 -0
  3. package/core/amountFormatHelpers.ts +238 -34
  4. package/core/backup/RemoteSyncReader.ts +2 -5
  5. package/core/backup/codec.ts +2 -2
  6. package/core/backup/push.ts +1 -1
  7. package/core/config.tsx +12 -5
  8. package/core/contacts/contactActivity.ts +153 -0
  9. package/core/contacts/contactCache.ts +41 -0
  10. package/core/contacts/contactsStore.ts +183 -0
  11. package/core/context/WalletContext.tsx +55 -10
  12. package/core/demo/demoAssets.ts +60 -0
  13. package/core/demo/demoLedger.ts +240 -0
  14. package/core/demo/demoMandalaRuntime.ts +96 -0
  15. package/core/demo/demoMode.ts +38 -0
  16. package/core/demo/demoWallet.ts +25 -0
  17. package/core/demo/index.ts +26 -0
  18. package/core/demo/useDemo.ts +59 -0
  19. package/core/headers/OfflineFirstChaintracks.ts +52 -14
  20. package/core/headers/headerStore.ts +7 -10
  21. package/core/i18n/translations.tsx +1234 -74
  22. package/core/identity/contactLink.ts +36 -0
  23. package/core/identity/handleRegistry/client.ts +285 -0
  24. package/core/identity/handleRegistry/profileCert.ts +254 -0
  25. package/core/identity/handleRegistry/registration.ts +559 -0
  26. package/core/identity/handleRegistry/resolver.ts +247 -0
  27. package/core/identity/handleRegistry/rules.ts +104 -0
  28. package/core/index.ts +20 -2
  29. package/core/localpay/pendingAborts.ts +5 -1
  30. package/core/monitor/MonitorSupervisor.ts +121 -0
  31. package/core/monitor/TaskBackupPush.ts +1 -1
  32. package/core/monitor/TaskCreditInbox.ts +1 -1
  33. package/core/monitor/TaskDrainOutbox.ts +1 -1
  34. package/core/monitor/TaskSendOffline.ts +1 -1
  35. package/core/net/online.ts +49 -0
  36. package/core/numberFormat.ts +19 -0
  37. package/core/offline/plan.ts +1 -1
  38. package/core/pay/recordProof.ts +2 -6
  39. package/core/services/arcadeBroadcastProvider.ts +1 -4
  40. package/core/services/exchangeRate.ts +1 -1
  41. package/core/services/externalOrigin.ts +5 -2
  42. package/core/services/vault/transfers.ts +2 -2
  43. package/core/services/walletServiceConfig.ts +31 -20
  44. package/core/storage/StorageExpoSQLite.ts +41 -34
  45. package/core/storage/methods/findSql.ts +3 -0
  46. package/core/storage/methods/listActionsSql.ts +8 -5
  47. package/core/storage/methods/listOutputsSql.ts +2 -2
  48. package/core/storage/methods/processOfflineActions.ts +2 -3
  49. package/core/storage/methods/reviewStatusSql.ts +7 -2
  50. package/core/storage/schema/createTables.ts +29 -0
  51. package/core/toolboxConfig.ts +70 -0
  52. package/core/toolboxTypes.ts +40 -0
  53. package/core/userAvatar.ts +79 -0
  54. package/core/walletMonitor.ts +8 -3
  55. package/package.json +7 -7
  56. package/ui/activityFilter.ts +115 -0
  57. package/ui/components/pay/PaymentSuccessOverlay.tsx +46 -6
  58. package/ui/components/pay/RecipientField.tsx +84 -70
  59. package/ui/components/pay/StepBar.tsx +32 -0
  60. package/ui/components/pay/UniversalSend.tsx +677 -149
  61. package/ui/components/ui/PencilEditField.tsx +109 -0
  62. package/ui/components/ui/SlideOverFromRight.tsx +86 -0
  63. package/ui/components/wallet/ActivityRow.tsx +222 -120
  64. package/ui/components/wallet/AmountInput.tsx +18 -6
  65. package/ui/components/wallet/ContactActivityList.tsx +149 -0
  66. package/ui/components/wallet/ContactSigil.tsx +49 -0
  67. package/ui/components/wallet/EditPictureSheet.tsx +99 -0
  68. package/ui/components/wallet/FitAmount.tsx +148 -0
  69. package/ui/components/wallet/IconPickerSheet.tsx +168 -0
  70. package/ui/components/wallet/IdentifierRow.tsx +69 -0
  71. package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
  72. package/ui/components/wallet/ProfileButton.tsx +62 -0
  73. package/ui/components/wallet/UserAvatar.tsx +85 -0
  74. package/ui/components/wallet/avatarIcons.ts +122 -0
  75. package/ui/hooks/useContactsStore.ts +10 -0
  76. package/ui/hooks/useMandala.ts +18 -1
  77. package/ui/hooks/useOnline.ts +65 -20
  78. package/ui/index.ts +26 -1
  79. package/ui/screens/ContactScreen.tsx +289 -0
  80. package/ui/screens/ContactsScreen.tsx +373 -0
  81. package/ui/screens/IdentifierScreen.tsx +234 -0
  82. package/ui/screens/NewContactScreen.tsx +362 -0
  83. package/ui/screens/PayScreen.tsx +20 -7
  84. package/ui/screens/ProfileScreen.tsx +783 -0
  85. package/ui/screens/TransactionDetailScreen.tsx +419 -0
  86. package/ui/screens/TrustScreen.tsx +1 -1
  87. package/ui/screens/WalletConfigScreen.tsx +42 -0
  88. package/ui/screens/WalletHomeScreen.tsx +528 -83
  89. package/ui/tokenStatus.ts +21 -0
  90. package/ui/txStatus.ts +43 -5
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The "IDENTIFIER" row of a grouped card: the key abbreviated in monospace
3
+ * with a copy button on the right. Shared by Contact, New Contact and
4
+ * Profile so the same key reads the same way on all three.
5
+ */
6
+ import React, { useCallback } from 'react'
7
+ import { StyleSheet, Text, View } from 'react-native'
8
+ import { useTranslation } from 'react-i18next'
9
+ import { useTheme, spacing, typography } from '@bsv/expo-wallet-toolbox'
10
+ import PressableScale from '../ui/PressableScale'
11
+ import { showToast } from '../ui/Toast'
12
+ import { abbreviateKey } from '../../../core/pay/counterparty'
13
+
14
+ type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
15
+ let ioniconsComponent: IoniconsComponent | undefined
16
+ function loadIonicons(): IoniconsComponent {
17
+ if (!ioniconsComponent) {
18
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
19
+ ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
20
+ }
21
+ return ioniconsComponent
22
+ }
23
+
24
+ /**
25
+ * Loaded lazily for the same reason every native module in this package is:
26
+ * the `ui` barrel must stay parseable under Jest, which cannot load the
27
+ * clipboard module's native binding.
28
+ */
29
+ type ClipboardModule = typeof import('@react-native-clipboard/clipboard').default
30
+ let clipboardModule: ClipboardModule | undefined
31
+ function loadClipboard(): ClipboardModule {
32
+ if (!clipboardModule) {
33
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
34
+ clipboardModule = require('@react-native-clipboard/clipboard').default as ClipboardModule
35
+ }
36
+ return clipboardModule
37
+ }
38
+
39
+ export default function IdentifierRow({ identityKey }: { identityKey: string }) {
40
+ const { t } = useTranslation()
41
+ const { colors } = useTheme()
42
+ const Ionicons = loadIonicons()
43
+ const onCopy = useCallback(() => {
44
+ loadClipboard().setString(identityKey)
45
+ showToast(t('copied'), { type: 'success' })
46
+ }, [identityKey, t])
47
+ return (
48
+ <View style={styles.row}>
49
+ <Text style={[styles.key, { color: colors.textPrimary }]} numberOfLines={1} ellipsizeMode="middle">
50
+ {abbreviateKey(identityKey)}
51
+ </Text>
52
+ <PressableScale
53
+ onPress={onCopy}
54
+ haptic="tap"
55
+ style={styles.copyBtn}
56
+ accessibilityRole="button"
57
+ accessibilityLabel={t('contact_copy_identifier')}
58
+ >
59
+ <Ionicons name="copy-outline" size={18} color={colors.textSecondary} />
60
+ </PressableScale>
61
+ </View>
62
+ )
63
+ }
64
+
65
+ const styles = StyleSheet.create({
66
+ row: { flexDirection: 'row', alignItems: 'center', minHeight: 48, paddingLeft: spacing.lg, paddingRight: spacing.xs },
67
+ key: { ...typography.subhead, fontFamily: 'monospace', flex: 1 },
68
+ copyBtn: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center' }
69
+ })
@@ -12,7 +12,6 @@
12
12
  */
13
13
  import React from 'react'
14
14
  import { StyleSheet, Text, View } from 'react-native'
15
- import { useSafeAreaInsets } from 'react-native-safe-area-context'
16
15
  import { useTheme, spacing, radii, typography, i18n } from '@bsv/expo-wallet-toolbox'
17
16
  import PressableScale from '../ui/PressableScale'
18
17
 
@@ -34,14 +33,15 @@ export const ImportFromBackupPrompt: React.FC<{
34
33
  }> = ({ visible, onImport }) => {
35
34
  const { colors } = useTheme()
36
35
  const Ionicons = loadIonicons()
37
- const insets = useSafeAreaInsets()
38
36
 
39
37
  if (!visible) return null
40
38
 
41
39
  return (
42
- <View style={[styles.wrapper, { paddingBottom: insets.bottom + spacing.md }]} pointerEvents="box-none">
40
+ <View style={[styles.wrapper, { paddingBottom: CARD_INSET }]} pointerEvents="box-none">
43
41
  <View style={[styles.card, { backgroundColor: colors.sheetBackground, borderColor: colors.separator }]}>
44
- <Ionicons name="download-outline" size={22} color={colors.accent} style={styles.icon} />
42
+ <View style={[styles.iconCircle, { backgroundColor: colors.fill }]}>
43
+ <Ionicons name="download-outline" size={22} color={colors.accent} />
44
+ </View>
45
45
  <View style={styles.textGroup}>
46
46
  <Text style={[styles.title, { color: colors.textPrimary }]}>{t('import_prompt_title')}</Text>
47
47
  <Text style={[styles.body, { color: colors.textSecondary }]}>{t('import_prompt_body')}</Text>
@@ -54,6 +54,19 @@ export const ImportFromBackupPrompt: React.FC<{
54
54
  )
55
55
  }
56
56
 
57
+ /**
58
+ * The card hugs the bottom of the screen, so its corners have to agree with the
59
+ * screen's own. Concentric rounding means the inner radius is the outer one
60
+ * less the gap between them — anything else and the two curves visibly fight.
61
+ *
62
+ * The display corner is a constant because no RN API reports it. 55pt is the
63
+ * modern iPhone notch-era radius; on a device that differs (an iPad, most
64
+ * Android hardware) the card is merely a little rounder or flatter than its
65
+ * housing, which is a far smaller error than not following it at all.
66
+ */
67
+ const SCREEN_CORNER = 55
68
+ const CARD_INSET = spacing.lg
69
+
57
70
  const styles = StyleSheet.create({
58
71
  wrapper: {
59
72
  position: 'absolute',
@@ -62,30 +75,39 @@ const styles = StyleSheet.create({
62
75
  bottom: 0,
63
76
  zIndex: 30,
64
77
  alignItems: 'center',
65
- paddingHorizontal: spacing.lg
78
+ paddingHorizontal: CARD_INSET
66
79
  },
67
80
  card: {
68
81
  width: '100%',
69
82
  maxWidth: 380,
70
- borderRadius: radii.lg,
83
+ borderRadius: SCREEN_CORNER - CARD_INSET,
71
84
  borderWidth: StyleSheet.hairlineWidth,
72
- padding: spacing.lg,
85
+ padding: spacing.xxl,
73
86
  alignItems: 'center',
74
- gap: spacing.sm,
87
+ gap: spacing.md,
75
88
  shadowColor: '#000',
76
89
  shadowOffset: { width: 0, height: 4 },
77
90
  shadowOpacity: 0.15,
78
91
  shadowRadius: 12,
79
92
  elevation: 6
80
93
  },
81
- icon: { marginBottom: spacing.xs },
82
- textGroup: { alignItems: 'center', gap: 2 },
94
+ iconCircle: {
95
+ width: 44,
96
+ height: 44,
97
+ borderRadius: 22,
98
+ alignItems: 'center',
99
+ justifyContent: 'center',
100
+ marginBottom: spacing.xs
101
+ },
102
+ textGroup: { alignItems: 'center', gap: spacing.xs },
83
103
  title: { ...typography.subhead, fontWeight: '600', textAlign: 'center' },
84
104
  body: { ...typography.footnote, textAlign: 'center' },
85
105
  button: {
86
- marginTop: spacing.xs,
87
- paddingVertical: spacing.sm,
88
- paddingHorizontal: spacing.lg,
106
+ // Set apart from the copy it acts on, and given enough height that a pill
107
+ // border reads as a control rather than as a caption in a box.
108
+ marginTop: spacing.sm,
109
+ paddingVertical: spacing.md,
110
+ paddingHorizontal: spacing.xl,
89
111
  borderRadius: radii.pill,
90
112
  borderWidth: StyleSheet.hairlineWidth
91
113
  },
@@ -0,0 +1,62 @@
1
+ /**
2
+ * 34pt chrome-disc profile button, top-left of Home. Wears whatever avatar
3
+ * icon the user picked in Profile — the same `core/userAvatar.ts` choice the
4
+ * profile hero draws, so the two can never disagree.
5
+ *
6
+ * Original note: 34pt chrome-disc profile button, top-left of Home — passed through
7
+ * `WalletHomeScreen`'s existing (previously unused) `topLeft` prop from the
8
+ * host app's `app/index.tsx`, so this needed no package API change. Same disc
9
+ * as the settings button on the right (surfaceRaised + hairline), so the two
10
+ * bookend the header as a matched pair.
11
+ */
12
+ import React from 'react'
13
+ import { StyleSheet } from 'react-native'
14
+ import { useTheme, useUserAvatarIcon } from '@bsv/expo-wallet-toolbox'
15
+ import { useTranslation } from 'react-i18next'
16
+ import PressableScale from '../ui/PressableScale'
17
+ import { AvatarGlyph } from './UserAvatar'
18
+
19
+ type ExpoRouterModule = typeof import('expo-router')
20
+ let expoRouterMod: ExpoRouterModule | undefined
21
+ function loadExpoRouter(): ExpoRouterModule {
22
+ if (!expoRouterMod) {
23
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
24
+ expoRouterMod = require('expo-router') as ExpoRouterModule
25
+ }
26
+ return expoRouterMod
27
+ }
28
+
29
+ export default function ProfileButton() {
30
+ const { colors } = useTheme()
31
+ const { t } = useTranslation()
32
+ const { router } = loadExpoRouter()
33
+ const avatar = useUserAvatarIcon()
34
+ return (
35
+ <PressableScale
36
+ onPress={() => router.push('/profile' as never)}
37
+ haptic="tap"
38
+ hitSlop={5}
39
+ style={[styles.disc, { backgroundColor: colors.surfaceRaised, borderColor: colors.surfaceRaisedBorder }]}
40
+ accessibilityRole="button"
41
+ accessibilityLabel={t('profile')}
42
+ >
43
+ <AvatarGlyph
44
+ family={avatar?.family ?? 'ionicons'}
45
+ name={avatar?.name ?? 'person-outline'}
46
+ size={17}
47
+ color={colors.textSecondary}
48
+ />
49
+ </PressableScale>
50
+ )
51
+ }
52
+
53
+ const styles = StyleSheet.create({
54
+ disc: {
55
+ width: 34,
56
+ height: 34,
57
+ borderRadius: 17,
58
+ borderWidth: StyleSheet.hairlineWidth,
59
+ alignItems: 'center',
60
+ justifyContent: 'center'
61
+ }
62
+ })
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The user's own face, wherever "you" is drawn.
3
+ *
4
+ * One component so the home button and the profile hero can never disagree
5
+ * about what the user picked. With no choice stored it falls back to the
6
+ * plain person glyph those surfaces have always shown, so an install that
7
+ * never opens the picker looks exactly as it did.
8
+ */
9
+ import React from 'react'
10
+ import { StyleSheet, View } from 'react-native'
11
+ import { useTheme, useUserAvatarIcon, type AvatarIconFamily } from '@bsv/expo-wallet-toolbox'
12
+
13
+ type VectorIcons = typeof import('@expo/vector-icons')
14
+ let vectorIcons: VectorIcons | undefined
15
+ function loadIcons(): VectorIcons {
16
+ if (!vectorIcons) {
17
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
18
+ vectorIcons = require('@expo/vector-icons') as VectorIcons
19
+ }
20
+ return vectorIcons
21
+ }
22
+
23
+ /** Draw one catalogue entry, whichever family it came from. */
24
+ export function AvatarGlyph({
25
+ family,
26
+ name,
27
+ size,
28
+ color
29
+ }: {
30
+ family: AvatarIconFamily
31
+ name: string
32
+ size: number
33
+ color: string
34
+ }) {
35
+ const { Ionicons, MaterialCommunityIcons } = loadIcons()
36
+ const Icon = family === 'ionicons' ? Ionicons : MaterialCommunityIcons
37
+ return <Icon name={name as never} size={size} color={color} />
38
+ }
39
+
40
+ export default function UserAvatar({
41
+ size = 34,
42
+ /** Glyph size; defaults to roughly half the disc, as the 34pt button does. */
43
+ glyphSize,
44
+ color,
45
+ background,
46
+ borderColor,
47
+ style
48
+ }: {
49
+ size?: number
50
+ glyphSize?: number
51
+ color?: string
52
+ background?: string
53
+ borderColor?: string
54
+ style?: object
55
+ }) {
56
+ const { colors } = useTheme()
57
+ const chosen = useUserAvatarIcon()
58
+ const glyph = glyphSize ?? Math.round(size * 0.5)
59
+ return (
60
+ <View
61
+ style={[
62
+ styles.disc,
63
+ {
64
+ width: size,
65
+ height: size,
66
+ borderRadius: size / 2,
67
+ backgroundColor: background ?? colors.surfaceRaised,
68
+ borderColor: borderColor ?? colors.surfaceRaisedBorder
69
+ },
70
+ style
71
+ ]}
72
+ >
73
+ <AvatarGlyph
74
+ family={chosen?.family ?? 'ionicons'}
75
+ name={chosen?.name ?? 'person-outline'}
76
+ size={glyph}
77
+ color={color ?? colors.textSecondary}
78
+ />
79
+ </View>
80
+ )
81
+ }
82
+
83
+ const styles = StyleSheet.create({
84
+ disc: { alignItems: 'center', justifyContent: 'center', borderWidth: StyleSheet.hairlineWidth, overflow: 'hidden' }
85
+ })
@@ -0,0 +1,122 @@
1
+ /**
2
+ * The icons offered as an avatar, grouped the way the picker shows them.
3
+ *
4
+ * Only families this app already ships (see `@expo/vector-icons`): Ionicons
5
+ * for people, nature and objects, MaterialCommunityIcons for the animals,
6
+ * which Ionicons has almost none of. Nothing here adds a dependency.
7
+ *
8
+ * Chosen for being something a person would actually WEAR — creatures and
9
+ * characters, not UI furniture. Every name below was checked against the
10
+ * shipped glyph maps; a name that is not in them renders as a blank square,
11
+ * which is why this list is explicit rather than generated from a prefix.
12
+ */
13
+ import type { AvatarIconFamily } from '@bsv/expo-wallet-toolbox'
14
+
15
+ export interface AvatarIconOption {
16
+ family: AvatarIconFamily
17
+ name: string
18
+ }
19
+
20
+ export interface AvatarIconGroup {
21
+ /** i18n key for the section heading, with an English fallback. */
22
+ labelKey: string
23
+ labelFallback: string
24
+ icons: AvatarIconOption[]
25
+ }
26
+
27
+ const mc = (name: string): AvatarIconOption => ({ family: 'material-community', name })
28
+ const io = (name: string): AvatarIconOption => ({ family: 'ionicons', name })
29
+
30
+ export const AVATAR_ICON_GROUPS: AvatarIconGroup[] = [
31
+ {
32
+ labelKey: 'avatar_group_animals',
33
+ labelFallback: 'Animals',
34
+ icons: [
35
+ mc('cat'),
36
+ mc('dog'),
37
+ mc('rabbit'),
38
+ mc('owl'),
39
+ mc('panda'),
40
+ mc('koala'),
41
+ mc('penguin'),
42
+ mc('bird'),
43
+ mc('duck'),
44
+ mc('horse'),
45
+ mc('elephant'),
46
+ mc('kangaroo'),
47
+ mc('cow'),
48
+ mc('pig'),
49
+ mc('sheep'),
50
+ mc('turtle'),
51
+ mc('tortoise'),
52
+ mc('snake'),
53
+ mc('dolphin'),
54
+ mc('shark'),
55
+ mc('fish'),
56
+ mc('jellyfish'),
57
+ mc('butterfly'),
58
+ mc('bee'),
59
+ mc('ladybug'),
60
+ mc('snail'),
61
+ mc('spider'),
62
+ mc('bat'),
63
+ mc('unicorn')
64
+ ]
65
+ },
66
+ {
67
+ labelKey: 'avatar_group_characters',
68
+ labelFallback: 'Characters',
69
+ icons: [
70
+ mc('emoticon-happy-outline'),
71
+ mc('emoticon-cool-outline'),
72
+ mc('robot'),
73
+ mc('alien'),
74
+ mc('ghost'),
75
+ mc('account'),
76
+ mc('human'),
77
+ mc('sunglasses'),
78
+ io('happy-outline'),
79
+ io('person-outline'),
80
+ io('people-outline'),
81
+ io('skull-outline')
82
+ ]
83
+ },
84
+ {
85
+ labelKey: 'avatar_group_nature',
86
+ labelFallback: 'Nature',
87
+ icons: [
88
+ io('leaf-outline'),
89
+ io('flower-outline'),
90
+ io('paw-outline'),
91
+ io('planet-outline'),
92
+ io('moon-outline'),
93
+ io('sunny-outline'),
94
+ io('snow-outline'),
95
+ io('flame-outline'),
96
+ io('star-outline'),
97
+ io('heart-outline'),
98
+ io('diamond-outline'),
99
+ io('flash-outline')
100
+ ]
101
+ },
102
+ {
103
+ labelKey: 'avatar_group_things',
104
+ labelFallback: 'Things',
105
+ icons: [
106
+ io('rocket-outline'),
107
+ io('game-controller-outline'),
108
+ io('musical-note-outline'),
109
+ io('headset-outline'),
110
+ io('camera-outline'),
111
+ io('bicycle-outline'),
112
+ io('football-outline'),
113
+ io('basketball-outline'),
114
+ io('pizza-outline'),
115
+ io('ice-cream-outline'),
116
+ io('cafe-outline'),
117
+ io('balloon-outline'),
118
+ io('gift-outline'),
119
+ io('glasses-outline')
120
+ ]
121
+ }
122
+ ]
@@ -0,0 +1,10 @@
1
+ import { useMemo } from 'react'
2
+ import { useWallet } from '@bsv/expo-wallet-toolbox'
3
+ import { createContactsStore, type ContactsDb, type ContactsStore } from '../../core/contacts/contactsStore'
4
+
5
+ /** The contacts store for the open wallet, or null before its database is ready. */
6
+ export function useContactsStore(): ContactsStore | null {
7
+ const { storage } = useWallet()
8
+ const db = storage?.sqliteDb
9
+ return useMemo(() => (db ? createContactsStore(db as unknown as ContactsDb) : null), [db])
10
+ }
@@ -55,6 +55,20 @@ function loadExpoRouter(): ExpoRouterModule {
55
55
  return expoRouterMod
56
56
  }
57
57
 
58
+ /**
59
+ * Demo mode's runtime, or a constant `null` in anything but a dev bundle.
60
+ *
61
+ * Resolved once at module scope behind `__DEV__` so the demo folder is
62
+ * required only into a dev bundle: a release build inlines `__DEV__` as false
63
+ * and folds the require — and everything it reaches — out entirely. Same
64
+ * pattern as `utils/AgentationGate.tsx`. Called unconditionally below, because
65
+ * it is a hook and its identity must not change between renders.
66
+ */
67
+ const useDemoRuntime: () => MandalaRuntime | null = __DEV__
68
+ ? // eslint-disable-next-line @typescript-eslint/no-require-imports
69
+ (require('../../core/demo') as typeof import('../../core/demo')).useDemoMandalaRuntime
70
+ : () => null
71
+
58
72
  /** Injected runtime. `undefined` means "ask the wallet context"; `null` means "none". */
59
73
  const MandalaRuntimeContext = createContext<MandalaRuntime | null | undefined>(undefined)
60
74
 
@@ -74,11 +88,14 @@ export function MandalaProvider({
74
88
  * that render money want `useMandala()`.
75
89
  */
76
90
  export function useMandalaRuntime(): MandalaRuntime | null {
91
+ // Before everything else: in demo mode the stablecoin half of the wallet is
92
+ // the demo ledger, whatever the real wallet has built.
93
+ const demo = useDemoRuntime()
77
94
  const injected = useContext(MandalaRuntimeContext)
78
95
  // `undefined` on the context until the wallet is built, and on every chain
79
96
  // but mainnet — which IS the chain gate, not an error state.
80
97
  const fromWallet = useWallet()?.mandala ?? null
81
- const runtime = injected !== undefined ? injected : fromWallet
98
+ const runtime = demo ?? (injected !== undefined ? injected : fromWallet)
82
99
  // `available` is the runtime's own chain gate; a runtime that says it is not
83
100
  // available is the same as none at all for every surface below.
84
101
  return runtime && runtime.available ? runtime : null
@@ -1,8 +1,9 @@
1
- import { useEffect, useRef, useState } from 'react'
2
- import { getOnline, subscribeOnline } from '@bsv/expo-wallet-toolbox'
1
+ import { useEffect, useState } from 'react'
2
+ import { getOnline, probeOnline, subscribeOnline } from '@bsv/expo-wallet-toolbox'
3
3
 
4
4
  /**
5
- * How long a device must keep reporting offline before the UI says so.
5
+ * How long a device must keep reporting offline before the UI even asks whether
6
+ * it is.
6
7
  *
7
8
  * Connectivity flaps: NetInfo emits during handovers, on waking, and while a
8
9
  * native probe is still settling, and the first of those emissions can arrive
@@ -13,40 +14,84 @@ import { getOnline, subscribeOnline } from '@bsv/expo-wallet-toolbox'
13
14
  */
14
15
  export const OFFLINE_CONFIRM_MS = 2500
15
16
 
17
+ /**
18
+ * How often an offline claim is put to the network again while it stands.
19
+ *
20
+ * NetInfo will not emit again for a snapshot that is merely out of date, so
21
+ * left to NetInfo alone a wrong banner would stay until the next network
22
+ * change. This is what lets it clear itself.
23
+ */
24
+ export const OFFLINE_RECHECK_MS = 15_000
25
+
16
26
  /**
17
27
  * Starts optimistic. A first render that wrongly says "online" costs a failed
18
28
  * request; a first render that wrongly says "offline" hides the online payment
19
29
  * rails from a user who has signal, which is worse.
30
+ *
31
+ * NetInfo's offline verdict is a claim, not a fact. On iOS it is a cached
32
+ * reachability snapshot (the OS sends no callbacks while the app is suspended)
33
+ * plus an HTTP probe of a Google host, and either can read offline for a phone
34
+ * whose connection works. So once a report has held for `confirmMs`, a real
35
+ * request to the wallet's own hosts decides: only if that also fails does the
36
+ * UI say offline, and while it does the request is repeated every `recheckMs`.
20
37
  */
21
- export function useOnline(confirmMs: number = OFFLINE_CONFIRM_MS): boolean {
38
+ export function useOnline(confirmMs: number = OFFLINE_CONFIRM_MS, recheckMs: number = OFFLINE_RECHECK_MS): boolean {
22
39
  const [online, setOnline] = useState(true)
23
- // Held in a ref so a pending confirmation survives re-renders and is cleared
24
- // the moment connectivity returns.
25
- const pendingOffline = useRef<ReturnType<typeof setTimeout> | null>(null)
26
40
 
27
41
  useEffect(() => {
28
42
  let cancelled = false
43
+ /** NetInfo's latest verdict is offline: the claim being put to the network. */
44
+ let claimedOffline = false
45
+ let warned = false
46
+ let checking = false
47
+ let timer: ReturnType<typeof setTimeout> | null = null
29
48
 
30
- const clearPending = () => {
31
- if (pendingOffline.current !== null) {
32
- clearTimeout(pendingOffline.current)
33
- pendingOffline.current = null
49
+ const clearTimer = () => {
50
+ if (timer !== null) {
51
+ clearTimeout(timer)
52
+ timer = null
53
+ }
54
+ }
55
+
56
+ const schedule = (ms: number) => {
57
+ timer = setTimeout(() => {
58
+ timer = null
59
+ void verify()
60
+ }, ms)
61
+ }
62
+
63
+ /** Asks the network. Repeats for as long as NetInfo keeps insisting on offline. */
64
+ const verify = async () => {
65
+ checking = true
66
+ let reached = false
67
+ try {
68
+ reached = (await probeOnline()) === true
69
+ } catch {
70
+ // A probe that cannot even run is an offline answer, not a crash.
71
+ }
72
+ checking = false
73
+ // Superseded while the request was out: connectivity came back, or unmounted.
74
+ if (cancelled || !claimedOffline) return
75
+ if (reached && !warned) {
76
+ warned = true
77
+ console.warn('[net] NetInfo reports offline but a live request got through; treating as online')
34
78
  }
79
+ setOnline(reached)
80
+ schedule(recheckMs)
35
81
  }
36
82
 
37
- /** Online applies at once; offline only after it has held for `confirmMs`. */
38
83
  const apply = (next: boolean) => {
39
84
  if (cancelled) return
85
+ claimedOffline = !next
40
86
  if (next) {
41
- clearPending()
87
+ clearTimer()
88
+ warned = false
42
89
  setOnline(true)
43
90
  return
44
91
  }
45
- if (pendingOffline.current !== null) return
46
- pendingOffline.current = setTimeout(() => {
47
- pendingOffline.current = null
48
- if (!cancelled) setOnline(false)
49
- }, confirmMs)
92
+ // Already waiting out the window, or mid-request: that pass covers this report.
93
+ if (timer !== null || checking) return
94
+ schedule(confirmMs)
50
95
  }
51
96
 
52
97
  void getOnline()
@@ -61,10 +106,10 @@ export function useOnline(confirmMs: number = OFFLINE_CONFIRM_MS): boolean {
61
106
 
62
107
  return () => {
63
108
  cancelled = true
64
- clearPending()
109
+ clearTimer()
65
110
  unsubscribe()
66
111
  }
67
- }, [confirmMs])
112
+ }, [confirmMs, recheckMs])
68
113
 
69
114
  return online
70
115
  }
package/ui/index.ts CHANGED
@@ -163,7 +163,7 @@ export {
163
163
  tokenAmountMask,
164
164
  tokenAmountParts
165
165
  } from './tokenFormat'
166
- export { tokenStatusKey, tokenStatusTone, tokenStatusDetailKey, type TokenStatusTone } from './tokenStatus'
166
+ export { tokenStatusKey, tokenRowStatusView, tokenStatusTone, tokenStatusDetailKey, type TokenStatusTone } from './tokenStatus'
167
167
  export { SEEN_ASSETS_KEY, SEEN_EVICTIONS_KEY, markSeen, readSeen, useSeenSet, type SeenSet } from './tokenSeen'
168
168
  export { default as AssetAmount, type AssetAmountProps } from './components/wallet/AssetAmount'
169
169
  export { announceEviction, evictionsFrom, type EvictionNotice } from './components/wallet/tokenEviction'
@@ -179,3 +179,28 @@ export {
179
179
  } from './components/pay/tokenSendCopy'
180
180
  export type { HandleReceiveProps } from './components/pay/HandleReceive'
181
181
  export type { AmountInputAsset } from './components/wallet/AmountInput'
182
+
183
+ // Contacts, profile, and the pencil-edit affordance they share (2026-09-18)
184
+ export { ContactsScreen } from './screens/ContactsScreen'
185
+ export { ContactScreen } from './screens/ContactScreen'
186
+ export { NewContactScreen } from './screens/NewContactScreen'
187
+ export { ProfileScreen } from './screens/ProfileScreen'
188
+ export { IdentifierScreen } from './screens/IdentifierScreen'
189
+ export { default as ProfileButton } from './components/wallet/ProfileButton'
190
+ export { default as ContactSigil } from './components/wallet/ContactSigil'
191
+ export { PencilEditField, type PencilEditFieldProps } from './components/ui/PencilEditField'
192
+
193
+ export {
194
+ default as TransactionDetailScreen,
195
+ type TransactionDetailParams,
196
+ type TransactionAction
197
+ } from './screens/TransactionDetailScreen'
198
+
199
+ export { default as SlideOverFromRight } from './components/ui/SlideOverFromRight'
200
+
201
+ export { default as UserAvatar, AvatarGlyph } from './components/wallet/UserAvatar'
202
+ export { AVATAR_ICON_GROUPS, type AvatarIconOption, type AvatarIconGroup } from './components/wallet/avatarIcons'
203
+
204
+ export { default as IconPickerSheet } from './components/wallet/IconPickerSheet'
205
+ export { default as EditPictureSheet, type EditPictureOption } from './components/wallet/EditPictureSheet'
206
+