@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,920 @@
|
|
|
1
|
+
import React, { useContext, useState, useCallback, useMemo, useEffect, useRef } from 'react'
|
|
2
|
+
import { View, Text, StyleSheet, TouchableOpacity, ScrollView } from 'react-native'
|
|
3
|
+
import Sheet from './Sheet'
|
|
4
|
+
import PressableScale from './PressableScale'
|
|
5
|
+
import { useTranslation } from 'react-i18next'
|
|
6
|
+
import AmountDisplay from '../wallet/AmountDisplay'
|
|
7
|
+
import {
|
|
8
|
+
spacing,
|
|
9
|
+
radii,
|
|
10
|
+
typography,
|
|
11
|
+
useTheme,
|
|
12
|
+
WalletContext,
|
|
13
|
+
UserContext,
|
|
14
|
+
ExchangeRateContext,
|
|
15
|
+
formatAmountParts,
|
|
16
|
+
haptics
|
|
17
|
+
} from '@bsv/expo-wallet-toolbox'
|
|
18
|
+
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Dev preview — set to true to keep the BTMS spend sheet visible for design work
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
const DEV_BTMS_PREVIEW = false
|
|
23
|
+
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
26
|
+
// etc.), one of which reaches expo-font -> expo-asset -- untransformed ESM
|
|
27
|
+
// that Jest cannot parse when eagerly pulled in via the `ui` package barrel.
|
|
28
|
+
// Loaded lazily, only when actually rendering, same pattern as this
|
|
29
|
+
// package's other native-module-boundary fixes (expo-router, expo-blur).
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
type IoniconsComponent = typeof import('@expo/vector-icons').Ionicons
|
|
32
|
+
let ioniconsComponent: IoniconsComponent | undefined
|
|
33
|
+
function loadIonicons(): IoniconsComponent {
|
|
34
|
+
if (!ioniconsComponent) {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
36
|
+
ioniconsComponent = require('@expo/vector-icons').Ionicons as IoniconsComponent
|
|
37
|
+
}
|
|
38
|
+
return ioniconsComponent
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// Types
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
type PermissionKind = 'protocol' | 'basket' | 'certificate' | 'spending' | 'group' | 'btms'
|
|
46
|
+
|
|
47
|
+
interface GroupProtocol {
|
|
48
|
+
protocolID: [number, string]
|
|
49
|
+
counterparty?: string
|
|
50
|
+
description?: string
|
|
51
|
+
}
|
|
52
|
+
interface GroupBasket {
|
|
53
|
+
basket: string
|
|
54
|
+
description?: string
|
|
55
|
+
}
|
|
56
|
+
interface GroupCertificate {
|
|
57
|
+
type: string
|
|
58
|
+
verifierPublicKey?: string
|
|
59
|
+
fields?: string[]
|
|
60
|
+
description?: string
|
|
61
|
+
}
|
|
62
|
+
interface GroupSpending {
|
|
63
|
+
amount: number
|
|
64
|
+
description?: string
|
|
65
|
+
}
|
|
66
|
+
interface GroupPermissions {
|
|
67
|
+
protocolPermissions?: GroupProtocol[]
|
|
68
|
+
basketAccess?: GroupBasket[]
|
|
69
|
+
certificateAccess?: GroupCertificate[]
|
|
70
|
+
spendingAuthorization?: GroupSpending
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Common shape derived from the four existing modals. */
|
|
74
|
+
interface ActivePermission {
|
|
75
|
+
kind: PermissionKind
|
|
76
|
+
requestID: string
|
|
77
|
+
originator: string
|
|
78
|
+
title: string
|
|
79
|
+
description: string
|
|
80
|
+
/** `unit` is split out so amounts can set the figure and its unit at
|
|
81
|
+
* different sizes; rows whose value is not an amount simply omit it. */
|
|
82
|
+
details: { label: string; value: string; unit?: string }[]
|
|
83
|
+
/** Certificate-specific list of required fields. */
|
|
84
|
+
fields?: string[]
|
|
85
|
+
/** Spending-specific authorization amount (satoshis). */
|
|
86
|
+
amount?: number
|
|
87
|
+
/** Whether this is a renewal rather than a first-time request. */
|
|
88
|
+
renewal?: boolean
|
|
89
|
+
/** Group-specific sub-permissions. */
|
|
90
|
+
groupPermissions?: GroupPermissions
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
// Helpers
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Derive the human-friendly "what is being asked" description for each
|
|
99
|
+
* permission type. Technical specifics go into the expandable Details section.
|
|
100
|
+
*/
|
|
101
|
+
function deriveActive(
|
|
102
|
+
ctx: {
|
|
103
|
+
protocolRequests: any[]
|
|
104
|
+
basketRequests: any[]
|
|
105
|
+
certificateRequests: any[]
|
|
106
|
+
spendingRequests: any[]
|
|
107
|
+
btmsRequests: any[]
|
|
108
|
+
protocolAccessModalOpen: boolean
|
|
109
|
+
basketAccessModalOpen: boolean
|
|
110
|
+
certificateAccessModalOpen: boolean
|
|
111
|
+
spendingAuthorizationModalOpen: boolean
|
|
112
|
+
},
|
|
113
|
+
formatSats: (satoshis: number) => { value: string; unit: string }
|
|
114
|
+
): ActivePermission | null {
|
|
115
|
+
// Dev preview — override ctx with real captured data so the description
|
|
116
|
+
// logic below is exercised exactly as it would be in production.
|
|
117
|
+
if (DEV_BTMS_PREVIEW) {
|
|
118
|
+
ctx = {
|
|
119
|
+
...ctx,
|
|
120
|
+
btmsRequests: [
|
|
121
|
+
{
|
|
122
|
+
originator: 'btms.metanet.app',
|
|
123
|
+
message: JSON.stringify({
|
|
124
|
+
type: 'btms_spend',
|
|
125
|
+
sendAmount: 23,
|
|
126
|
+
tokenName: 'Goose',
|
|
127
|
+
assetId: '615a06abf1b0eeac9ff1f8ac438bb1de830f70144e94b9868cad55f47d08f924.0',
|
|
128
|
+
changeAmount: 17,
|
|
129
|
+
totalInputAmount: 40
|
|
130
|
+
}),
|
|
131
|
+
resolve: () => {}
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Priority: spending > certificate > protocol > basket > btms (spending is most
|
|
138
|
+
// time-sensitive). We show only one at a time — exactly like the originals.
|
|
139
|
+
|
|
140
|
+
if (ctx.spendingAuthorizationModalOpen && ctx.spendingRequests.length > 0) {
|
|
141
|
+
const r = ctx.spendingRequests[0]
|
|
142
|
+
// Map lineItems [{type, satoshis, description}] to detail rows
|
|
143
|
+
const lineItemDetails: { label: string; value: string; unit?: string }[] = (r.lineItems ?? []).map(
|
|
144
|
+
(item: { description?: string; satoshis: number }) => ({
|
|
145
|
+
label: item.description || 'Payment',
|
|
146
|
+
...formatSats(item.satoshis)
|
|
147
|
+
})
|
|
148
|
+
)
|
|
149
|
+
return {
|
|
150
|
+
kind: 'spending',
|
|
151
|
+
requestID: r.requestID,
|
|
152
|
+
originator: r.originator || 'Unknown app',
|
|
153
|
+
title: 'Spending Authorization',
|
|
154
|
+
description: r.description || 'wants to spend from your wallet',
|
|
155
|
+
amount: r.authorizationAmount,
|
|
156
|
+
renewal: r.renewal,
|
|
157
|
+
details: lineItemDetails
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (ctx.certificateAccessModalOpen && ctx.certificateRequests.length > 0) {
|
|
162
|
+
const r = ctx.certificateRequests[0]
|
|
163
|
+
const certType = r.certificate?.certType ?? r.certificateType
|
|
164
|
+
const verifier = r.certificate?.verifier ?? r.verifierPublicKey
|
|
165
|
+
const fieldsArray: string[] = r.fieldsArray ?? (r.certificate?.fields ? Object.keys(r.certificate.fields) : [])
|
|
166
|
+
|
|
167
|
+
const details: { label: string; value: string }[] = []
|
|
168
|
+
if (certType) details.push({ label: 'Certificate type', value: certType })
|
|
169
|
+
if (verifier) details.push({ label: 'Verifier', value: truncate(verifier, 20) })
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
kind: 'certificate',
|
|
173
|
+
requestID: r.requestID,
|
|
174
|
+
originator: r.originator || 'Unknown app',
|
|
175
|
+
title: r.renewal ? 'Certificate Access Renewal' : 'Certificate Access',
|
|
176
|
+
description: r.description || 'wants to access certificate information',
|
|
177
|
+
renewal: r.renewal,
|
|
178
|
+
fields: fieldsArray.length > 0 ? fieldsArray : undefined,
|
|
179
|
+
details
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (ctx.protocolAccessModalOpen && ctx.protocolRequests.length > 0) {
|
|
184
|
+
const r = ctx.protocolRequests[0]
|
|
185
|
+
return {
|
|
186
|
+
kind: 'protocol',
|
|
187
|
+
requestID: r.requestID,
|
|
188
|
+
originator: r.originator || 'Unknown app',
|
|
189
|
+
title: r.renewal ? 'Protocol Access Renewal' : 'Protocol Access',
|
|
190
|
+
description: r.description || 'wants to use a cryptographic protocol',
|
|
191
|
+
renewal: r.renewal,
|
|
192
|
+
details: [
|
|
193
|
+
{ label: 'Protocol ID', value: truncate(r.protocolID, 28) },
|
|
194
|
+
{ label: 'Security level', value: String(r.protocolSecurityLevel) }
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (ctx.basketAccessModalOpen && ctx.basketRequests.length > 0) {
|
|
200
|
+
const r = ctx.basketRequests[0]
|
|
201
|
+
return {
|
|
202
|
+
kind: 'basket',
|
|
203
|
+
requestID: r.requestID,
|
|
204
|
+
originator: r.originator || 'Unknown app',
|
|
205
|
+
title: r.renewal ? 'Basket Access Renewal' : 'Basket Access',
|
|
206
|
+
description: r.reason || 'wants to access a transaction basket',
|
|
207
|
+
renewal: r.renewal,
|
|
208
|
+
details: r.basket ? [{ label: 'Basket', value: r.basket }] : []
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// btms: driven purely by queue length — no separate modal-open flag needed
|
|
213
|
+
if (ctx.btmsRequests.length > 0) {
|
|
214
|
+
const r = ctx.btmsRequests[0]
|
|
215
|
+
let promptData: {
|
|
216
|
+
type?: string
|
|
217
|
+
action?: string
|
|
218
|
+
assetId?: string
|
|
219
|
+
sendAmount?: number
|
|
220
|
+
tokenName?: string
|
|
221
|
+
changeAmount?: number
|
|
222
|
+
totalInputAmount?: number
|
|
223
|
+
burnAmount?: number
|
|
224
|
+
burnAll?: boolean
|
|
225
|
+
} = {}
|
|
226
|
+
try {
|
|
227
|
+
promptData = JSON.parse(r.message)
|
|
228
|
+
} catch {
|
|
229
|
+
// message not valid JSON — ignore, use defaults
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Build a human-readable description using amount + token name where available
|
|
233
|
+
let description: string
|
|
234
|
+
if (promptData.type === 'btms_spend' && promptData.sendAmount != null && promptData.tokenName) {
|
|
235
|
+
description = `wants to spend ${promptData.sendAmount} ${promptData.tokenName} tokens`
|
|
236
|
+
} else if (promptData.type === 'btms_burn' && promptData.burnAmount != null && promptData.tokenName) {
|
|
237
|
+
description = `wants to burn ${promptData.burnAmount} ${promptData.tokenName} tokens`
|
|
238
|
+
} else {
|
|
239
|
+
description = `wants to ${promptData.action || 'access BTMS tokens'}`
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const details: { label: string; value: string }[] = []
|
|
243
|
+
if (promptData.tokenName) details.push({ label: 'Token', value: promptData.tokenName })
|
|
244
|
+
if (promptData.sendAmount != null) details.push({ label: 'Send amount', value: String(promptData.sendAmount) })
|
|
245
|
+
if (promptData.changeAmount != null) details.push({ label: 'Change', value: String(promptData.changeAmount) })
|
|
246
|
+
if (promptData.totalInputAmount != null)
|
|
247
|
+
details.push({ label: 'Total input', value: String(promptData.totalInputAmount) })
|
|
248
|
+
if (promptData.assetId) details.push({ label: 'Asset ID', value: truncate(promptData.assetId, 28) })
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
kind: 'btms',
|
|
252
|
+
// btms requests are resolved via advanceBtmsQueue, not permissionsManager — use a sentinel requestID
|
|
253
|
+
requestID: '',
|
|
254
|
+
originator: r.originator || 'Unknown app',
|
|
255
|
+
title: 'Token Spend Request',
|
|
256
|
+
description,
|
|
257
|
+
details
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return null
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function truncate(str: string, max: number): string {
|
|
265
|
+
if (!str) return ''
|
|
266
|
+
return str.length > max ? str.slice(0, max - 1) + '\u2026' : str
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Map permission kind to the themed accent color key. */
|
|
270
|
+
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
// Component
|
|
273
|
+
// ---------------------------------------------------------------------------
|
|
274
|
+
|
|
275
|
+
const PermissionSheet: React.FC = () => {
|
|
276
|
+
const { t } = useTranslation()
|
|
277
|
+
const { colors } = useTheme()
|
|
278
|
+
const Ionicons = loadIonicons()
|
|
279
|
+
|
|
280
|
+
const {
|
|
281
|
+
protocolRequests,
|
|
282
|
+
basketRequests,
|
|
283
|
+
certificateRequests,
|
|
284
|
+
spendingRequests,
|
|
285
|
+
btmsRequests,
|
|
286
|
+
advanceProtocolQueue,
|
|
287
|
+
advanceBasketQueue,
|
|
288
|
+
advanceCertificateQueue,
|
|
289
|
+
advanceSpendingQueue,
|
|
290
|
+
advanceBtmsQueue,
|
|
291
|
+
managers,
|
|
292
|
+
settings
|
|
293
|
+
} = useContext(WalletContext)
|
|
294
|
+
|
|
295
|
+
const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
|
|
296
|
+
const currency = settings?.currency || 'BSV'
|
|
297
|
+
const formatSats = useCallback(
|
|
298
|
+
(satoshis: number) => formatAmountParts(satoshis, currency, satoshisPerUSD, { abbreviate: true, usdToFiat }),
|
|
299
|
+
[currency, satoshisPerUSD, usdToFiat]
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
const {
|
|
303
|
+
protocolAccessModalOpen,
|
|
304
|
+
setProtocolAccessModalOpen,
|
|
305
|
+
basketAccessModalOpen,
|
|
306
|
+
setBasketAccessModalOpen,
|
|
307
|
+
certificateAccessModalOpen,
|
|
308
|
+
setCertificateAccessModalOpen,
|
|
309
|
+
spendingAuthorizationModalOpen,
|
|
310
|
+
setSpendingAuthorizationModalOpen
|
|
311
|
+
} = useContext(UserContext)
|
|
312
|
+
|
|
313
|
+
const [detailsExpanded, setDetailsExpanded] = useState(false)
|
|
314
|
+
const [granted, setGranted] = useState(false)
|
|
315
|
+
const grantTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
316
|
+
// Stores the executeGrant closure that is scheduled but not yet fired, so it
|
|
317
|
+
// can be flushed synchronously if a higher-priority request preempts.
|
|
318
|
+
const pendingGrantRef = useRef<(() => void) | null>(null)
|
|
319
|
+
|
|
320
|
+
// Clear the pending grant timer (or flush it) on unmount to prevent stale handler calls.
|
|
321
|
+
useEffect(() => {
|
|
322
|
+
return () => {
|
|
323
|
+
if (grantTimerRef.current !== null) {
|
|
324
|
+
clearTimeout(grantTimerRef.current)
|
|
325
|
+
grantTimerRef.current = null
|
|
326
|
+
}
|
|
327
|
+
if (pendingGrantRef.current !== null) {
|
|
328
|
+
pendingGrantRef.current()
|
|
329
|
+
pendingGrantRef.current = null
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}, [])
|
|
333
|
+
|
|
334
|
+
// Derive what (if anything) we should show.
|
|
335
|
+
const active = useMemo(
|
|
336
|
+
() =>
|
|
337
|
+
deriveActive(
|
|
338
|
+
{
|
|
339
|
+
protocolRequests,
|
|
340
|
+
basketRequests,
|
|
341
|
+
certificateRequests,
|
|
342
|
+
spendingRequests,
|
|
343
|
+
btmsRequests,
|
|
344
|
+
protocolAccessModalOpen,
|
|
345
|
+
basketAccessModalOpen,
|
|
346
|
+
certificateAccessModalOpen,
|
|
347
|
+
spendingAuthorizationModalOpen
|
|
348
|
+
},
|
|
349
|
+
formatSats
|
|
350
|
+
),
|
|
351
|
+
[
|
|
352
|
+
protocolRequests,
|
|
353
|
+
basketRequests,
|
|
354
|
+
certificateRequests,
|
|
355
|
+
spendingRequests,
|
|
356
|
+
btmsRequests,
|
|
357
|
+
protocolAccessModalOpen,
|
|
358
|
+
basketAccessModalOpen,
|
|
359
|
+
certificateAccessModalOpen,
|
|
360
|
+
spendingAuthorizationModalOpen,
|
|
361
|
+
formatSats
|
|
362
|
+
]
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
const visible = active !== null
|
|
366
|
+
|
|
367
|
+
// Figure and unit are set at different sizes, so they have to be formatted
|
|
368
|
+
// apart — same treatment as the wallet balance.
|
|
369
|
+
const amountParts = useMemo(
|
|
370
|
+
() =>
|
|
371
|
+
active?.kind === 'spending' && active.amount != null
|
|
372
|
+
? formatAmountParts(active.amount, currency, satoshisPerUSD, { abbreviate: true, usdToFiat })
|
|
373
|
+
: { value: '', unit: '' },
|
|
374
|
+
[active, currency, satoshisPerUSD, usdToFiat]
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
// Reset granted morph whenever a new permission request arrives.
|
|
378
|
+
// Keyed on requestID so repeated requests (even same kind) each start fresh.
|
|
379
|
+
// If a grant was pending (400 ms timer still running), flush it synchronously
|
|
380
|
+
// before switching to the new request so the user's confirmation is honoured.
|
|
381
|
+
const activeRequestID = active?.requestID
|
|
382
|
+
useEffect(() => {
|
|
383
|
+
if (grantTimerRef.current !== null) {
|
|
384
|
+
clearTimeout(grantTimerRef.current)
|
|
385
|
+
grantTimerRef.current = null
|
|
386
|
+
}
|
|
387
|
+
if (pendingGrantRef.current !== null) {
|
|
388
|
+
pendingGrantRef.current()
|
|
389
|
+
pendingGrantRef.current = null
|
|
390
|
+
}
|
|
391
|
+
setGranted(false)
|
|
392
|
+
}, [activeRequestID])
|
|
393
|
+
|
|
394
|
+
// ---- Deny ----
|
|
395
|
+
const handleDeny = useCallback(async () => {
|
|
396
|
+
if (granted) return
|
|
397
|
+
if (!active) return
|
|
398
|
+
haptics.warning()
|
|
399
|
+
if (active.kind === 'btms') {
|
|
400
|
+
// BTMS uses its own promise-based resolution — no permissionsManager.denyPermission
|
|
401
|
+
advanceBtmsQueue(false)
|
|
402
|
+
} else {
|
|
403
|
+
try {
|
|
404
|
+
await managers.permissionsManager?.denyPermission(active.requestID)
|
|
405
|
+
} catch {
|
|
406
|
+
// User denial is expected -- not an error condition
|
|
407
|
+
}
|
|
408
|
+
switch (active.kind) {
|
|
409
|
+
case 'protocol':
|
|
410
|
+
advanceProtocolQueue()
|
|
411
|
+
setProtocolAccessModalOpen(false)
|
|
412
|
+
break
|
|
413
|
+
case 'basket':
|
|
414
|
+
advanceBasketQueue()
|
|
415
|
+
setBasketAccessModalOpen(false)
|
|
416
|
+
break
|
|
417
|
+
case 'certificate':
|
|
418
|
+
advanceCertificateQueue()
|
|
419
|
+
setCertificateAccessModalOpen(false)
|
|
420
|
+
break
|
|
421
|
+
case 'spending':
|
|
422
|
+
advanceSpendingQueue()
|
|
423
|
+
setSpendingAuthorizationModalOpen(false)
|
|
424
|
+
break
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
setDetailsExpanded(false)
|
|
428
|
+
}, [
|
|
429
|
+
granted,
|
|
430
|
+
active,
|
|
431
|
+
managers.permissionsManager,
|
|
432
|
+
advanceProtocolQueue,
|
|
433
|
+
advanceBasketQueue,
|
|
434
|
+
advanceCertificateQueue,
|
|
435
|
+
advanceSpendingQueue,
|
|
436
|
+
advanceBtmsQueue,
|
|
437
|
+
setProtocolAccessModalOpen,
|
|
438
|
+
setBasketAccessModalOpen,
|
|
439
|
+
setCertificateAccessModalOpen,
|
|
440
|
+
setSpendingAuthorizationModalOpen
|
|
441
|
+
])
|
|
442
|
+
|
|
443
|
+
// ---- Grant ----
|
|
444
|
+
// Runs the actual grant logic (queue advance + modal close). Separated so
|
|
445
|
+
// the UI can show the checkmark morph for 400 ms before dismissal.
|
|
446
|
+
// Takes an explicit snapshot of the request to act on so it is safe to call
|
|
447
|
+
// from the flush-on-preempt path where `active` may have already changed.
|
|
448
|
+
const executeGrant = useCallback((request: ActivePermission) => {
|
|
449
|
+
// Clear the pending ref so flush-on-preempt guards don't double-fire.
|
|
450
|
+
pendingGrantRef.current = null
|
|
451
|
+
|
|
452
|
+
if (request.kind === 'btms') {
|
|
453
|
+
advanceBtmsQueue(true)
|
|
454
|
+
} else if (request.kind === 'spending') {
|
|
455
|
+
managers.permissionsManager?.grantPermission({
|
|
456
|
+
requestID: request.requestID,
|
|
457
|
+
ephemeral: true,
|
|
458
|
+
amount: request.amount
|
|
459
|
+
})
|
|
460
|
+
advanceSpendingQueue()
|
|
461
|
+
setSpendingAuthorizationModalOpen(false)
|
|
462
|
+
} else {
|
|
463
|
+
managers.permissionsManager?.grantPermission({
|
|
464
|
+
requestID: request.requestID
|
|
465
|
+
})
|
|
466
|
+
switch (request.kind) {
|
|
467
|
+
case 'protocol':
|
|
468
|
+
advanceProtocolQueue()
|
|
469
|
+
setProtocolAccessModalOpen(false)
|
|
470
|
+
break
|
|
471
|
+
case 'basket':
|
|
472
|
+
advanceBasketQueue()
|
|
473
|
+
setBasketAccessModalOpen(false)
|
|
474
|
+
break
|
|
475
|
+
case 'certificate':
|
|
476
|
+
advanceCertificateQueue()
|
|
477
|
+
setCertificateAccessModalOpen(false)
|
|
478
|
+
break
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
setDetailsExpanded(false)
|
|
482
|
+
// Reset granted so that consecutive BTMS requests (sharing sentinel requestID '')
|
|
483
|
+
// don't leave the sheet permanently in granted state / deadlocked.
|
|
484
|
+
setGranted(false)
|
|
485
|
+
}, [
|
|
486
|
+
managers.permissionsManager,
|
|
487
|
+
advanceProtocolQueue,
|
|
488
|
+
advanceBasketQueue,
|
|
489
|
+
advanceCertificateQueue,
|
|
490
|
+
advanceSpendingQueue,
|
|
491
|
+
advanceBtmsQueue,
|
|
492
|
+
setProtocolAccessModalOpen,
|
|
493
|
+
setBasketAccessModalOpen,
|
|
494
|
+
setCertificateAccessModalOpen,
|
|
495
|
+
setSpendingAuthorizationModalOpen
|
|
496
|
+
])
|
|
497
|
+
|
|
498
|
+
const handleGrant = useCallback(() => {
|
|
499
|
+
if (!active || granted) return
|
|
500
|
+
haptics.success()
|
|
501
|
+
setGranted(true)
|
|
502
|
+
if (grantTimerRef.current !== null) {
|
|
503
|
+
clearTimeout(grantTimerRef.current)
|
|
504
|
+
}
|
|
505
|
+
// Capture the request at grant time — executeGrant now takes it explicitly.
|
|
506
|
+
const requestSnapshot = active
|
|
507
|
+
const pendingFn = () => executeGrant(requestSnapshot)
|
|
508
|
+
pendingGrantRef.current = pendingFn
|
|
509
|
+
grantTimerRef.current = setTimeout(() => {
|
|
510
|
+
grantTimerRef.current = null
|
|
511
|
+
pendingFn()
|
|
512
|
+
}, 400)
|
|
513
|
+
}, [active, granted, executeGrant])
|
|
514
|
+
|
|
515
|
+
return (
|
|
516
|
+
<Sheet visible={visible} onClose={handleDeny} heightPercent={0.92} fitContent={active?.kind !== 'group'}>
|
|
517
|
+
{active && (
|
|
518
|
+
<View style={active.kind === 'group' ? styles.sheetInnerGroup : undefined}>
|
|
519
|
+
<View style={[styles.content, active.kind === 'group' && { flex: 1 }]}>
|
|
520
|
+
{/* -------- Originator / domain -------- */}
|
|
521
|
+
<View style={styles.originatorRow}>
|
|
522
|
+
<View
|
|
523
|
+
style={[
|
|
524
|
+
styles.faviconPlaceholder,
|
|
525
|
+
{ backgroundColor: colors.surfaceSunken, borderColor: colors.surfaceSunkenBorder }
|
|
526
|
+
]}
|
|
527
|
+
>
|
|
528
|
+
<Text style={[styles.faviconLetter, { color: colors.successStrong }]}>
|
|
529
|
+
{(active.originator[0] ?? '?').toUpperCase()}
|
|
530
|
+
</Text>
|
|
531
|
+
</View>
|
|
532
|
+
<Text style={[styles.originator, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
533
|
+
{active.originator}
|
|
534
|
+
</Text>
|
|
535
|
+
</View>
|
|
536
|
+
|
|
537
|
+
{/* -------- Renewal badge -------- */}
|
|
538
|
+
{active.renewal && (
|
|
539
|
+
<View style={[styles.renewalBadge, { backgroundColor: colors.accentSecondary + '1A' }]}>
|
|
540
|
+
<Text style={[styles.renewalText, { color: colors.accentSecondary }]}>{t('renewal')}</Text>
|
|
541
|
+
</View>
|
|
542
|
+
)}
|
|
543
|
+
|
|
544
|
+
{/* -------- Group permissions list -------- */}
|
|
545
|
+
{active.kind === 'group' && active.groupPermissions && (
|
|
546
|
+
<ScrollView style={styles.groupScroll} bounces={false}>
|
|
547
|
+
{active.groupPermissions.spendingAuthorization && (
|
|
548
|
+
<View style={[styles.groupSection, { borderColor: colors.separator }]}>
|
|
549
|
+
<Text style={[styles.groupSectionTitle, { color: colors.textSecondary }]}>
|
|
550
|
+
{t('spending_section')}
|
|
551
|
+
</Text>
|
|
552
|
+
<View style={styles.groupRow}>
|
|
553
|
+
<Text style={[styles.groupRowLabel, { color: colors.textPrimary }]}>
|
|
554
|
+
<AmountDisplay>{active.groupPermissions.spendingAuthorization.amount}</AmountDisplay>
|
|
555
|
+
</Text>
|
|
556
|
+
{active.groupPermissions.spendingAuthorization.description && (
|
|
557
|
+
<Text style={[styles.groupRowDesc, { color: colors.textSecondary }]}>
|
|
558
|
+
{active.groupPermissions.spendingAuthorization.description}
|
|
559
|
+
</Text>
|
|
560
|
+
)}
|
|
561
|
+
</View>
|
|
562
|
+
</View>
|
|
563
|
+
)}
|
|
564
|
+
{active.groupPermissions.protocolPermissions &&
|
|
565
|
+
active.groupPermissions.protocolPermissions.length > 0 && (
|
|
566
|
+
<View style={[styles.groupSection, { borderColor: colors.separator }]}>
|
|
567
|
+
<Text style={[styles.groupSectionTitle, { color: colors.textSecondary }]}>
|
|
568
|
+
{t('protocols_section')}
|
|
569
|
+
</Text>
|
|
570
|
+
{active.groupPermissions.protocolPermissions.map((p, i) => (
|
|
571
|
+
<View key={i} style={styles.groupRow}>
|
|
572
|
+
<Text style={[styles.groupRowLabel, { color: colors.textPrimary }]}>{p.protocolID[1]}</Text>
|
|
573
|
+
{p.description && (
|
|
574
|
+
<Text style={[styles.groupRowDesc, { color: colors.textSecondary }]}>{p.description}</Text>
|
|
575
|
+
)}
|
|
576
|
+
</View>
|
|
577
|
+
))}
|
|
578
|
+
</View>
|
|
579
|
+
)}
|
|
580
|
+
{active.groupPermissions.basketAccess && active.groupPermissions.basketAccess.length > 0 && (
|
|
581
|
+
<View style={[styles.groupSection, { borderColor: colors.separator }]}>
|
|
582
|
+
<Text style={[styles.groupSectionTitle, { color: colors.textSecondary }]}>
|
|
583
|
+
{t('baskets_section')}
|
|
584
|
+
</Text>
|
|
585
|
+
{active.groupPermissions.basketAccess.map((b, i) => (
|
|
586
|
+
<View key={i} style={styles.groupRow}>
|
|
587
|
+
<Text style={[styles.groupRowLabel, { color: colors.textPrimary }]}>{b.basket}</Text>
|
|
588
|
+
{b.description && (
|
|
589
|
+
<Text style={[styles.groupRowDesc, { color: colors.textSecondary }]}>{b.description}</Text>
|
|
590
|
+
)}
|
|
591
|
+
</View>
|
|
592
|
+
))}
|
|
593
|
+
</View>
|
|
594
|
+
)}
|
|
595
|
+
{active.groupPermissions.certificateAccess && active.groupPermissions.certificateAccess.length > 0 && (
|
|
596
|
+
<View style={[styles.groupSection, { borderColor: colors.separator }]}>
|
|
597
|
+
<Text style={[styles.groupSectionTitle, { color: colors.textSecondary }]}>
|
|
598
|
+
{t('certificates_section')}
|
|
599
|
+
</Text>
|
|
600
|
+
{active.groupPermissions.certificateAccess.map((c, i) => (
|
|
601
|
+
<View key={i} style={styles.groupRow}>
|
|
602
|
+
<Text style={[styles.groupRowLabel, { color: colors.textPrimary }]}>{c.type}</Text>
|
|
603
|
+
{c.description && (
|
|
604
|
+
<Text style={[styles.groupRowDesc, { color: colors.textSecondary }]}>{c.description}</Text>
|
|
605
|
+
)}
|
|
606
|
+
{c.fields && c.fields.length > 0 && (
|
|
607
|
+
<Text style={[styles.groupRowDesc, { color: colors.textTertiary }]}>
|
|
608
|
+
Fields: {c.fields.join(', ')}
|
|
609
|
+
</Text>
|
|
610
|
+
)}
|
|
611
|
+
</View>
|
|
612
|
+
))}
|
|
613
|
+
</View>
|
|
614
|
+
)}
|
|
615
|
+
</ScrollView>
|
|
616
|
+
)}
|
|
617
|
+
|
|
618
|
+
{/* -------- Expandable details (scrollable if tall) -------- */}
|
|
619
|
+
{active.kind !== 'group' && (active.details.length > 0 || (active.fields && active.fields.length > 0)) && (
|
|
620
|
+
<View style={styles.detailsSection}>
|
|
621
|
+
<TouchableOpacity
|
|
622
|
+
onPress={() => setDetailsExpanded(prev => !prev)}
|
|
623
|
+
style={styles.detailsToggle}
|
|
624
|
+
activeOpacity={0.7}
|
|
625
|
+
>
|
|
626
|
+
<Text style={[styles.detailsToggleText, { color: colors.textSecondary }]}>
|
|
627
|
+
{detailsExpanded ? t('hide_details') : t('details')}
|
|
628
|
+
</Text>
|
|
629
|
+
<Ionicons
|
|
630
|
+
name={detailsExpanded ? 'chevron-up' : 'chevron-down'}
|
|
631
|
+
size={12}
|
|
632
|
+
color={colors.textSecondary}
|
|
633
|
+
style={styles.chevron}
|
|
634
|
+
/>
|
|
635
|
+
</TouchableOpacity>
|
|
636
|
+
|
|
637
|
+
{detailsExpanded && (
|
|
638
|
+
<ScrollView
|
|
639
|
+
style={[
|
|
640
|
+
styles.detailsCard,
|
|
641
|
+
{ backgroundColor: colors.surfaceRowExpanded, borderColor: colors.surfaceRaisedBorder }
|
|
642
|
+
]}
|
|
643
|
+
bounces={false}
|
|
644
|
+
>
|
|
645
|
+
{active.details.map((d, i) => (
|
|
646
|
+
<View key={i} style={styles.detailRow}>
|
|
647
|
+
<Text style={[styles.detailLabel, { color: colors.textSecondary }]}>{d.label}</Text>
|
|
648
|
+
<Text style={[styles.detailValue, { color: colors.textPrimary }]} numberOfLines={1}>
|
|
649
|
+
{d.value}
|
|
650
|
+
{d.unit ? (
|
|
651
|
+
<Text style={[styles.detailUnit, { color: colors.textSecondary }]}> {d.unit}</Text>
|
|
652
|
+
) : null}
|
|
653
|
+
</Text>
|
|
654
|
+
</View>
|
|
655
|
+
))}
|
|
656
|
+
{active.fields && active.fields.length > 0 && (
|
|
657
|
+
<>
|
|
658
|
+
<Text style={[styles.detailLabel, { color: colors.textSecondary, marginTop: spacing.sm }]}>
|
|
659
|
+
{t('requested_fields')}
|
|
660
|
+
</Text>
|
|
661
|
+
{active.fields.map((f, i) => (
|
|
662
|
+
<Text key={i} style={[styles.fieldItem, { color: colors.textPrimary }]}>
|
|
663
|
+
{'\u2022'} {f}
|
|
664
|
+
</Text>
|
|
665
|
+
))}
|
|
666
|
+
</>
|
|
667
|
+
)}
|
|
668
|
+
</ScrollView>
|
|
669
|
+
)}
|
|
670
|
+
</View>
|
|
671
|
+
)}
|
|
672
|
+
|
|
673
|
+
{/* -------- The ask, then the figure. The sentence is the quiet
|
|
674
|
+
half: it says what for, the amount says how much. -------- */}
|
|
675
|
+
<View style={styles.askBlock}>
|
|
676
|
+
<Text style={[styles.description, { color: colors.textSecondary }]}>{active.description}</Text>
|
|
677
|
+
|
|
678
|
+
{active.kind === 'spending' && active.amount != null && (
|
|
679
|
+
<Text style={[styles.amountValue, { color: colors.textPrimary }]}>
|
|
680
|
+
{amountParts.value}
|
|
681
|
+
{amountParts.unit ? (
|
|
682
|
+
<Text style={[styles.amountUnit, { color: colors.textSecondary }]}> {amountParts.unit}</Text>
|
|
683
|
+
) : null}
|
|
684
|
+
</Text>
|
|
685
|
+
)}
|
|
686
|
+
</View>
|
|
687
|
+
</View>
|
|
688
|
+
|
|
689
|
+
{/* -------- Action buttons — pinned at bottom, never move -------- */}
|
|
690
|
+
<View style={styles.buttonRow}>
|
|
691
|
+
<PressableScale
|
|
692
|
+
style={[
|
|
693
|
+
styles.buttonDeny,
|
|
694
|
+
{ backgroundColor: colors.surfaceRaised, borderColor: colors.surfaceRaisedBorder }
|
|
695
|
+
]}
|
|
696
|
+
onPress={handleDeny}
|
|
697
|
+
disabled={granted}
|
|
698
|
+
>
|
|
699
|
+
<Text style={[styles.buttonDenyText, { color: colors.textPrimary }]}>{t('reject')}</Text>
|
|
700
|
+
</PressableScale>
|
|
701
|
+
|
|
702
|
+
{/* Accent-filled and the only shadowed element in the drawer, so the
|
|
703
|
+
confirming action is unmistakable without being coloured green —
|
|
704
|
+
chroma here would read as "safe" before the user has read it. */}
|
|
705
|
+
<PressableScale
|
|
706
|
+
style={[styles.buttonAllow, { backgroundColor: colors.accent }]}
|
|
707
|
+
onPress={handleGrant}
|
|
708
|
+
disabled={granted}
|
|
709
|
+
>
|
|
710
|
+
{granted
|
|
711
|
+
? <Ionicons name="checkmark" size={22} color={colors.textOnAccent} />
|
|
712
|
+
: <Text style={[styles.buttonAllowText, { color: colors.textOnAccent }]}>{t('authorize')}</Text>
|
|
713
|
+
}
|
|
714
|
+
</PressableScale>
|
|
715
|
+
</View>
|
|
716
|
+
</View>
|
|
717
|
+
)}
|
|
718
|
+
</Sheet>
|
|
719
|
+
)
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// ---------------------------------------------------------------------------
|
|
723
|
+
// Styles
|
|
724
|
+
// ---------------------------------------------------------------------------
|
|
725
|
+
|
|
726
|
+
const styles = StyleSheet.create({
|
|
727
|
+
sheetInnerGroup: {
|
|
728
|
+
flex: 1,
|
|
729
|
+
justifyContent: 'flex-end'
|
|
730
|
+
},
|
|
731
|
+
content: {
|
|
732
|
+
paddingHorizontal: spacing.xl,
|
|
733
|
+
paddingTop: spacing.lg,
|
|
734
|
+
paddingBottom: spacing.sm
|
|
735
|
+
},
|
|
736
|
+
|
|
737
|
+
// Originator
|
|
738
|
+
originatorRow: {
|
|
739
|
+
flexDirection: 'row',
|
|
740
|
+
alignItems: 'center',
|
|
741
|
+
marginBottom: spacing.lg
|
|
742
|
+
},
|
|
743
|
+
faviconPlaceholder: {
|
|
744
|
+
width: 40,
|
|
745
|
+
height: 40,
|
|
746
|
+
borderRadius: 12,
|
|
747
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
748
|
+
alignItems: 'center',
|
|
749
|
+
justifyContent: 'center',
|
|
750
|
+
marginRight: spacing.md
|
|
751
|
+
},
|
|
752
|
+
faviconLetter: {
|
|
753
|
+
fontSize: 17,
|
|
754
|
+
fontWeight: '700'
|
|
755
|
+
},
|
|
756
|
+
originator: {
|
|
757
|
+
fontSize: 15,
|
|
758
|
+
fontWeight: '600',
|
|
759
|
+
letterSpacing: -0.1,
|
|
760
|
+
flex: 1
|
|
761
|
+
},
|
|
762
|
+
|
|
763
|
+
// Renewal badge
|
|
764
|
+
renewalBadge: {
|
|
765
|
+
alignSelf: 'flex-start',
|
|
766
|
+
paddingHorizontal: spacing.sm,
|
|
767
|
+
paddingVertical: spacing.xs,
|
|
768
|
+
borderRadius: radii.sm,
|
|
769
|
+
marginBottom: spacing.md
|
|
770
|
+
},
|
|
771
|
+
renewalText: {
|
|
772
|
+
...typography.caption1,
|
|
773
|
+
fontWeight: '600'
|
|
774
|
+
},
|
|
775
|
+
|
|
776
|
+
// The ask
|
|
777
|
+
askBlock: {
|
|
778
|
+
alignItems: 'center',
|
|
779
|
+
paddingTop: spacing.xxl
|
|
780
|
+
},
|
|
781
|
+
description: {
|
|
782
|
+
fontSize: 13.5,
|
|
783
|
+
lineHeight: 18,
|
|
784
|
+
textAlign: 'center'
|
|
785
|
+
},
|
|
786
|
+
amountValue: {
|
|
787
|
+
fontSize: 42,
|
|
788
|
+
fontWeight: '700',
|
|
789
|
+
lineHeight: 44,
|
|
790
|
+
letterSpacing: -1.1,
|
|
791
|
+
marginTop: 9,
|
|
792
|
+
fontVariant: ['tabular-nums']
|
|
793
|
+
},
|
|
794
|
+
amountUnit: {
|
|
795
|
+
fontSize: 19,
|
|
796
|
+
fontWeight: '600',
|
|
797
|
+
letterSpacing: 0
|
|
798
|
+
},
|
|
799
|
+
|
|
800
|
+
// Details
|
|
801
|
+
detailsSection: {
|
|
802
|
+
marginBottom: 0
|
|
803
|
+
},
|
|
804
|
+
detailsToggle: {
|
|
805
|
+
flexDirection: 'row',
|
|
806
|
+
alignItems: 'center',
|
|
807
|
+
alignSelf: 'flex-start',
|
|
808
|
+
paddingVertical: spacing.xs
|
|
809
|
+
},
|
|
810
|
+
detailsToggleText: {
|
|
811
|
+
fontSize: 12.5,
|
|
812
|
+
fontWeight: '600'
|
|
813
|
+
},
|
|
814
|
+
chevron: {
|
|
815
|
+
marginLeft: 6
|
|
816
|
+
},
|
|
817
|
+
detailsCard: {
|
|
818
|
+
borderRadius: 14,
|
|
819
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
820
|
+
paddingHorizontal: spacing.lg,
|
|
821
|
+
paddingVertical: 5,
|
|
822
|
+
marginTop: spacing.md,
|
|
823
|
+
maxHeight: 180
|
|
824
|
+
},
|
|
825
|
+
detailRow: {
|
|
826
|
+
flexDirection: 'row',
|
|
827
|
+
justifyContent: 'space-between',
|
|
828
|
+
alignItems: 'center',
|
|
829
|
+
gap: spacing.md,
|
|
830
|
+
paddingVertical: 10
|
|
831
|
+
},
|
|
832
|
+
detailLabel: {
|
|
833
|
+
fontSize: 13,
|
|
834
|
+
flexShrink: 1
|
|
835
|
+
},
|
|
836
|
+
detailValue: {
|
|
837
|
+
fontSize: 13.5,
|
|
838
|
+
fontWeight: '600',
|
|
839
|
+
textAlign: 'right',
|
|
840
|
+
fontVariant: ['tabular-nums']
|
|
841
|
+
},
|
|
842
|
+
detailUnit: {
|
|
843
|
+
fontSize: 11.5,
|
|
844
|
+
fontWeight: '500'
|
|
845
|
+
},
|
|
846
|
+
fieldItem: {
|
|
847
|
+
...typography.footnote,
|
|
848
|
+
marginLeft: spacing.md,
|
|
849
|
+
marginTop: spacing.xs
|
|
850
|
+
},
|
|
851
|
+
|
|
852
|
+
// Group permissions
|
|
853
|
+
groupScroll: {
|
|
854
|
+
flex: 1
|
|
855
|
+
},
|
|
856
|
+
groupSection: {
|
|
857
|
+
borderTopWidth: StyleSheet.hairlineWidth,
|
|
858
|
+
paddingTop: spacing.sm,
|
|
859
|
+
marginBottom: spacing.sm
|
|
860
|
+
},
|
|
861
|
+
groupSectionTitle: {
|
|
862
|
+
...typography.caption1,
|
|
863
|
+
fontWeight: '600',
|
|
864
|
+
textTransform: 'uppercase',
|
|
865
|
+
letterSpacing: 0.5,
|
|
866
|
+
marginBottom: spacing.xs
|
|
867
|
+
},
|
|
868
|
+
groupRow: {
|
|
869
|
+
paddingVertical: spacing.xs
|
|
870
|
+
},
|
|
871
|
+
groupRowLabel: {
|
|
872
|
+
...typography.subhead,
|
|
873
|
+
fontWeight: '500'
|
|
874
|
+
},
|
|
875
|
+
groupRowDesc: {
|
|
876
|
+
...typography.footnote,
|
|
877
|
+
marginTop: 1
|
|
878
|
+
},
|
|
879
|
+
|
|
880
|
+
// Buttons — pinned outside ScrollView so they never move. No rule above them:
|
|
881
|
+
// the whitespace under the amount already separates reading from acting, and
|
|
882
|
+
// a hairline there boxed the figure in.
|
|
883
|
+
buttonRow: {
|
|
884
|
+
flexDirection: 'row',
|
|
885
|
+
gap: 10,
|
|
886
|
+
paddingHorizontal: spacing.xl,
|
|
887
|
+
paddingTop: 22,
|
|
888
|
+
paddingBottom: 40
|
|
889
|
+
},
|
|
890
|
+
buttonDeny: {
|
|
891
|
+
flex: 1,
|
|
892
|
+
height: 52,
|
|
893
|
+
borderRadius: 14,
|
|
894
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
895
|
+
alignItems: 'center',
|
|
896
|
+
justifyContent: 'center'
|
|
897
|
+
},
|
|
898
|
+
buttonDenyText: {
|
|
899
|
+
fontSize: 15,
|
|
900
|
+
fontWeight: '600'
|
|
901
|
+
},
|
|
902
|
+
buttonAllow: {
|
|
903
|
+
flex: 1,
|
|
904
|
+
height: 52,
|
|
905
|
+
borderRadius: 14,
|
|
906
|
+
alignItems: 'center',
|
|
907
|
+
justifyContent: 'center',
|
|
908
|
+
shadowColor: '#000',
|
|
909
|
+
shadowOpacity: 0.28,
|
|
910
|
+
shadowRadius: 14,
|
|
911
|
+
shadowOffset: { width: 0, height: 8 },
|
|
912
|
+
elevation: 4
|
|
913
|
+
},
|
|
914
|
+
buttonAllowText: {
|
|
915
|
+
fontSize: 15,
|
|
916
|
+
fontWeight: '700'
|
|
917
|
+
}
|
|
918
|
+
})
|
|
919
|
+
|
|
920
|
+
export default PermissionSheet
|