@bsv/expo-wallet-toolbox 0.28.0 → 0.30.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 +33 -0
- package/core/backup/appData.ts +16 -3
- package/core/backup/codec.ts +15 -2
- package/core/i18n/translations.tsx +2802 -196
- package/package.json +1 -1
- package/ui/components/pay/NearbyFlow.tsx +460 -197
- package/ui/components/vault/EnrollWizard.tsx +84 -10
- package/ui/index.ts +2 -0
|
@@ -314,7 +314,17 @@ export interface EnrollWizardProps {
|
|
|
314
314
|
* tell whether the card opens a vault: it treats that as "unknown" and a reset needs the affirmation.
|
|
315
315
|
*/
|
|
316
316
|
cardGate?: {
|
|
317
|
-
|
|
317
|
+
/**
|
|
318
|
+
* `onProgress` gets how far the scan is (0 to 1) after each place it checks. `signal` is aborted when the
|
|
319
|
+
* person skips the check or the page closes: the check then ends soon, and its answer is ignored.
|
|
320
|
+
*/
|
|
321
|
+
check: (
|
|
322
|
+
serial: string,
|
|
323
|
+
options?: {
|
|
324
|
+
onProgress?: (progress: { checked: number; fraction: number }) => void
|
|
325
|
+
signal?: AbortSignal
|
|
326
|
+
}
|
|
327
|
+
) => Promise<VaultCardFunds>
|
|
318
328
|
args: (
|
|
319
329
|
result: VaultCardFunds | null,
|
|
320
330
|
affirmed: boolean
|
|
@@ -400,6 +410,10 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({
|
|
|
400
410
|
/** The chain check for the card on the reset page or the slot-occupied page. null while it runs. */
|
|
401
411
|
const [cardCheck, setCardCheck] = useState<VaultCardFunds | null>(null)
|
|
402
412
|
const [checkRound, setCheckRound] = useState(0)
|
|
413
|
+
/** How far the running check is, 0 to 1. null before the scan reports, or with no cardGate. */
|
|
414
|
+
const [cardProgress, setCardProgress] = useState<number | null>(null)
|
|
415
|
+
/** The running check: `skipCardCheck` stops it and drops its answer. */
|
|
416
|
+
const cardRunRef = useRef<{ live: boolean; stop: () => void } | null>(null)
|
|
403
417
|
/** "Any funds in a vault that uses this key are lost for good if you reset it." */
|
|
404
418
|
const [lossAck, setLossAck] = useState(false)
|
|
405
419
|
/** A write (finalizeEnrollment / addVaultKey) is in flight. */
|
|
@@ -458,23 +472,43 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({
|
|
|
458
472
|
sub === 'reset' || (sub === 'error' && keyError?.code === 'slot-occupied') ? keyError?.resetSerial : undefined
|
|
459
473
|
useEffect(() => {
|
|
460
474
|
setCardCheck(null)
|
|
475
|
+
setCardProgress(null)
|
|
461
476
|
// a new check starts: the sentence ticked for an earlier result is not carried over to this one
|
|
462
477
|
setLossAck(false)
|
|
463
478
|
if (!gateSerial) return
|
|
464
|
-
let live = true
|
|
465
479
|
const unknown = (reason: string): VaultCardFunds => ({ kind: 'unknown', serial: gateSerial, reason, problems: 0 })
|
|
466
480
|
if (!cardGate) {
|
|
467
481
|
setCardCheck(unknown('no-check'))
|
|
468
482
|
return
|
|
469
483
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
484
|
+
const controller = new AbortController()
|
|
485
|
+
const run = { live: true, stop: () => controller.abort() }
|
|
486
|
+
cardRunRef.current = run
|
|
487
|
+
cardGate
|
|
488
|
+
.check(gateSerial, {
|
|
489
|
+
onProgress: progress => run.live && setCardProgress(progress.fraction),
|
|
490
|
+
signal: controller.signal
|
|
491
|
+
})
|
|
492
|
+
.then(
|
|
493
|
+
result => run.live && setCardCheck(result),
|
|
494
|
+
() => run.live && setCardCheck(unknown('check-failed'))
|
|
495
|
+
)
|
|
474
496
|
return () => {
|
|
475
|
-
|
|
497
|
+
// the page closed or a new check started: this scan stops sending requests, and its answer is dropped
|
|
498
|
+
run.live = false
|
|
499
|
+
run.stop()
|
|
500
|
+
if (cardRunRef.current === run) cardRunRef.current = null
|
|
476
501
|
}
|
|
477
502
|
}, [gateSerial, cardGate, checkRound])
|
|
503
|
+
/** The person does not wait for the check. The answer is "unknown": a reset still needs the loss sentence. */
|
|
504
|
+
const skipCardCheck = () => {
|
|
505
|
+
const run = cardRunRef.current
|
|
506
|
+
if (run) {
|
|
507
|
+
run.live = false
|
|
508
|
+
run.stop()
|
|
509
|
+
}
|
|
510
|
+
if (gateSerial) setCardCheck({ kind: 'unknown', serial: gateSerial, reason: 'skipped', problems: 0 })
|
|
511
|
+
}
|
|
478
512
|
/** What resetPivApplication takes, or null while the card may not be reset or replaced. */
|
|
479
513
|
const gateArgs: { fundsClearance: VaultResetClearance } | { acknowledgeFundsLoss: true } | null = cardGate
|
|
480
514
|
? cardGate.args(cardCheck, lossAck)
|
|
@@ -1149,7 +1183,27 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({
|
|
|
1149
1183
|
const cardGateBlock = (
|
|
1150
1184
|
<>
|
|
1151
1185
|
{cardCheck === null && (
|
|
1152
|
-
|
|
1186
|
+
<>
|
|
1187
|
+
<BalancedText style={[styles.p, { color: colors.textSecondary }]}>{t('vault_card_checking')}</BalancedText>
|
|
1188
|
+
{(() => {
|
|
1189
|
+
const percent = Math.floor((cardProgress ?? 0) * 100)
|
|
1190
|
+
return (
|
|
1191
|
+
<View
|
|
1192
|
+
style={styles.progress}
|
|
1193
|
+
accessibilityRole="progressbar"
|
|
1194
|
+
accessibilityValue={{ min: 0, max: 100, now: percent }}
|
|
1195
|
+
>
|
|
1196
|
+
<View style={[styles.progressTrack, { backgroundColor: colors.backgroundSecondary }]}>
|
|
1197
|
+
<View style={[styles.progressFill, { backgroundColor: colors.accent, width: `${percent}%` }]} />
|
|
1198
|
+
</View>
|
|
1199
|
+
<Text style={[styles.progressLabel, { color: colors.textSecondary }]}>
|
|
1200
|
+
{t('vault_card_progress', { percent })}
|
|
1201
|
+
</Text>
|
|
1202
|
+
</View>
|
|
1203
|
+
)
|
|
1204
|
+
})()}
|
|
1205
|
+
<ActionButton label={t('vault_card_skip')} variant="outline" onPress={skipCardCheck} />
|
|
1206
|
+
</>
|
|
1153
1207
|
)}
|
|
1154
1208
|
{cardCheck?.kind === 'funds' && (
|
|
1155
1209
|
<>
|
|
@@ -1162,10 +1216,30 @@ export const EnrollWizard: React.FC<EnrollWizardProps> = ({
|
|
|
1162
1216
|
)}
|
|
1163
1217
|
</>
|
|
1164
1218
|
)}
|
|
1165
|
-
{cardCheck?.kind === 'unknown' && (
|
|
1219
|
+
{cardCheck?.kind === 'unknown' && cardCheck.reason === 'skipped' && (
|
|
1220
|
+
<>
|
|
1221
|
+
<Text style={[styles.h1, { color: colors.textPrimary }]}>{t('vault_card_skipped_title')}</Text>
|
|
1222
|
+
<BalancedText style={[styles.p, { color: colors.textSecondary }]}>
|
|
1223
|
+
{t('vault_card_skipped_body')}
|
|
1224
|
+
</BalancedText>
|
|
1225
|
+
<ActionButton
|
|
1226
|
+
label={t('vault_card_check')}
|
|
1227
|
+
variant="outline"
|
|
1228
|
+
onPress={() => setCheckRound(round => round + 1)}
|
|
1229
|
+
/>
|
|
1230
|
+
</>
|
|
1231
|
+
)}
|
|
1232
|
+
{cardCheck?.kind === 'unknown' && cardCheck.reason !== 'skipped' && (
|
|
1166
1233
|
<>
|
|
1167
1234
|
<Text style={[styles.h1, { color: colors.textPrimary }]}>{t('vault_card_unknown_title')}</Text>
|
|
1168
|
-
<BalancedText style={[styles.p, { color: colors.textSecondary }]}>
|
|
1235
|
+
<BalancedText style={[styles.p, { color: colors.textSecondary }]}>
|
|
1236
|
+
{t('vault_card_unknown_body')}
|
|
1237
|
+
</BalancedText>
|
|
1238
|
+
{cardCheck.reason !== 'no-check' && (
|
|
1239
|
+
<Text style={[styles.warn, { color: colors.textTertiary }]}>
|
|
1240
|
+
{t('vault_card_reason', { reason: cardCheck.reason })}
|
|
1241
|
+
</Text>
|
|
1242
|
+
)}
|
|
1169
1243
|
{cardGate && (
|
|
1170
1244
|
<ActionButton
|
|
1171
1245
|
label={t('vault_card_retry')}
|