@bsv/expo-wallet-toolbox 0.1.3 → 0.2.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/core/backup/RemoteSyncReader.ts +59 -9
- package/core/backup/client.ts +60 -27
- package/core/backup/restore.ts +54 -4
- package/core/backup/restoreOnImport.ts +1 -0
- package/core/context/WalletContext.tsx +24 -12
- package/core/localpay/transport/ble.ts +6 -6
- package/core/localpay/transport/socket.ts +31 -22
- package/core/pay/creditInbox.ts +3 -1
- package/core/peerpay/outbox.ts +75 -35
- package/core/storage/StorageExpoSQLite.ts +16 -17
- package/package.json +1 -1
- package/ui/components/pay/AddressReceive.tsx +2 -1
- package/ui/components/pay/HandleReceive.tsx +2 -1
- package/ui/components/pay/NearbyFlow.tsx +9 -5
- package/ui/components/pay/PaymentSuccessOverlay.tsx +2 -1
- package/ui/components/pay/UniversalSend.tsx +9 -5
- package/ui/components/wallet/ActivityRow.tsx +20 -13
- package/ui/components/wallet/AmountDisplay.tsx +4 -7
- package/ui/dismissTarget.ts +19 -0
- package/ui/hooks/useSpendableBalance.ts +44 -17
- package/ui/hooks/useVaultBalance.ts +48 -17
- package/ui/index.ts +1 -0
- package/ui/screens/PayScreen.tsx +4 -2
- package/ui/screens/WalletHomeScreen.tsx +3 -1
|
@@ -22,29 +22,60 @@ export function useVaultBalance(): { balance: number | null; loading: boolean; r
|
|
|
22
22
|
const transferInFlight = vaultState.phase === 'preparing' || vaultState.phase === 'broadcasting'
|
|
23
23
|
const [balance, setBalance] = useState<number | null>(null)
|
|
24
24
|
const [loading, setLoading] = useState(false)
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
// refetched each time the figure changed.
|
|
25
|
+
const [refreshVersion, setRefreshVersion] = useState(0)
|
|
26
|
+
// Read the latest figure without making balance changes trigger another read.
|
|
28
27
|
const balanceRef = useRef<number | null>(null)
|
|
29
28
|
balanceRef.current = balance
|
|
29
|
+
const inFlightRef = useRef(false)
|
|
30
|
+
const pendingRef = useRef<(() => Promise<void>) | null>(null)
|
|
30
31
|
|
|
31
32
|
const refresh = useCallback(() => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
setLoading(prev => (balanceRef.current === null ? true : prev))
|
|
35
|
-
getVaultBalance(pm as unknown as VaultWallet, adminOriginator)
|
|
36
|
-
.then(setBalance)
|
|
37
|
-
.catch(() => {
|
|
38
|
-
/* leave the last known balance in place on a transient failure */
|
|
39
|
-
})
|
|
40
|
-
.finally(() => setLoading(false))
|
|
41
|
-
}, [managers?.permissionsManager, adminOriginator])
|
|
33
|
+
setRefreshVersion(prev => prev + 1)
|
|
34
|
+
}, [])
|
|
42
35
|
|
|
43
36
|
useEffect(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
let cancelled = false
|
|
38
|
+
const pm = managers?.permissionsManager
|
|
39
|
+
if (transferInFlight || !pm) {
|
|
40
|
+
setLoading(false)
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const read = async () => {
|
|
45
|
+
if (balanceRef.current === null) setLoading(true)
|
|
46
|
+
try {
|
|
47
|
+
const next = await getVaultBalance(pm as unknown as VaultWallet, adminOriginator)
|
|
48
|
+
if (!cancelled) setBalance(next)
|
|
49
|
+
} catch {
|
|
50
|
+
// Leave the last known balance in place on a transient failure.
|
|
51
|
+
} finally {
|
|
52
|
+
if (!cancelled) setLoading(false)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Retain only the latest invalidation while a read is in flight. Cleanup
|
|
57
|
+
// also discards results from reads that started before the transfer freeze.
|
|
58
|
+
pendingRef.current = read
|
|
59
|
+
if (!inFlightRef.current) {
|
|
60
|
+
inFlightRef.current = true
|
|
61
|
+
void (async () => {
|
|
62
|
+
try {
|
|
63
|
+
while (pendingRef.current) {
|
|
64
|
+
const next = pendingRef.current
|
|
65
|
+
pendingRef.current = null
|
|
66
|
+
await next()
|
|
67
|
+
}
|
|
68
|
+
} finally {
|
|
69
|
+
inFlightRef.current = false
|
|
70
|
+
}
|
|
71
|
+
})()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return () => {
|
|
75
|
+
cancelled = true
|
|
76
|
+
if (pendingRef.current === read) pendingRef.current = null
|
|
77
|
+
}
|
|
78
|
+
}, [managers?.permissionsManager, adminOriginator, txStatusVersion, transferInFlight, refreshVersion])
|
|
48
79
|
|
|
49
80
|
return { balance, loading, refresh }
|
|
50
81
|
}
|
package/ui/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const CANARY_UI = 'ui'
|
|
2
2
|
|
|
3
3
|
// Shared UI primitives (components/ui)
|
|
4
|
+
export type { DismissTarget } from './dismissTarget'
|
|
4
5
|
export { showAlert, AlertHost } from './components/ui/AlertCard'
|
|
5
6
|
export type { AlertButton, AlertOptions } from './components/ui/AlertCard'
|
|
6
7
|
export { showChoiceSheet, choiceSheetOrder } from './components/ui/ChoiceSheet'
|
package/ui/screens/PayScreen.tsx
CHANGED
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
import { getPendingCorruptNotice, readUnprocessedPending } from '../../core/localpay/pending'
|
|
43
43
|
import { nearbyAdvisory } from '../../core/localpay/nearbyAdvisory'
|
|
44
44
|
import { NearbyAdvisoryModal } from '../components/pay/NearbyAdvisoryModal'
|
|
45
|
+
import type { DismissTarget } from '../dismissTarget'
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* @expo/vector-icons' index barrel re-exports every icon set (AntDesign,
|
|
@@ -99,7 +100,7 @@ export interface PayScreenProps {
|
|
|
99
100
|
* screen somewhere other than the app root — e.g. a browser app that puts
|
|
100
101
|
* the wallet at `/wallet` — should pass that route here instead.
|
|
101
102
|
*/
|
|
102
|
-
dismissTo?:
|
|
103
|
+
dismissTo?: DismissTarget
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
@@ -181,6 +182,7 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
181
182
|
)
|
|
182
183
|
/** Get side: the hub's raw amount, carried into the method. */
|
|
183
184
|
const [requestSats, setRequestSats] = useState('')
|
|
185
|
+
const initialNearbyRequest = useMemo(() => ({ sats: requestSatsFrom(requestSats) }), [requestSats])
|
|
184
186
|
// One camera raise per deep link; a cancelled advisory must not re-open it.
|
|
185
187
|
const [scanOnMount, setScanOnMount] = useState(paramCell === 'pay-nearby')
|
|
186
188
|
|
|
@@ -387,7 +389,7 @@ export function PayScreen({ dismissTo = '/' }: PayScreenProps = {}) {
|
|
|
387
389
|
switch (method) {
|
|
388
390
|
case 'get-nearby':
|
|
389
391
|
return nearbyAdvisorySeen ? (
|
|
390
|
-
<NearbyFlow role="payee" initialRequest={
|
|
392
|
+
<NearbyFlow role="payee" initialRequest={initialNearbyRequest} onExit={goBack} dismissTo={dismissTo} />
|
|
391
393
|
) : null
|
|
392
394
|
case 'get-handle':
|
|
393
395
|
return <HandleReceive initialSats={sats} dismissTo={dismissTo} />
|
|
@@ -1090,6 +1090,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
1090
1090
|
|
|
1091
1091
|
return (
|
|
1092
1092
|
<ActivityRow
|
|
1093
|
+
currency={currency}
|
|
1093
1094
|
action={item}
|
|
1094
1095
|
rowKey={key}
|
|
1095
1096
|
offlineStatus={offline?.status}
|
|
@@ -1102,12 +1103,13 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
1102
1103
|
onAbort={onAbort}
|
|
1103
1104
|
onSendPaymentDetails={onSendPaymentDetails}
|
|
1104
1105
|
onSendAgain={onFailedSendAgain}
|
|
1105
|
-
onCancelParked={
|
|
1106
|
+
onCancelParked={onCancelParked}
|
|
1106
1107
|
/>
|
|
1107
1108
|
)
|
|
1108
1109
|
},
|
|
1109
1110
|
[
|
|
1110
1111
|
colors,
|
|
1112
|
+
currency,
|
|
1111
1113
|
offlineByTxid,
|
|
1112
1114
|
busyRow,
|
|
1113
1115
|
busyLabel,
|