@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,438 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
|
+
import { View, Text, TouchableOpacity, StyleSheet, Modal, ScrollView } from 'react-native'
|
|
3
|
+
import { observer } from 'mobx-react-lite'
|
|
4
|
+
import { WalletClient } from '@bsv/sdk'
|
|
5
|
+
import type { WalletProtocol } from '@bsv/sdk'
|
|
6
|
+
import * as SecureStore from 'expo-secure-store'
|
|
7
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
8
|
+
import { useTranslation } from 'react-i18next'
|
|
9
|
+
import { GroupedSection } from '../components/ui/GroupedList'
|
|
10
|
+
import { ListRow } from '../components/ui/ListRow'
|
|
11
|
+
import { showToast } from '../components/ui/Toast'
|
|
12
|
+
import QRScanner from '../components/QRScanner'
|
|
13
|
+
import {
|
|
14
|
+
useTheme,
|
|
15
|
+
spacing,
|
|
16
|
+
radii,
|
|
17
|
+
typography,
|
|
18
|
+
useWallet,
|
|
19
|
+
guardVaultAccess,
|
|
20
|
+
capWalletArgs,
|
|
21
|
+
ADMIN_ORIGINATOR,
|
|
22
|
+
connectionStore,
|
|
23
|
+
type Connection,
|
|
24
|
+
useWalletConnection,
|
|
25
|
+
lastSeqKey
|
|
26
|
+
} from '@bsv/expo-wallet-toolbox'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* expo-clipboard ships an untransformed ESM build (its Clipboard.js imports
|
|
30
|
+
* from expo-modules-core with a bare `import` statement) that Jest cannot
|
|
31
|
+
* parse when eagerly pulled in via the `ui` package barrel. Required lazily,
|
|
32
|
+
* only when a handler actually touches the clipboard, same pattern as this
|
|
33
|
+
* package's other native-module-boundary fixes (@react-native-clipboard,
|
|
34
|
+
* expo-router, expo-blur).
|
|
35
|
+
*/
|
|
36
|
+
type ExpoClipboardModule = typeof import('expo-clipboard')
|
|
37
|
+
let expoClipboardModule: ExpoClipboardModule | undefined
|
|
38
|
+
function loadExpoClipboard(): ExpoClipboardModule {
|
|
39
|
+
if (!expoClipboardModule) {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
41
|
+
expoClipboardModule = require('expo-clipboard') as ExpoClipboardModule
|
|
42
|
+
}
|
|
43
|
+
return expoClipboardModule
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
48
|
+
* etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
|
|
49
|
+
* that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
|
|
50
|
+
* Ionicons is loaded lazily, only when actually rendering, same pattern as
|
|
51
|
+
* this package's other native-module-boundary fixes (expo-router, expo-blur).
|
|
52
|
+
*/
|
|
53
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
54
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
55
|
+
function loadIonicons(): IoniconsComponent {
|
|
56
|
+
if (!ioniconsComponent) {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
58
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
59
|
+
}
|
|
60
|
+
return ioniconsComponent
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* expo-router is required lazily rather than imported at module scope: this
|
|
65
|
+
* file is barrel-exported from the package's `ui` entry point, and a static
|
|
66
|
+
* top-level `import` of expo-router pulls in its own untransformed JSX
|
|
67
|
+
* source (Navigator.js etc.), which Jest cannot parse for any consumer of the
|
|
68
|
+
* barrel, even one that never navigates. Same pattern as this package's other
|
|
69
|
+
* lazy expo-router loads (WalletHomeScreen.tsx, VaultScreen.tsx, etc.).
|
|
70
|
+
*/
|
|
71
|
+
type ExpoRouterModule = typeof import('expo-router')
|
|
72
|
+
let expoRouterMod: ExpoRouterModule | undefined
|
|
73
|
+
function loadExpoRouter(): ExpoRouterModule {
|
|
74
|
+
if (!expoRouterMod) {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
76
|
+
expoRouterMod = require('expo-router') as ExpoRouterModule
|
|
77
|
+
}
|
|
78
|
+
return expoRouterMod
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface PairingParams {
|
|
82
|
+
[key: string]: string // required by Expo Router's UnknownInputParams
|
|
83
|
+
topic: string
|
|
84
|
+
backendIdentityKey: string
|
|
85
|
+
protocolID: string
|
|
86
|
+
origin: string
|
|
87
|
+
expiry: string
|
|
88
|
+
sig: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
type ParseResult = { params: PairingParams; error: null } | { params: null; error: string }
|
|
92
|
+
|
|
93
|
+
function parsePairingUri(raw: string): ParseResult {
|
|
94
|
+
try {
|
|
95
|
+
const url = new URL(raw)
|
|
96
|
+
if (url.protocol !== 'bsv-wallet:') return { params: null, error: 'Not a bsv-wallet:// URI' }
|
|
97
|
+
|
|
98
|
+
const g = (k: string) => url.searchParams.get(k) ?? ''
|
|
99
|
+
const topic = g('topic')
|
|
100
|
+
const backendIdentityKey = g('backendIdentityKey')
|
|
101
|
+
const protocolID = g('protocolID')
|
|
102
|
+
const origin = g('origin')
|
|
103
|
+
const expiry = g('expiry')
|
|
104
|
+
const sig = g('sig')
|
|
105
|
+
|
|
106
|
+
if (!topic || !backendIdentityKey || !protocolID || !origin || !expiry) {
|
|
107
|
+
return { params: null, error: 'QR code is missing required fields' }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (Date.now() / 1000 > Number(expiry)) {
|
|
111
|
+
return { params: null, error: 'This QR code has expired — ask the desktop to generate a new one' }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let originUrl: URL
|
|
115
|
+
try {
|
|
116
|
+
originUrl = new URL(origin)
|
|
117
|
+
} catch {
|
|
118
|
+
return { params: null, error: 'Origin URL is not valid' }
|
|
119
|
+
}
|
|
120
|
+
if (originUrl.protocol !== 'http:' && originUrl.protocol !== 'https:') {
|
|
121
|
+
return { params: null, error: 'Origin must use http:// or https://' }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!/^0[23][0-9a-fA-F]{64}$/.test(backendIdentityKey)) {
|
|
125
|
+
return { params: null, error: 'Backend identity key is not a valid public key' }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let proto: unknown
|
|
129
|
+
try {
|
|
130
|
+
proto = JSON.parse(protocolID)
|
|
131
|
+
} catch {
|
|
132
|
+
return { params: null, error: 'protocolID is not valid JSON' }
|
|
133
|
+
}
|
|
134
|
+
if (!Array.isArray(proto) || proto.length !== 2 || typeof proto[0] !== 'number' || typeof proto[1] !== 'string') {
|
|
135
|
+
return { params: null, error: 'protocolID must be a [number, string] tuple' }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return { params: { topic, backendIdentityKey, protocolID, origin, expiry, sig }, error: null }
|
|
139
|
+
} catch {
|
|
140
|
+
return { params: null, error: 'Could not read QR code' }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function domainFromOrigin(origin: string): string {
|
|
145
|
+
try {
|
|
146
|
+
return new URL(origin).hostname
|
|
147
|
+
} catch {
|
|
148
|
+
return origin
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
153
|
+
const { colors } = useTheme()
|
|
154
|
+
const { t } = useTranslation()
|
|
155
|
+
const { managers } = useWallet()
|
|
156
|
+
const { connect, reconnect } = useWalletConnection()
|
|
157
|
+
const insets = useSafeAreaInsets()
|
|
158
|
+
const [scanning, setScanning] = useState(false)
|
|
159
|
+
const { router, useLocalSearchParams } = loadExpoRouter()
|
|
160
|
+
const Ionicons = loadIonicons()
|
|
161
|
+
const deepLinkParams = useLocalSearchParams<PairingParams>()
|
|
162
|
+
|
|
163
|
+
// Auto-connect when navigated here with deep link pairing params
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (!deepLinkParams.topic || !managers.permissionsManager) return
|
|
166
|
+
const uri = `bsv-wallet://pair?topic=${deepLinkParams.topic}&backendIdentityKey=${deepLinkParams.backendIdentityKey}&protocolID=${encodeURIComponent(deepLinkParams.protocolID)}&origin=${encodeURIComponent(deepLinkParams.origin)}&expiry=${deepLinkParams.expiry}&sig=${deepLinkParams.sig}`
|
|
167
|
+
handleScan(uri)
|
|
168
|
+
}, [deepLinkParams.topic, managers.permissionsManager]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
169
|
+
|
|
170
|
+
async function handleScan(data: string) {
|
|
171
|
+
setScanning(false)
|
|
172
|
+
const result = parsePairingUri(data)
|
|
173
|
+
if (!result.params) {
|
|
174
|
+
showToast(`${t('invalid_qr_code')}: ${result.error}`, { type: 'error' })
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
if (!managers.permissionsManager) {
|
|
178
|
+
showToast(`${t('wallet_not_ready')}: ${t('please_log_in_first')}`, { type: 'error' })
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
const originator = domainFromOrigin(result.params.origin)
|
|
182
|
+
const wallet = new WalletClient(capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR)), originator)
|
|
183
|
+
try {
|
|
184
|
+
await connect(result.params, wallet)
|
|
185
|
+
} catch (err) {
|
|
186
|
+
showToast(`${t('connection_failed')}: ${err instanceof Error ? err.message : t('unknown_error')}`, { type: 'error' })
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function handleDisconnect(conn: Connection) {
|
|
191
|
+
connectionStore.setStatus(conn.sessionId, 'disconnected')
|
|
192
|
+
|
|
193
|
+
if (!managers.permissionsManager) return
|
|
194
|
+
try {
|
|
195
|
+
const protocolID = JSON.parse(conn.protocolID) as WalletProtocol
|
|
196
|
+
const wallet = new WalletClient(capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR)), domainFromOrigin(conn.origin))
|
|
197
|
+
const ws = new WebSocket(`${conn.relay}/ws?topic=${conn.sessionId}&role=mobile`)
|
|
198
|
+
|
|
199
|
+
ws.onopen = async () => {
|
|
200
|
+
try {
|
|
201
|
+
const storedSeq = await SecureStore.getItemAsync(lastSeqKey(conn.sessionId))
|
|
202
|
+
const seq = storedSeq ? Number(storedSeq) + 1 : 1
|
|
203
|
+
const payload = JSON.stringify({
|
|
204
|
+
id: crypto.randomUUID(),
|
|
205
|
+
seq,
|
|
206
|
+
method: 'session_revoke',
|
|
207
|
+
params: {}
|
|
208
|
+
})
|
|
209
|
+
const plaintext = Array.from(new TextEncoder().encode(payload))
|
|
210
|
+
const { ciphertext } = await wallet.encrypt({
|
|
211
|
+
protocolID,
|
|
212
|
+
keyID: conn.sessionId,
|
|
213
|
+
counterparty: conn.backendIdentityKey,
|
|
214
|
+
plaintext
|
|
215
|
+
})
|
|
216
|
+
ws.send(
|
|
217
|
+
JSON.stringify({
|
|
218
|
+
topic: conn.sessionId,
|
|
219
|
+
ciphertext: Buffer.from(ciphertext).toString('base64url')
|
|
220
|
+
})
|
|
221
|
+
)
|
|
222
|
+
} finally {
|
|
223
|
+
ws.close()
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
ws.onerror = () => ws.close()
|
|
227
|
+
} catch (e) {
|
|
228
|
+
console.warn('[connections] session_revoke failed:', e)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async function handleReconnect(conn: Connection) {
|
|
233
|
+
if (!managers.permissionsManager) return
|
|
234
|
+
const wallet = new WalletClient(capWalletArgs(guardVaultAccess(managers.permissionsManager as any, ADMIN_ORIGINATOR)), domainFromOrigin(conn.origin))
|
|
235
|
+
try {
|
|
236
|
+
await reconnect(conn, wallet)
|
|
237
|
+
} catch (err) {
|
|
238
|
+
showToast(`${t('reconnect_failed')}: ${err instanceof Error ? err.message : t('unknown_error')}`, { type: 'error' })
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const active = connectionStore.connections.filter(c => c.status === 'active')
|
|
243
|
+
const inactive = connectionStore.connections.filter(c => c.status !== 'active')
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
<View style={[styles.container, { backgroundColor: colors.backgroundSecondary, paddingTop: insets.top }]}>
|
|
247
|
+
{/* Header — matches settings/payments pattern */}
|
|
248
|
+
<View style={[styles.header, { borderBottomColor: colors.separator }]}>
|
|
249
|
+
<TouchableOpacity onPress={() => router.back()} style={styles.headerButton}>
|
|
250
|
+
<Ionicons name="chevron-back" size={24} color={colors.textSecondary} />
|
|
251
|
+
</TouchableOpacity>
|
|
252
|
+
<Text style={[styles.headerTitle, { color: colors.textPrimary }]}>{t('connections')}</Text>
|
|
253
|
+
<View style={styles.headerButton} />
|
|
254
|
+
</View>
|
|
255
|
+
|
|
256
|
+
<ScrollView contentContainerStyle={styles.scrollContent}>
|
|
257
|
+
{connectionStore.connections.length === 0 ? (
|
|
258
|
+
<View style={styles.empty}>
|
|
259
|
+
<Ionicons name="wifi-outline" size={48} color={colors.textSecondary} style={{ marginBottom: spacing.md }} />
|
|
260
|
+
<Text style={[styles.emptyTitle, { color: colors.textPrimary }]}>{t('no_connections_yet')}</Text>
|
|
261
|
+
<Text style={[styles.emptySubtitle, { color: colors.textSecondary }]}>
|
|
262
|
+
{t('no_connections_subtitle')}
|
|
263
|
+
</Text>
|
|
264
|
+
</View>
|
|
265
|
+
) : (
|
|
266
|
+
<>
|
|
267
|
+
{active.length > 0 && (
|
|
268
|
+
<GroupedSection header={t('connections_active')}>
|
|
269
|
+
{active.map((item, idx) => (
|
|
270
|
+
<ListRow
|
|
271
|
+
key={item.sessionId}
|
|
272
|
+
label={domainFromOrigin(item.origin)}
|
|
273
|
+
value={new Date(item.connectedAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })}
|
|
274
|
+
icon="wifi-outline"
|
|
275
|
+
iconColor={colors.success}
|
|
276
|
+
showChevron={false}
|
|
277
|
+
isLast={idx === active.length - 1}
|
|
278
|
+
trailing={
|
|
279
|
+
<TouchableOpacity
|
|
280
|
+
onPress={() => void handleDisconnect(item)}
|
|
281
|
+
style={styles.trailingAction}
|
|
282
|
+
activeOpacity={0.6}
|
|
283
|
+
>
|
|
284
|
+
<Text style={[styles.trailingActionText, { color: colors.error }]}>{t('disconnect')}</Text>
|
|
285
|
+
</TouchableOpacity>
|
|
286
|
+
}
|
|
287
|
+
/>
|
|
288
|
+
))}
|
|
289
|
+
</GroupedSection>
|
|
290
|
+
)}
|
|
291
|
+
{inactive.length > 0 && (
|
|
292
|
+
<GroupedSection header={t('connections_disconnected')}>
|
|
293
|
+
{inactive.map((item, idx) => (
|
|
294
|
+
<ListRow
|
|
295
|
+
key={item.sessionId}
|
|
296
|
+
label={domainFromOrigin(item.origin)}
|
|
297
|
+
icon="wifi-outline"
|
|
298
|
+
iconColor={colors.textTertiary}
|
|
299
|
+
showChevron={false}
|
|
300
|
+
isLast={idx === inactive.length - 1}
|
|
301
|
+
trailing={
|
|
302
|
+
<View style={styles.trailingRow}>
|
|
303
|
+
<TouchableOpacity
|
|
304
|
+
onPress={() => void handleReconnect(item)}
|
|
305
|
+
style={styles.trailingAction}
|
|
306
|
+
activeOpacity={0.6}
|
|
307
|
+
>
|
|
308
|
+
<Text style={[styles.trailingActionText, { color: colors.info }]}>{t('reconnect')}</Text>
|
|
309
|
+
</TouchableOpacity>
|
|
310
|
+
<TouchableOpacity
|
|
311
|
+
onPress={() => {
|
|
312
|
+
void SecureStore.deleteItemAsync(lastSeqKey(item.sessionId))
|
|
313
|
+
connectionStore.remove(item.sessionId)
|
|
314
|
+
}}
|
|
315
|
+
style={[styles.trailingAction, { marginLeft: spacing.md }]}
|
|
316
|
+
activeOpacity={0.6}
|
|
317
|
+
>
|
|
318
|
+
<Ionicons name="trash-outline" size={16} color={colors.textTertiary} />
|
|
319
|
+
</TouchableOpacity>
|
|
320
|
+
</View>
|
|
321
|
+
}
|
|
322
|
+
/>
|
|
323
|
+
))}
|
|
324
|
+
</GroupedSection>
|
|
325
|
+
)}
|
|
326
|
+
</>
|
|
327
|
+
)}
|
|
328
|
+
|
|
329
|
+
</ScrollView>
|
|
330
|
+
|
|
331
|
+
<View style={[styles.footer, { borderTopColor: colors.separator }]}>
|
|
332
|
+
<TouchableOpacity style={[styles.scanBtn, { backgroundColor: colors.accent }]} onPress={() => setScanning(true)}>
|
|
333
|
+
<Ionicons name="qr-code-outline" size={20} color={colors.textOnAccent} style={{ marginRight: spacing.sm }} />
|
|
334
|
+
<Text style={[styles.scanBtnText, { color: colors.textOnAccent }]}>{t('scan_qr_code')}</Text>
|
|
335
|
+
</TouchableOpacity>
|
|
336
|
+
<TouchableOpacity
|
|
337
|
+
style={[styles.pasteBtn, { borderColor: colors.separator }]}
|
|
338
|
+
onPress={async () => {
|
|
339
|
+
const text = await loadExpoClipboard().getStringAsync()
|
|
340
|
+
if (text) handleScan(text.trim())
|
|
341
|
+
}}
|
|
342
|
+
>
|
|
343
|
+
<Ionicons name="clipboard-outline" size={18} color={colors.textSecondary} style={{ marginRight: spacing.xs }} />
|
|
344
|
+
<Text style={[styles.pasteBtnText, { color: colors.textSecondary }]}>{t('paste_uri')}</Text>
|
|
345
|
+
</TouchableOpacity>
|
|
346
|
+
</View>
|
|
347
|
+
|
|
348
|
+
<Modal visible={scanning} animationType="slide" onRequestClose={() => setScanning(false)}>
|
|
349
|
+
<QRScanner onScan={handleScan} onClose={() => setScanning(false)} hintText={t('scan_wallet_qr_hint')} />
|
|
350
|
+
</Modal>
|
|
351
|
+
</View>
|
|
352
|
+
)
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
// ── Styles ─────────────────────────────────────────────────────────────────────
|
|
356
|
+
|
|
357
|
+
const styles = StyleSheet.create({
|
|
358
|
+
container: {
|
|
359
|
+
flex: 1
|
|
360
|
+
},
|
|
361
|
+
header: {
|
|
362
|
+
flexDirection: 'row',
|
|
363
|
+
alignItems: 'center',
|
|
364
|
+
justifyContent: 'space-between',
|
|
365
|
+
paddingHorizontal: spacing.sm,
|
|
366
|
+
paddingVertical: spacing.md,
|
|
367
|
+
borderBottomWidth: StyleSheet.hairlineWidth
|
|
368
|
+
},
|
|
369
|
+
headerButton: {
|
|
370
|
+
width: 44,
|
|
371
|
+
height: 44,
|
|
372
|
+
alignItems: 'center',
|
|
373
|
+
justifyContent: 'center'
|
|
374
|
+
},
|
|
375
|
+
headerTitle: {
|
|
376
|
+
...typography.headline,
|
|
377
|
+
fontWeight: '600'
|
|
378
|
+
},
|
|
379
|
+
scrollContent: {
|
|
380
|
+
paddingTop: spacing.xxl,
|
|
381
|
+
paddingBottom: spacing.xxxl,
|
|
382
|
+
flexGrow: 1
|
|
383
|
+
},
|
|
384
|
+
empty: {
|
|
385
|
+
alignItems: 'center',
|
|
386
|
+
paddingTop: 80,
|
|
387
|
+
paddingHorizontal: spacing.xxxl
|
|
388
|
+
},
|
|
389
|
+
emptyTitle: {
|
|
390
|
+
...typography.headline,
|
|
391
|
+
marginBottom: spacing.sm
|
|
392
|
+
},
|
|
393
|
+
emptySubtitle: {
|
|
394
|
+
...typography.subhead,
|
|
395
|
+
textAlign: 'center',
|
|
396
|
+
lineHeight: 20
|
|
397
|
+
},
|
|
398
|
+
trailingRow: {
|
|
399
|
+
flexDirection: 'row',
|
|
400
|
+
alignItems: 'center'
|
|
401
|
+
},
|
|
402
|
+
trailingAction: {
|
|
403
|
+
paddingVertical: spacing.xs,
|
|
404
|
+
paddingHorizontal: spacing.sm
|
|
405
|
+
},
|
|
406
|
+
trailingActionText: {
|
|
407
|
+
...typography.footnote,
|
|
408
|
+
fontWeight: '600'
|
|
409
|
+
},
|
|
410
|
+
footer: {
|
|
411
|
+
padding: spacing.xl,
|
|
412
|
+
borderTopWidth: StyleSheet.hairlineWidth
|
|
413
|
+
},
|
|
414
|
+
scanBtn: {
|
|
415
|
+
flexDirection: 'row',
|
|
416
|
+
alignItems: 'center',
|
|
417
|
+
justifyContent: 'center',
|
|
418
|
+
paddingVertical: spacing.lg,
|
|
419
|
+
borderRadius: radii.lg
|
|
420
|
+
},
|
|
421
|
+
scanBtnText: {
|
|
422
|
+
...typography.callout,
|
|
423
|
+
fontWeight: '600'
|
|
424
|
+
},
|
|
425
|
+
pasteBtn: {
|
|
426
|
+
flexDirection: 'row',
|
|
427
|
+
alignItems: 'center',
|
|
428
|
+
justifyContent: 'center',
|
|
429
|
+
paddingVertical: spacing.md,
|
|
430
|
+
marginTop: spacing.sm,
|
|
431
|
+
borderRadius: radii.lg,
|
|
432
|
+
borderWidth: StyleSheet.hairlineWidth
|
|
433
|
+
},
|
|
434
|
+
pasteBtnText: {
|
|
435
|
+
...typography.footnote,
|
|
436
|
+
fontWeight: '500'
|
|
437
|
+
}
|
|
438
|
+
})
|