@bsv/expo-wallet-toolbox 0.4.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.
- package/CHANGELOG.md +547 -0
- package/README.md +19 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/amountFormatHelpers.ts +238 -34
- package/core/backup/RemoteSyncReader.ts +2 -5
- package/core/backup/codec.ts +2 -2
- package/core/backup/push.ts +1 -1
- package/core/config.tsx +16 -1
- package/core/contacts/contactActivity.ts +153 -0
- package/core/contacts/contactCache.ts +41 -0
- package/core/contacts/contactsStore.ts +183 -0
- package/core/context/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +464 -30
- package/core/demo/demoAssets.ts +60 -0
- package/core/demo/demoLedger.ts +240 -0
- package/core/demo/demoMandalaRuntime.ts +96 -0
- package/core/demo/demoMode.ts +38 -0
- package/core/demo/demoWallet.ts +25 -0
- package/core/demo/index.ts +26 -0
- package/core/demo/useDemo.ts +59 -0
- package/core/headers/OfflineFirstChaintracks.ts +52 -14
- package/core/headers/headerStore.ts +7 -10
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +4562 -986
- package/core/identity/contactLink.ts +36 -0
- package/core/identity/handleRegistry/client.ts +285 -0
- package/core/identity/handleRegistry/profileCert.ts +254 -0
- package/core/identity/handleRegistry/registration.ts +559 -0
- package/core/identity/handleRegistry/resolver.ts +247 -0
- package/core/identity/handleRegistry/rules.ts +104 -0
- package/core/index.ts +116 -15
- package/core/localpay/build.ts +674 -37
- package/core/localpay/codec.ts +68 -5
- package/core/localpay/pending.ts +240 -22
- package/core/localpay/pendingAborts.ts +5 -1
- package/core/localpay/settlementAck.ts +149 -0
- package/core/localpay/types.ts +14 -1
- package/core/localpay/verify.ts +118 -69
- package/core/mandala/abortGuard.ts +134 -0
- package/core/mandala/basketMigration.ts +166 -0
- package/core/mandala/bundle.ts +244 -0
- package/core/mandala/createRuntime.ts +2437 -0
- package/core/mandala/drain.ts +670 -0
- package/core/mandala/permissionModule.ts +642 -0
- package/core/mandala/resendTransfer.ts +175 -0
- package/core/mandala/runtime.ts +357 -0
- package/core/mandala/settlementStore.ts +412 -0
- package/core/mandala/types.ts +290 -0
- package/core/monitor/MonitorSupervisor.ts +121 -0
- package/core/monitor/TaskBackupPush.ts +1 -1
- package/core/monitor/TaskCreditInbox.ts +1 -1
- package/core/monitor/TaskDrainOutbox.ts +1 -1
- package/core/monitor/TaskSendOffline.ts +1 -1
- package/core/net/online.ts +49 -0
- package/core/numberFormat.ts +19 -0
- package/core/offline/cancelParked.ts +94 -1
- package/core/offline/payerHold.ts +152 -12
- package/core/offline/plan.ts +1 -1
- package/core/offline/tokenFrames.ts +197 -0
- package/core/parsePeerPayURI.ts +70 -17
- package/core/pay/rails/address.ts +51 -3
- package/core/pay/rails/handle.ts +88 -9
- package/core/pay/rails/index.ts +16 -6
- package/core/pay/rails/nearby.ts +114 -4
- package/core/pay/recordProof.ts +2 -6
- package/core/services/arcadeBroadcastProvider.ts +1 -4
- package/core/services/capWalletArgs.ts +8 -9
- package/core/services/exchangeRate.ts +1 -1
- package/core/services/externalOrigin.ts +42 -0
- package/core/services/vault/VaultKeyService.ts +912 -251
- package/core/services/vault/ceremony.ts +435 -367
- package/core/services/vault/ceremonyHost.ts +27 -21
- package/core/services/vault/devMock.ts +30 -7
- package/core/services/vault/driver.ts +95 -41
- package/core/services/vault/guard.ts +514 -56
- package/core/services/vault/hardwareLease.ts +22 -0
- package/core/services/vault/mockYubiKey.ts +258 -90
- package/core/services/vault/pivReset.ts +145 -0
- package/core/services/vault/r1comb.ts +976 -0
- package/core/services/vault/session.ts +93 -26
- package/core/services/vault/transfers.ts +2617 -747
- package/core/services/vault/types.ts +100 -43
- package/core/services/vault/vaultStore.ts +991 -74
- package/core/services/walletConnectionValidation.ts +293 -0
- package/core/services/walletServiceConfig.ts +31 -20
- package/core/storage/StorageExpoSQLite.ts +420 -87
- package/core/storage/dbImage.ts +48 -0
- package/core/storage/methods/findSql.ts +3 -54
- package/core/storage/methods/listActionsSql.ts +8 -5
- package/core/storage/methods/listOutputsSql.ts +9 -5
- package/core/storage/methods/offlineActions.ts +15 -0
- package/core/storage/methods/processOfflineActions.ts +265 -9
- package/core/storage/methods/reviewStatusSql.ts +7 -2
- package/core/storage/methods/walletBalanceSql.ts +16 -4
- package/core/storage/schema/createTables.ts +152 -0
- package/core/storage/sqlUpdateValue.ts +24 -0
- package/core/toolboxConfig.ts +182 -1
- package/core/toolboxTypes.ts +40 -0
- package/core/userAvatar.ts +79 -0
- package/core/walletMonitor.ts +8 -3
- package/core/walletRepair/runWalletCheck.ts +19 -2
- package/package.json +31 -30
- package/ui/activityFilter.ts +115 -0
- package/ui/components/QRScanner.tsx +1 -1
- package/ui/components/pay/AdmissionNotice.tsx +99 -0
- package/ui/components/pay/AssetPicker.tsx +184 -0
- package/ui/components/pay/AvailableBalance.tsx +33 -2
- package/ui/components/pay/HandleReceive.tsx +213 -50
- package/ui/components/pay/NearbyFlow.tsx +616 -69
- package/ui/components/pay/PayForm.tsx +73 -8
- package/ui/components/pay/PaymentSuccessOverlay.tsx +89 -8
- package/ui/components/pay/RecipientField.tsx +132 -73
- package/ui/components/pay/RequestHub.tsx +68 -8
- package/ui/components/pay/ResultBanner.tsx +41 -4
- package/ui/components/pay/StepBar.tsx +32 -0
- package/ui/components/pay/UniversalSend.tsx +1118 -86
- package/ui/components/pay/tokenSendCopy.ts +116 -0
- package/ui/components/pay/useRecipientInput.ts +36 -7
- package/ui/components/ui/PencilEditField.tsx +109 -0
- package/ui/components/ui/PermissionSheet.tsx +65 -4
- package/ui/components/ui/Sheet.tsx +9 -2
- package/ui/components/ui/SlideOverFromRight.tsx +86 -0
- package/ui/components/vault/EnrollWizard.tsx +1432 -488
- package/ui/components/vault/KeyChooser.tsx +96 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
- package/ui/components/vault/vaultErrorCopy.ts +145 -0
- package/ui/components/wallet/ActivityRow.tsx +283 -97
- package/ui/components/wallet/AmountInput.tsx +92 -28
- package/ui/components/wallet/AssetAmount.tsx +95 -0
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
- package/ui/components/wallet/ContactActivityList.tsx +149 -0
- package/ui/components/wallet/ContactSigil.tsx +49 -0
- package/ui/components/wallet/EditPictureSheet.tsx +99 -0
- package/ui/components/wallet/FitAmount.tsx +148 -0
- package/ui/components/wallet/IconPickerSheet.tsx +168 -0
- package/ui/components/wallet/IdentifierRow.tsx +69 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
- package/ui/components/wallet/ProfileButton.tsx +62 -0
- package/ui/components/wallet/UserAvatar.tsx +85 -0
- package/ui/components/wallet/avatarIcons.ts +122 -0
- package/ui/components/wallet/tokenEviction.ts +65 -0
- package/ui/hooks/useContactsStore.ts +10 -0
- package/ui/hooks/useExportWalletData.ts +39 -0
- package/ui/hooks/useMandala.ts +320 -0
- package/ui/hooks/useOnline.ts +65 -20
- package/ui/hooks/useVaultBalance.ts +105 -7
- package/ui/hooks/useVaultCoverage.ts +52 -0
- package/ui/importDatabases.ts +7 -3
- package/ui/index.ts +75 -7
- package/ui/screens/ConnectionsScreen.tsx +46 -29
- package/ui/screens/ContactScreen.tsx +289 -0
- package/ui/screens/ContactsScreen.tsx +373 -0
- package/ui/screens/IdentifierScreen.tsx +234 -0
- package/ui/screens/NewContactScreen.tsx +362 -0
- package/ui/screens/PairScreen.tsx +12 -12
- package/ui/screens/PayScreen.tsx +145 -12
- package/ui/screens/ProfileScreen.tsx +783 -0
- package/ui/screens/SettingsScreen.tsx +18 -9
- package/ui/screens/TransactionDetailScreen.tsx +419 -0
- package/ui/screens/TrustScreen.tsx +1 -1
- package/ui/screens/VaultScreen.tsx +925 -171
- package/ui/screens/VaultTransferScreen.tsx +376 -123
- package/ui/screens/WalletCheckScreen.tsx +10 -1
- package/ui/screens/WalletConfigScreen.tsx +80 -16
- package/ui/screens/WalletHomeScreen.tsx +915 -139
- package/ui/screens/homeBadges.ts +9 -1
- package/ui/screens/tokenRowTitle.ts +68 -0
- package/ui/tokenFormat.ts +108 -0
- package/ui/tokenSeen.ts +75 -0
- package/ui/tokenStatus.ts +100 -0
- package/ui/txStatus.ts +43 -5
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/services/vault/k1.ts +0 -75
- package/core/services/vault/sealing.ts +0 -84
- package/core/services/vault/vaultDerivation.ts +0 -152
- package/core/services/vault/vaultPassphrase.ts +0 -287
- package/ui/components/vault/PassphraseField.tsx +0 -306
- package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
- package/ui/screens/VaultRecoverScreen.tsx +0 -226
|
@@ -7,13 +7,16 @@
|
|
|
7
7
|
* code is handed up to the Pay screen, which swaps this form for NearbyFlow.
|
|
8
8
|
* Nothing here is chosen by the user except the recipient and the amount.
|
|
9
9
|
*
|
|
10
|
-
* The form recomposes by what the field resolved to: a note field
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* The form recomposes by what the field resolved to: a note field is shown
|
|
11
|
+
* for both handles and addresses (in BSV mode — a token has no address rail
|
|
12
|
+
* at all, D4). For a handle the note is sent to the counterparty and becomes
|
|
13
|
+
* their action's description; for an address there is no counterparty
|
|
14
|
+
* channel to carry it over, so it is purely the sender's own record for
|
|
15
|
+
* their own outbound description. The "they are not notified" consequence is
|
|
16
|
+
* shown only for addresses, where it is load-bearing — a user who pastes an
|
|
17
|
+
* address expecting messaging-style delivery has effectively posted cash.
|
|
15
18
|
*/
|
|
16
|
-
import React, { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
|
19
|
+
import React, { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useMemo, useState, useRef } from 'react'
|
|
17
20
|
import { ActivityIndicator, Modal, ScrollView, StyleSheet, Text, TextInput, View } from 'react-native'
|
|
18
21
|
import { useTranslation } from 'react-i18next'
|
|
19
22
|
|
|
@@ -28,19 +31,35 @@ import { showToast } from '../ui/Toast'
|
|
|
28
31
|
import { ConsequenceNote, PayAmountField, PayCta, PayField } from './PayForm'
|
|
29
32
|
import PaymentSuccessOverlay from './PaymentSuccessOverlay'
|
|
30
33
|
import ResultBanner from './ResultBanner'
|
|
31
|
-
import RecipientField from './RecipientField'
|
|
34
|
+
import RecipientField, { type RecipientRow } from './RecipientField'
|
|
35
|
+
import StepBar, { type PayStep } from './StepBar'
|
|
32
36
|
import { useMessageBoxConfig } from './MessageBoxConfig'
|
|
33
|
-
import { useRecipientInput, type RecipientTarget } from './useRecipientInput'
|
|
37
|
+
import { useRecipientInput, type RecipientTarget, type PeerPayRequest } from './useRecipientInput'
|
|
38
|
+
import { tokenSendCopy, tokenThrowCopy, type TokenSendCopy } from './tokenSendCopy'
|
|
39
|
+
import { useAssetStatus, useMandala } from '../../hooks/useMandala'
|
|
40
|
+
import { useSpendableBalance } from '../../hooks/useSpendableBalance'
|
|
41
|
+
import { useContactsStore } from '../../hooks/useContactsStore'
|
|
42
|
+
import ContactSigil from '../wallet/ContactSigil'
|
|
43
|
+
import { formatTokenAmount, formatTokenAmountWithUnit } from '../../tokenFormat'
|
|
44
|
+
import { abbreviateKey } from '../../../core/pay/counterparty'
|
|
45
|
+
import type { ContactRow } from '../../../core/contacts/contactsStore'
|
|
46
|
+
import { createHandleRegistryClient } from '../../../core/identity/handleRegistry/client'
|
|
47
|
+
import type { RegistryProfile } from '../../../core/identity/handleRegistry/profileCert'
|
|
34
48
|
import {
|
|
35
49
|
useTheme,
|
|
36
50
|
spacing,
|
|
37
51
|
typography,
|
|
38
52
|
radii,
|
|
39
53
|
hitTargets,
|
|
54
|
+
formatSatoshisAsBsvDecimal,
|
|
55
|
+
useWallet,
|
|
40
56
|
useWalletManagers,
|
|
57
|
+
useWalletStatus,
|
|
41
58
|
CONSEQUENCE_KEYS,
|
|
42
59
|
NO_MESSAGE_BOX,
|
|
43
60
|
cancelOutboxPayment,
|
|
61
|
+
classifyRecipientInput,
|
|
62
|
+
getHandleRegistryConfig,
|
|
44
63
|
isMessageBoxNetworkError,
|
|
45
64
|
makePeerPayClient,
|
|
46
65
|
retryDelivery,
|
|
@@ -56,6 +75,23 @@ import {
|
|
|
56
75
|
} from '@bsv/expo-wallet-toolbox'
|
|
57
76
|
import type { DismissTarget } from '../../dismissTarget'
|
|
58
77
|
|
|
78
|
+
/**
|
|
79
|
+
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
80
|
+
* etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
|
|
81
|
+
* that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
|
|
82
|
+
* Ionicons is loaded lazily, only when actually rendering, same pattern as
|
|
83
|
+
* this package's other native-module-boundary fixes.
|
|
84
|
+
*/
|
|
85
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
86
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
87
|
+
function loadIonicons(): IoniconsComponent {
|
|
88
|
+
if (!ioniconsComponent) {
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
90
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
91
|
+
}
|
|
92
|
+
return ioniconsComponent
|
|
93
|
+
}
|
|
94
|
+
|
|
59
95
|
/**
|
|
60
96
|
* expo-status-bar's package.json `main` points straight at its raw
|
|
61
97
|
* TypeScript source (no compiled build output ships), and the unscoped,
|
|
@@ -91,6 +127,11 @@ function loadExpoRouter(): ExpoRouterModule {
|
|
|
91
127
|
return expoRouterMod
|
|
92
128
|
}
|
|
93
129
|
|
|
130
|
+
/** The registry's own debounce. Deliberately a third constant rather than a
|
|
131
|
+
* shared one: `useRecipientInput`'s overlay timer and `ProfileScreen`'s
|
|
132
|
+
* availability timer are separate decisions that happen to agree today. */
|
|
133
|
+
const REGISTRY_SEARCH_DEBOUNCE_MS = 400
|
|
134
|
+
|
|
94
135
|
// ── Outgoing Section ─────────────────────────────────────────────────────────
|
|
95
136
|
|
|
96
137
|
interface OutgoingSectionProps {
|
|
@@ -178,11 +219,36 @@ function OutgoingSection({ entries, retryingId, colors, t, onRetry, onCancel }:
|
|
|
178
219
|
)
|
|
179
220
|
}
|
|
180
221
|
|
|
222
|
+
/**
|
|
223
|
+
* What the host screen can ask of the form: walk back one step. Returns false
|
|
224
|
+
* when already on the first step, so the host knows to leave the screen
|
|
225
|
+
* instead — the header's one back chevron serves both (2026-09-18 design: no
|
|
226
|
+
* second back control inside the form).
|
|
227
|
+
*/
|
|
228
|
+
export interface UniversalSendHandle {
|
|
229
|
+
back(): boolean
|
|
230
|
+
}
|
|
231
|
+
|
|
181
232
|
export interface UniversalSendProps {
|
|
182
233
|
/** A recipient known before the form opened: a peerpay deep link or `?identityKey=`. */
|
|
183
234
|
initialTarget?: Extract<RecipientTarget, { kind: 'handle' }>
|
|
184
235
|
/** Prefilled amount in satoshis from a peerpay link or `?sats=`. */
|
|
185
236
|
initialSats?: number
|
|
237
|
+
/**
|
|
238
|
+
* Prefilled TOKEN amount from a peerpay link's `asset=`/`amount=`: base units
|
|
239
|
+
* of that asset. Takes precedence over `initialSats` — a link names one money.
|
|
240
|
+
* The figure only ever shows while that asset is the one selected (see the
|
|
241
|
+
* unit tag on the figure below), so a link for a token this wallet turns out
|
|
242
|
+
* not to hold seeds nothing.
|
|
243
|
+
*/
|
|
244
|
+
initialTokenAmount?: { assetId: string; baseUnits: number }
|
|
245
|
+
/**
|
|
246
|
+
* The asset this payment is denominated in. `null` is BSV — the default, and
|
|
247
|
+
* what every existing flow assumes. Controlled by the Pay screen so the
|
|
248
|
+
* choice survives a hop into Get paid and back.
|
|
249
|
+
*/
|
|
250
|
+
selectedAssetId?: string | null
|
|
251
|
+
onSelectAsset?: (assetId: string | null) => void
|
|
186
252
|
/** Error text from a malformed peerpay link, shown as a banner. */
|
|
187
253
|
initialNotice?: string | null
|
|
188
254
|
/** Open the scanner as soon as the form mounts (deep link `cell=pay-nearby`). */
|
|
@@ -191,56 +257,523 @@ export interface UniversalSendProps {
|
|
|
191
257
|
onNearbySession: (session: Session) => void
|
|
192
258
|
/** Where the post-payment overlay sends the user. Defaults to `/`. */
|
|
193
259
|
dismissTo?: DismissTarget
|
|
260
|
+
/** Which of the three steps is on screen — the host names its header by it. */
|
|
261
|
+
onStepChange?: (step: PayStep) => void
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The typed (or link-supplied) figure, tagged with the unit it was entered in:
|
|
266
|
+
* `null` for satoshis, an assetId for that token's base units.
|
|
267
|
+
*/
|
|
268
|
+
interface Figure {
|
|
269
|
+
text: string
|
|
270
|
+
unit: string | null
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function seedFigure(sats?: number, token?: { assetId: string; baseUnits: number }): Figure {
|
|
274
|
+
if (token && Number.isFinite(token.baseUnits) && token.baseUnits > 0) {
|
|
275
|
+
return { text: String(Math.round(token.baseUnits)), unit: token.assetId }
|
|
276
|
+
}
|
|
277
|
+
if (sats && sats > 0) return { text: String(sats), unit: null }
|
|
278
|
+
return { text: '', unit: null }
|
|
194
279
|
}
|
|
195
280
|
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
281
|
+
function UniversalSendInner(
|
|
282
|
+
{
|
|
283
|
+
initialTarget,
|
|
284
|
+
initialSats,
|
|
285
|
+
initialTokenAmount,
|
|
286
|
+
initialNotice,
|
|
287
|
+
openScannerOnMount = false,
|
|
288
|
+
onNearbySession,
|
|
289
|
+
selectedAssetId,
|
|
290
|
+
onSelectAsset,
|
|
291
|
+
dismissTo = '/',
|
|
292
|
+
onStepChange
|
|
293
|
+
}: UniversalSendProps,
|
|
294
|
+
ref: React.ForwardedRef<UniversalSendHandle>
|
|
295
|
+
) {
|
|
204
296
|
const { t } = useTranslation()
|
|
205
297
|
const { colors } = useTheme()
|
|
206
298
|
const StatusBar = loadStatusBar()
|
|
299
|
+
const Ionicons = loadIonicons()
|
|
207
300
|
const { managers, adminOriginator, storage } = useWalletManagers()
|
|
301
|
+
const { walletBuilt } = useWalletStatus()
|
|
302
|
+
const { walletUserId, selectedNetwork } = useWallet()
|
|
208
303
|
const wallet = managers?.permissionsManager || null
|
|
209
304
|
|
|
305
|
+
// ── the three-step flow (who / amount / review, 2026-09-18 design) ──────
|
|
306
|
+
// A recipient known before the form opened (a deep link, a scan on the way
|
|
307
|
+
// in) starts on 'amount' — the identity is already decided. Everything
|
|
308
|
+
// else about this form is unchanged; `step` only decides which of the
|
|
309
|
+
// sections below is on screen.
|
|
310
|
+
const [step, setStep] = useState<PayStep>(initialTarget ? 'amount' : 'who')
|
|
311
|
+
// A second deep link while this form is mounted re-adopts the recipient
|
|
312
|
+
// (see useRecipientInput's own initialTarget effect) and must jump the
|
|
313
|
+
// step forward the same way the initial mount does — a link naming a
|
|
314
|
+
// payee is a stronger signal than whatever step the user was on.
|
|
315
|
+
useEffect(() => {
|
|
316
|
+
if (initialTarget) setStep('amount')
|
|
317
|
+
}, [initialTarget?.identityKey])
|
|
318
|
+
const contactsStore = useContactsStore()
|
|
319
|
+
const [contactMatches, setContactMatches] = useState<ContactRow[]>([])
|
|
320
|
+
const [registryMatches, setRegistryMatches] = useState<RegistryProfile[]>([])
|
|
321
|
+
const [registrySearching, setRegistrySearching] = useState(false)
|
|
322
|
+
const [registryError, setRegistryError] = useState(false)
|
|
323
|
+
/**
|
|
324
|
+
* Two strings, not the config object. `getHandleRegistryConfig` builds a
|
|
325
|
+
* fresh `{ domain, url }` on every call, so memoising on the object gives the
|
|
326
|
+
* client a new identity every render, which gives the registry effect below a
|
|
327
|
+
* changed dependency every render — and its own `setState` then schedules the
|
|
328
|
+
* next render. That is an unbreakable loop ("Maximum update depth exceeded")
|
|
329
|
+
* in which the 400 ms debounce is also cleared before it can ever fire.
|
|
330
|
+
*/
|
|
331
|
+
const registry = getHandleRegistryConfig(selectedNetwork)
|
|
332
|
+
const registryDomain = registry?.domain
|
|
333
|
+
const registryUrl = registry?.url
|
|
334
|
+
const registryClient = useMemo(
|
|
335
|
+
() =>
|
|
336
|
+
registryDomain && registryUrl
|
|
337
|
+
? createHandleRegistryClient({ pinned: { domain: registryDomain, url: registryUrl } })
|
|
338
|
+
: null,
|
|
339
|
+
[registryDomain, registryUrl]
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
// ── the asset axis ──────────────────────────────────────────────────
|
|
343
|
+
// Every line below is gated on `asset`: with no token held, `balances` is
|
|
344
|
+
// empty, `asset` is null, the picker renders nothing and this form is
|
|
345
|
+
// byte-for-byte the form it was.
|
|
346
|
+
const mandala = useMandala()
|
|
347
|
+
const spendableSats = useSpendableBalance()
|
|
348
|
+
const [localAssetId, setLocalAssetId] = useState<string | null>(null)
|
|
349
|
+
const assetId = selectedAssetId !== undefined ? selectedAssetId : localAssetId
|
|
350
|
+
const setAssetId = onSelectAsset ?? setLocalAssetId
|
|
351
|
+
const balances = mandala.balances ?? []
|
|
352
|
+
const holding = balances.find(b => b.asset.assetId === assetId) ?? null
|
|
353
|
+
const asset = holding?.asset ?? null
|
|
354
|
+
const issuer = asset?.issuerName || t('token_issuer_fallback')
|
|
355
|
+
/**
|
|
356
|
+
* Regulatory/registry facts for the selected asset (paused, frozen, this
|
|
357
|
+
* wallet's own registration, whether the metadata even resolved), from the
|
|
358
|
+
* runtime's ~10s cache. `null` (unknown/loading) blocks nothing — ux §4.2
|
|
359
|
+
* rule 3: pre-flight may only ever say "no", never invent a "yes" and never
|
|
360
|
+
* gate on an answer it does not have yet.
|
|
361
|
+
*/
|
|
362
|
+
const assetStatus = useAssetStatus(asset?.assetId ?? null).status
|
|
363
|
+
|
|
210
364
|
// Read-only here: the server is configured in Settings › Advanced.
|
|
211
365
|
const { messageBoxUrl } = useMessageBoxConfig(t)
|
|
212
366
|
const isConfigured = !!messageBoxUrl && messageBoxUrl !== NO_MESSAGE_BOX
|
|
213
367
|
|
|
214
|
-
|
|
368
|
+
/**
|
|
369
|
+
* The figure, tagged with the unit it was entered in. The field shows it and
|
|
370
|
+
* a send reads it ONLY while that unit is the one in force — an asset counts
|
|
371
|
+
* only once this wallet is known to hold it — so any change of money (the
|
|
372
|
+
* picker, a link naming a different one, the screen dropping an asset that
|
|
373
|
+
* turns out not to be held) blanks the figure instead of letting "2500" be
|
|
374
|
+
* read as 25.00 USDX one moment and 2,500 satoshis the next.
|
|
375
|
+
*/
|
|
376
|
+
const [figure, setFigure] = useState<Figure>(() => seedFigure(initialSats, initialTokenAmount))
|
|
377
|
+
const unit = asset?.assetId ?? null
|
|
378
|
+
const sendAmount = figure.unit === unit ? figure.text : ''
|
|
379
|
+
const setSendAmount = (text: string) => setFigure({ text, unit })
|
|
215
380
|
const [note, setNote] = useState('')
|
|
216
381
|
const [notice, setNotice] = useState<{ type: 'error'; message: string } | null>(
|
|
217
382
|
initialNotice ? { type: 'error', message: initialNotice } : null
|
|
218
383
|
)
|
|
219
384
|
const [isSending, setIsSending] = useState(false)
|
|
220
385
|
const [sendResult, setSendResult] = useState<{ type: 'success' | 'error'; message: string } | null>(null)
|
|
386
|
+
/**
|
|
387
|
+
* The failed-token-send note, kept apart from `sendResult` because it carries
|
|
388
|
+
* an action ("Check again") that a plain banner has nowhere to put.
|
|
389
|
+
*/
|
|
390
|
+
const [tokenFailure, setTokenFailure] = useState<TokenSendCopy | null>(null)
|
|
221
391
|
/** The success moment, held until acknowledged — same screen as every rail. */
|
|
222
|
-
const [sent, setSent] = useState<{
|
|
392
|
+
const [sent, setSent] = useState<{
|
|
393
|
+
amount: number
|
|
394
|
+
recipient?: string
|
|
395
|
+
/** Set only for a handle/token send — offers "Add to contacts" on the success screen. */
|
|
396
|
+
recipientIdentityKey?: string
|
|
397
|
+
/** Token mode: the figure in the asset's own units. */
|
|
398
|
+
amountText?: string
|
|
399
|
+
/** Whether the issuer has confirmed it yet — never claimed, only reported. */
|
|
400
|
+
statusNote?: string
|
|
401
|
+
} | null>(null)
|
|
402
|
+
/** Set once `sent` names a handle recipient who is not already a saved
|
|
403
|
+
* contact — null while that check is pending or once it comes back "already saved". */
|
|
404
|
+
const [offerAddContact, setOfferAddContact] = useState<{
|
|
405
|
+
identityKey: string
|
|
406
|
+
name?: string
|
|
407
|
+
handle?: string
|
|
408
|
+
} | null>(null)
|
|
223
409
|
const [outbox, setOutbox] = useState<OutboxEntry[]>([])
|
|
224
410
|
const [retryingId, setRetryingId] = useState<string | null>(null)
|
|
225
411
|
|
|
226
|
-
|
|
412
|
+
/**
|
|
413
|
+
* A token request, decided against a KNOWN set of holdings: the form
|
|
414
|
+
* switches to that token when this wallet holds it and takes `amount` in
|
|
415
|
+
* its base units (or leaves the figure to the user for an open request). A
|
|
416
|
+
* token this wallet does not hold cannot be paid from here, so the
|
|
417
|
+
* recipient is kept, the figure is not — a figure typed for the previous
|
|
418
|
+
* money must never stay armed at the new payee — and the banner says why;
|
|
419
|
+
* paying that person in BSV is still one tap away.
|
|
420
|
+
*/
|
|
421
|
+
const applyTokenRequest = (
|
|
422
|
+
request: PeerPayRequest,
|
|
423
|
+
balances: { asset: { assetId: string } }[],
|
|
424
|
+
opts: { deferred: boolean }
|
|
425
|
+
) => {
|
|
426
|
+
const held = balances.some(b => b.asset.assetId === request.asset)
|
|
427
|
+
if (!held) {
|
|
428
|
+
// Back to BSV, as the banner says; the figure typed for the old money
|
|
429
|
+
// must never stay armed at the new payee.
|
|
430
|
+
setAssetId(null)
|
|
431
|
+
setFigure(current => ({ ...current, text: '' }))
|
|
432
|
+
setNotice({ type: 'error', message: t('pay_asset_link_not_held') })
|
|
433
|
+
return
|
|
434
|
+
}
|
|
435
|
+
setAssetId(request.asset as string)
|
|
436
|
+
// A request applied LATER never writes over a figure the user has typed
|
|
437
|
+
// since; the link's own figure is taken only at the moment the link arrives.
|
|
438
|
+
if (!opts.deferred || figure.text === '') {
|
|
439
|
+
setFigure({ text: request.amount ? String(request.amount) : '', unit: request.asset as string })
|
|
440
|
+
}
|
|
441
|
+
setNotice(null)
|
|
442
|
+
setTokenFailure(null)
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Whether this wallet can EVER hold a token here. The runtime is published at
|
|
446
|
+
* wallet build, and only on a chain with Mandala endpoints — so no runtime on
|
|
447
|
+
* a built wallet is a settled fact (holds nothing, ever), while no runtime on
|
|
448
|
+
* a wallet still building is merely unknown.
|
|
449
|
+
*/
|
|
450
|
+
const tokensNever = walletBuilt && !mandala.available
|
|
451
|
+
/**
|
|
452
|
+
* A token link that arrived before the first balance read landed. `null`
|
|
453
|
+
* balances mean UNKNOWN, never "holds nothing" (useMandala's contract), and a
|
|
454
|
+
* pre-flight may only ever say "no" to a fact it has — so the request waits,
|
|
455
|
+
* and the effect below decides it the moment the holdings are known.
|
|
456
|
+
*/
|
|
457
|
+
const pendingTokenRequestRef = useRef<PeerPayRequest | null>(null)
|
|
458
|
+
/**
|
|
459
|
+
* A pasted or scanned link named a money, and maybe a figure. `sats` is a
|
|
460
|
+
* BSV request: the form switches to BSV and takes the figure. `asset` is a
|
|
461
|
+
* token request, decided now if the holdings are known (or can never be
|
|
462
|
+
* held), otherwise parked until they are — see the effect below `recipient`.
|
|
463
|
+
*/
|
|
464
|
+
const onPeerPayRequest = (request: PeerPayRequest) => {
|
|
465
|
+
// A request that names money (a link's `sats=`/`amount=`, typed, pasted or
|
|
466
|
+
// scanned) is "amount pre-populated by QR/deep link" whichever way it
|
|
467
|
+
// arrived — so it jumps the same way a deep-linked `initialTarget` does.
|
|
468
|
+
// A bare handle/key with no figure never reaches this function at all
|
|
469
|
+
// (see useRecipientInput's `requestOf`), so Continue still decides step
|
|
470
|
+
// for every ordinary "who" entry.
|
|
471
|
+
setStep('amount')
|
|
472
|
+
if (request.asset !== undefined) {
|
|
473
|
+
if (tokensNever) {
|
|
474
|
+
applyTokenRequest(request, [], { deferred: false })
|
|
475
|
+
} else if (mandala.balances === null) {
|
|
476
|
+
pendingTokenRequestRef.current = request
|
|
477
|
+
} else {
|
|
478
|
+
applyTokenRequest(request, mandala.balances, { deferred: false })
|
|
479
|
+
}
|
|
480
|
+
return
|
|
481
|
+
}
|
|
482
|
+
if (request.sats !== undefined) {
|
|
483
|
+
pendingTokenRequestRef.current = null
|
|
484
|
+
setAssetId(null)
|
|
485
|
+
setFigure({ text: String(request.sats), unit: null })
|
|
486
|
+
setNotice(null)
|
|
487
|
+
setTokenFailure(null)
|
|
488
|
+
}
|
|
489
|
+
}
|
|
227
490
|
const onPeerPayError = useCallback((message: string) => setNotice({ type: 'error', message }), [])
|
|
228
491
|
const recipient = useRecipientInput({
|
|
229
492
|
wallet,
|
|
230
493
|
adminOriginator,
|
|
231
494
|
initialTarget,
|
|
232
|
-
|
|
495
|
+
onPeerPayRequest,
|
|
233
496
|
onPeerPayError,
|
|
234
497
|
onNearbySession
|
|
235
498
|
})
|
|
236
499
|
const target = recipient.target
|
|
237
500
|
|
|
501
|
+
// Local contacts, searched ahead of the 400ms overlay debounce (instant —
|
|
502
|
+
// this is a local SQLite read) and merged into the same dropdown. Contacts
|
|
503
|
+
// come first; an overlay hit for an identity key already in the merged list
|
|
504
|
+
// is dropped rather than shown twice. An empty query shows every contact as
|
|
505
|
+
// "Recent" (RecipientField's `recentLabel`) rather than nothing.
|
|
506
|
+
useEffect(() => {
|
|
507
|
+
if (!contactsStore || walletUserId === null || recipient.selectedIdentity || target) {
|
|
508
|
+
setContactMatches([])
|
|
509
|
+
return
|
|
510
|
+
}
|
|
511
|
+
let cancelled = false
|
|
512
|
+
void contactsStore.searchContacts(walletUserId, recipient.inputText).then(rows => {
|
|
513
|
+
if (!cancelled) setContactMatches(rows)
|
|
514
|
+
})
|
|
515
|
+
return () => {
|
|
516
|
+
cancelled = true
|
|
517
|
+
}
|
|
518
|
+
}, [contactsStore, walletUserId, recipient.inputText, recipient.selectedIdentity, target])
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* The registry tier: people who can be paid by name. Its own timer — the
|
|
522
|
+
* contacts effect above has none, which is right for a local SQLite read and
|
|
523
|
+
* would be one request per keystroke here — and its own notice, so a
|
|
524
|
+
* registry outage never takes the contacts already on screen with it.
|
|
525
|
+
*
|
|
526
|
+
* It never fires for text that already resolved to a key or an address
|
|
527
|
+
* (`classifyRecipientInput`), for fewer than two characters (shorter than
|
|
528
|
+
* the registry's own minimum), with no registry configured, or before the
|
|
529
|
+
* wallet user is known.
|
|
530
|
+
*/
|
|
531
|
+
useEffect(() => {
|
|
532
|
+
const query = recipient.inputText.trim()
|
|
533
|
+
const routable =
|
|
534
|
+
!!registryClient &&
|
|
535
|
+
typeof walletUserId === 'number' &&
|
|
536
|
+
!recipient.selectedIdentity &&
|
|
537
|
+
!target &&
|
|
538
|
+
classifyRecipientInput(query).kind === 'search' &&
|
|
539
|
+
query.length >= 2
|
|
540
|
+
if (!routable) {
|
|
541
|
+
// Only here, and only when there is something to clear: an unconditional
|
|
542
|
+
// `setRegistryMatches([])` hands React a new array reference on every
|
|
543
|
+
// run, which it can never bail out of.
|
|
544
|
+
setRegistryMatches(rows => (rows.length === 0 ? rows : []))
|
|
545
|
+
setRegistrySearching(false)
|
|
546
|
+
return
|
|
547
|
+
}
|
|
548
|
+
let cancelled = false
|
|
549
|
+
setRegistrySearching(true)
|
|
550
|
+
const timer = setTimeout(async () => {
|
|
551
|
+
try {
|
|
552
|
+
const rows = await registryClient.search(query)
|
|
553
|
+
if (cancelled) return
|
|
554
|
+
setRegistryMatches(rows)
|
|
555
|
+
setRegistryError(false)
|
|
556
|
+
} catch (error) {
|
|
557
|
+
console.error('Handle registry search error:', error)
|
|
558
|
+
if (cancelled) return
|
|
559
|
+
setRegistryMatches([])
|
|
560
|
+
setRegistryError(true)
|
|
561
|
+
} finally {
|
|
562
|
+
if (!cancelled) setRegistrySearching(false)
|
|
563
|
+
}
|
|
564
|
+
}, REGISTRY_SEARCH_DEBOUNCE_MS)
|
|
565
|
+
return () => {
|
|
566
|
+
cancelled = true
|
|
567
|
+
clearTimeout(timer)
|
|
568
|
+
}
|
|
569
|
+
}, [registryClient, walletUserId, recipient.inputText, recipient.selectedIdentity, target])
|
|
570
|
+
|
|
571
|
+
const mergedSearchResults = useMemo((): RecipientRow[] => {
|
|
572
|
+
const contactIdentities: RecipientRow[] = contactMatches.map(c => ({
|
|
573
|
+
identityKey: c.identityKey,
|
|
574
|
+
name: c.name,
|
|
575
|
+
avatarURL: c.cachedAvatarUrl ?? '',
|
|
576
|
+
abbreviatedKey: abbreviateKey(c.identityKey),
|
|
577
|
+
badgeIconURL: '',
|
|
578
|
+
badgeLabel: '',
|
|
579
|
+
badgeClickURL: '',
|
|
580
|
+
...(c.cachedHandle ? { secondaryLine: c.cachedHandle } : {})
|
|
581
|
+
}))
|
|
582
|
+
const seen = new Set(contactIdentities.map(c => c.identityKey))
|
|
583
|
+
// Contacts, then the registry, then the overlay. A person the user has
|
|
584
|
+
// already labelled is shown with that label; a registry row states the
|
|
585
|
+
// name the owner published and the handle it belongs to.
|
|
586
|
+
//
|
|
587
|
+
// One key, one row, across the WHOLE list — so `seen` is consulted and
|
|
588
|
+
// added to in the same pass. Filtering first would let two certificates
|
|
589
|
+
// for one subject through together, which the pinned registry cannot
|
|
590
|
+
// produce but a foreign host answering `search` can.
|
|
591
|
+
const registryIdentities: RecipientRow[] = []
|
|
592
|
+
for (const p of registryMatches) {
|
|
593
|
+
if (seen.has(p.identityKey)) continue
|
|
594
|
+
seen.add(p.identityKey)
|
|
595
|
+
registryIdentities.push({
|
|
596
|
+
identityKey: p.identityKey,
|
|
597
|
+
// A display name is the owner's own unvalidated plaintext, and this row
|
|
598
|
+
// is the one place it is drawn ABOVE the handle it belongs to. A name
|
|
599
|
+
// shaped like an address therefore reads as somebody else's
|
|
600
|
+
// `handle@domain` — and it is the name, not the handle, that the field
|
|
601
|
+
// and the review card carry from here on. A name that can be mistaken
|
|
602
|
+
// for an address is no name.
|
|
603
|
+
name: (p.displayName?.includes('@') ? '' : p.displayName) || p.handle,
|
|
604
|
+
avatarURL: '',
|
|
605
|
+
abbreviatedKey: abbreviateKey(p.identityKey),
|
|
606
|
+
badgeIconURL: '',
|
|
607
|
+
badgeLabel: t('pay_trust_handle_attested'),
|
|
608
|
+
badgeClickURL: '',
|
|
609
|
+
secondaryLine: p.paymail
|
|
610
|
+
})
|
|
611
|
+
}
|
|
612
|
+
return [
|
|
613
|
+
...contactIdentities,
|
|
614
|
+
...registryIdentities,
|
|
615
|
+
...recipient.searchResults.filter(r => !seen.has(r.identityKey))
|
|
616
|
+
]
|
|
617
|
+
}, [contactMatches, registryMatches, recipient.searchResults, t])
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* The handle of the row the user picked, so the success screen's "Save as
|
|
621
|
+
* contact" can carry it into the new contact — held against the KEY it
|
|
622
|
+
* belongs to, not as a bare string.
|
|
623
|
+
*
|
|
624
|
+
* `handleSend` clears the field through the hook's own `clearRecipient`
|
|
625
|
+
* rather than the wrapper below, deliberately, so this survives the send and
|
|
626
|
+
* the overlay can still read it. A bare string would therefore also outlive
|
|
627
|
+
* its owner: pay someone with a handle, then pay a pasted key from the same
|
|
628
|
+
* mounted form, and the second person would be offered for saving with the
|
|
629
|
+
* first person's `handle@domain`.
|
|
630
|
+
*/
|
|
631
|
+
const selectedHandleRef = useRef<{ identityKey: string; handle: string } | undefined>(undefined)
|
|
632
|
+
/**
|
|
633
|
+
* The same fact, as state, for the review card — which is the one screen
|
|
634
|
+
* whose whole job is the last check before money moves, and which otherwise
|
|
635
|
+
* draws a name over an abbreviated key and never shows the `handle@domain`
|
|
636
|
+
* being paid at all. State rather than the ref above because the card is
|
|
637
|
+
* rendered, and a ref does not re-render; both rather than one because the
|
|
638
|
+
* ref must outlive the send and this must not survive a new recipient.
|
|
639
|
+
*/
|
|
640
|
+
const [pickedHandle, setPickedHandle] = useState<{ identityKey: string; handle: string } | null>(null)
|
|
641
|
+
const onSelectIdentity = (identity: RecipientRow) => {
|
|
642
|
+
const picked = identity.secondaryLine?.includes('@')
|
|
643
|
+
? { identityKey: identity.identityKey, handle: identity.secondaryLine }
|
|
644
|
+
: undefined
|
|
645
|
+
selectedHandleRef.current = picked
|
|
646
|
+
setPickedHandle(picked ?? null)
|
|
647
|
+
recipient.selectIdentity(identity)
|
|
648
|
+
}
|
|
649
|
+
const onClearRecipient = () => {
|
|
650
|
+
selectedHandleRef.current = undefined
|
|
651
|
+
setPickedHandle(null)
|
|
652
|
+
recipient.clearRecipient()
|
|
653
|
+
}
|
|
654
|
+
// Whether the resolved recipient is already a saved contact — the review
|
|
655
|
+
// step's trust tag names this before "registered"/"unverified".
|
|
656
|
+
const [targetIsContact, setTargetIsContact] = useState(false)
|
|
657
|
+
useEffect(() => {
|
|
658
|
+
if (!contactsStore || walletUserId === null || target?.kind !== 'handle') {
|
|
659
|
+
setTargetIsContact(false)
|
|
660
|
+
return
|
|
661
|
+
}
|
|
662
|
+
let cancelled = false
|
|
663
|
+
void contactsStore.getContact(walletUserId, target.identityKey).then(c => {
|
|
664
|
+
if (!cancelled) setTargetIsContact(!!c)
|
|
665
|
+
})
|
|
666
|
+
return () => {
|
|
667
|
+
cancelled = true
|
|
668
|
+
}
|
|
669
|
+
}, [contactsStore, walletUserId, target])
|
|
670
|
+
|
|
671
|
+
// The success screen's "Add to contacts" offer: only for a handle send, and
|
|
672
|
+
// only once confirmed absent from contacts (checked fresh here rather than
|
|
673
|
+
// reusing `targetIsContact` — `target` may already be cleared by the time
|
|
674
|
+
// this runs, and a check against the stale ONE this send actually used is
|
|
675
|
+
// what the button must reflect).
|
|
676
|
+
useEffect(() => {
|
|
677
|
+
setOfferAddContact(null)
|
|
678
|
+
if (!sent?.recipientIdentityKey || !contactsStore || walletUserId === null) return
|
|
679
|
+
let cancelled = false
|
|
680
|
+
const identityKey = sent.recipientIdentityKey
|
|
681
|
+
void contactsStore.getContact(walletUserId, identityKey).then(c => {
|
|
682
|
+
if (cancelled || c) return
|
|
683
|
+
// Only the handle of the person actually paid: see selectedHandleRef.
|
|
684
|
+
const picked = selectedHandleRef.current
|
|
685
|
+
setOfferAddContact({
|
|
686
|
+
identityKey,
|
|
687
|
+
name: sent.recipient,
|
|
688
|
+
...(picked?.identityKey === identityKey ? { handle: picked.handle } : {})
|
|
689
|
+
})
|
|
690
|
+
})
|
|
691
|
+
return () => {
|
|
692
|
+
cancelled = true
|
|
693
|
+
}
|
|
694
|
+
}, [sent, contactsStore, walletUserId])
|
|
695
|
+
|
|
696
|
+
const onAddContact = useCallback(() => {
|
|
697
|
+
if (!offerAddContact) return
|
|
698
|
+
setSent(null)
|
|
699
|
+
loadExpoRouter().router.push({
|
|
700
|
+
pathname: '/contact/add',
|
|
701
|
+
params: {
|
|
702
|
+
identityKey: offerAddContact.identityKey,
|
|
703
|
+
name: offerAddContact.name ?? '',
|
|
704
|
+
handle: offerAddContact.handle ?? '',
|
|
705
|
+
source: 'pay'
|
|
706
|
+
}
|
|
707
|
+
} as never)
|
|
708
|
+
}, [offerAddContact])
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* A token link that arrived before the holdings were known. `null` balances
|
|
712
|
+
* mean UNKNOWN, never "holds nothing" (useMandala's contract), and a
|
|
713
|
+
* pre-flight may only ever say "no" to a fact it has — so the request waits
|
|
714
|
+
* here and is decided the moment the holdings land (or the wallet finishes
|
|
715
|
+
* building with no token runtime). Applied only if the recipient is still
|
|
716
|
+
* the payee the link named: the user may have retargeted while it waited,
|
|
717
|
+
* and a figure in a money nobody at the new payee asked for must never arm.
|
|
718
|
+
*/
|
|
719
|
+
const balancesKnown = mandala.balances !== null
|
|
720
|
+
useEffect(() => {
|
|
721
|
+
const pending = pendingTokenRequestRef.current
|
|
722
|
+
if (!pending) return
|
|
723
|
+
if (!tokensNever && mandala.balances === null) return
|
|
724
|
+
pendingTokenRequestRef.current = null
|
|
725
|
+
if (target?.kind !== 'handle' || target.identityKey !== pending.identityKey) return
|
|
726
|
+
applyTokenRequest(pending, tokensNever ? [] : (mandala.balances ?? []), { deferred: true })
|
|
727
|
+
// Keyed on the two events that can settle a parked request; everything
|
|
728
|
+
// else it reads is a plain closure over this render.
|
|
729
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
730
|
+
}, [balancesKnown, mandala.balances, tokensNever])
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Whether the issuer's registry admits the typed recipient, for the ONE
|
|
734
|
+
* asset selected — the counterpart to `recipientRefusal`'s synchronous D4
|
|
735
|
+
* (address-shape) check, which never touches the registry at all. Asked
|
|
736
|
+
* only once the field has RESOLVED to an identity key: half-typed text is
|
|
737
|
+
* not a recipient, and `undefined` (unknown/still asking) never disables
|
|
738
|
+
* the CTA — only a proven `false` does (ux §4.2 rule 3).
|
|
739
|
+
*/
|
|
740
|
+
const [recipientAdmitted, setRecipientAdmitted] = useState<boolean | undefined>(undefined)
|
|
741
|
+
useEffect(() => {
|
|
742
|
+
setRecipientAdmitted(undefined)
|
|
743
|
+
if (!asset || target?.kind !== 'handle' || !assetStatus) return
|
|
744
|
+
let live = true
|
|
745
|
+
void assetStatus
|
|
746
|
+
.recipientAdmitted(target.identityKey)
|
|
747
|
+
.then(admitted => {
|
|
748
|
+
if (live) setRecipientAdmitted(admitted)
|
|
749
|
+
})
|
|
750
|
+
.catch(() => {
|
|
751
|
+
// Fails open, same as every other pre-flight read: an unreachable
|
|
752
|
+
// registry is UNKNOWN, never a proven refusal.
|
|
753
|
+
if (live) setRecipientAdmitted(undefined)
|
|
754
|
+
})
|
|
755
|
+
return () => {
|
|
756
|
+
live = false
|
|
757
|
+
}
|
|
758
|
+
}, [asset, target, assetStatus])
|
|
759
|
+
|
|
238
760
|
// A second deep link while mounted re-adopts the recipient (useRecipientInput);
|
|
239
761
|
// the amount and the notice it carried must follow, or Pay sends the OLD
|
|
240
762
|
// figure to the NEW person.
|
|
763
|
+
// Keyed on the figure's parts, not the object: a host that rebuilds the
|
|
764
|
+
// token-amount object every render must not reseed over what is being typed.
|
|
765
|
+
const initialTokenAssetId = initialTokenAmount?.assetId
|
|
766
|
+
const initialTokenBaseUnits = initialTokenAmount?.baseUnits
|
|
241
767
|
useEffect(() => {
|
|
242
|
-
|
|
243
|
-
|
|
768
|
+
setFigure(
|
|
769
|
+
seedFigure(
|
|
770
|
+
initialSats,
|
|
771
|
+
initialTokenAssetId !== undefined && initialTokenBaseUnits !== undefined
|
|
772
|
+
? { assetId: initialTokenAssetId, baseUnits: initialTokenBaseUnits }
|
|
773
|
+
: undefined
|
|
774
|
+
)
|
|
775
|
+
)
|
|
776
|
+
}, [initialSats, initialTokenAssetId, initialTokenBaseUnits])
|
|
244
777
|
useEffect(() => {
|
|
245
778
|
setNotice(initialNotice ? { type: 'error', message: initialNotice } : null)
|
|
246
779
|
}, [initialNotice])
|
|
@@ -316,7 +849,16 @@ function UniversalSend({
|
|
|
316
849
|
// The overlay stages its own haptic (inside Celebration) and tone; firing
|
|
317
850
|
// haptics.success() here would double the beat. Only a human-readable
|
|
318
851
|
// name goes on the success screen — a raw identity key is noise there.
|
|
319
|
-
setSent({
|
|
852
|
+
setSent({
|
|
853
|
+
amount: paidSats,
|
|
854
|
+
recipient: recipient.selectedIdentity?.name,
|
|
855
|
+
recipientIdentityKey: to.identityKey,
|
|
856
|
+
// The handle rail always drops the payment in the recipient's message
|
|
857
|
+
// box rather than handing it over in person — worth saying explicitly
|
|
858
|
+
// here, since it is the one thing an in-person (Nearby) payer never
|
|
859
|
+
// has to wonder about (ux §4.2/§8 "Success / arrival").
|
|
860
|
+
statusNote: t('pay_sent_handed_to_wallet')
|
|
861
|
+
})
|
|
320
862
|
},
|
|
321
863
|
[peerPayClient, storage, wallet, adminOriginator, messageBoxUrl, note, recipient.selectedIdentity, loadOutbox, t]
|
|
322
864
|
)
|
|
@@ -328,36 +870,133 @@ function UniversalSend({
|
|
|
328
870
|
wallet: wallet as any,
|
|
329
871
|
adminOriginator,
|
|
330
872
|
address: to.address,
|
|
331
|
-
satoshis: sats
|
|
873
|
+
satoshis: sats,
|
|
874
|
+
note
|
|
332
875
|
})
|
|
333
876
|
setSent({ amount: paidSatoshis, recipient: to.address })
|
|
334
877
|
},
|
|
335
|
-
[wallet, adminOriginator, t]
|
|
878
|
+
[wallet, adminOriginator, note, t]
|
|
879
|
+
)
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* The token send. One call, because the runtime owns the whole pipeline —
|
|
883
|
+
* coin selection, the blinded lock, the noSend build, the overlay submit, the
|
|
884
|
+
* journal and the abort on refusal. What this screen owns is the sentence the
|
|
885
|
+
* holder reads afterwards, and the rule that a refusal is the only outcome
|
|
886
|
+
* allowed to promise "nothing was sent".
|
|
887
|
+
*/
|
|
888
|
+
const sendToken = useCallback(
|
|
889
|
+
async (to: Extract<RecipientTarget, { kind: 'handle' }>, baseUnits: number): Promise<boolean> => {
|
|
890
|
+
const runtime = mandala.runtime
|
|
891
|
+
if (!runtime || !asset) throw new Error(t('wallet_not_ready'))
|
|
892
|
+
const ctx = {
|
|
893
|
+
ticker: asset.ticker,
|
|
894
|
+
issuer: asset.issuerName,
|
|
895
|
+
issuerFallback: t('token_issuer_fallback'),
|
|
896
|
+
reasonFallback: t('token_err_reason_unknown')
|
|
897
|
+
}
|
|
898
|
+
const result = await runtime.sendToHandle({
|
|
899
|
+
assetId: asset.assetId,
|
|
900
|
+
recipientIdentityKey: to.identityKey,
|
|
901
|
+
baseUnits,
|
|
902
|
+
...(note.trim() ? { note: note.trim() } : {})
|
|
903
|
+
})
|
|
904
|
+
if (result.kind !== 'sent') {
|
|
905
|
+
// The banner narrows the reason to one sentence; the console keeps the
|
|
906
|
+
// whole of it. On a rail that contacts nothing at send time, the raw
|
|
907
|
+
// message IS the diagnosis (a MessageBox that would not open, a wallet
|
|
908
|
+
// that could not sign) and is the only place it survives.
|
|
909
|
+
console.warn('[pay] token send failed:', result.kind, result.message ?? (result as { code?: string }).code)
|
|
910
|
+
setTokenFailure(tokenSendCopy(result, ctx))
|
|
911
|
+
// A refusal must leave the review step exactly as it is — the banner
|
|
912
|
+
// that explains it lives there, and stepping back to "who" (as a
|
|
913
|
+
// successful send does) would carry the user straight past it.
|
|
914
|
+
return false
|
|
915
|
+
}
|
|
916
|
+
setSent({
|
|
917
|
+
amount: 0,
|
|
918
|
+
recipient: recipient.selectedIdentity?.name,
|
|
919
|
+
recipientIdentityKey: to.identityKey,
|
|
920
|
+
// Never falls back to the satoshi renderer: a token figure it could not
|
|
921
|
+
// format would print as satoshis, which is a wrong number rather than a
|
|
922
|
+
// missing one.
|
|
923
|
+
amountText: formatTokenAmountWithUnit(baseUnits, asset) ?? t('token_row_amount_pending'),
|
|
924
|
+
// `notified === false` takes priority: the money moved either way, but
|
|
925
|
+
// the recipient has not been TOLD it did (the lib's own notify retries
|
|
926
|
+
// in the background — see `TokenSendResult.notified`), and that is the
|
|
927
|
+
// more useful thing to tell the payer, whether or not the coin is
|
|
928
|
+
// settled yet.
|
|
929
|
+
//
|
|
930
|
+
// Otherwise the handle rail now says SETTLING, not "not broadcast": a
|
|
931
|
+
// hand-over send never asked the overlay anything (§4.5 / wire §9.13),
|
|
932
|
+
// so the honest sentence is that the payment is made and is on its way
|
|
933
|
+
// to the issuer — which is exactly what the nearby rail has always
|
|
934
|
+
// said, and the same pair of keys says it. `settled` is kept ahead of
|
|
935
|
+
// it because it remains the runtime's own word for σ_I in hand, and a
|
|
936
|
+
// rail that one day hands one back must not be told to under-claim.
|
|
937
|
+
statusNote: !result.notified
|
|
938
|
+
? t('pay_sent_not_notified')
|
|
939
|
+
: result.settled
|
|
940
|
+
? t('token_sent_settled', { issuer })
|
|
941
|
+
: recipient.selectedIdentity?.name
|
|
942
|
+
? t('token_sent_settling', { issuer, payee: recipient.selectedIdentity.name })
|
|
943
|
+
: t('token_sent_settling_unnamed', { issuer })
|
|
944
|
+
})
|
|
945
|
+
mandala.refresh()
|
|
946
|
+
return true
|
|
947
|
+
},
|
|
948
|
+
[mandala, asset, issuer, recipient.selectedIdentity, note, t]
|
|
336
949
|
)
|
|
337
950
|
|
|
338
951
|
const handleSend = useCallback(async () => {
|
|
339
952
|
if (!target) return
|
|
340
953
|
// Guard before any side effect: a wallet that is not ready must leave the
|
|
341
954
|
// form exactly as typed, with a banner, not a cleared field and silence.
|
|
342
|
-
|
|
955
|
+
// On the token path the runtime IS the wallet — it holds its own manager,
|
|
956
|
+
// storage and journal — so that is what has to be ready.
|
|
957
|
+
if (asset ? !mandala.runtime : !wallet || !storage) {
|
|
343
958
|
flashResult({ type: 'error', message: t('wallet_not_ready') })
|
|
344
959
|
return
|
|
345
960
|
}
|
|
346
|
-
|
|
347
|
-
|
|
961
|
+
// The same integer either way — satoshis on the BSV rail, base units of the
|
|
962
|
+
// asset on the token rail. The field emits whole units in both modes.
|
|
963
|
+
const amount = Math.round(Number(sendAmount))
|
|
964
|
+
if (!Number.isFinite(amount) || amount <= 0) {
|
|
348
965
|
flashResult({ type: 'error', message: t('enter_valid_amount') })
|
|
349
966
|
return
|
|
350
967
|
}
|
|
351
968
|
haptics.confirm()
|
|
352
969
|
setIsSending(true)
|
|
970
|
+
setTokenFailure(null)
|
|
353
971
|
try {
|
|
354
|
-
if (
|
|
355
|
-
|
|
356
|
-
|
|
972
|
+
if (asset) {
|
|
973
|
+
// D4: a token has no address rail, and `canSend` has already refused
|
|
974
|
+
// one. This is the second gate, because the first is a render.
|
|
975
|
+
if (target.kind !== 'handle') return
|
|
976
|
+
const sent = await sendToken(target, amount)
|
|
977
|
+
if (!sent) return
|
|
978
|
+
} else if (target.kind === 'handle') await sendHandle(target, amount)
|
|
979
|
+
else await sendAddress(target, amount)
|
|
980
|
+
setFigure(current => ({ ...current, text: '' }))
|
|
357
981
|
setNote('')
|
|
358
982
|
recipient.clearRecipient()
|
|
983
|
+
setStep('who')
|
|
359
984
|
} catch (error: any) {
|
|
360
985
|
if (await handleWalletCheck(error)) return
|
|
986
|
+
if (asset) {
|
|
987
|
+
console.warn('[mandala] token send threw:', error)
|
|
988
|
+
// A throw out of the token path is NOT a refusal: the overlay may have
|
|
989
|
+
// admitted the transaction and lost the response, so the copy claims
|
|
990
|
+
// nothing and offers a balance check rather than a retry.
|
|
991
|
+
setTokenFailure(
|
|
992
|
+
tokenThrowCopy(error, {
|
|
993
|
+
ticker: asset.ticker,
|
|
994
|
+
issuer: asset.issuerName,
|
|
995
|
+
issuerFallback: t('token_issuer_fallback')
|
|
996
|
+
})
|
|
997
|
+
)
|
|
998
|
+
return
|
|
999
|
+
}
|
|
361
1000
|
const message =
|
|
362
1001
|
error instanceof RangeError
|
|
363
1002
|
? t('enter_valid_amount')
|
|
@@ -373,12 +1012,15 @@ function UniversalSend({
|
|
|
373
1012
|
}, [
|
|
374
1013
|
target,
|
|
375
1014
|
sendAmount,
|
|
1015
|
+
asset,
|
|
1016
|
+
sendToken,
|
|
376
1017
|
sendHandle,
|
|
377
1018
|
sendAddress,
|
|
378
1019
|
recipient,
|
|
379
1020
|
handleWalletCheck,
|
|
380
1021
|
flashResult,
|
|
381
1022
|
loadOutbox,
|
|
1023
|
+
mandala.runtime,
|
|
382
1024
|
t,
|
|
383
1025
|
wallet,
|
|
384
1026
|
storage
|
|
@@ -403,7 +1045,7 @@ function UniversalSend({
|
|
|
403
1045
|
setRetryingId(entry.id)
|
|
404
1046
|
try {
|
|
405
1047
|
await retryDelivery({ wallet: wallet as any, adminOriginator, client, storage, entry })
|
|
406
|
-
setSent({ amount: entry.token.amount })
|
|
1048
|
+
setSent({ amount: entry.token.amount, recipientIdentityKey: entry.recipient })
|
|
407
1049
|
} catch (e: any) {
|
|
408
1050
|
if (await handleWalletCheck(e)) return
|
|
409
1051
|
const reason = isMessageBoxNetworkError(e) ? t('message_box_unreachable') : e?.message || t('unknown_error')
|
|
@@ -480,79 +1122,416 @@ function UniversalSend({
|
|
|
480
1122
|
// Address sends never touch the box, so they are not held hostage by it.
|
|
481
1123
|
const handleBlockedByOutbox = isHandle && outbox.length > 0
|
|
482
1124
|
const handleFormValid = isHandle && amountOk && !isSending && isConfigured
|
|
483
|
-
|
|
1125
|
+
|
|
1126
|
+
// ── token pre-flight ────────────────────────────────────────────────
|
|
1127
|
+
// Advisory, and it may only ever say "no". Nothing here promises a send will
|
|
1128
|
+
// work; `resolveAssetState` and the registry both fail open, so a pre-flight
|
|
1129
|
+
// that said "this will work" would be the one claim they cannot support.
|
|
1130
|
+
const baseUnits = asset ? Math.round(Number(sendAmount)) || 0 : 0
|
|
1131
|
+
const overBalance = !!holding && baseUnits > holding.baseUnits
|
|
1132
|
+
/**
|
|
1133
|
+
* The runtime's plain reason this recipient cannot be paid in this asset —
|
|
1134
|
+
* an address (D4), an unregistered identity, a blocked one.
|
|
1135
|
+
*
|
|
1136
|
+
* Asked only once the field has RESOLVED to something. Half-typed text is not
|
|
1137
|
+
* a recipient, and answering "no" to it would put a refusal on screen for a
|
|
1138
|
+
* name the user is still in the middle of writing.
|
|
1139
|
+
*/
|
|
1140
|
+
const recipientRefusal =
|
|
1141
|
+
asset && mandala.runtime && target
|
|
1142
|
+
? mandala.runtime.recipientRefusal(target.kind === 'handle' ? target.identityKey : target.address)
|
|
1143
|
+
: null
|
|
1144
|
+
const tokenAddressRefused = !!asset && isAddress
|
|
1145
|
+
// Every one of these is a KNOWN-false fact, never an unknown one: `assetStatus`
|
|
1146
|
+
// is `null` until the first read lands and fails open on every later read, so
|
|
1147
|
+
// `=== true`/`=== false` (never a bare truthiness check) is what keeps a cold
|
|
1148
|
+
// read or an unreachable overlay from disabling the button on a guess.
|
|
1149
|
+
const paused = assetStatus?.paused === true
|
|
1150
|
+
const unidentified = assetStatus?.metadataResolved === false
|
|
1151
|
+
const selfUnregistered = assetStatus?.selfAdmitted === false
|
|
1152
|
+
// Only asked once the recipient resolved to a handle — an address is already
|
|
1153
|
+
// refused by D4 above, and half-typed text is not a recipient yet.
|
|
1154
|
+
const recipientRegistryRefused = !!asset && target?.kind === 'handle' && recipientAdmitted === false
|
|
1155
|
+
const frozenBaseUnits = assetStatus?.frozenBaseUnits ?? 0
|
|
1156
|
+
const tokenFormValid =
|
|
1157
|
+
!!asset &&
|
|
1158
|
+
isHandle &&
|
|
1159
|
+
amountOk &&
|
|
1160
|
+
!isSending &&
|
|
1161
|
+
!overBalance &&
|
|
1162
|
+
!recipientRefusal &&
|
|
1163
|
+
!tokenAddressRefused &&
|
|
1164
|
+
!paused &&
|
|
1165
|
+
!unidentified &&
|
|
1166
|
+
!selfUnregistered &&
|
|
1167
|
+
!recipientRegistryRefused
|
|
1168
|
+
|
|
1169
|
+
const canSend = asset
|
|
1170
|
+
? tokenFormValid
|
|
1171
|
+
: isAddress
|
|
1172
|
+
? amountOk && !isSending
|
|
1173
|
+
: handleFormValid && !handleBlockedByOutbox
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* At most one note, in this order — the same order as ux design §4.2's
|
|
1177
|
+
* pre-flight table: the reasons that block the CTA first (most specific
|
|
1178
|
+
* first), then the two that are advisory only (frozen, needs-BSV) and never
|
|
1179
|
+
* disable it. The BSV-fee note stays last and — this is the part that
|
|
1180
|
+
* matters — it NEVER disables the button: `useSpendableBalance()` returns
|
|
1181
|
+
* `null` on a cold open, `null < n` is `true` in JavaScript, and the
|
|
1182
|
+
* authoritative answer is the toolbox's own funding throw, which comes back
|
|
1183
|
+
* as the same sentence.
|
|
1184
|
+
*/
|
|
1185
|
+
const tokenNote: {
|
|
1186
|
+
key: string
|
|
1187
|
+
values?: Record<string, string>
|
|
1188
|
+
/** The runtime's own sentence, which wins over the key when it has one. */
|
|
1189
|
+
text?: string
|
|
1190
|
+
action?: 'get-bsv'
|
|
1191
|
+
} | null = asset
|
|
1192
|
+
? tokenAddressRefused
|
|
1193
|
+
? // D4, stated plainly. The runtime's own reason wins when it has one:
|
|
1194
|
+
// it knows which of the several reasons an address cannot be paid
|
|
1195
|
+
// applies, and a specific true sentence beats a general true sentence.
|
|
1196
|
+
{ key: 'pay_asset_no_address', values: { ticker: asset.ticker }, text: recipientRefusal ?? undefined }
|
|
1197
|
+
: paused
|
|
1198
|
+
? { key: 'pay_asset_paused', values: { issuer, ticker: asset.ticker } }
|
|
1199
|
+
: unidentified
|
|
1200
|
+
? { key: 'pay_asset_unidentified' }
|
|
1201
|
+
: selfUnregistered
|
|
1202
|
+
? { key: 'pay_asset_self_unregistered', values: { issuer, ticker: asset.ticker } }
|
|
1203
|
+
: recipientRegistryRefused
|
|
1204
|
+
? // The runtime's registry only answers a yes/no boolean, not WHY —
|
|
1205
|
+
// `accessMode` says which gate refused: a denylist hit is a block,
|
|
1206
|
+
// anything else (an allowlist gate, or none reported) reads as
|
|
1207
|
+
// "not registered yet", which is the truer default of the two.
|
|
1208
|
+
{
|
|
1209
|
+
key:
|
|
1210
|
+
assetStatus?.accessMode === 'denylist'
|
|
1211
|
+
? 'pay_asset_recipient_blocked'
|
|
1212
|
+
: 'pay_asset_recipient_unregistered',
|
|
1213
|
+
values: { issuer, ticker: asset.ticker }
|
|
1214
|
+
}
|
|
1215
|
+
: overBalance
|
|
1216
|
+
? { key: 'pay_asset_over_balance', values: { ticker: asset.ticker } }
|
|
1217
|
+
: frozenBaseUnits > 0
|
|
1218
|
+
? {
|
|
1219
|
+
key: 'pay_asset_frozen_note',
|
|
1220
|
+
values: { ticker: asset.ticker, amount: formatTokenAmount(frozenBaseUnits, asset.decimals) ?? '' }
|
|
1221
|
+
}
|
|
1222
|
+
: spendableSats === 0
|
|
1223
|
+
? { key: 'pay_asset_needs_bsv', values: { ticker: asset.ticker }, action: 'get-bsv' }
|
|
1224
|
+
: null
|
|
1225
|
+
: null
|
|
1226
|
+
|
|
1227
|
+
const backStep = useCallback(() => {
|
|
1228
|
+
setStep(prev => (prev === 'review' ? 'amount' : 'who'))
|
|
1229
|
+
}, [])
|
|
1230
|
+
useImperativeHandle(
|
|
1231
|
+
ref,
|
|
1232
|
+
() => ({
|
|
1233
|
+
back: () => {
|
|
1234
|
+
if (step === 'who') return false
|
|
1235
|
+
backStep()
|
|
1236
|
+
return true
|
|
1237
|
+
}
|
|
1238
|
+
}),
|
|
1239
|
+
[step, backStep]
|
|
1240
|
+
)
|
|
1241
|
+
// Taken off `recipient` here rather than called through it below: calling it
|
|
1242
|
+
// as a method would make the whole (rebuilt every render) `recipient` object
|
|
1243
|
+
// a dependency of the effect, and an effect that reran every render would
|
|
1244
|
+
// clear the overlay's own search notice the instant it was raised.
|
|
1245
|
+
const clearSearchError = recipient.clearSearchError
|
|
1246
|
+
useEffect(() => {
|
|
1247
|
+
onStepChange?.(step)
|
|
1248
|
+
// Neither search notice belongs on the amount or review screen: both are
|
|
1249
|
+
// about a recipient field that is no longer on screen.
|
|
1250
|
+
setRegistryError(false)
|
|
1251
|
+
clearSearchError()
|
|
1252
|
+
}, [step, onStepChange, clearSearchError])
|
|
1253
|
+
|
|
1254
|
+
// ── the review card's facts ──────────────────────────────────────────
|
|
1255
|
+
// Once money is moving, the figure is ALWAYS the asset that actually moves
|
|
1256
|
+
// (BSV or the token), never the display currency (2026-09-17 ruling):
|
|
1257
|
+
// "12.00 USD" on a BSV send reads as a stablecoin.
|
|
1258
|
+
const sendSats = Math.round(Number(sendAmount)) || 0
|
|
1259
|
+
const reviewAmount = asset
|
|
1260
|
+
? { value: formatTokenAmount(baseUnits, asset.decimals) ?? '', unit: asset.ticker }
|
|
1261
|
+
: { value: formatSatoshisAsBsvDecimal(sendSats), unit: 'BSV' }
|
|
1262
|
+
const reviewPrimary =
|
|
1263
|
+
recipient.selectedIdentity?.name ||
|
|
1264
|
+
(target?.kind === 'handle' ? abbreviateKey(target.identityKey) : target?.kind === 'address' ? target.address : '')
|
|
1265
|
+
// The handle the picked row carried, when it is still the row being paid —
|
|
1266
|
+
// the name above it may be anything its owner published, this is the address
|
|
1267
|
+
// the money is going to. An abbreviated key only when there is no handle.
|
|
1268
|
+
const reviewSecondary =
|
|
1269
|
+
recipient.selectedIdentity?.name && target?.kind === 'handle'
|
|
1270
|
+
? pickedHandle?.identityKey === target.identityKey
|
|
1271
|
+
? pickedHandle.handle
|
|
1272
|
+
: abbreviateKey(target.identityKey)
|
|
1273
|
+
: undefined
|
|
1274
|
+
const reviewTrust = targetIsContact
|
|
1275
|
+
? { icon: 'person-circle-outline', color: colors.textSecondary, text: t('pay_trust_contact') }
|
|
1276
|
+
: recipient.selectedIdentity
|
|
1277
|
+
? { icon: 'shield-checkmark-outline', color: colors.textSecondary, text: t('pay_trust_handle_attested') }
|
|
1278
|
+
: { icon: 'alert-circle-outline', color: colors.warning, text: t('pay_trust_unverified') }
|
|
1279
|
+
const showNoteRow = isHandle || (isAddress && !asset)
|
|
484
1280
|
|
|
485
1281
|
return (
|
|
486
1282
|
<ScrollView contentContainerStyle={styles.content} keyboardShouldPersistTaps="handled">
|
|
1283
|
+
<StepBar step={step} />
|
|
487
1284
|
{notice && <ResultBanner result={notice} onDismiss={() => setNotice(null)} colors={colors} />}
|
|
488
|
-
{
|
|
1285
|
+
{/* One notice for both remote tiers. Offline they fail on the same
|
|
1286
|
+
keystroke, and two banners carrying the identical sentence read as the
|
|
1287
|
+
error re-appearing when the first is dismissed. */}
|
|
1288
|
+
{(recipient.searchError || registryError) && (
|
|
489
1289
|
<ResultBanner
|
|
490
1290
|
result={{ type: 'error', message: t('identity_search_unavailable') }}
|
|
491
|
-
onDismiss={
|
|
1291
|
+
onDismiss={() => {
|
|
1292
|
+
recipient.clearSearchError()
|
|
1293
|
+
setRegistryError(false)
|
|
1294
|
+
}}
|
|
492
1295
|
colors={colors}
|
|
493
1296
|
/>
|
|
494
1297
|
)}
|
|
495
1298
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
1299
|
+
{step === 'who' && (
|
|
1300
|
+
<>
|
|
1301
|
+
<PayField labelKey="pay_review_to">
|
|
1302
|
+
<RecipientField
|
|
1303
|
+
selectedIdentity={recipient.selectedIdentity}
|
|
1304
|
+
inputText={recipient.inputText}
|
|
1305
|
+
target={recipient.target}
|
|
1306
|
+
inlineError={recipient.inlineError}
|
|
1307
|
+
isSearching={recipient.isSearching || registrySearching}
|
|
1308
|
+
searchResults={mergedSearchResults}
|
|
1309
|
+
colors={colors}
|
|
1310
|
+
t={t}
|
|
1311
|
+
onChangeText={recipient.onChangeText}
|
|
1312
|
+
onSelectIdentity={onSelectIdentity}
|
|
1313
|
+
onClear={onClearRecipient}
|
|
1314
|
+
onOpenScanner={recipient.openScanner}
|
|
1315
|
+
assetTicker={asset?.ticker}
|
|
1316
|
+
recentLabel={t('contacts_recent')}
|
|
1317
|
+
statusOverride={
|
|
1318
|
+
recipientRefusal && !tokenAddressRefused
|
|
1319
|
+
? { text: recipientRefusal, tone: 'warning' }
|
|
1320
|
+
: recipientRegistryRefused
|
|
1321
|
+
? {
|
|
1322
|
+
text: t(
|
|
1323
|
+
assetStatus?.accessMode === 'denylist'
|
|
1324
|
+
? 'pay_asset_recipient_blocked'
|
|
1325
|
+
: 'pay_asset_recipient_unregistered',
|
|
1326
|
+
{ issuer, ticker: asset?.ticker }
|
|
1327
|
+
),
|
|
1328
|
+
tone: 'warning'
|
|
1329
|
+
}
|
|
1330
|
+
: undefined
|
|
1331
|
+
}
|
|
1332
|
+
/>
|
|
1333
|
+
</PayField>
|
|
530
1334
|
|
|
531
|
-
|
|
532
|
-
|
|
1335
|
+
{/* No "Paying with" picker here (design 1b, 2026-09-15): the coin is
|
|
1336
|
+
chosen once, on Home's switcher, and arrives as `selectedAssetId`. */}
|
|
533
1337
|
|
|
534
|
-
|
|
535
|
-
|
|
1338
|
+
{target ? (
|
|
1339
|
+
<PayCta
|
|
1340
|
+
onPress={() => setStep('amount')}
|
|
1341
|
+
disabled={false}
|
|
1342
|
+
busy={false}
|
|
1343
|
+
label={t('pay_step_continue')}
|
|
1344
|
+
icon="arrow-forward"
|
|
1345
|
+
/>
|
|
1346
|
+
) : (
|
|
1347
|
+
<PressableScale
|
|
1348
|
+
onPress={() => loadExpoRouter().router.push('/contacts' as never)}
|
|
1349
|
+
haptic="tap"
|
|
1350
|
+
style={[
|
|
1351
|
+
styles.outlineBtn,
|
|
1352
|
+
{ backgroundColor: colors.surfaceRaised, borderColor: colors.surfaceRaisedBorder }
|
|
1353
|
+
]}
|
|
1354
|
+
accessibilityRole="button"
|
|
1355
|
+
>
|
|
1356
|
+
<Ionicons name="people-outline" size={18} color={colors.textPrimary} />
|
|
1357
|
+
<Text style={[styles.outlineBtnText, { color: colors.textPrimary }]}>{t('pay_step_contacts')}</Text>
|
|
1358
|
+
</PressableScale>
|
|
1359
|
+
)}
|
|
1360
|
+
|
|
1361
|
+
{outbox.length > 0 && (
|
|
1362
|
+
<OutgoingSection
|
|
1363
|
+
entries={outbox}
|
|
1364
|
+
retryingId={retryingId}
|
|
1365
|
+
colors={colors}
|
|
1366
|
+
t={t}
|
|
1367
|
+
onRetry={handleRetry}
|
|
1368
|
+
onCancel={handleCancel}
|
|
1369
|
+
/>
|
|
1370
|
+
)}
|
|
1371
|
+
</>
|
|
536
1372
|
)}
|
|
537
|
-
|
|
538
|
-
|
|
1373
|
+
|
|
1374
|
+
{step === 'amount' && (
|
|
1375
|
+
<>
|
|
1376
|
+
<PayAmountField
|
|
1377
|
+
value={sendAmount}
|
|
1378
|
+
onChangeText={setSendAmount}
|
|
1379
|
+
asset={asset ? { ticker: asset.ticker, decimals: asset.decimals } : undefined}
|
|
1380
|
+
maxValue={holding ? String(holding.baseUnits) : undefined}
|
|
1381
|
+
availableText={
|
|
1382
|
+
holding ? (formatTokenAmount(holding.baseUnits, holding.asset.decimals) ?? undefined) : undefined
|
|
1383
|
+
}
|
|
1384
|
+
/>
|
|
1385
|
+
|
|
1386
|
+
<PayCta
|
|
1387
|
+
onPress={() => setStep('review')}
|
|
1388
|
+
disabled={!amountOk}
|
|
1389
|
+
busy={false}
|
|
1390
|
+
label={t('pay_step_continue')}
|
|
1391
|
+
icon="arrow-forward"
|
|
1392
|
+
/>
|
|
1393
|
+
</>
|
|
539
1394
|
)}
|
|
540
1395
|
|
|
541
|
-
|
|
1396
|
+
{step === 'review' && target && (
|
|
1397
|
+
<>
|
|
1398
|
+
<View
|
|
1399
|
+
style={[styles.reviewCard, { backgroundColor: colors.backgroundElevated, borderColor: colors.separator }]}
|
|
1400
|
+
>
|
|
1401
|
+
<View style={[styles.reviewRow, { borderBottomColor: colors.separator }]}>
|
|
1402
|
+
<Text style={[styles.reviewLabel, { color: colors.textTertiary }]}>{t('pay_review_to')}</Text>
|
|
1403
|
+
{target.kind === 'handle' ? (
|
|
1404
|
+
<ContactSigil
|
|
1405
|
+
identityKey={target.identityKey}
|
|
1406
|
+
avatarUrl={recipient.selectedIdentity?.avatarURL || undefined}
|
|
1407
|
+
size={32}
|
|
1408
|
+
radius={16}
|
|
1409
|
+
/>
|
|
1410
|
+
) : (
|
|
1411
|
+
<View style={[styles.reviewAddressIcon, { backgroundColor: colors.fillTertiary }]}>
|
|
1412
|
+
<Ionicons name="wallet-outline" size={16} color={colors.textSecondary} />
|
|
1413
|
+
</View>
|
|
1414
|
+
)}
|
|
1415
|
+
<View style={styles.reviewToText}>
|
|
1416
|
+
<View style={styles.reviewNameRow}>
|
|
1417
|
+
<Text style={[styles.reviewName, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
1418
|
+
{reviewPrimary}
|
|
1419
|
+
</Text>
|
|
1420
|
+
{!!reviewSecondary && (
|
|
1421
|
+
<Text
|
|
1422
|
+
style={[styles.reviewNameSub, { color: colors.textSecondary }]}
|
|
1423
|
+
numberOfLines={1}
|
|
1424
|
+
ellipsizeMode="middle"
|
|
1425
|
+
>
|
|
1426
|
+
{reviewSecondary}
|
|
1427
|
+
</Text>
|
|
1428
|
+
)}
|
|
1429
|
+
</View>
|
|
1430
|
+
{target.kind === 'handle' && (
|
|
1431
|
+
<View style={styles.reviewTrustRow}>
|
|
1432
|
+
<Ionicons name={reviewTrust.icon as never} size={12} color={reviewTrust.color} />
|
|
1433
|
+
<Text style={[styles.reviewTrust, { color: reviewTrust.color }]} numberOfLines={1}>
|
|
1434
|
+
{reviewTrust.text}
|
|
1435
|
+
</Text>
|
|
1436
|
+
</View>
|
|
1437
|
+
)}
|
|
1438
|
+
</View>
|
|
1439
|
+
</View>
|
|
1440
|
+
|
|
1441
|
+
<View
|
|
1442
|
+
style={[styles.reviewRow, !showNoteRow && styles.reviewRowLast, { borderBottomColor: colors.separator }]}
|
|
1443
|
+
>
|
|
1444
|
+
<Text style={[styles.reviewLabel, { color: colors.textTertiary }]}>{t('pay_review_amount')}</Text>
|
|
1445
|
+
{/* No adjustsFontSizeToFit / numberOfLines: iOS's shrink floor is a fixed 4pt and in this
|
|
1446
|
+
flex row it collapsed the amount to illegible. A long amount wraps instead, so no digit
|
|
1447
|
+
is ever hidden on the screen that confirms it. */}
|
|
1448
|
+
<Text
|
|
1449
|
+
style={[styles.reviewAmount, { color: colors.textPrimary }]}
|
|
1450
|
+
accessibilityLabel={`${reviewAmount.value} ${reviewAmount.unit}`}
|
|
1451
|
+
>
|
|
1452
|
+
{reviewAmount.value}{' '}
|
|
1453
|
+
<Text style={[styles.reviewUnit, { color: colors.textSecondary }]}>{reviewAmount.unit}</Text>
|
|
1454
|
+
</Text>
|
|
1455
|
+
</View>
|
|
542
1456
|
|
|
543
|
-
|
|
1457
|
+
{showNoteRow && (
|
|
1458
|
+
<View style={[styles.reviewRow, styles.reviewRowLast]}>
|
|
1459
|
+
<Text style={[styles.reviewLabel, { color: colors.textTertiary }]}>{t('pay_review_note')}</Text>
|
|
1460
|
+
<TextInput
|
|
1461
|
+
value={note}
|
|
1462
|
+
onChangeText={setNote}
|
|
1463
|
+
placeholder={t('pay_review_note_edit')}
|
|
1464
|
+
placeholderTextColor={colors.textQuaternary}
|
|
1465
|
+
maxLength={280}
|
|
1466
|
+
style={[styles.reviewNoteInput, { color: colors.textPrimary }]}
|
|
1467
|
+
/>
|
|
1468
|
+
<Ionicons name="pencil-outline" size={16} color={colors.textTertiary} />
|
|
1469
|
+
</View>
|
|
1470
|
+
)}
|
|
1471
|
+
</View>
|
|
544
1472
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
1473
|
+
{/* Load-bearing for an address: this rail cannot notify the payee. Nothing
|
|
1474
|
+
for a handle, and nothing at all in token mode, where an address is
|
|
1475
|
+
refused rather than warned about. */}
|
|
1476
|
+
{isAddress && !asset && <ConsequenceNote textKey={CONSEQUENCE_KEYS.address} />}
|
|
1477
|
+
|
|
1478
|
+
{tokenNote && (
|
|
1479
|
+
<ConsequenceNote
|
|
1480
|
+
textKey={tokenNote.key}
|
|
1481
|
+
values={tokenNote.values}
|
|
1482
|
+
text={tokenNote.text}
|
|
1483
|
+
action={
|
|
1484
|
+
tokenNote.action === 'get-bsv'
|
|
1485
|
+
? {
|
|
1486
|
+
label: t('pay_asset_get_bsv'),
|
|
1487
|
+
onPress: () => loadExpoRouter().router.push('/pay?direction=get' as never)
|
|
1488
|
+
}
|
|
1489
|
+
: undefined
|
|
1490
|
+
}
|
|
1491
|
+
/>
|
|
1492
|
+
)}
|
|
1493
|
+
|
|
1494
|
+
{isHandle && !isConfigured && !asset && (
|
|
1495
|
+
<Text style={[styles.consequence, { color: colors.textSecondary }]}>{t('message_box_off_hint')}</Text>
|
|
1496
|
+
)}
|
|
1497
|
+
{handleFormValid && handleBlockedByOutbox && !asset && (
|
|
1498
|
+
<Text style={[styles.consequence, { color: colors.textSecondary }]}>{t('finish_or_cancel_outgoing')}</Text>
|
|
1499
|
+
)}
|
|
1500
|
+
|
|
1501
|
+
<PayCta onPress={handleSend} disabled={!canSend} busy={isSending} labelKey="send" />
|
|
1502
|
+
|
|
1503
|
+
{/* A failed token send, in the app's own failure channel: error tone,
|
|
1504
|
+
dismissible, and carrying at most one affordance. "Check again"
|
|
1505
|
+
refreshes the balance rather than re-sending, because a retry after a
|
|
1506
|
+
lost response builds a second spend of the same coins. */}
|
|
1507
|
+
{tokenFailure && (
|
|
1508
|
+
<ResultBanner
|
|
1509
|
+
result={{ type: 'error', message: t(tokenFailure.key, tokenFailure.values) }}
|
|
1510
|
+
onDismiss={() => setTokenFailure(null)}
|
|
1511
|
+
colors={colors}
|
|
1512
|
+
action={
|
|
1513
|
+
tokenFailure.action === 'check-again'
|
|
1514
|
+
? {
|
|
1515
|
+
label: t('token_err_check_again'),
|
|
1516
|
+
onPress: () => {
|
|
1517
|
+
mandala.refresh()
|
|
1518
|
+
setTokenFailure(null)
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
: tokenFailure.action === 'get-bsv'
|
|
1522
|
+
? {
|
|
1523
|
+
label: t('pay_asset_get_bsv'),
|
|
1524
|
+
onPress: () => loadExpoRouter().router.push('/pay?direction=get' as never)
|
|
1525
|
+
}
|
|
1526
|
+
: undefined
|
|
1527
|
+
}
|
|
1528
|
+
/>
|
|
1529
|
+
)}
|
|
1530
|
+
</>
|
|
554
1531
|
)}
|
|
555
1532
|
|
|
1533
|
+
{sendResult && <ResultBanner result={sendResult} onDismiss={() => setSendResult(null)} colors={colors} />}
|
|
1534
|
+
|
|
556
1535
|
<Modal
|
|
557
1536
|
visible={recipient.scannerVisible}
|
|
558
1537
|
animationType="slide"
|
|
@@ -572,7 +1551,10 @@ function UniversalSend({
|
|
|
572
1551
|
<PaymentSuccessOverlay
|
|
573
1552
|
direction="sent"
|
|
574
1553
|
amount={sent.amount}
|
|
1554
|
+
amountText={sent.amountText}
|
|
1555
|
+
statusNote={sent.statusNote}
|
|
575
1556
|
recipientName={sent.recipient}
|
|
1557
|
+
onAddContact={offerAddContact ? onAddContact : undefined}
|
|
576
1558
|
onDismiss={() => setSent(null)}
|
|
577
1559
|
dismissTo={dismissTo}
|
|
578
1560
|
/>
|
|
@@ -592,6 +1574,54 @@ const styles = StyleSheet.create({
|
|
|
592
1574
|
marginBottom: spacing.lg
|
|
593
1575
|
},
|
|
594
1576
|
|
|
1577
|
+
// Step 1's quiet second door: Contacts, on the chrome surface.
|
|
1578
|
+
outlineBtn: {
|
|
1579
|
+
flexDirection: 'row',
|
|
1580
|
+
alignItems: 'center',
|
|
1581
|
+
justifyContent: 'center',
|
|
1582
|
+
gap: spacing.sm,
|
|
1583
|
+
minHeight: 48,
|
|
1584
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
1585
|
+
borderRadius: radii.md,
|
|
1586
|
+
paddingVertical: spacing.md
|
|
1587
|
+
},
|
|
1588
|
+
outlineBtnText: { ...typography.subhead, fontWeight: '600' },
|
|
1589
|
+
|
|
1590
|
+
// Review card (step "review"): label-left rows, hairlines between them.
|
|
1591
|
+
reviewCard: {
|
|
1592
|
+
borderRadius: radii.lg,
|
|
1593
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
1594
|
+
marginBottom: spacing.lg,
|
|
1595
|
+
overflow: 'hidden'
|
|
1596
|
+
},
|
|
1597
|
+
reviewRow: {
|
|
1598
|
+
flexDirection: 'row',
|
|
1599
|
+
alignItems: 'center',
|
|
1600
|
+
gap: spacing.md,
|
|
1601
|
+
minHeight: 56,
|
|
1602
|
+
paddingVertical: spacing.md,
|
|
1603
|
+
paddingHorizontal: spacing.lg,
|
|
1604
|
+
borderBottomWidth: StyleSheet.hairlineWidth
|
|
1605
|
+
},
|
|
1606
|
+
reviewRowLast: { borderBottomWidth: 0 },
|
|
1607
|
+
reviewLabel: {
|
|
1608
|
+
width: 64,
|
|
1609
|
+
...typography.caption2,
|
|
1610
|
+
fontWeight: '600',
|
|
1611
|
+
letterSpacing: 0.8,
|
|
1612
|
+
textTransform: 'uppercase'
|
|
1613
|
+
},
|
|
1614
|
+
reviewAddressIcon: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center' },
|
|
1615
|
+
reviewToText: { flex: 1, minWidth: 0, gap: 2 },
|
|
1616
|
+
reviewNameRow: { flexDirection: 'row', alignItems: 'baseline', gap: spacing.sm, minWidth: 0 },
|
|
1617
|
+
reviewName: { ...typography.body, fontWeight: '600', flexShrink: 1 },
|
|
1618
|
+
reviewNameSub: { ...typography.subhead, flexShrink: 1 },
|
|
1619
|
+
reviewTrustRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.xs },
|
|
1620
|
+
reviewTrust: { ...typography.caption1 },
|
|
1621
|
+
reviewAmount: { ...typography.title2, fontWeight: '700', fontVariant: ['tabular-nums'], flex: 1 },
|
|
1622
|
+
reviewUnit: { ...typography.headline, fontWeight: '600' },
|
|
1623
|
+
reviewNoteInput: { ...typography.body, flex: 1, minWidth: 0, paddingVertical: 0 },
|
|
1624
|
+
|
|
595
1625
|
// Consequence line + call to action
|
|
596
1626
|
consequence: {
|
|
597
1627
|
...typography.footnote,
|
|
@@ -691,5 +1721,7 @@ const styles = StyleSheet.create({
|
|
|
691
1721
|
}
|
|
692
1722
|
})
|
|
693
1723
|
|
|
1724
|
+
const UniversalSend = forwardRef<UniversalSendHandle, UniversalSendProps>(UniversalSendInner)
|
|
1725
|
+
|
|
694
1726
|
// Wallet status updates in the parent do not change this form's inputs.
|
|
695
1727
|
export default memo(UniversalSend)
|