@bsv/expo-wallet-toolbox 0.11.7 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -0
- package/core/config.tsx +1 -1
- package/core/context/WalletContext.tsx +171 -19
- package/core/i18n/translations.tsx +120 -12
- package/core/index.ts +2 -0
- package/core/pay/beefRepair.ts +8 -3
- package/core/pay/rails/address.ts +43 -3
- package/core/pay/rails/handle.ts +1 -1
- package/core/pay/sweeper.ts +39 -4
- package/core/push/events.ts +142 -0
- package/core/push/pushAdvisory.ts +33 -0
- package/core/push/registration.ts +53 -0
- package/core/push/types.ts +31 -0
- package/core/toolboxConfig.ts +24 -1
- package/package.json +1 -1
- package/ui/components/pay/HandleReceive.tsx +141 -16
- package/ui/components/pay/NotificationAdvisoryModal.tsx +124 -0
- package/ui/components/ui/PermissionSheet.tsx +53 -8
- package/ui/index.ts +1 -0
- package/ui/screens/PayScreen.tsx +53 -0
- package/ui/screens/SettingsScreen.tsx +72 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,111 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Payment push notifications
|
|
6
|
+
|
|
7
|
+
A payment to the user's MessageBox handle can now wake the phone, through a
|
|
8
|
+
push adapter the host supplies. The package never imports a push SDK (its
|
|
9
|
+
native module would have to be linked by every host that merely installs the
|
|
10
|
+
package); the host wraps whichever one it ships and passes it in:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
configureToolbox({ push: myPushAdapter })
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- New exports: `getPushAdapter` and the types `PushAdapter`, `PushPermission`
|
|
17
|
+
and `PushOpenedEvent`. A host that passes no adapter keeps every push
|
|
18
|
+
feature off (no registration, no advisory, no Settings row), and
|
|
19
|
+
`getPushAdapter()` returns `undefined` rather than throwing when the toolbox
|
|
20
|
+
is unconfigured.
|
|
21
|
+
- Members added to `PushAdapter` later will be optional, so an adapter written
|
|
22
|
+
against this version keeps compiling and working.
|
|
23
|
+
- Device registration: once the wallet is up, and again on foreground and on
|
|
24
|
+
token refresh, the FCM token is registered (`registerDevice`) with the
|
|
25
|
+
MessageBox host the inbox reads, bound to the identity the inbox reads for.
|
|
26
|
+
A cached marker of the last registered host, identity and token makes the
|
|
27
|
+
common case no network call at all. Nothing happens without an adapter or
|
|
28
|
+
without notification permission, and a failure is logged (the error message
|
|
29
|
+
only, never the token or identity key) and contained. A sync that hangs is
|
|
30
|
+
given up on after 30 s so it cannot block the ones after it.
|
|
31
|
+
- A tap on a payment notification opens Activity and runs an inbox pass. A push
|
|
32
|
+
that arrives while the app is in the foreground only triggers an inbox pass,
|
|
33
|
+
so the existing credit toast shows and no system banner does. A push never
|
|
34
|
+
credits anything itself.
|
|
35
|
+
|
|
36
|
+
### Notification advisory and Settings row
|
|
37
|
+
|
|
38
|
+
- The first time the user picks Share remote link on Get paid, an in-app modal
|
|
39
|
+
(`NotificationAdvisoryModal`, new export) explains the OS prompt that
|
|
40
|
+
follows: it lets BSV Wallet tell them about a payment while the app is in the
|
|
41
|
+
background. Continue asks the OS; Not now does not. It is shown once, and
|
|
42
|
+
only while the permission is still undetermined.
|
|
43
|
+
- Settings has a Payment notifications row, On or Off. Pressing it turns
|
|
44
|
+
notifications on (the OS prompt) or, once the OS has been asked, opens the OS
|
|
45
|
+
settings. A denial is not forgotten when the screen re-reads the permission.
|
|
46
|
+
The advisory and the row appear only when the host passed a push adapter.
|
|
47
|
+
|
|
48
|
+
### Receive screen: live payments
|
|
49
|
+
|
|
50
|
+
The Receive (handle) screen now listens for payments on a live MessageBox
|
|
51
|
+
connection and keeps polling as a fallback.
|
|
52
|
+
|
|
53
|
+
- While the connection is up, the satoshi inbox is re-read every 15 s and
|
|
54
|
+
immediately when a live payment arrives; the token inbox stays on its 5 s
|
|
55
|
+
tick. Without a live connection both poll every 5 s as before.
|
|
56
|
+
- Each listening session uses a fresh client. A `MessageBoxClient` remembers
|
|
57
|
+
the rooms it joined across a disconnect, so reusing one would reconnect the
|
|
58
|
+
socket without re-joining the room and slow the poll for nothing.
|
|
59
|
+
- The listener runs only while the screen is focused and the app is active.
|
|
60
|
+
|
|
61
|
+
### Address payments: faster sweep
|
|
62
|
+
|
|
63
|
+
An address payment reaches no one, so there is nothing to push; the wallet
|
|
64
|
+
finds it by looking.
|
|
65
|
+
|
|
66
|
+
- The address sweep now runs every 5 s instead of every 30 s (foreground
|
|
67
|
+
only, as before).
|
|
68
|
+
- `WocConfig` gains an optional `apiKey`, and the new `wocRequestInit(woc)`
|
|
69
|
+
export turns it into the `woc-api-key` request header. The header is sent
|
|
70
|
+
only when a caller sets `apiKey`; the key is never logged. `wocConfigFor`
|
|
71
|
+
does not set it, so the address sweep, BEEF repair, recovery and the other
|
|
72
|
+
address-rail calls stay on WhatsOnChain's unauthenticated limit: the host's
|
|
73
|
+
app-wide key is shared with broadcast, and a 5 s poll across every install
|
|
74
|
+
would drain it.
|
|
75
|
+
- HTTP 429 from WhatsOnChain throws the new `WocRateLimited` error (exported
|
|
76
|
+
from the address rail), which stops the pass and makes the sweep sit out the
|
|
77
|
+
next 30 s instead of retrying on every tick.
|
|
78
|
+
- New sweeper exports: `SWEEP_BACKOFF_TICKS`, `consumeBackoff` and
|
|
79
|
+
`backoffAfterSweepError`.
|
|
80
|
+
|
|
81
|
+
### Translations
|
|
82
|
+
|
|
83
|
+
New strings in all 12 locales: the advisory title, body and buttons, and the
|
|
84
|
+
Settings row and its On and Off values.
|
|
85
|
+
|
|
86
|
+
### Default MessageBox host
|
|
87
|
+
|
|
88
|
+
- The default MessageBox host is now https://messagebox.bsvblockchain.tech
|
|
89
|
+
(was gmb.bsvblockchain.tech). A saved custom host is unchanged.
|
|
90
|
+
|
|
91
|
+
## 0.11.8
|
|
92
|
+
|
|
93
|
+
### Grouped permission prompt
|
|
94
|
+
|
|
95
|
+
A site whose `manifest.json` declares `metanet.groupPermissions` is now asked
|
|
96
|
+
for them in one drawer when it connects (`waitForAuthentication`), the same
|
|
97
|
+
sheet and buttons as a spending prompt, listing the spending allowance and each
|
|
98
|
+
protocol, basket and certificate the site says it needs.
|
|
99
|
+
|
|
100
|
+
- Authorize grants exactly that set (`grantGroupedPermission`), minting its
|
|
101
|
+
permission tokens, and the site carries on without further prompts for them.
|
|
102
|
+
- Reject, or swiping the drawer away, grants nothing and lets the site carry
|
|
103
|
+
on; each permission is then prompted for on its own when used. A hard deny
|
|
104
|
+
would make the site's `waitForAuthentication` throw.
|
|
105
|
+
- The request holds the origin's permission lock until answered, which is why
|
|
106
|
+
0.11.7 turned grouped seeking off; it is back on now that it is answered.
|
|
107
|
+
- A spending prompt already open is shown first.
|
|
108
|
+
|
|
3
109
|
## 0.11.7
|
|
4
110
|
|
|
5
111
|
### Sites with a grouped-permission manifest no longer hang
|
package/core/config.tsx
CHANGED
|
@@ -19,7 +19,7 @@ export function toWalletChain(chain: AppChain): WalletChain {
|
|
|
19
19
|
|
|
20
20
|
export const DEFAULT_WAB_URL = 'noWAB'
|
|
21
21
|
export const DEFAULT_STORAGE_URL = 'local'
|
|
22
|
-
export const DEFAULT_MESSAGEBOX_URL = 'https://
|
|
22
|
+
export const DEFAULT_MESSAGEBOX_URL = 'https://messagebox.bsvblockchain.tech'
|
|
23
23
|
/**
|
|
24
24
|
* Encrypted wallet-backup log.
|
|
25
25
|
*
|
|
@@ -136,7 +136,7 @@ const MANDALA_OUTPOINT_LIST_MAX_PAGES = 1000
|
|
|
136
136
|
|
|
137
137
|
import type { AppChain } from '../config'
|
|
138
138
|
import { DEFAULT_STORAGE_URL, DEFAULT_CHAIN, ADMIN_ORIGINATOR, toWalletChain } from '../config'
|
|
139
|
-
import { getBackupUrl, getMandalaEndpoints } from '../toolboxConfig'
|
|
139
|
+
import { getBackupUrl, getMandalaEndpoints, getPushAdapter } from '../toolboxConfig'
|
|
140
140
|
import {
|
|
141
141
|
DEFAULT_AUTO_APPROVE_THRESHOLD,
|
|
142
142
|
AUTO_APPROVE_COOLDOWN_MS,
|
|
@@ -211,6 +211,8 @@ import { replayPendingAborts, verifyDeclinedAborts } from '../localpay/pendingAb
|
|
|
211
211
|
import { TaskSendOffline } from '../monitor/TaskSendOffline'
|
|
212
212
|
import { MONITOR_STALL_MS, MonitorSupervisor } from '../monitor/MonitorSupervisor'
|
|
213
213
|
import { TaskCreditInbox } from '../monitor/TaskCreditInbox'
|
|
214
|
+
import { attachPushHandlers, coalesceRuns } from '../push/events'
|
|
215
|
+
import { syncPushRegistration } from '../push/registration'
|
|
214
216
|
import { drainUnsentEntries, TaskDrainOutbox } from '../monitor/TaskDrainOutbox'
|
|
215
217
|
import { TaskBackupPush } from '../monitor/TaskBackupPush'
|
|
216
218
|
import { pushOnce } from '../backup/push'
|
|
@@ -245,7 +247,14 @@ import {
|
|
|
245
247
|
import { getOutboxEntries, pruneExpiredSent, unsentEntries } from '../peerpay/outbox'
|
|
246
248
|
import { MAX_HEX_RESPONSE_CHARS, wocConfigFor } from '../pay/rails/address'
|
|
247
249
|
import { PeerPayClient } from '@bsv/message-box-client'
|
|
248
|
-
import {
|
|
250
|
+
import {
|
|
251
|
+
SWEEP_INTERVAL_MS,
|
|
252
|
+
backoffAfterSweepError,
|
|
253
|
+
consumeBackoff,
|
|
254
|
+
runSweep,
|
|
255
|
+
shouldSweepNow,
|
|
256
|
+
sweptTotal
|
|
257
|
+
} from '../pay/sweeper'
|
|
249
258
|
import { formatAmount } from '../amountFormatHelpers'
|
|
250
259
|
import { useTranslation } from 'react-i18next'
|
|
251
260
|
import { HEADER_CHECKPOINTS } from '../headers/checkpoints'
|
|
@@ -368,12 +377,14 @@ export interface WalletContextValue {
|
|
|
368
377
|
certificateRequests: CertificateAccessRequest[]
|
|
369
378
|
protocolRequests: ProtocolAccessRequest[]
|
|
370
379
|
spendingRequests: SpendingRequest[]
|
|
380
|
+
groupRequests: GroupPermissionRequest[]
|
|
371
381
|
btmsRequests: BtmsRequest[]
|
|
372
382
|
mandalaRequests: MandalaRequest[]
|
|
373
383
|
advanceBasketQueue: () => void
|
|
374
384
|
advanceCertificateQueue: () => void
|
|
375
385
|
advanceProtocolQueue: () => void
|
|
376
386
|
advanceSpendingQueue: () => void
|
|
387
|
+
advanceGroupQueue: () => void
|
|
377
388
|
advanceBtmsQueue: (approved: boolean) => void
|
|
378
389
|
advanceMandalaQueue: (approved: boolean) => void
|
|
379
390
|
finalizeConfig: (wabConfig: WABConfig) => boolean
|
|
@@ -477,12 +488,14 @@ export const WalletContext = createContext<WalletContextValue>({
|
|
|
477
488
|
certificateRequests: [],
|
|
478
489
|
protocolRequests: [],
|
|
479
490
|
spendingRequests: [],
|
|
491
|
+
groupRequests: [],
|
|
480
492
|
btmsRequests: [],
|
|
481
493
|
mandalaRequests: [],
|
|
482
494
|
advanceBasketQueue: () => {},
|
|
483
495
|
advanceCertificateQueue: () => {},
|
|
484
496
|
advanceProtocolQueue: () => {},
|
|
485
497
|
advanceSpendingQueue: () => {},
|
|
498
|
+
advanceGroupQueue: () => {},
|
|
486
499
|
advanceBtmsQueue: () => {},
|
|
487
500
|
advanceMandalaQueue: () => {},
|
|
488
501
|
finalizeConfig: () => false,
|
|
@@ -585,6 +598,19 @@ type SpendingRequest = {
|
|
|
585
598
|
lineItems: any[]
|
|
586
599
|
}
|
|
587
600
|
|
|
601
|
+
/** A site's grouped permission request, from its manifest's
|
|
602
|
+
* `metanet.groupPermissions` (WalletPermissionsManager.waitForAuthentication). */
|
|
603
|
+
export type GroupPermissionRequest = {
|
|
604
|
+
requestID: string
|
|
605
|
+
originator: string
|
|
606
|
+
permissions: {
|
|
607
|
+
spendingAuthorization?: { amount: number; description?: string }
|
|
608
|
+
protocolPermissions?: Array<{ protocolID: [number, string]; counterparty?: string; description?: string }>
|
|
609
|
+
basketAccess?: Array<{ basket: string; description?: string }>
|
|
610
|
+
certificateAccess?: Array<{ type: string; verifierPublicKey?: string; fields?: string[]; description?: string }>
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
588
614
|
type BtmsRequest = {
|
|
589
615
|
/** The originator (dApp domain) requesting BTMS token access */
|
|
590
616
|
originator: string
|
|
@@ -689,6 +715,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
689
715
|
const appStateRef = useRef<AppStateStatus>(AppState.currentState)
|
|
690
716
|
const monitorSupervisorRef = useRef<MonitorSupervisor | null>(null)
|
|
691
717
|
const monitorRef = useRef<Monitor | null>(null)
|
|
718
|
+
// Push notifications. `pushDetachRef` removes the adapter listeners the
|
|
719
|
+
// current build attached; `pushSyncRef` is that build's registration sync,
|
|
720
|
+
// which the foreground handler calls so a permission granted from OS Settings
|
|
721
|
+
// registers on return. Both are cleared wherever the monitor is torn down.
|
|
722
|
+
const pushDetachRef = useRef<(() => void) | undefined>(undefined)
|
|
723
|
+
const pushSyncRef = useRef<(() => Promise<void>) | undefined>(undefined)
|
|
692
724
|
// The offline-first chain tracker and the header store it wraps. Populated
|
|
693
725
|
// in buildWallet (tracker synchronously, store once the background open
|
|
694
726
|
// finishes); the reconnect top-up effect below reuses both rather than
|
|
@@ -918,6 +950,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
918
950
|
...focusOpts,
|
|
919
951
|
openModal: setSpendingAuthorizationModalOpen
|
|
920
952
|
})
|
|
953
|
+
// Shown by the permission sheet whenever it has a head, like BTMS/Mandala.
|
|
954
|
+
const groupQueue = usePermissionQueue<GroupPermissionRequest>(focusOpts)
|
|
921
955
|
const btmsQueue = usePermissionQueue<BtmsRequest>(focusOpts)
|
|
922
956
|
|
|
923
957
|
const advanceBtmsQueue = useCallback(
|
|
@@ -1101,6 +1135,15 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1101
1135
|
[spendingQueue.enqueue]
|
|
1102
1136
|
)
|
|
1103
1137
|
|
|
1138
|
+
const groupedPermissionCallback = useCallback(
|
|
1139
|
+
async (args: GroupPermissionRequest): Promise<void> => {
|
|
1140
|
+
const { requestID, originator, permissions } = args ?? ({} as GroupPermissionRequest)
|
|
1141
|
+
if (!requestID || !permissions) return
|
|
1142
|
+
groupQueue.enqueue({ requestID, originator, permissions })
|
|
1143
|
+
},
|
|
1144
|
+
[groupQueue.enqueue]
|
|
1145
|
+
)
|
|
1146
|
+
|
|
1104
1147
|
// ---- WAB + network + storage configuration ----
|
|
1105
1148
|
const [selectedMethod, setSelectedMethod] = useState<string>('')
|
|
1106
1149
|
const [selectedNetwork, setSelectedNetwork] = useState<AppChain>(DEFAULT_CHAIN)
|
|
@@ -1708,14 +1751,11 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1708
1751
|
seekCertificateDisclosurePermissions: false,
|
|
1709
1752
|
seekCertificateRelinquishmentPermissions: false,
|
|
1710
1753
|
seekCertificateListingPermissions: false,
|
|
1711
|
-
//
|
|
1712
|
-
//
|
|
1713
|
-
//
|
|
1714
|
-
//
|
|
1715
|
-
|
|
1716
|
-
// appeared either (fast.brc.dev). Every request still gets its own
|
|
1717
|
-
// prompt. Turn this back on together with a grouped prompt.
|
|
1718
|
-
seekGroupedPermission: false,
|
|
1754
|
+
// A site whose manifest declares metanet.groupPermissions is asked
|
|
1755
|
+
// for them all in one sheet during waitForAuthentication. The request
|
|
1756
|
+
// holds that origin's permission lock until answered, so it MUST be
|
|
1757
|
+
// handled (onGroupedPermissionRequested, below) or the site hangs.
|
|
1758
|
+
seekGroupedPermission: true,
|
|
1719
1759
|
seekPermissionsForIdentityKeyRevelation: false,
|
|
1720
1760
|
seekPermissionsForIdentityResolution: false,
|
|
1721
1761
|
seekPermissionsForKeyLinkageRevelation: false,
|
|
@@ -1738,6 +1778,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1738
1778
|
if (spendingAuthorizationCallback) {
|
|
1739
1779
|
permissionsManager.bindCallback('onSpendingAuthorizationRequested', spendingAuthorizationCallback)
|
|
1740
1780
|
}
|
|
1781
|
+
permissionsManager.bindCallback('onGroupedPermissionRequested', groupedPermissionCallback as any)
|
|
1741
1782
|
if (certificateAccessCallback) {
|
|
1742
1783
|
permissionsManager.bindCallback('onCertificateAccessRequested', certificateAccessCallback)
|
|
1743
1784
|
}
|
|
@@ -1873,6 +1914,18 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1873
1914
|
monitorOptions.saveLastSSEEventId = (id: string) => phoneStorage!.setKeyValue(SSE_KEY, id)
|
|
1874
1915
|
}
|
|
1875
1916
|
const monitor = await createWalletMonitor(monitorOptions)
|
|
1917
|
+
// The MessageBox host this wallet talks to, or undefined when the
|
|
1918
|
+
// user turned MessageBox off. One definition for the CreditInbox task
|
|
1919
|
+
// and the push registration below, so a device token is always
|
|
1920
|
+
// registered on exactly the host the inbox reads.
|
|
1921
|
+
const readMessageBoxHost = async (): Promise<string | undefined> => {
|
|
1922
|
+
const saved = await AsyncStorage.getItem(MESSAGE_BOX_URL_KEY)
|
|
1923
|
+
return saved === NO_MESSAGE_BOX
|
|
1924
|
+
? undefined
|
|
1925
|
+
: !saved || saved === LEGACY_MESSAGE_BOX_URL
|
|
1926
|
+
? DEFAULT_MESSAGE_BOX_URL
|
|
1927
|
+
: saved
|
|
1928
|
+
}
|
|
1876
1929
|
|
|
1877
1930
|
// Release held offline transactions when signal returns — registered
|
|
1878
1931
|
// BEFORE the defaults, and the order matters. Monitor.runOnce collects
|
|
@@ -1964,13 +2017,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1964
2017
|
new TaskCreditInbox(
|
|
1965
2018
|
monitor,
|
|
1966
2019
|
async () => {
|
|
1967
|
-
const
|
|
1968
|
-
const messageBoxUrl =
|
|
1969
|
-
saved === NO_MESSAGE_BOX
|
|
1970
|
-
? undefined
|
|
1971
|
-
: !saved || saved === LEGACY_MESSAGE_BOX_URL
|
|
1972
|
-
? DEFAULT_MESSAGE_BOX_URL
|
|
1973
|
-
: saved
|
|
2020
|
+
const messageBoxUrl = await readMessageBoxHost()
|
|
1974
2021
|
if (!messageBoxUrl) return { accepted: 0, attention: 0, pending: false }
|
|
1975
2022
|
let client: PeerPayClient
|
|
1976
2023
|
try {
|
|
@@ -2270,6 +2317,67 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
2270
2317
|
return null
|
|
2271
2318
|
}
|
|
2272
2319
|
monitorRef.current = monitor
|
|
2320
|
+
|
|
2321
|
+
// Push: a payment for this identity wakes the phone (the MessageBox
|
|
2322
|
+
// host sends the FCM message), and a push only ever means "look at
|
|
2323
|
+
// the inbox now" — the credit, sound and toast come from the
|
|
2324
|
+
// CreditInbox pass registered above, so nothing is shown or credited
|
|
2325
|
+
// twice.
|
|
2326
|
+
//
|
|
2327
|
+
// Wired HERE, after the supersession check and with no await between
|
|
2328
|
+
// the two, on purpose. A build that was replaced mid-flight never
|
|
2329
|
+
// reaches this line, so it can neither register a token against a
|
|
2330
|
+
// wallet being torn down nor detach the listeners a newer build wired.
|
|
2331
|
+
// Every teardown clears the refs before it yields, so a build that is
|
|
2332
|
+
// superseded after this line is cleaned up by whoever superseded it.
|
|
2333
|
+
//
|
|
2334
|
+
// Registration reads the same host as the CreditInbox task and derives
|
|
2335
|
+
// the identity key and the client's wallet from the SAME
|
|
2336
|
+
// permissionsManager, so the token is bound to the identity the inbox
|
|
2337
|
+
// is actually reading. Startup, token refresh and foreground can all
|
|
2338
|
+
// fire it at once; coalesceRuns never runs two at a time and folds an
|
|
2339
|
+
// overlapping burst into one rerun. Push is an enhancement: nothing
|
|
2340
|
+
// here may throw into the build.
|
|
2341
|
+
if (phoneStorage) {
|
|
2342
|
+
const syncPush = coalesceRuns(async () => {
|
|
2343
|
+
const adapter = getPushAdapter()
|
|
2344
|
+
if (!adapter) return
|
|
2345
|
+
const host = await readMessageBoxHost()
|
|
2346
|
+
let identityKey: string
|
|
2347
|
+
try {
|
|
2348
|
+
identityKey = (await permissionsManager.getPublicKey({ identityKey: true }, adminOriginator)).publicKey
|
|
2349
|
+
} catch (e) {
|
|
2350
|
+
console.warn(
|
|
2351
|
+
`[push] could not read the identity key; skipping registration: ${e instanceof Error ? e.message : String(e)}`
|
|
2352
|
+
)
|
|
2353
|
+
return
|
|
2354
|
+
}
|
|
2355
|
+
const result = await syncPushRegistration({
|
|
2356
|
+
adapter,
|
|
2357
|
+
host,
|
|
2358
|
+
identityKey,
|
|
2359
|
+
makeClient: h =>
|
|
2360
|
+
new MessageBoxClient({
|
|
2361
|
+
host: h,
|
|
2362
|
+
walletClient: permissionsManager as never,
|
|
2363
|
+
originator: adminOriginator
|
|
2364
|
+
})
|
|
2365
|
+
})
|
|
2366
|
+
if (result === 'failed') console.warn('[push] device registration with the MessageBox host failed')
|
|
2367
|
+
})
|
|
2368
|
+
pushSyncRef.current = syncPush
|
|
2369
|
+
void syncPush()
|
|
2370
|
+
const pushAdapter = getPushAdapter()
|
|
2371
|
+
pushDetachRef.current?.()
|
|
2372
|
+
pushDetachRef.current = pushAdapter
|
|
2373
|
+
? attachPushHandlers({
|
|
2374
|
+
adapter: pushAdapter,
|
|
2375
|
+
requestInboxPass: () => TaskCreditInbox.requestNow(),
|
|
2376
|
+
openActivity: () => loadExpoRouter().router.push('/transactions'),
|
|
2377
|
+
onTokenRefresh: () => void syncPush()
|
|
2378
|
+
})
|
|
2379
|
+
: undefined
|
|
2380
|
+
}
|
|
2273
2381
|
InteractionManager.runAfterInteractions(() => {
|
|
2274
2382
|
// Re-check identity: stopTasks() before startTasks() is a no-op
|
|
2275
2383
|
// (it only clears a flag the loop hasn't set yet), so a rebuild/
|
|
@@ -2364,6 +2472,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
2364
2472
|
basketAccessCallback,
|
|
2365
2473
|
spendingAuthorizationCallback,
|
|
2366
2474
|
certificateAccessCallback,
|
|
2475
|
+
groupedPermissionCallback,
|
|
2367
2476
|
btmsPromptHandler,
|
|
2368
2477
|
mandalaPromptHandler,
|
|
2369
2478
|
runHeaderSync,
|
|
@@ -2557,6 +2666,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
2557
2666
|
vaultStore.clearScope()
|
|
2558
2667
|
vaultCeremony.cancel()
|
|
2559
2668
|
|
|
2669
|
+
// Push listeners and the registration sync belong to the wallet being
|
|
2670
|
+
// torn down; nothing may fire them against it from here on.
|
|
2671
|
+
pushDetachRef.current?.()
|
|
2672
|
+
pushDetachRef.current = undefined
|
|
2673
|
+
pushSyncRef.current = undefined
|
|
2674
|
+
|
|
2560
2675
|
// Stop any running monitor and let its current pass drain before the
|
|
2561
2676
|
// storage teardown below closes the connection under it.
|
|
2562
2677
|
{
|
|
@@ -2623,6 +2738,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
2623
2738
|
vaultStore.clearScope()
|
|
2624
2739
|
vaultCeremony.cancel()
|
|
2625
2740
|
|
|
2741
|
+
// Push listeners and the registration sync belong to the wallet being
|
|
2742
|
+
// torn down; nothing may fire them against it from here on.
|
|
2743
|
+
pushDetachRef.current?.()
|
|
2744
|
+
pushDetachRef.current = undefined
|
|
2745
|
+
pushSyncRef.current = undefined
|
|
2746
|
+
|
|
2626
2747
|
// Stop any running monitor and let its current pass drain before the
|
|
2627
2748
|
// storage teardown below closes the connection under it.
|
|
2628
2749
|
{
|
|
@@ -2834,9 +2955,16 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
2834
2955
|
// the first NetInfo event would delay the common case.
|
|
2835
2956
|
let online = true
|
|
2836
2957
|
const woc = wocConfigFor(selectedNetwork)
|
|
2958
|
+
// Ticks still to sit out after a WhatsOnChain 429. Every tick spends one,
|
|
2959
|
+
// including the app-active and back-online ones, so none of them can reach
|
|
2960
|
+
// WhatsOnChain while the backoff is pending.
|
|
2961
|
+
let backoffTicks = 0
|
|
2837
2962
|
|
|
2838
2963
|
const tick = async () => {
|
|
2839
2964
|
if (cancelled) return
|
|
2965
|
+
const backoff = consumeBackoff(backoffTicks)
|
|
2966
|
+
backoffTicks = backoff.remaining
|
|
2967
|
+
if (backoff.skip) return
|
|
2840
2968
|
if (
|
|
2841
2969
|
!shouldSweepNow({
|
|
2842
2970
|
walletBuilt: true,
|
|
@@ -2868,8 +2996,10 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
2868
2996
|
type: 'success'
|
|
2869
2997
|
})
|
|
2870
2998
|
}
|
|
2871
|
-
} catch {
|
|
2872
|
-
// Best-effort. Every address stays watched and the next tick retries
|
|
2999
|
+
} catch (error) {
|
|
3000
|
+
// Best-effort. Every address stays watched and the next tick retries —
|
|
3001
|
+
// except after a rate limit, which sits out SWEEP_BACKOFF_TICKS first.
|
|
3002
|
+
backoffTicks = backoffAfterSweepError(error, backoffTicks)
|
|
2873
3003
|
} finally {
|
|
2874
3004
|
addressSweepingRef.current = false
|
|
2875
3005
|
}
|
|
@@ -3005,6 +3135,9 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3005
3135
|
if (TaskSendOffline.hasPending) TaskSendOffline.requestNow()
|
|
3006
3136
|
TaskCreditInbox.requestNow()
|
|
3007
3137
|
if (TaskDrainOutbox.hasPending) TaskDrainOutbox.requestNow()
|
|
3138
|
+
// A notification permission granted from OS Settings, or a token the OS
|
|
3139
|
+
// rotated while away, registers on return. No-ops when already current.
|
|
3140
|
+
void pushSyncRef.current?.()
|
|
3008
3141
|
}
|
|
3009
3142
|
|
|
3010
3143
|
appStateRef.current = nextAppState
|
|
@@ -3048,6 +3181,9 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3048
3181
|
try {
|
|
3049
3182
|
monitorRef.current?.stopTasks()
|
|
3050
3183
|
} catch {}
|
|
3184
|
+
pushDetachRef.current?.()
|
|
3185
|
+
pushDetachRef.current = undefined
|
|
3186
|
+
pushSyncRef.current = undefined
|
|
3051
3187
|
if (ledgerBumpTimerRef.current) {
|
|
3052
3188
|
clearTimeout(ledgerBumpTimerRef.current)
|
|
3053
3189
|
ledgerBumpTimerRef.current = null
|
|
@@ -3077,6 +3213,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3077
3213
|
// comment warned about — everything above this point already ran
|
|
3078
3214
|
// synchronously before any promise existed to await.
|
|
3079
3215
|
return (async () => {
|
|
3216
|
+
// Push listeners and the registration sync belong to the wallet being
|
|
3217
|
+
// torn down; nothing may fire them against it from here on.
|
|
3218
|
+
pushDetachRef.current?.()
|
|
3219
|
+
pushDetachRef.current = undefined
|
|
3220
|
+
pushSyncRef.current = undefined
|
|
3221
|
+
|
|
3080
3222
|
// Tear the wallet down the same way rebuildWallet does. Logout used to
|
|
3081
3223
|
// skip this, which orphaned a running monitor AND left the SQLite
|
|
3082
3224
|
// connection open: a re-import of the same phrase then opened a second
|
|
@@ -3678,12 +3820,14 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3678
3820
|
certificateRequests: certificateQueue.requests,
|
|
3679
3821
|
protocolRequests: protocolQueue.requests,
|
|
3680
3822
|
spendingRequests: spendingQueue.requests,
|
|
3823
|
+
groupRequests: groupQueue.requests,
|
|
3681
3824
|
btmsRequests: btmsQueue.requests,
|
|
3682
3825
|
mandalaRequests: mandalaQueue.requests,
|
|
3683
3826
|
advanceBasketQueue: basketQueue.advance,
|
|
3684
3827
|
advanceCertificateQueue: certificateQueue.advance,
|
|
3685
3828
|
advanceProtocolQueue: protocolQueue.advance,
|
|
3686
3829
|
advanceSpendingQueue: spendingQueue.advance,
|
|
3830
|
+
advanceGroupQueue: groupQueue.advance,
|
|
3687
3831
|
advanceBtmsQueue,
|
|
3688
3832
|
advanceMandalaQueue,
|
|
3689
3833
|
finalizeConfig,
|
|
@@ -3727,12 +3871,14 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3727
3871
|
certificateQueue.requests,
|
|
3728
3872
|
protocolQueue.requests,
|
|
3729
3873
|
spendingQueue.requests,
|
|
3874
|
+
groupQueue.requests,
|
|
3730
3875
|
btmsQueue.requests,
|
|
3731
3876
|
mandalaQueue.requests,
|
|
3732
3877
|
basketQueue.advance,
|
|
3733
3878
|
certificateQueue.advance,
|
|
3734
3879
|
protocolQueue.advance,
|
|
3735
3880
|
spendingQueue.advance,
|
|
3881
|
+
groupQueue.advance,
|
|
3736
3882
|
advanceBtmsQueue,
|
|
3737
3883
|
advanceMandalaQueue,
|
|
3738
3884
|
finalizeConfig,
|
|
@@ -3828,12 +3974,14 @@ export interface WalletQueuesSlice {
|
|
|
3828
3974
|
certificateRequests: CertificateAccessRequest[]
|
|
3829
3975
|
protocolRequests: ProtocolAccessRequest[]
|
|
3830
3976
|
spendingRequests: SpendingRequest[]
|
|
3977
|
+
groupRequests: GroupPermissionRequest[]
|
|
3831
3978
|
btmsRequests: BtmsRequest[]
|
|
3832
3979
|
mandalaRequests: MandalaRequest[]
|
|
3833
3980
|
advanceBasketQueue: () => void
|
|
3834
3981
|
advanceCertificateQueue: () => void
|
|
3835
3982
|
advanceProtocolQueue: () => void
|
|
3836
3983
|
advanceSpendingQueue: () => void
|
|
3984
|
+
advanceGroupQueue: () => void
|
|
3837
3985
|
advanceBtmsQueue: (approved: boolean) => void
|
|
3838
3986
|
advanceMandalaQueue: (approved: boolean) => void
|
|
3839
3987
|
}
|
|
@@ -3845,12 +3993,14 @@ export const useWalletQueues = (): WalletQueuesSlice => {
|
|
|
3845
3993
|
certificateRequests: ctx.certificateRequests,
|
|
3846
3994
|
protocolRequests: ctx.protocolRequests,
|
|
3847
3995
|
spendingRequests: ctx.spendingRequests,
|
|
3996
|
+
groupRequests: ctx.groupRequests,
|
|
3848
3997
|
btmsRequests: ctx.btmsRequests,
|
|
3849
3998
|
mandalaRequests: ctx.mandalaRequests,
|
|
3850
3999
|
advanceBasketQueue: ctx.advanceBasketQueue,
|
|
3851
4000
|
advanceCertificateQueue: ctx.advanceCertificateQueue,
|
|
3852
4001
|
advanceProtocolQueue: ctx.advanceProtocolQueue,
|
|
3853
4002
|
advanceSpendingQueue: ctx.advanceSpendingQueue,
|
|
4003
|
+
advanceGroupQueue: ctx.advanceGroupQueue,
|
|
3854
4004
|
advanceBtmsQueue: ctx.advanceBtmsQueue,
|
|
3855
4005
|
advanceMandalaQueue: ctx.advanceMandalaQueue
|
|
3856
4006
|
}),
|
|
@@ -3859,12 +4009,14 @@ export const useWalletQueues = (): WalletQueuesSlice => {
|
|
|
3859
4009
|
ctx.certificateRequests,
|
|
3860
4010
|
ctx.protocolRequests,
|
|
3861
4011
|
ctx.spendingRequests,
|
|
4012
|
+
ctx.groupRequests,
|
|
3862
4013
|
ctx.btmsRequests,
|
|
3863
4014
|
ctx.mandalaRequests,
|
|
3864
4015
|
ctx.advanceBasketQueue,
|
|
3865
4016
|
ctx.advanceCertificateQueue,
|
|
3866
4017
|
ctx.advanceProtocolQueue,
|
|
3867
4018
|
ctx.advanceSpendingQueue,
|
|
4019
|
+
ctx.advanceGroupQueue,
|
|
3868
4020
|
ctx.advanceBtmsQueue,
|
|
3869
4021
|
ctx.advanceMandalaQueue
|
|
3870
4022
|
]
|