@bsv/expo-wallet-toolbox 0.2.0 → 0.3.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,62 @@
1
+ /**
2
+ * Urbit sigil: a deterministic glyph for an @p name such as `~sampel-palnet`.
3
+ * The wallet uses it as the avatar for a counterparty it has no name or
4
+ * picture for, so two payments to the same key are recognisably the same
5
+ * person at a glance without showing them a hex string.
6
+ */
7
+ import React, { useMemo } from 'react'
8
+ import type { StyleProp, ViewStyle } from 'react-native'
9
+ import { SvgXml } from 'react-native-svg'
10
+ // Only ever the `core` entry. The package root pulls in a DOM React renderer
11
+ // that touches `document` at import time, which does not exist on a device.
12
+ import sigil from '@urbit/sigil-js/core'
13
+
14
+ interface SigilProps {
15
+ /** A canonical @p, `~`-prefixed. */
16
+ point: string
17
+ /** Rendered edge in dp; the sigil is always square. */
18
+ size: number
19
+ /** Symbol colour. */
20
+ foreground: string
21
+ /**
22
+ * Tile colour. Must be a solid: sigil-js draws the cut-lines inside each
23
+ * glyph in this colour, so alpha would leave gaps in the shapes.
24
+ */
25
+ background: string
26
+ /**
27
+ * sigil-js's own detail switch. `none` (the default) is the icon form: the
28
+ * inner lines that `default` adds are illegible at avatar size and just
29
+ * make every glyph look equally busy.
30
+ */
31
+ detail?: 'none' | 'default'
32
+ style?: StyleProp<ViewStyle>
33
+ }
34
+
35
+ // sigil-js emits this on the root <svg> for the browser, where an inline svg
36
+ // is otherwise `inline` and picks up line-height slop. Fabric has no such
37
+ // value and logs an error for it on every render, so it is cut before parsing.
38
+ const DOM_ONLY_STYLE = ' style="display: block;"'
39
+
40
+ export default function Sigil({
41
+ point,
42
+ size,
43
+ foreground,
44
+ background,
45
+ detail = 'none',
46
+ style
47
+ }: SigilProps): React.JSX.Element | null {
48
+ const xml = useMemo(() => {
49
+ try {
50
+ return sigil({ point, size, foreground, background, detail, space: 'default' }).replace(DOM_ONLY_STYLE, '')
51
+ } catch {
52
+ // A malformed @p (unknown syllable, odd length) throws inside sigil-js.
53
+ // One bad label must not take a whole activity list down with it.
54
+ return null
55
+ }
56
+ }, [point, size, foreground, background, detail])
57
+
58
+ if (xml === null) return null
59
+ // sigil-js writes `viewbox` in lower case, which the xml parser does not map
60
+ // onto the `viewBox` prop, so the box is restated here or nothing scales.
61
+ return <SvgXml xml={xml} width={size} height={size} viewBox={`0 0 ${size} ${size}`} style={style} />
62
+ }
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * One row of the wallet's activity list.
3
3
  *
4
- * Reading order is direction → what it was → how much, then status and time
5
- * underneath. The per-transaction utilities (status, explorer, resend, cancel)
4
+ * Reading order is who (a sigil avatar for the counterparty, with direction on
5
+ * the tile edge) → what it was → how much, then status and time underneath.
6
+ * The per-transaction utilities (status, explorer, resend, cancel)
6
7
  * are NOT on the row: they used to sit permanently on the right, four icons
7
8
  * deep, which made every row look equally busy whether or not anything needed
8
9
  * doing. They now live behind a tap, and the expanded row lifts onto its own
@@ -12,13 +13,27 @@
12
13
  * txid to a clipboard is not that — it is debugging, and it used to crowd out
13
14
  * the two chips that actually resolve a stuck payment.
14
15
  */
15
- import React, { memo, useContext } from 'react'
16
+ import React, { memo, useContext, useMemo } from 'react'
16
17
  import { View, Text, StyleSheet, ActivityIndicator } from 'react-native'
17
18
  import { useTranslation } from 'react-i18next'
18
19
  import type { WalletAction } from '@bsv/sdk'
19
- import { useTheme, spacing, radii, typography, useWallet, ExchangeRateContext, formatAmount, formatAmountParts } from '@bsv/expo-wallet-toolbox'
20
+ import {
21
+ useTheme,
22
+ spacing,
23
+ radii,
24
+ typography,
25
+ useWallet,
26
+ ExchangeRateContext,
27
+ formatAmount,
28
+ formatAmountParts,
29
+ counterpartyOf,
30
+ counterpartyHue,
31
+ sigilPointOf,
32
+ sigilPalette
33
+ } from '@bsv/expo-wallet-toolbox'
20
34
  import { txStatusView, toneColor } from '../../txStatus'
