@bsv/expo-wallet-toolbox 0.1.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/LICENSE.txt +28 -0
- package/README.md +512 -0
- package/assets/sounds/payment-receive.wav +0 -0
- package/assets/sounds/payment-send.wav +0 -0
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/amountFormatHelpers.ts +330 -0
- package/core/backup/RemoteSyncReader.ts +94 -0
- package/core/backup/client.ts +111 -0
- package/core/backup/codec.ts +218 -0
- package/core/backup/constants.ts +88 -0
- package/core/backup/cursor.ts +138 -0
- package/core/backup/derive.ts +46 -0
- package/core/backup/deviceId.ts +33 -0
- package/core/backup/erase.ts +67 -0
- package/core/backup/preference.ts +33 -0
- package/core/backup/push.ts +295 -0
- package/core/backup/restore.ts +152 -0
- package/core/backup/restoreOnImport.ts +119 -0
- package/core/backup/status.ts +46 -0
- package/core/config.tsx +47 -0
- package/core/constants.ts +35 -0
- package/core/context/ExchangeRateContext.tsx +69 -0
- package/core/context/LocalStorageProvider.tsx +225 -0
- package/core/context/UserContext.tsx +129 -0
- package/core/context/VaultContext.tsx +79 -0
- package/core/context/WalletConnectionContext.tsx +454 -0
- package/core/context/WalletContext.tsx +2938 -0
- package/core/context/buildGeneration.ts +37 -0
- package/core/deviceTier.ts +89 -0
- package/core/diskSpace.ts +62 -0
- package/core/displayCurrencies.ts +56 -0
- package/core/headers/OfflineFirstChaintracks.ts +176 -0
- package/core/headers/checkpoints.ts +39 -0
- package/core/headers/fs.ts +119 -0
- package/core/headers/headerStore.ts +333 -0
- package/core/headers/prewarm.ts +36 -0
- package/core/headers/syncHeaders.ts +73 -0
- package/core/hooks/useConfirmationSound.ts +135 -0
- package/core/hooks/useHaptics.ts +51 -0
- package/core/hooks/usePermissionQueue.ts +69 -0
- package/core/i18n/translations.tsx +6692 -0
- package/core/index.ts +295 -0
- package/core/localpay/blePermissions.ts +32 -0
- package/core/localpay/build.ts +392 -0
- package/core/localpay/codec.ts +338 -0
- package/core/localpay/deviceCaps.ts +175 -0
- package/core/localpay/nearbyAdvisory.ts +32 -0
- package/core/localpay/nearbyPermissions.ts +34 -0
- package/core/localpay/pending.ts +385 -0
- package/core/localpay/pendingAborts.ts +67 -0
- package/core/localpay/qr.ts +16 -0
- package/core/localpay/session.ts +277 -0
- package/core/localpay/sessionPolicy.ts +5 -0
- package/core/localpay/transport/awdl.ts +11 -0
- package/core/localpay/transport/ble.ts +159 -0
- package/core/localpay/transport/nearby.ts +12 -0
- package/core/localpay/transport/race.ts +110 -0
- package/core/localpay/transport/select.ts +128 -0
- package/core/localpay/transport/socket.ts +244 -0
- package/core/localpay/types.ts +82 -0
- package/core/localpay/verify.ts +204 -0
- package/core/logging.config.ts +10 -0
- package/core/logging.ts +77 -0
- package/core/mnemonicWallet.ts +180 -0
- package/core/monitor/TaskBackupPush.ts +168 -0
- package/core/monitor/TaskCreditInbox.ts +116 -0
- package/core/monitor/TaskDrainOutbox.ts +122 -0
- package/core/monitor/TaskSendOffline.ts +123 -0
- package/core/monitor/unfailRetry.ts +116 -0
- package/core/net/chainMatch.ts +34 -0
- package/core/net/online.ts +34 -0
- package/core/offline/cancelParked.ts +56 -0
- package/core/offline/hold.ts +127 -0
- package/core/offline/order.ts +109 -0
- package/core/offline/payerHold.ts +144 -0
- package/core/offline/plan.ts +264 -0
- package/core/offline/queueGrace.ts +52 -0
- package/core/parsePeerPayURI.ts +119 -0
- package/core/pay/beefRepair.ts +106 -0
- package/core/pay/creditErrors.ts +46 -0
- package/core/pay/creditInbox.ts +202 -0
- package/core/pay/damagedInbox.ts +64 -0
- package/core/pay/proofNudge.ts +23 -0
- package/core/pay/provenTxFromBump.ts +31 -0
- package/core/pay/rails/address.ts +329 -0
- package/core/pay/rails/handle.ts +617 -0
- package/core/pay/rails/index.ts +197 -0
- package/core/pay/rails/nearby.ts +79 -0
- package/core/pay/receiveFocus.ts +13 -0
- package/core/pay/recordProof.ts +91 -0
- package/core/pay/refreshProofGuard.ts +34 -0
- package/core/pay/sweeper.ts +75 -0
- package/core/pay/tokenAmount.ts +18 -0
- package/core/pay/userError.ts +18 -0
- package/core/pay/watchlist.ts +126 -0
- package/core/peerpay/control.ts +122 -0
- package/core/peerpay/handleResendRequests.ts +475 -0
- package/core/peerpay/inboxAttempts.ts +33 -0
- package/core/peerpay/metadataDecryptor.ts +42 -0
- package/core/peerpay/offlineNacks.ts +96 -0
- package/core/peerpay/outbox.ts +209 -0
- package/core/peerpay/rebuildToken.ts +76 -0
- package/core/peerpay/resendBeef.ts +115 -0
- package/core/services/arcadeBroadcastProvider.ts +214 -0
- package/core/services/capWalletArgs.ts +99 -0
- package/core/services/exchangeRate.ts +63 -0
- package/core/services/secrets/envelope.ts +102 -0
- package/core/services/secrets/hkdf.ts +37 -0
- package/core/services/secrets/index.ts +63 -0
- package/core/services/secrets/kek.ts +274 -0
- package/core/services/secrets/migration.ts +188 -0
- package/core/services/secrets/policy.ts +120 -0
- package/core/services/secrets/storage.ts +54 -0
- package/core/services/secrets/store.ts +125 -0
- package/core/services/secrets/types.ts +85 -0
- package/core/services/usdFxRates.ts +101 -0
- package/core/services/vault/VaultKeyService.ts +312 -0
- package/core/services/vault/backupAttestation.ts +136 -0
- package/core/services/vault/ceremony.ts +972 -0
- package/core/services/vault/ceremonyHost.ts +46 -0
- package/core/services/vault/devMock.ts +22 -0
- package/core/services/vault/driver.ts +197 -0
- package/core/services/vault/guard.ts +90 -0
- package/core/services/vault/k1.ts +75 -0
- package/core/services/vault/mockYubiKey.ts +217 -0
- package/core/services/vault/random.ts +20 -0
- package/core/services/vault/sealing.ts +84 -0
- package/core/services/vault/session.ts +59 -0
- package/core/services/vault/transfers.ts +1151 -0
- package/core/services/vault/types.ts +109 -0
- package/core/services/vault/vaultDerivation.ts +152 -0
- package/core/services/vault/vaultPassphrase.ts +287 -0
- package/core/services/vault/vaultStore.ts +104 -0
- package/core/services/walletArgLimits.ts +234 -0
- package/core/services/walletServiceConfig.ts +170 -0
- package/core/storage/LocalStorageAdapter.ts +58 -0
- package/core/storage/README.md +391 -0
- package/core/storage/StorageExpoSQLite.ts +2008 -0
- package/core/storage/errors.ts +73 -0
- package/core/storage/index.ts +3 -0
- package/core/storage/methods/findSql.ts +286 -0
- package/core/storage/methods/historyNotes.ts +61 -0
- package/core/storage/methods/listActionsSql.ts +212 -0
- package/core/storage/methods/listOutputsSql.ts +211 -0
- package/core/storage/methods/offlineActions.ts +156 -0
- package/core/storage/methods/processOfflineActions.ts +503 -0
- package/core/storage/methods/reclaim.ts +135 -0
- package/core/storage/methods/reviewStatusSql.ts +167 -0
- package/core/storage/methods/unprovenWithoutReqSql.ts +26 -0
- package/core/storage/methods/walletBalanceSql.ts +55 -0
- package/core/storage/schema/createTables.ts +385 -0
- package/core/storage/skipQueuedAncestors.ts +29 -0
- package/core/storage/sqlUpdateValue.ts +12 -0
- package/core/stores/ConnectionStore.ts +71 -0
- package/core/theme/ThemeContext.tsx +182 -0
- package/core/theme/assertThemeContrast.ts +109 -0
- package/core/theme/motion.ts +50 -0
- package/core/theme/tokens.ts +232 -0
- package/core/theme/useThemeStyles.tsx +156 -0
- package/core/walletDbRegistry.ts +110 -0
- package/core/walletMonitor.ts +149 -0
- package/core/walletRepair/runWalletCheck.ts +195 -0
- package/core/walletRepair/shouldReleaseUtxo.ts +18 -0
- package/package.json +86 -0
- package/ui/backupShares.ts +367 -0
- package/ui/components/QRScanner.tsx +353 -0
- package/ui/components/pay/AddressReceive.tsx +507 -0
- package/ui/components/pay/AvailableBalance.tsx +61 -0
- package/ui/components/pay/HandleReceive.tsx +896 -0
- package/ui/components/pay/MessageBoxConfig.tsx +256 -0
- package/ui/components/pay/NearbyAdvisoryModal.tsx +111 -0
- package/ui/components/pay/NearbyFlow.tsx +2542 -0
- package/ui/components/pay/OfflineNotice.tsx +337 -0
- package/ui/components/pay/PayCellRow.tsx +101 -0
- package/ui/components/pay/PayForm.tsx +223 -0
- package/ui/components/pay/PaymentQrDisplay.tsx +105 -0
- package/ui/components/pay/PaymentSuccessOverlay.tsx +266 -0
- package/ui/components/pay/RecipientField.tsx +308 -0
- package/ui/components/pay/RequestHub.tsx +75 -0
- package/ui/components/pay/ResultBanner.tsx +69 -0
- package/ui/components/pay/UniversalSend.tsx +687 -0
- package/ui/components/pay/useRecipientInput.ts +270 -0
- package/ui/components/security/WalletLockNotice.tsx +138 -0
- package/ui/components/ui/AlertCard.tsx +223 -0
- package/ui/components/ui/AppLogo.tsx +166 -0
- package/ui/components/ui/BlurChrome.tsx +72 -0
- package/ui/components/ui/Celebration.tsx +84 -0
- package/ui/components/ui/ChoiceSheet.ts +69 -0
- package/ui/components/ui/CustomSafeArea.tsx +74 -0
- package/ui/components/ui/ErrorBoundary.tsx +154 -0
- package/ui/components/ui/GroupedList.tsx +125 -0
- package/ui/components/ui/IconButton.tsx +105 -0
- package/ui/components/ui/ListRow.tsx +197 -0
- package/ui/components/ui/PermissionSheet.tsx +920 -0
- package/ui/components/ui/PresenceRow.tsx +215 -0
- package/ui/components/ui/PressableScale.tsx +105 -0
- package/ui/components/ui/ScreenGradient.tsx +47 -0
- package/ui/components/ui/ScrollFade.tsx +76 -0
- package/ui/components/ui/Sheet.tsx +342 -0
- package/ui/components/ui/Toast.tsx +142 -0
- package/ui/components/ui/index.ts +8 -0
- package/ui/components/vault/EnrollWizard.tsx +627 -0
- package/ui/components/vault/PassphraseField.tsx +306 -0
- package/ui/components/vault/PhraseBackupSheet.tsx +227 -0
- package/ui/components/vault/VaultBackdrop.tsx +354 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +327 -0
- package/ui/components/wallet/ActivityRow.tsx +408 -0
- package/ui/components/wallet/AmountDisplay.tsx +48 -0
- package/ui/components/wallet/AmountInput.tsx +256 -0
- package/ui/components/wallet/BackupReminderSheet.tsx +168 -0
- package/ui/components/wallet/Balance.tsx +144 -0
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +133 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +93 -0
- package/ui/exportDatabases.ts +122 -0
- package/ui/exportTransactions.ts +129 -0
- package/ui/hooks/useOfflineNoticeActions.ts +136 -0
- package/ui/hooks/useOnline.ts +70 -0
- package/ui/hooks/useSpendableBalance.ts +58 -0
- package/ui/hooks/useVaultBalance.ts +50 -0
- package/ui/importDatabases.ts +170 -0
- package/ui/index.ts +136 -0
- package/ui/isImageUrl.ts +10 -0
- package/ui/printRecoveryShares.ts +93 -0
- package/ui/resolveIdentity.ts +125 -0
- package/ui/screens/ConnectionsScreen.tsx +438 -0
- package/ui/screens/LogsScreen.tsx +432 -0
- package/ui/screens/PairScreen.tsx +288 -0
- package/ui/screens/PayScreen.tsx +479 -0
- package/ui/screens/SettingsScreen.tsx +180 -0
- package/ui/screens/TrustScreen.tsx +831 -0
- package/ui/screens/VaultRecoverScreen.tsx +226 -0
- package/ui/screens/VaultScreen.tsx +423 -0
- package/ui/screens/VaultTransferScreen.tsx +293 -0
- package/ui/screens/WalletCheckScreen.tsx +539 -0
- package/ui/screens/WalletConfigScreen.tsx +1095 -0
- package/ui/screens/WalletHomeScreen.tsx +1597 -0
- package/ui/screens/homeBadges.ts +18 -0
- package/ui/txStatus.ts +79 -0
- package/ui/validateTrust.ts +44 -0
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get paid → someone with this app.
|
|
3
|
+
*
|
|
4
|
+
* Your handle in three forms, because the counterparty's situation decides
|
|
5
|
+
* which one works: a QR to scan across a table, a copyable key to paste, and a
|
|
6
|
+
* peerpay: link to send through any messaging app. The QR and link encode a
|
|
7
|
+
* peerpay link with the remote host url, so the payer learns where to deliver
|
|
8
|
+
* without an overlay lookup. The key below the QR is a bare identity key.
|
|
9
|
+
*
|
|
10
|
+
* Below it: nothing, when all is well. Arriving payments are credited the moment
|
|
11
|
+
* this screen sees them — accepting was never a decision anyone could act on,
|
|
12
|
+
* since the money is already theirs and refusing only leaves it in the box. The
|
|
13
|
+
* list below appears only for payments the wallet could NOT credit, and exists
|
|
14
|
+
* so those can be retried or, when they are structurally broken, given up on.
|
|
15
|
+
*/
|
|
16
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
17
|
+
import {
|
|
18
|
+
ActivityIndicator,
|
|
19
|
+
AppState,
|
|
20
|
+
Image,
|
|
21
|
+
ScrollView,
|
|
22
|
+
Share,
|
|
23
|
+
StyleSheet,
|
|
24
|
+
Text,
|
|
25
|
+
TouchableOpacity,
|
|
26
|
+
View
|
|
27
|
+
} from 'react-native'
|
|
28
|
+
import { useTranslation } from 'react-i18next'
|
|
29
|
+
import { PeerPayClient, type IncomingPayment } from '@bsv/message-box-client'
|
|
30
|
+
import { type DisplayableIdentity } from '@bsv/sdk'
|
|
31
|
+
|
|
32
|
+
import ResultBanner from './ResultBanner'
|
|
33
|
+
import ReceivedOverlay from './PaymentSuccessOverlay'
|
|
34
|
+
import { useMessageBoxConfig } from './MessageBoxConfig'
|
|
35
|
+
import AmountDisplay from '../wallet/AmountDisplay'
|
|
36
|
+
import PressableScale from '../ui/PressableScale'
|
|
37
|
+
import { showAlert } from '../ui/AlertCard'
|
|
38
|
+
import { showToast } from '../ui/Toast'
|
|
39
|
+
import { makeIdentityClient, resolveIdentity } from '../../resolveIdentity'
|
|
40
|
+
import { makeBeefRepair } from '../../../core/pay/beefRepair'
|
|
41
|
+
import { wocConfigFor } from '../../../core/pay/rails/address'
|
|
42
|
+
import { makeCreditClassifier } from '../../../core/pay/creditErrors'
|
|
43
|
+
import { satoshisFromToken } from '../../../core/pay/tokenAmount'
|
|
44
|
+
import { userFacingPayError } from '../../../core/pay/userError'
|
|
45
|
+
import { creditInboxOnce, INBOX_DESCRIPTION, type CreditInboxResult } from '../../../core/pay/creditInbox'
|
|
46
|
+
import { setReceiveInboxFocused } from '../../../core/pay/receiveFocus'
|
|
47
|
+
import { TaskCreditInbox } from '../../../core/monitor/TaskCreditInbox'
|
|
48
|
+
import { useOnline } from '../../hooks/useOnline'
|
|
49
|
+
import { type DamagedInboxMessage } from '../../../core/pay/damagedInbox'
|
|
50
|
+
import { getOnline } from '../../../core/net/online'
|
|
51
|
+
import { saveInboxAttempts } from '../../../core/peerpay/inboxAttempts'
|
|
52
|
+
import {
|
|
53
|
+
useTheme,
|
|
54
|
+
radii,
|
|
55
|
+
spacing,
|
|
56
|
+
typography,
|
|
57
|
+
useWallet,
|
|
58
|
+
NO_MESSAGE_BOX,
|
|
59
|
+
acceptWithRetry,
|
|
60
|
+
discardIncoming,
|
|
61
|
+
internalizeIncoming,
|
|
62
|
+
needsAttention,
|
|
63
|
+
peerPayLinkFor,
|
|
64
|
+
type InboxAttempt
|
|
65
|
+
} from '@bsv/expo-wallet-toolbox'
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
69
|
+
* etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
|
|
70
|
+
* that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
|
|
71
|
+
* Ionicons is loaded lazily, only when actually rendering, same pattern as
|
|
72
|
+
* this package's other native-module-boundary fixes (expo-router, expo-blur).
|
|
73
|
+
*/
|
|
74
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
75
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
76
|
+
function loadIonicons(): IoniconsComponent {
|
|
77
|
+
if (!ioniconsComponent) {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
79
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
80
|
+
}
|
|
81
|
+
return ioniconsComponent
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* expo-router is required lazily rather than imported at module scope: this
|
|
86
|
+
* file is barrel-exported from the package's `ui` entry point, and a static
|
|
87
|
+
* top-level `import` of expo-router pulls in its own untransformed JSX
|
|
88
|
+
* source (Navigator.js etc.), which Jest cannot parse for any consumer of the
|
|
89
|
+
* barrel, even one that never navigates. Same pattern as
|
|
90
|
+
* core/context/WalletContext.tsx's and WalletHomeScreen.tsx's lazy
|
|
91
|
+
* expo-router load. `useFocusEffect` is a hook, but calling it via
|
|
92
|
+
* `loadExpoRouter().useFocusEffect(...)` is equivalent to calling it directly
|
|
93
|
+
* — the module is cached after the first call, so it is the exact same
|
|
94
|
+
* function reference on every render, which is what the rules of hooks
|
|
95
|
+
* actually require (a stable, unconditional call per render).
|
|
96
|
+
*/
|
|
97
|
+
type ExpoRouterModule = typeof import('expo-router')
|
|
98
|
+
let expoRouterMod: ExpoRouterModule | undefined
|
|
99
|
+
function loadExpoRouter(): ExpoRouterModule {
|
|
100
|
+
if (!expoRouterMod) {
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
102
|
+
expoRouterMod = require('expo-router') as ExpoRouterModule
|
|
103
|
+
}
|
|
104
|
+
return expoRouterMod
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @react-native-clipboard/clipboard reaches for its native TurboModule at
|
|
109
|
+
* import time (`TurboModuleRegistry.getEnforcing`), which throws under Jest
|
|
110
|
+
* (no native binary registered there) even though the module itself
|
|
111
|
+
* transforms fine. Required lazily, only when a handler actually copies
|
|
112
|
+
* something, so importing the `ui` barrel never touches the native module.
|
|
113
|
+
* Same pattern as WalletHomeScreen.tsx's lazy clipboard load.
|
|
114
|
+
*/
|
|
115
|
+
type ClipboardModule = typeof import('@react-native-clipboard/clipboard').default
|
|
116
|
+
let clipboardModule: ClipboardModule | undefined
|
|
117
|
+
function loadClipboard(): ClipboardModule {
|
|
118
|
+
if (!clipboardModule) {
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
120
|
+
clipboardModule = require('@react-native-clipboard/clipboard').default as ClipboardModule
|
|
121
|
+
}
|
|
122
|
+
return clipboardModule
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* react-native-qrcode-svg ships an untransformed ESM build that Jest cannot
|
|
127
|
+
* parse when eagerly pulled in via the `ui` package barrel, even for a
|
|
128
|
+
* consumer that never renders one. Loaded lazily, only when actually
|
|
129
|
+
* rendering, same pattern as this package's other native/ESM-boundary fixes.
|
|
130
|
+
* `mod?.default ?? mod` mirrors Babel's default-interop rather than a plain
|
|
131
|
+
* `.default` access, since this repo's test mock for the module
|
|
132
|
+
* (`jest.mock('react-native-qrcode-svg', () => 'QRCode')`) has no
|
|
133
|
+
* `__esModule`/`default` shape.
|
|
134
|
+
*/
|
|
135
|
+
type QRCodeComponent = typeof import('react-native-qrcode-svg').default
|
|
136
|
+
let qrCodeComponent: QRCodeComponent | undefined
|
|
137
|
+
function loadQRCode(): QRCodeComponent {
|
|
138
|
+
if (!qrCodeComponent) {
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
140
|
+
const mod = require('react-native-qrcode-svg')
|
|
141
|
+
qrCodeComponent = (mod?.default ?? mod) as QRCodeComponent
|
|
142
|
+
}
|
|
143
|
+
return qrCodeComponent
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* How often the inbox is re-read while this screen is in front.
|
|
148
|
+
*
|
|
149
|
+
* Five seconds is the "it just appeared" threshold without making the poll the
|
|
150
|
+
* app's most frequent network call: it is one MessageBox list read, and it stops
|
|
151
|
+
* entirely on blur, on background and during an accept.
|
|
152
|
+
*/
|
|
153
|
+
const INBOX_POLL_MS = 5000
|
|
154
|
+
|
|
155
|
+
// ── Needs attention ──────────────────────────────────────────────────────────
|
|
156
|
+
//
|
|
157
|
+
// Replaces the old accept list. An arriving payment is credited automatically
|
|
158
|
+
// (see autoAcceptInbox in the handle rail), so the only rows here are the ones
|
|
159
|
+
// the wallet could NOT credit after MAX_AUTO_ATTEMPTS tries, plus environmental
|
|
160
|
+
// failures still waiting on the network. That makes this a problem queue, not
|
|
161
|
+
// an inbox: every row offers a retry, and a discard for the structurally
|
|
162
|
+
// broken ones that will never succeed.
|
|
163
|
+
//
|
|
164
|
+
// There is deliberately no empty state. When nothing is wrong the section is
|
|
165
|
+
// absent entirely — an inbox that is always visible and always empty trains
|
|
166
|
+
// people to ignore it, and this is the one place that must be noticed.
|
|
167
|
+
|
|
168
|
+
interface AttentionSectionProps {
|
|
169
|
+
readonly payments: IncomingPayment[]
|
|
170
|
+
readonly attempts: Record<string, InboxAttempt>
|
|
171
|
+
readonly damagedIds: ReadonlySet<string>
|
|
172
|
+
readonly senderIdentities: Record<string, DisplayableIdentity | null>
|
|
173
|
+
readonly busyId: string | null
|
|
174
|
+
readonly colors: ReturnType<typeof import('@bsv/expo-wallet-toolbox').useTheme>['colors']
|
|
175
|
+
readonly t: ReturnType<typeof import('react-i18next').useTranslation>['t']
|
|
176
|
+
readonly onRetry: (p: IncomingPayment) => void
|
|
177
|
+
readonly onDiscard: (p: IncomingPayment) => void
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function AttentionSection({
|
|
181
|
+
payments,
|
|
182
|
+
attempts,
|
|
183
|
+
damagedIds,
|
|
184
|
+
senderIdentities,
|
|
185
|
+
busyId,
|
|
186
|
+
colors,
|
|
187
|
+
t,
|
|
188
|
+
onRetry,
|
|
189
|
+
onDiscard
|
|
190
|
+
}: AttentionSectionProps) {
|
|
191
|
+
if (payments.length === 0) return null
|
|
192
|
+
return (
|
|
193
|
+
<>
|
|
194
|
+
<Text style={[styles.sectionTitle, { color: colors.textPrimary }]}>{t('pay_inbox_attention')}</Text>
|
|
195
|
+
<Text style={[styles.attentionHint, { color: colors.textSecondary }]}>{t('pay_inbox_attention_hint')}</Text>
|
|
196
|
+
<View
|
|
197
|
+
style={[
|
|
198
|
+
styles.paymentsList,
|
|
199
|
+
{ backgroundColor: colors.backgroundSecondary, borderColor: colors.warning + '40' }
|
|
200
|
+
]}
|
|
201
|
+
>
|
|
202
|
+
{payments.map((payment, idx) => {
|
|
203
|
+
const id = String(payment.messageId)
|
|
204
|
+
const isDamaged = damagedIds.has(id)
|
|
205
|
+
const kind = attempts[id]?.kind
|
|
206
|
+
const facing = userFacingPayError(attempts[id]?.error)
|
|
207
|
+
const error = isDamaged
|
|
208
|
+
? t('payment_arrived_damaged')
|
|
209
|
+
: kind === 'environmental'
|
|
210
|
+
? t('waiting_network_confirm')
|
|
211
|
+
: facing.offerWalletCheck
|
|
212
|
+
? t(facing.key)
|
|
213
|
+
: (attempts[id]?.error ?? '')
|
|
214
|
+
return (
|
|
215
|
+
<AttentionRow
|
|
216
|
+
key={id}
|
|
217
|
+
payment={payment}
|
|
218
|
+
identity={senderIdentities[payment.sender ?? '']}
|
|
219
|
+
error={error}
|
|
220
|
+
offerWalletCheck={!isDamaged && kind !== 'environmental' && facing.offerWalletCheck}
|
|
221
|
+
isDamaged={isDamaged}
|
|
222
|
+
isLast={idx === payments.length - 1}
|
|
223
|
+
isBusy={busyId === id}
|
|
224
|
+
onRetry={() => onRetry(payment)}
|
|
225
|
+
onDiscard={() => onDiscard(payment)}
|
|
226
|
+
colors={colors}
|
|
227
|
+
t={t}
|
|
228
|
+
/>
|
|
229
|
+
)
|
|
230
|
+
})}
|
|
231
|
+
</View>
|
|
232
|
+
</>
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
interface AttentionRowProps {
|
|
237
|
+
readonly payment: IncomingPayment
|
|
238
|
+
readonly identity: DisplayableIdentity | null | undefined
|
|
239
|
+
readonly error: string
|
|
240
|
+
readonly offerWalletCheck?: boolean
|
|
241
|
+
readonly isDamaged: boolean
|
|
242
|
+
readonly isLast: boolean
|
|
243
|
+
readonly isBusy: boolean
|
|
244
|
+
readonly onRetry: () => void
|
|
245
|
+
readonly onDiscard: () => void
|
|
246
|
+
readonly colors: ReturnType<typeof import('@bsv/expo-wallet-toolbox').useTheme>['colors']
|
|
247
|
+
readonly t: ReturnType<typeof import('react-i18next').useTranslation>['t']
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function AttentionRow({
|
|
251
|
+
payment,
|
|
252
|
+
identity,
|
|
253
|
+
error,
|
|
254
|
+
offerWalletCheck,
|
|
255
|
+
isDamaged,
|
|
256
|
+
isLast,
|
|
257
|
+
isBusy,
|
|
258
|
+
onRetry,
|
|
259
|
+
onDiscard,
|
|
260
|
+
colors,
|
|
261
|
+
t
|
|
262
|
+
}: AttentionRowProps) {
|
|
263
|
+
const Ionicons = loadIonicons()
|
|
264
|
+
const senderKey = payment.sender ?? ''
|
|
265
|
+
const satoshis = isDamaged ? undefined : satoshisFromToken(payment.token)?.satoshis
|
|
266
|
+
return (
|
|
267
|
+
<View
|
|
268
|
+
style={[
|
|
269
|
+
styles.paymentRow,
|
|
270
|
+
!isLast && { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: colors.separator }
|
|
271
|
+
]}
|
|
272
|
+
>
|
|
273
|
+
{identity?.avatarURL ? (
|
|
274
|
+
<Image source={{ uri: identity.avatarURL }} style={styles.paymentAvatar} />
|
|
275
|
+
) : (
|
|
276
|
+
<View style={[styles.paymentAvatarPlaceholder, { backgroundColor: colors.accent }]}>
|
|
277
|
+
<Ionicons name="person" size={24} color={colors.background} />
|
|
278
|
+
</View>
|
|
279
|
+
)}
|
|
280
|
+
|
|
281
|
+
<View style={styles.paymentInfo}>
|
|
282
|
+
<Text style={[styles.paymentSenderName, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
283
|
+
{identity?.name ?? t('unknown')}
|
|
284
|
+
</Text>
|
|
285
|
+
<Text style={[styles.paymentSender, { color: colors.textSecondary }]} numberOfLines={1}>
|
|
286
|
+
{identity?.abbreviatedKey ?? `${senderKey.slice(0, 16)}…`}
|
|
287
|
+
</Text>
|
|
288
|
+
{/* The reason, verbatim from the wallet. It is the only thing that tells
|
|
289
|
+
the user whether a retry has any chance of working. */}
|
|
290
|
+
{!!error && (
|
|
291
|
+
<Text style={[styles.attentionError, { color: colors.warning }]} numberOfLines={2}>
|
|
292
|
+
{error}
|
|
293
|
+
</Text>
|
|
294
|
+
)}
|
|
295
|
+
|
|
296
|
+
<View style={[styles.attentionActions, { borderTopColor: colors.separator }]}>
|
|
297
|
+
<TouchableOpacity
|
|
298
|
+
onPress={onRetry}
|
|
299
|
+
disabled={isBusy || isDamaged}
|
|
300
|
+
style={[
|
|
301
|
+
styles.attentionButton,
|
|
302
|
+
{ borderRightWidth: StyleSheet.hairlineWidth, borderRightColor: colors.separator }
|
|
303
|
+
]}
|
|
304
|
+
>
|
|
305
|
+
{isBusy && !isDamaged ? (
|
|
306
|
+
<ActivityIndicator size="small" color={colors.accent} />
|
|
307
|
+
) : (
|
|
308
|
+
<Text
|
|
309
|
+
style={[
|
|
310
|
+
styles.attentionButtonText,
|
|
311
|
+
{ color: isDamaged ? colors.textSecondary : colors.accent, opacity: isDamaged ? 0.4 : 1 }
|
|
312
|
+
]}
|
|
313
|
+
>
|
|
314
|
+
{t('retry')}
|
|
315
|
+
</Text>
|
|
316
|
+
)}
|
|
317
|
+
</TouchableOpacity>
|
|
318
|
+
{/* One tap opens a confirmation alert — uncommon irreversible action. */}
|
|
319
|
+
<TouchableOpacity onPress={onDiscard} disabled={isBusy} style={styles.attentionButton}>
|
|
320
|
+
<Text style={[styles.attentionButtonText, { color: colors.textSecondary }]} numberOfLines={1}>
|
|
321
|
+
{t('dismiss')}
|
|
322
|
+
</Text>
|
|
323
|
+
</TouchableOpacity>
|
|
324
|
+
{offerWalletCheck && (
|
|
325
|
+
<TouchableOpacity
|
|
326
|
+
onPress={() => loadExpoRouter().router.push('/wallet-check' as never)}
|
|
327
|
+
disabled={isBusy}
|
|
328
|
+
style={styles.attentionButton}
|
|
329
|
+
>
|
|
330
|
+
<Text style={[styles.attentionButtonText, { color: colors.accent }]} numberOfLines={1}>
|
|
331
|
+
{t('check_wallet')}
|
|
332
|
+
</Text>
|
|
333
|
+
</TouchableOpacity>
|
|
334
|
+
)}
|
|
335
|
+
</View>
|
|
336
|
+
</View>
|
|
337
|
+
|
|
338
|
+
{typeof satoshis === 'number' && (
|
|
339
|
+
<View style={styles.paymentActions}>
|
|
340
|
+
<Text style={[styles.paymentAmount, { color: colors.textSecondary }]}>
|
|
341
|
+
<AmountDisplay>{satoshis}</AmountDisplay>
|
|
342
|
+
</Text>
|
|
343
|
+
</View>
|
|
344
|
+
)}
|
|
345
|
+
</View>
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export default function HandleReceive({ initialSats }: { initialSats?: number } = {}) {
|
|
350
|
+
const { t } = useTranslation()
|
|
351
|
+
const { colors } = useTheme()
|
|
352
|
+
const Ionicons = loadIonicons()
|
|
353
|
+
const QRCode = loadQRCode()
|
|
354
|
+
const { useFocusEffect } = loadExpoRouter()
|
|
355
|
+
const { managers, adminOriginator, selectedNetwork, storage, peekLastMissHeight } = useWallet()
|
|
356
|
+
const wallet = managers?.permissionsManager || null
|
|
357
|
+
const online = useOnline()
|
|
358
|
+
|
|
359
|
+
const [identityKey, setIdentityKey] = useState('')
|
|
360
|
+
const [identityError, setIdentityError] = useState(false)
|
|
361
|
+
const [copied, setCopied] = useState(false)
|
|
362
|
+
const { messageBoxUrl } = useMessageBoxConfig(t)
|
|
363
|
+
const isConfigured = !!messageBoxUrl && messageBoxUrl !== NO_MESSAGE_BOX
|
|
364
|
+
|
|
365
|
+
const [payments, setPayments] = useState<IncomingPayment[]>([])
|
|
366
|
+
/** Inbox rows listIncomingPayments dropped or that fail token shape. */
|
|
367
|
+
const [damaged, setDamaged] = useState<DamagedInboxMessage[]>([])
|
|
368
|
+
const [senderIdentities, setSenderIdentities] = useState<Record<string, DisplayableIdentity | null>>({})
|
|
369
|
+
const [result, setResult] = useState<{ type: 'success' | 'error'; message: string } | null>(null)
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* The success moment, held until the payee acknowledges it. Set by the credit
|
|
373
|
+
* pass; cleared only by the overlay's Done.
|
|
374
|
+
*/
|
|
375
|
+
const [received, setReceived] = useState<{ amount: number; count: number } | null>(null)
|
|
376
|
+
|
|
377
|
+
/** Payments the wallet has failed to credit, keyed by message id. */
|
|
378
|
+
const [attempts, setAttempts] = useState<Record<string, InboxAttempt>>({})
|
|
379
|
+
/** The row whose retry or discard is running. */
|
|
380
|
+
const [busyId, setBusyId] = useState<string | null>(null)
|
|
381
|
+
|
|
382
|
+
/** One inbox read at a time — see fetchPayments. */
|
|
383
|
+
const fetchingRef = useRef(false)
|
|
384
|
+
/** The live attempt map, for discard copy that must not close over stale state. */
|
|
385
|
+
const attemptsRef = useRef<Record<string, InboxAttempt>>({})
|
|
386
|
+
useEffect(() => {
|
|
387
|
+
attemptsRef.current = attempts
|
|
388
|
+
}, [attempts])
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Whether this screen is the one on top. Pushing another route leaves this
|
|
392
|
+
* component mounted, so mount alone is not "the user is looking at it".
|
|
393
|
+
*/
|
|
394
|
+
const focusedRef = useRef(true)
|
|
395
|
+
const identityInFlightRef = useRef(false)
|
|
396
|
+
const loadIdentityKey = useCallback(async () => {
|
|
397
|
+
if (!wallet || identityInFlightRef.current) return
|
|
398
|
+
identityInFlightRef.current = true
|
|
399
|
+
setIdentityError(false)
|
|
400
|
+
try {
|
|
401
|
+
const r = await wallet.getPublicKey({ identityKey: true }, adminOriginator)
|
|
402
|
+
if (r?.publicKey) setIdentityKey(r.publicKey)
|
|
403
|
+
} catch {
|
|
404
|
+
setIdentityError(true)
|
|
405
|
+
} finally {
|
|
406
|
+
identityInFlightRef.current = false
|
|
407
|
+
}
|
|
408
|
+
}, [wallet, adminOriginator])
|
|
409
|
+
|
|
410
|
+
useFocusEffect(
|
|
411
|
+
useCallback(() => {
|
|
412
|
+
focusedRef.current = true
|
|
413
|
+
setReceiveInboxFocused(true)
|
|
414
|
+
if (!identityKey) void loadIdentityKey()
|
|
415
|
+
return () => {
|
|
416
|
+
focusedRef.current = false
|
|
417
|
+
setReceiveInboxFocused(false)
|
|
418
|
+
}
|
|
419
|
+
}, [identityKey, loadIdentityKey])
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
const peerPayClient = useMemo<PeerPayClient | null>(() => {
|
|
423
|
+
if (!isConfigured || !messageBoxUrl || !wallet) return null
|
|
424
|
+
try {
|
|
425
|
+
return new PeerPayClient({
|
|
426
|
+
messageBoxHost: messageBoxUrl,
|
|
427
|
+
walletClient: wallet as any,
|
|
428
|
+
originator: adminOriginator
|
|
429
|
+
})
|
|
430
|
+
} catch {
|
|
431
|
+
return null
|
|
432
|
+
}
|
|
433
|
+
}, [isConfigured, messageBoxUrl, wallet, adminOriginator])
|
|
434
|
+
|
|
435
|
+
// BRC-125 with this app's url extension: the payer learns where to deliver
|
|
436
|
+
// without an overlay lookup. Omitted when no server is configured, since
|
|
437
|
+
// there is then nowhere to point them.
|
|
438
|
+
const link = identityKey ? peerPayLinkFor(identityKey, initialSats, isConfigured ? messageBoxUrl : undefined) : ''
|
|
439
|
+
|
|
440
|
+
const handleCopy = useCallback(() => {
|
|
441
|
+
if (!identityKey) return
|
|
442
|
+
loadClipboard().setString(identityKey)
|
|
443
|
+
setCopied(true)
|
|
444
|
+
setTimeout(() => setCopied(false), 2000)
|
|
445
|
+
}, [identityKey])
|
|
446
|
+
|
|
447
|
+
const handleShare = useCallback(() => {
|
|
448
|
+
if (!link) return
|
|
449
|
+
// Share.share rejects when the sheet is dismissed on some platforms; a
|
|
450
|
+
// dismissed share sheet is not an error worth a toast.
|
|
451
|
+
void Share.share({ message: link }).catch(() => {})
|
|
452
|
+
}, [link])
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Second chance for a payment whose proof no longer verifies. The token's
|
|
456
|
+
* merkle path was minted at send time and a reorg since then invalidates it
|
|
457
|
+
* without changing the transaction, so the proof is re-fetched by txid. Only
|
|
458
|
+
* consulted after internalizeAction has already failed, and it declines while
|
|
459
|
+
* offline — see core/pay/beefRepair.ts.
|
|
460
|
+
*/
|
|
461
|
+
const repairBeef = useMemo(
|
|
462
|
+
() => makeBeefRepair({ woc: wocConfigFor(selectedNetwork), online: getOnline }),
|
|
463
|
+
[selectedNetwork]
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
const internalize = useCallback(
|
|
467
|
+
async (payment: IncomingPayment, description: string) => {
|
|
468
|
+
const client = peerPayClient
|
|
469
|
+
if (!client || !wallet) throw new Error(t('wallet_not_ready'))
|
|
470
|
+
await internalizeIncoming(wallet as any, client, adminOriginator, payment, description, repairBeef)
|
|
471
|
+
},
|
|
472
|
+
[peerPayClient, wallet, adminOriginator, t, repairBeef]
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
const applyCreditResult = useCallback((outcome: CreditInboxResult) => {
|
|
476
|
+
TaskCreditInbox.lastAttentionCount = outcome.attentionCount
|
|
477
|
+
attemptsRef.current = outcome.attempts
|
|
478
|
+
setAttempts(outcome.attempts)
|
|
479
|
+
setPayments(outcome.displayPayments)
|
|
480
|
+
setDamaged(outcome.damaged)
|
|
481
|
+
if (outcome.accepted > 0) {
|
|
482
|
+
// Full screen and held until acknowledged, not a toast. Money arriving
|
|
483
|
+
// can be missed entirely — phone face down, in a pocket, not being
|
|
484
|
+
// looked at — and whether it landed is the one thing a payee must never
|
|
485
|
+
// be left unsure about. Everything not left in the attempt map was
|
|
486
|
+
// credited, so that is what the figure sums.
|
|
487
|
+
const credited = outcome.payments.filter(p => !outcome.attempts[String(p.messageId)])
|
|
488
|
+
setReceived({
|
|
489
|
+
amount: credited.reduce((sum, p) => sum + (satoshisFromToken(p.token)?.satoshis ?? 0), 0),
|
|
490
|
+
count: outcome.accepted
|
|
491
|
+
})
|
|
492
|
+
}
|
|
493
|
+
}, [])
|
|
494
|
+
|
|
495
|
+
const runCredit = useCallback(
|
|
496
|
+
async (force?: string[]) => {
|
|
497
|
+
const client = peerPayClient
|
|
498
|
+
if (!client || !messageBoxUrl || messageBoxUrl === NO_MESSAGE_BOX) return undefined
|
|
499
|
+
const classify = await makeCreditClassifier({
|
|
500
|
+
getOnline: () => online,
|
|
501
|
+
peekLastMissHeight
|
|
502
|
+
})
|
|
503
|
+
const outcome = await creditInboxOnce({
|
|
504
|
+
client,
|
|
505
|
+
messageBoxUrl,
|
|
506
|
+
storage: storage ?? undefined,
|
|
507
|
+
force,
|
|
508
|
+
classify,
|
|
509
|
+
accept: payment => acceptWithRetry(client, messageBoxUrl, payment, INBOX_DESCRIPTION, internalize)
|
|
510
|
+
})
|
|
511
|
+
applyCreditResult(outcome)
|
|
512
|
+
return outcome
|
|
513
|
+
},
|
|
514
|
+
[peerPayClient, messageBoxUrl, storage, online, peekLastMissHeight, internalize, applyCreditResult]
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
const fetchPayments = useCallback(
|
|
518
|
+
async (options: { silent?: boolean } = {}) => {
|
|
519
|
+
const client = peerPayClient
|
|
520
|
+
if (!client || !messageBoxUrl || messageBoxUrl === NO_MESSAGE_BOX) return
|
|
521
|
+
// One read at a time. The poll, the refresh button and every accept all
|
|
522
|
+
// reach this, and two overlapping reads can land out of order — the older
|
|
523
|
+
// response winning would resurrect a row that was just internalized.
|
|
524
|
+
if (fetchingRef.current) return
|
|
525
|
+
fetchingRef.current = true
|
|
526
|
+
try {
|
|
527
|
+
const outcome = await runCredit()
|
|
528
|
+
const displayList = outcome?.displayPayments ?? []
|
|
529
|
+
const idClient = makeIdentityClient(wallet as any, adminOriginator)
|
|
530
|
+
if (idClient) {
|
|
531
|
+
const senders = [...new Set(displayList.map(p => p.sender).filter(Boolean))] as string[]
|
|
532
|
+
const entries = await Promise.all(senders.map(s => resolveIdentity(idClient, s)))
|
|
533
|
+
setSenderIdentities(Object.fromEntries(entries))
|
|
534
|
+
}
|
|
535
|
+
} catch (error: any) {
|
|
536
|
+
// A silent read is a poll the user did not ask for, so it fails quietly:
|
|
537
|
+
// at one read every few seconds, a dead network would otherwise raise a
|
|
538
|
+
// toast per tick. Only a read the user triggered reports failure.
|
|
539
|
+
if (!options.silent) {
|
|
540
|
+
showToast(`${t('connection_failed')}: ${error?.message || t('unknown_error')}`, { type: 'error' })
|
|
541
|
+
}
|
|
542
|
+
} finally {
|
|
543
|
+
fetchingRef.current = false
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
[peerPayClient, messageBoxUrl, wallet, adminOriginator, t, runCredit]
|
|
547
|
+
)
|
|
548
|
+
|
|
549
|
+
useEffect(() => {
|
|
550
|
+
void fetchPayments()
|
|
551
|
+
}, [fetchPayments])
|
|
552
|
+
|
|
553
|
+
// Read through a ref so the poll below depends only on the client, and is
|
|
554
|
+
// never torn down and restarted by an unrelated re-render.
|
|
555
|
+
const fetchRef = useRef(fetchPayments)
|
|
556
|
+
useEffect(() => {
|
|
557
|
+
fetchRef.current = fetchPayments
|
|
558
|
+
}, [fetchPayments])
|
|
559
|
+
|
|
560
|
+
// ── Poll the inbox ──
|
|
561
|
+
//
|
|
562
|
+
// A payment arrives whenever the sender's wallet delivers it and MessageBox has
|
|
563
|
+
// no push channel here, so "it appears on its own" means polling — but only
|
|
564
|
+
// while someone is actually looking at this screen. Unmount and blur stop it
|
|
565
|
+
// because a poll nobody can see spends battery; a backgrounded app stops it
|
|
566
|
+
// for the same reason and because iOS will suspend the timer anyway. The
|
|
567
|
+
// shared creditInboxOnce mutex serializes with TaskCreditInbox.
|
|
568
|
+
useEffect(() => {
|
|
569
|
+
if (!peerPayClient) return
|
|
570
|
+
let cancelled = false
|
|
571
|
+
|
|
572
|
+
const tick = () => {
|
|
573
|
+
if (cancelled || !focusedRef.current) return
|
|
574
|
+
if (AppState.currentState !== 'active') return
|
|
575
|
+
void fetchRef.current({ silent: true })
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const interval = setInterval(tick, INBOX_POLL_MS)
|
|
579
|
+
// Returning to the app should show what arrived while it was away, rather
|
|
580
|
+
// than waiting out the rest of an interval.
|
|
581
|
+
const appSubscription = AppState.addEventListener('change', next => {
|
|
582
|
+
if (next === 'active') tick()
|
|
583
|
+
})
|
|
584
|
+
|
|
585
|
+
return () => {
|
|
586
|
+
cancelled = true
|
|
587
|
+
clearInterval(interval)
|
|
588
|
+
appSubscription.remove()
|
|
589
|
+
}
|
|
590
|
+
}, [peerPayClient])
|
|
591
|
+
|
|
592
|
+
/** Retry one row that had given up. Runs the whole pass, forcing this id. */
|
|
593
|
+
const handleRetry = useCallback(
|
|
594
|
+
async (payment: IncomingPayment) => {
|
|
595
|
+
const id = String(payment.messageId)
|
|
596
|
+
if (damaged.some(d => d.messageId === id)) return
|
|
597
|
+
setBusyId(id)
|
|
598
|
+
try {
|
|
599
|
+
await runCredit([id])
|
|
600
|
+
} finally {
|
|
601
|
+
setBusyId(null)
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
[runCredit, damaged]
|
|
605
|
+
)
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Give up on a row. One tap opens a confirmation alert; confirming NACKs the
|
|
609
|
+
* sender then acks. If the NACK fails the row stays.
|
|
610
|
+
*/
|
|
611
|
+
const handleDiscard = useCallback(
|
|
612
|
+
async (payment: IncomingPayment) => {
|
|
613
|
+
const client = peerPayClient
|
|
614
|
+
if (!client) return
|
|
615
|
+
const id = String(payment.messageId)
|
|
616
|
+
const isDamaged = damaged.some(d => d.messageId === id)
|
|
617
|
+
const voided = !isDamaged && attemptsRef.current[id]?.kind === 'double_spend'
|
|
618
|
+
const choice = await showAlert(
|
|
619
|
+
voided
|
|
620
|
+
? {
|
|
621
|
+
title: t('discard_void_title'),
|
|
622
|
+
message: t('discard_void_body'),
|
|
623
|
+
buttons: [{ text: t('done'), key: 'done' }]
|
|
624
|
+
}
|
|
625
|
+
: {
|
|
626
|
+
title: t('discard_payment_title'),
|
|
627
|
+
message: t('discard_payment_body'),
|
|
628
|
+
buttons: [
|
|
629
|
+
{ text: t('cancel'), style: 'cancel', key: 'cancel' },
|
|
630
|
+
{ text: t('discard'), style: 'destructive', key: 'discard' }
|
|
631
|
+
]
|
|
632
|
+
}
|
|
633
|
+
)
|
|
634
|
+
if (voided ? choice !== 'done' : choice !== 'discard') return
|
|
635
|
+
setBusyId(id)
|
|
636
|
+
try {
|
|
637
|
+
const reason = isDamaged ? 'corrupt' : voided ? 'double_spent' : 'uncreditible'
|
|
638
|
+
await discardIncoming(client, payment, reason)
|
|
639
|
+
// Drop it locally too: it will never be listed again, so waiting for the
|
|
640
|
+
// next poll would leave a row on screen that no longer exists.
|
|
641
|
+
setAttempts(prev => {
|
|
642
|
+
const next = { ...prev }
|
|
643
|
+
delete next[id]
|
|
644
|
+
attemptsRef.current = next
|
|
645
|
+
if (storage) void saveInboxAttempts(storage, next)
|
|
646
|
+
return next
|
|
647
|
+
})
|
|
648
|
+
setDamaged(prev => prev.filter(d => d.messageId !== id))
|
|
649
|
+
setPayments(prev => prev.filter(p => String(p.messageId) !== id))
|
|
650
|
+
TaskCreditInbox.lastAttentionCount = Math.max(0, TaskCreditInbox.lastAttentionCount - 1)
|
|
651
|
+
setResult({ type: 'success', message: t('pay_dismissed') })
|
|
652
|
+
} catch (e: any) {
|
|
653
|
+
showToast(e?.message || t('unknown_error'), { type: 'error' })
|
|
654
|
+
} finally {
|
|
655
|
+
setBusyId(null)
|
|
656
|
+
setTimeout(() => setResult(null), 5000)
|
|
657
|
+
}
|
|
658
|
+
},
|
|
659
|
+
[peerPayClient, damaged, t, storage]
|
|
660
|
+
)
|
|
661
|
+
|
|
662
|
+
const damagedIds = useMemo(() => new Set(damaged.map(d => d.messageId)), [damaged])
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* The rows worth showing: payments the wallet has given up on, environmental
|
|
666
|
+
* failures still waiting on the network, plus inbox bodies that never parsed
|
|
667
|
+
* into tokens. Everything else was credited.
|
|
668
|
+
*/
|
|
669
|
+
const attention = useMemo(
|
|
670
|
+
() =>
|
|
671
|
+
payments.filter(p => {
|
|
672
|
+
const id = String(p.messageId)
|
|
673
|
+
return damagedIds.has(id) || needsAttention(attempts[id]) || attempts[id]?.kind === 'environmental'
|
|
674
|
+
}),
|
|
675
|
+
[payments, attempts, damagedIds]
|
|
676
|
+
)
|
|
677
|
+
|
|
678
|
+
return (
|
|
679
|
+
// Scrolls, because a 240pt QR plus the inbox overflows a small screen and a
|
|
680
|
+
// note being edited puts the keyboard over the row that owns it.
|
|
681
|
+
<ScrollView contentContainerStyle={styles.container} keyboardShouldPersistTaps="handled">
|
|
682
|
+
{/* Your handle. The QR is the focal element — it is the thing physically
|
|
683
|
+
held up to another device. */}
|
|
684
|
+
{/* The figure the code asks for, as its price. Only when one was named. */}
|
|
685
|
+
{initialSats !== undefined && initialSats > 0 && (
|
|
686
|
+
<Text style={[styles.requestedAmount, { color: colors.textPrimary }]}>
|
|
687
|
+
<AmountDisplay>{initialSats}</AmountDisplay>
|
|
688
|
+
</Text>
|
|
689
|
+
)}
|
|
690
|
+
<View style={styles.qrHero}>
|
|
691
|
+
{identityKey ? (
|
|
692
|
+
<View style={styles.qrPlate}>
|
|
693
|
+
<QRCode value={link} size={240} color="#000" backgroundColor="#fff" />
|
|
694
|
+
</View>
|
|
695
|
+
) : identityError ? (
|
|
696
|
+
<View style={styles.identityError}>
|
|
697
|
+
<Text style={[styles.identityErrorText, { color: colors.error }]}>{t('unknown_error')}</Text>
|
|
698
|
+
<PressableScale
|
|
699
|
+
onPress={() => void loadIdentityKey()}
|
|
700
|
+
haptic="tap"
|
|
701
|
+
style={styles.identityRetry}
|
|
702
|
+
accessibilityRole="button"
|
|
703
|
+
accessibilityLabel={t('activity_load_retry')}
|
|
704
|
+
>
|
|
705
|
+
<Text style={[styles.identityRetryLabel, { color: colors.accent }]}>{t('activity_load_retry')}</Text>
|
|
706
|
+
</PressableScale>
|
|
707
|
+
</View>
|
|
708
|
+
) : (
|
|
709
|
+
<ActivityIndicator size="large" color={colors.textSecondary} />
|
|
710
|
+
)}
|
|
711
|
+
</View>
|
|
712
|
+
|
|
713
|
+
<Text style={[styles.keyText, { color: colors.textSecondary }]} numberOfLines={1} ellipsizeMode="middle">
|
|
714
|
+
{identityKey}
|
|
715
|
+
</Text>
|
|
716
|
+
|
|
717
|
+
<View style={styles.actionRow}>
|
|
718
|
+
<TouchableOpacity onPress={handleCopy} style={[styles.action, { backgroundColor: colors.fillTertiary }]}>
|
|
719
|
+
<Ionicons
|
|
720
|
+
name={copied ? 'checkmark' : 'copy-outline'}
|
|
721
|
+
size={18}
|
|
722
|
+
color={copied ? colors.success : colors.textSecondary}
|
|
723
|
+
/>
|
|
724
|
+
<Text style={[styles.actionText, { color: copied ? colors.success : colors.textSecondary }]}>
|
|
725
|
+
{copied ? t('copied') : t('pay_copy')}
|
|
726
|
+
</Text>
|
|
727
|
+
</TouchableOpacity>
|
|
728
|
+
<TouchableOpacity
|
|
729
|
+
onPress={handleShare}
|
|
730
|
+
disabled={!link}
|
|
731
|
+
style={[styles.action, { backgroundColor: colors.fillTertiary, opacity: link ? 1 : 0.5 }]}
|
|
732
|
+
>
|
|
733
|
+
<Ionicons name="share-outline" size={18} color={colors.textSecondary} />
|
|
734
|
+
<Text style={[styles.actionText, { color: colors.textSecondary }]}>{t('pay_share_link')}</Text>
|
|
735
|
+
</TouchableOpacity>
|
|
736
|
+
</View>
|
|
737
|
+
|
|
738
|
+
{/* Only the payments the wallet gave up on. Everything else was credited
|
|
739
|
+
the moment it was seen, so there is nothing here to accept. */}
|
|
740
|
+
{isConfigured && (
|
|
741
|
+
<AttentionSection
|
|
742
|
+
payments={attention}
|
|
743
|
+
attempts={attempts}
|
|
744
|
+
damagedIds={damagedIds}
|
|
745
|
+
senderIdentities={senderIdentities}
|
|
746
|
+
busyId={busyId}
|
|
747
|
+
colors={colors}
|
|
748
|
+
t={t}
|
|
749
|
+
onRetry={handleRetry}
|
|
750
|
+
onDiscard={handleDiscard}
|
|
751
|
+
/>
|
|
752
|
+
)}
|
|
753
|
+
{result && <ResultBanner result={result} onDismiss={() => setResult(null)} colors={colors} />}
|
|
754
|
+
|
|
755
|
+
{/* The moment money arrives. A Modal, so it covers the header too. */}
|
|
756
|
+
{received && (
|
|
757
|
+
<ReceivedOverlay amount={received.amount} count={received.count} onDismiss={() => setReceived(null)} />
|
|
758
|
+
)}
|
|
759
|
+
</ScrollView>
|
|
760
|
+
)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
const styles = StyleSheet.create({
|
|
764
|
+
container: {
|
|
765
|
+
paddingHorizontal: spacing.lg,
|
|
766
|
+
paddingTop: spacing.lg
|
|
767
|
+
},
|
|
768
|
+
|
|
769
|
+
// Needs attention
|
|
770
|
+
attentionHint: {
|
|
771
|
+
...typography.footnote,
|
|
772
|
+
marginBottom: spacing.md
|
|
773
|
+
},
|
|
774
|
+
attentionError: {
|
|
775
|
+
...typography.caption1,
|
|
776
|
+
marginTop: spacing.xs
|
|
777
|
+
},
|
|
778
|
+
attentionActions: {
|
|
779
|
+
flexDirection: 'row',
|
|
780
|
+
borderTopWidth: StyleSheet.hairlineWidth,
|
|
781
|
+
marginTop: spacing.sm
|
|
782
|
+
},
|
|
783
|
+
attentionButton: {
|
|
784
|
+
flex: 1,
|
|
785
|
+
alignItems: 'center',
|
|
786
|
+
justifyContent: 'center',
|
|
787
|
+
paddingVertical: spacing.sm + 2
|
|
788
|
+
},
|
|
789
|
+
attentionButtonText: {
|
|
790
|
+
...typography.subhead,
|
|
791
|
+
fontWeight: '500'
|
|
792
|
+
},
|
|
793
|
+
|
|
794
|
+
// Your handle
|
|
795
|
+
requestedAmount: { ...typography.title2, textAlign: 'center', marginBottom: spacing.lg },
|
|
796
|
+
qrHero: {
|
|
797
|
+
alignItems: 'center',
|
|
798
|
+
marginBottom: spacing.lg
|
|
799
|
+
},
|
|
800
|
+
qrPlate: {
|
|
801
|
+
padding: spacing.lg,
|
|
802
|
+
borderRadius: radii.xl,
|
|
803
|
+
backgroundColor: '#fff'
|
|
804
|
+
},
|
|
805
|
+
identityError: { alignItems: 'center', gap: spacing.md, padding: spacing.xl },
|
|
806
|
+
identityErrorText: { ...typography.subhead, textAlign: 'center' },
|
|
807
|
+
identityRetry: {
|
|
808
|
+
minHeight: 44,
|
|
809
|
+
minWidth: 44,
|
|
810
|
+
alignItems: 'center',
|
|
811
|
+
justifyContent: 'center',
|
|
812
|
+
paddingHorizontal: spacing.lg
|
|
813
|
+
},
|
|
814
|
+
identityRetryLabel: { ...typography.subhead, fontWeight: '600' },
|
|
815
|
+
keyText: {
|
|
816
|
+
...typography.caption1,
|
|
817
|
+
fontFamily: 'monospace',
|
|
818
|
+
textAlign: 'center',
|
|
819
|
+
marginBottom: spacing.md
|
|
820
|
+
},
|
|
821
|
+
actionRow: {
|
|
822
|
+
flexDirection: 'row',
|
|
823
|
+
gap: spacing.sm,
|
|
824
|
+
marginBottom: spacing.xl
|
|
825
|
+
},
|
|
826
|
+
action: {
|
|
827
|
+
flex: 1,
|
|
828
|
+
flexDirection: 'row',
|
|
829
|
+
alignItems: 'center',
|
|
830
|
+
justifyContent: 'center',
|
|
831
|
+
gap: spacing.xs,
|
|
832
|
+
paddingVertical: spacing.sm + 2,
|
|
833
|
+
borderRadius: radii.md
|
|
834
|
+
},
|
|
835
|
+
actionText: {
|
|
836
|
+
...typography.subhead,
|
|
837
|
+
fontWeight: '500'
|
|
838
|
+
},
|
|
839
|
+
|
|
840
|
+
// Section
|
|
841
|
+
sectionTitle: {
|
|
842
|
+
...typography.title3,
|
|
843
|
+
marginBottom: spacing.md
|
|
844
|
+
},
|
|
845
|
+
|
|
846
|
+
// Incoming payments
|
|
847
|
+
paymentsList: {
|
|
848
|
+
borderRadius: radii.md,
|
|
849
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
850
|
+
overflow: 'hidden'
|
|
851
|
+
},
|
|
852
|
+
paymentRow: {
|
|
853
|
+
flexDirection: 'row',
|
|
854
|
+
alignItems: 'center',
|
|
855
|
+
paddingVertical: spacing.md,
|
|
856
|
+
paddingHorizontal: spacing.lg,
|
|
857
|
+
gap: spacing.md
|
|
858
|
+
},
|
|
859
|
+
paymentAvatar: {
|
|
860
|
+
width: 42,
|
|
861
|
+
height: 42,
|
|
862
|
+
borderRadius: 21,
|
|
863
|
+
flexShrink: 0
|
|
864
|
+
},
|
|
865
|
+
paymentAvatarPlaceholder: {
|
|
866
|
+
width: 42,
|
|
867
|
+
height: 42,
|
|
868
|
+
borderRadius: 21,
|
|
869
|
+
alignItems: 'center',
|
|
870
|
+
justifyContent: 'center',
|
|
871
|
+
flexShrink: 0
|
|
872
|
+
},
|
|
873
|
+
paymentInfo: {
|
|
874
|
+
flex: 1,
|
|
875
|
+
minWidth: 0
|
|
876
|
+
},
|
|
877
|
+
paymentSenderName: {
|
|
878
|
+
...typography.subhead,
|
|
879
|
+
fontWeight: '600',
|
|
880
|
+
marginBottom: 1
|
|
881
|
+
},
|
|
882
|
+
paymentSender: {
|
|
883
|
+
...typography.caption1,
|
|
884
|
+
fontFamily: 'monospace',
|
|
885
|
+
marginBottom: spacing.xs
|
|
886
|
+
},
|
|
887
|
+
paymentActions: {
|
|
888
|
+
alignItems: 'flex-end',
|
|
889
|
+
gap: spacing.xs,
|
|
890
|
+
flexShrink: 0
|
|
891
|
+
},
|
|
892
|
+
paymentAmount: {
|
|
893
|
+
...typography.footnote,
|
|
894
|
+
fontWeight: '700'
|
|
895
|
+
}
|
|
896
|
+
})
|