@bsv/expo-wallet-toolbox 0.2.1 → 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.
- package/README.md +26 -1
- package/core/amountFormatHelpers.ts +16 -30
- package/core/context/WalletContext.tsx +15 -3
- package/core/index.ts +16 -5
- package/core/localpay/build.ts +4 -1
- package/core/localpay/pending.ts +5 -2
- package/core/pay/counterparty.ts +159 -0
- package/core/pay/creditInbox.ts +0 -3
- package/core/pay/patp.ts +181 -0
- package/core/pay/rails/address.ts +47 -7
- package/core/pay/rails/handle.ts +24 -14
- package/core/peerpay/handleResendRequests.ts +1 -2
- package/core/storage/StorageExpoSQLite.ts +37 -0
- package/core/storage/methods/listActionsSql.ts +9 -0
- package/core/theme/sigilPalette.ts +83 -0
- package/package.json +3 -1
- package/ui/components/pay/HandleReceive.tsx +4 -4
- package/ui/components/ui/AppLogo.tsx +9 -1
- package/ui/components/ui/Sigil.tsx +62 -0
- package/ui/components/wallet/ActivityRow.tsx +87 -24
- package/ui/isImageUrl.ts +16 -3
- package/ui/screens/TrustScreen.tsx +105 -23
- package/ui/screens/WalletCheckScreen.tsx +3 -3
package/ui/isImageUrl.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
() =>
|
|
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
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
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
|
|
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,
|
|
196
|
-
internalizeIncoming(wallet as never, client, adminOriginator, p,
|
|
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 }
|