21
35
  import PressableScale from '../ui/PressableScale'
36
+ import Sigil from '../ui/Sigil'
22
37
 
23
38
  /**
24
39
  * @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
@@ -48,11 +63,14 @@ function loadMaterialCommunityIcons(): MaterialCommunityIconsComponent {
48
63
  return materialCommunityIconsComponent
49
64
  }
50
65
 
51
- /** A row as storage actually returns it: `reference` and `created_at` are real
52
- * columns the SDK's WalletAction type does not declare. */
66
+ /** A row as storage actually returns it: `reference`, `created_at` and
67
+ * `senderIdentityKey` are real columns the SDK's WalletAction type does not
68
+ * declare. The sender key is what an inbound peer payment records about who
69
+ * paid, since nothing else on the row does. */
53
70
  export type ActivityAction = WalletAction & {
54
71
  reference?: string
55
72
  created_at?: string | number | Date
73
+ senderIdentityKey?: string
56
74
  }
57
75
 
58
76
  interface Props {
@@ -117,7 +135,7 @@ function ActivityRowBase({
117
135
  onCancelParked
118
136
  }: Props & { currency: string }) {
119
137
  const { t } = useTranslation()
120
- const { colors } = useTheme()
138
+ const { colors, isDark } = useTheme()
121
139
  const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
122
140
  const MaterialCommunityIcons = loadMaterialCommunityIcons()
123
141
 
@@ -144,6 +162,22 @@ function ActivityRowBase({
144
162
  const amountColor = incoming ? colors.successAmount : colors.textPrimary
145
163
  const unitColor = incoming ? colors.successAmount : colors.textSecondary
146
164
 
165
+ // Keyed on the label contents rather than on `action` or `labels`: every
166
+ // poll hands the row a fresh action object with a fresh labels array for the
167
+ // same transaction, so only a scalar key keeps the @p derivation from
168
+ // re-running per poll. Newline cannot appear in a stored label, so the join
169
+ // is unambiguous.
170
+ const { labels, senderIdentityKey, txid } = action
171
+ const labelsKey = labels?.join('\n') ?? ''
172
+ const face = useMemo(() => {
173
+ const cp = counterpartyOf({ labels: labelsKey === '' ? undefined : labelsKey.split('\n'), senderIdentityKey, txid })
174
+ return cp ? { point: sigilPointOf(cp), hue: counterpartyHue(cp) } : null
175
+ }, [labelsKey, senderIdentityKey, txid])
176
+ // Resolved outside the memo: the hue is a property of the counterparty, the
177
+ // colours it maps to are a property of the theme, and the theme can flip
178
+ // under a mounted row. Two HSL conversions per render are not worth a dep.
179
+ const palette = face ? sigilPalette(face.hue, !!isDark) : null
180
+
147
181
  // A parked payment was built and shown as a code, but never released: it is
148
182
  // not on chain and no task will put it there. An explorer link would 404 and
149
183
  // a Refresh would ask the network about a transaction it has never seen, so
@@ -187,23 +221,50 @@ function ActivityRowBase({
187
221
  accessibilityState={{ expanded }}
188
222
  accessibilityLabel={action.description || t('transactions')}
189
223
  >
190
- <View
191
- style={[
192
- styles.glyph,
193
- incoming
194
- ? {
195
- backgroundColor: colors.successStrong + '1A',
196
- borderColor: colors.successStrong + '2E'
197
- }
198
- : { backgroundColor: colors.surfaceSunken, borderColor: colors.surfaceSunkenBorder }
199
- ]}
200
- >
201
- <MaterialCommunityIcons
202
- name={incoming ? 'arrow-bottom-left' : 'arrow-top-right'}
203
- size={16}
204
- color={incoming ? colors.successStrong : colors.textSecondary}
205
- />
206
- </View>
224
+ {/* The sigil fills the tile, so direction moves to the border tint
225
+ alone: the same tints as the arrow tile, so a mixed list still
226
+ reads consistently down the left edge. The tile takes the
227
+ counterparty's own colour, and the sigil is drawn in exactly that
228
+ pair: sigil-js cuts its glyph lines in the background colour, so
229
+ the fill must be the same solid or the cuts show as a halo. */}
230
+ {face !== null && palette !== null ? (
231
+ <View
232
+ style={[
233
+ styles.glyph,
234
+ styles.avatar,
235
+ {
236
+ backgroundColor: palette.background,
237
+ borderColor: incoming ? colors.successStrong + '2E' : colors.surfaceSunkenBorder
238
+ }
239
+ ]}
240
+ >
241
+ <Sigil
242
+ point={face.point}
243
+ size={38}
244
+ foreground={palette.foreground}
245
+ background={palette.background}
246
+ detail="default"
247
+ />
248
+ </View>
249
+ ) : (
250
+ <View
251
+ style={[
252
+ styles.glyph,
253
+ incoming
254
+ ? {
255
+ backgroundColor: colors.successStrong + '1A',
256
+ borderColor: colors.successStrong + '2E'
257
+ }
258
+ : { backgroundColor: colors.surfaceSunken, borderColor: colors.surfaceSunkenBorder }
259
+ ]}
260
+ >
261
+ <MaterialCommunityIcons
262
+ name={incoming ? 'arrow-bottom-left' : 'arrow-top-right'}
263
+ size={16}
264
+ color={incoming ? colors.successStrong : colors.textSecondary}
265
+ />
266
+ </View>
267
+ )}
207
268
 
208
269
  <View style={styles.middle}>
209
270
  <Text style={[styles.description, { color: colors.textPrimary }]} numberOfLines={1}>
@@ -362,6 +423,8 @@ const styles = StyleSheet.create({
362
423
  alignItems: 'center',
363
424
  justifyContent: 'center'
364
425
  },
426
+ // Clips the square sigil to the tile's rounded corners.
427
+ avatar: { overflow: 'hidden' },
365
428
  middle: { flex: 1, minWidth: 0 },
366
429
  // 14.5/500 rather than body 17/400: the row is scanned, not read, and at 17pt
367
430
  // the description crowds the amount on narrow phones.
package/ui/isImageUrl.ts CHANGED
@@ -1,9 +1,22 @@
1
- import { Image } from 'react-native'
1
+ /**
2
+ * expo-image is required lazily: its package entry is raw TypeScript that Jest
3
+ * does not transform under this package's documented config, and this helper
4
+ * is reached from the `ui` barrel. TrustScreen gives its Image the same
5
+ * treatment.
6
+ */
7
+ type ExpoImageModule = typeof import('expo-image')
8
+ let expoImage: ExpoImageModule | undefined
9
+ function loadExpoImage(): ExpoImageModule {
10
+ if (!expoImage) {
11
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
12
+ expoImage = require('expo-image') as ExpoImageModule
13
+ }
14
+ return expoImage
15
+ }
2
16
 
3
17
  export default async (url: string): Promise<boolean> => {
4
18
  try {
5
- await Image.prefetch(url)
6
- return true
19
+ return await loadExpoImage().Image.prefetch(url)
7
20
  } catch {
8
21
  return false
9
22
  }
@@ -6,12 +6,16 @@ import {
6
6
  ScrollView,
7
7
  TextInput,
8
8
  TouchableOpacity,
9
- Image,
10
9
  Modal,
11
10
  ActivityIndicator
12
11
  } from 'react-native'
12
+ import type { StyleProp, ViewStyle } from 'react-native'
13
+ import { SvgUri } from 'react-native-svg'
13
14
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
14
15
  import { useTranslation } from 'react-i18next'
16
+ // Same deep path WalletContext uses: the package root does not re-export the
17
+ // settings types.
18
+ import type { Certifier as WalletCertifier } from '@bsv/wallet-toolbox-mobile/out/src/WalletSettingsManager'
15
19
  import validateTrust from '../validateTrust'
16
20
  import { GroupedSection } from '../components/ui/GroupedList'
17
21
  import { showAlert } from '../components/ui/AlertCard'
@@ -34,6 +38,22 @@ function loadIonicons(): IoniconsComponent {
34
38
  return ioniconsComponent
35
39
  }
36
40
 
41
+ /**
42
+ * expo-image's package entry is raw TypeScript (`main: src/index.ts`), which
43
+ * Jest does not transform under this package's documented config. Requiring
44
+ * it at render time keeps the `ui` barrel importable in consumers' test
45
+ * suites, the same boundary treatment @expo/vector-icons gets above.
46
+ */
47
+ type ExpoImageComponent = typeof import('expo-image').Image
48
+ let expoImageComponent: ExpoImageComponent | undefined
49
+ function loadExpoImage(): ExpoImageComponent {
50
+ if (!expoImageComponent) {
51
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
52
+ expoImageComponent = require('expo-image').Image as ExpoImageComponent
53
+ }
54
+ return expoImageComponent
55
+ }
56
+
37
57
  /**
38
58
  * expo-router is required lazily rather than imported at module scope: this
39
59
  * file is barrel-exported from the package's `ui` entry point, and a static
@@ -53,12 +73,71 @@ function loadExpoRouter(): ExpoRouterModule {
53
73
  }
54
74
 
55
75
  // -------------------- Types --------------------
56
- export type Certifier = {
57
- name: string
58
- description: string
59
- icon?: string
60
- identityKey: string
61
- trust: number // 1..10
76
+ /**
77
+ * The wallet's own settings type, not a local copy: a local copy is how this
78
+ * screen came to read `icon` while every shipped default (and the library's
79
+ * WalletSettingsManager) stores the URL as `iconUrl`, so the built-in
80
+ * certifiers never showed their icons.
81
+ */
82
+ export type Certifier = WalletCertifier
83
+
84
+ /**
85
+ * Builds before 0.3.0 saved a user-added provider's icon under `icon`. A
86
+ * wallet upgraded in place holds those entries next to `iconUrl` ones, so the
87
+ * screen accepts both on load and writes only the canonical field back.
88
+ * `iconUrl` wins if an entry somehow carries both.
89
+ */
90
+ export function normaliseCertifier(c: Certifier & { icon?: string }): Certifier {
91
+ const { icon, ...rest } = c
92
+ if (rest.iconUrl || !icon) return rest
93
+ return { ...rest, iconUrl: icon }
94
+ }
95
+
96
+ /**
97
+ * An icon URL is a promise the certifier's manifest made, not a guarantee: two
98
+ * of the shipped defaults point at .ico favicons the iOS decoder rejects, and
99
+ * any provider can move its file. The initial-letter tile is therefore the
100
+ * fallback for a failed load as well as for a missing URL, so a broken icon
101
+ * never leaves an empty square where the letter used to be.
102
+ */
103
+ function CertifierIcon({
104
+ url,
105
+ name,
106
+ style,
107
+ placeholderStyle,
108
+ colors
109
+ }: {
110
+ url?: string
111
+ name?: string
112
+ style: React.ComponentProps<ExpoImageComponent>['style']
113
+ placeholderStyle: StyleProp<ViewStyle>
114
+ colors: { accent: string; background: string }
115
+ }) {
116
+ const Image = loadExpoImage()
117
+ // Remembers which URL failed rather than a bare flag, so a corrected URL on
118
+ // the same row gets a fresh attempt.
119
+ const [failedUrl, setFailedUrl] = useState<string | null>(null)
120
+ if (!url || failedUrl === url) {
121
+ return (
122
+ <View style={[placeholderStyle, { backgroundColor: colors.accent }]}>
123
+ <Text style={{ color: colors.background, fontWeight: '700' }}>{name?.[0] || '?'}</Text>
124
+ </View>
125
+ )
126
+ }
127
+ // expo-image hands an SVG to the platform decoder, which on iOS drops
128
+ // percentage-positioned <text> and similar authoring shortcuts, so a vector
129
+ // mark can come out blank or with its glyph in a corner. react-native-svg's
130
+ // own parser is already in the bundle for the activity sigils and handles
131
+ // those, and its fetch or parse failures surface through onError like a
132
+ // raster load would. The wrapper carries the tile's size and radius.
133
+ if (/\.svg(?:[?#]|$)/i.test(url)) {
134
+ return (
135
+ <View style={[style as StyleProp<ViewStyle>, { overflow: 'hidden' }]}>
136
+ <SvgUri uri={url} width="100%" height="100%" onError={() => setFailedUrl(url)} />
137
+ </View>
138
+ )
139
+ }
140
+ return <Image source={{ uri: url }} style={style} onError={() => setFailedUrl(url)} />
62
141
  }
63
142
 
64
143
  // -------------------- Helpers --------------------
@@ -98,7 +177,10 @@ export function TrustScreen() {
98
177
 
99
178
  // Source of truth from Settings — sort by trust descending so position matches priority
100
179
  const initialTrusted: Certifier[] = useMemo(
101
- () => [...(settings?.trustSettings?.trustedCertifiers || [])].sort((a, b) => b.trust - a.trust),
180
+ () =>
181
+ (settings?.trustSettings?.trustedCertifiers || [])
182
+ .map(normaliseCertifier)
183
+ .sort((a, b) => b.trust - a.trust),
102
184
  [settings?.trustSettings?.trustedCertifiers]
103
185
  )
104
186
 
@@ -240,13 +322,13 @@ export function TrustScreen() {
240
322
  ]}
241
323
  >
242
324
  <View style={styles.certifierHeader}>
243
- {item.icon ? (
244
- <Image source={{ uri: item.icon }} style={styles.certifierIcon} />
245
- ) : (
246
- <View style={[styles.certifierIconPlaceholder, { backgroundColor: colors.accent }]}>
247
- <Text style={{ color: colors.background, fontWeight: '700' }}>{item.name?.[0] || '?'}</Text>
248
- </View>
249
- )}
325
+ <CertifierIcon
326
+ url={item.iconUrl}
327
+ name={item.name}
328
+ style={styles.certifierIcon}
329
+ placeholderStyle={styles.certifierIconPlaceholder}
330
+ colors={colors}
331
+ />
250
332
  <View style={{ flex: 1 }}>
251
333
  <Text style={[styles.certifierName, { color: colors.textPrimary }]} numberOfLines={1}>
252
334
  {item.name}
@@ -554,13 +636,13 @@ function AddProviderModal({
554
636
  {fieldsValid && (
555
637
  <View style={[styles.previewBox, { borderColor: colors.separator, backgroundColor: colors.fillTertiary }]}>
556
638
  <View style={{ flexDirection: 'row', alignItems: 'center' }}>
557
- {icon ? (
558
- <Image source={{ uri: icon }} style={styles.previewIcon} />
559
- ) : (
560
- <View style={[styles.previewIcon, { backgroundColor: colors.accent, justifyContent: 'center', alignItems: 'center' }]}>
561
- <Text style={{ color: colors.background, fontWeight: '700' }}>{name?.[0] || '?'}</Text>
562
- </View>
563
- )}
639
+ <CertifierIcon
640
+ url={icon}
641
+ name={name}
642
+ style={styles.previewIcon}
643
+ placeholderStyle={[styles.previewIcon, { justifyContent: 'center', alignItems: 'center' }]}
644
+ colors={colors}
645
+ />
564
646
  <View style={{ marginLeft: spacing.md, flex: 1 }}>
565
647
  <Text style={{ fontWeight: '700', color: colors.textPrimary }}>{name}</Text>
566
648
  <Text style={[styles.previewKey, { color: colors.textSecondary }]}>{maskKey(identityKey)}</Text>
@@ -590,7 +672,7 @@ function AddProviderModal({
590
672
  </TouchableOpacity>
591
673
  <TouchableOpacity
592
674
  disabled={!ready}
593
- onPress={() => onAdd({ name, description, icon, identityKey })}
675
+ onPress={() => onAdd({ name, description, iconUrl: icon, identityKey })}
594
676
  style={[styles.saveBtn, { backgroundColor: colors.accent, opacity: ready ? 1 : 0.5, flex: 0 }]}
595
677
  >
596
678
  <Ionicons name="shield-checkmark-outline" size={16} color={colors.background} />
@@ -17,7 +17,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage'
17
17
  import { PeerPayClient } from '@bsv/message-box-client'
18
18
  import { showAlert } from '../components/ui/AlertCard'
19
19
  import { makeCreditClassifier } from '../../core/pay/creditErrors'
20
- import { creditInboxOnce, INBOX_DESCRIPTION } from '../../core/pay/creditInbox'
20
+ import { creditInboxOnce } from '../../core/pay/creditInbox'
21
21
  import { makeBeefRepair } from '../../core/pay/beefRepair'
22
22
  import {
23
23
  acceptWithRetry,
@@ -192,8 +192,8 @@ function useWalletCheckPorts(): WalletCheckPorts {
192
192
  storage: storage ?? undefined,
193
193
  classify,
194
194
  accept: payment =>
195
- acceptWithRetry(client, messageBoxUrl, payment, INBOX_DESCRIPTION, (p, d) =>
196
- internalizeIncoming(wallet as never, client, adminOriginator, p, d, repairBeef)
195
+ acceptWithRetry(client, messageBoxUrl, payment, p =>
196
+ internalizeIncoming(wallet as never, client, adminOriginator, p, repairBeef)
197
197
  )
198
198
  })
199
199
  return { accepted: outcome.accepted }