@bsv/expo-wallet-toolbox 0.15.2 → 0.17.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +199 -0
  2. package/core/backup/appData.ts +5 -1
  3. package/core/backup/codec.ts +9 -3
  4. package/core/backup/contactsBackup.ts +145 -0
  5. package/core/backup/push.ts +14 -0
  6. package/core/backup/restore.ts +26 -4
  7. package/core/backup/restoreOnImport.ts +28 -4
  8. package/core/contacts/contactsStore.ts +47 -3
  9. package/core/context/LocalStorageProvider.tsx +3 -1
  10. package/core/context/WalletContext.tsx +256 -76
  11. package/core/context/startupPrewarm.ts +54 -0
  12. package/core/directpay/dialFailure.ts +56 -0
  13. package/core/directpay/index.ts +7 -0
  14. package/core/directpay/payFlow.ts +117 -0
  15. package/core/directpay/paymentKey.ts +16 -0
  16. package/core/directpay/settings.ts +253 -0
  17. package/core/directpay/status.ts +52 -0
  18. package/core/directpay/types.ts +128 -0
  19. package/core/hooks/useConfirmationSound.ts +7 -0
  20. package/core/i18n/translations.tsx +354 -12
  21. package/core/identity/handleRegistry/client.ts +2 -1
  22. package/core/identity/handleRegistry/profileKeys.ts +16 -0
  23. package/core/identity/handleRegistry/resolver.ts +2 -1
  24. package/core/identity/handleRegistry/rules.ts +7 -3
  25. package/core/index.ts +14 -2
  26. package/core/localpay/build.ts +4 -3
  27. package/core/localpay/session.ts +6 -0
  28. package/core/localpay/transport/select.ts +64 -3
  29. package/core/localpay/verify.ts +2 -1
  30. package/core/net/trimTrailingSlashes.ts +13 -0
  31. package/core/parsePeerPayURI.ts +25 -2
  32. package/core/pay/creditInbox.ts +31 -1
  33. package/core/pay/rails/address.ts +3 -2
  34. package/core/pay/rails/handle.ts +8 -2
  35. package/core/pay/rails/index.ts +6 -4
  36. package/core/pos/protocol.ts +172 -0
  37. package/core/profiles/discovery.ts +17 -8
  38. package/core/profiles/profileStore.ts +34 -7
  39. package/core/profiles/removalProblems.ts +41 -0
  40. package/core/push/registration.ts +2 -1
  41. package/core/services/callbackToken.ts +7 -0
  42. package/core/services/revokeConnection.ts +98 -0
  43. package/core/storage/schema/createTables.ts +24 -0
  44. package/core/toolboxConfig.ts +85 -5
  45. package/package.json +1 -1
  46. package/ui/components/pay/MessageBoxConfig.tsx +2 -1
  47. package/ui/components/pay/NearbyFlow.tsx +410 -7
  48. package/ui/exportTransactions.ts +26 -13
  49. package/ui/index.ts +2 -2
  50. package/ui/screens/ConnectionsScreen.tsx +8 -63
  51. package/ui/screens/ProfileScreen.tsx +2 -40
  52. package/ui/screens/WalletConfigScreen.tsx +57 -51
@@ -41,6 +41,11 @@ export interface ContactRow {
41
41
  source: ContactSource
42
42
  createdAt: string
43
43
  updatedAt: string
44
+ /** Starred by the user. */
45
+ favourite: boolean
46
+ /** When the user took them out of the address book; set means hidden from
47
+ * lists and searches but kept, so it can be undone. */
48
+ removedAt?: string
44
49
  }
45
50
 
46
51
  interface ContactDbRow {
@@ -54,6 +59,9 @@ interface ContactDbRow {
54
59
  source: string
55
60
  created_at: string
56
61
  updated_at: string
62
+ // added by ensureContactsColumns; absent on a table that predates them
63
+ favourite?: number | null
64
+ removedAt?: string | null
57
65
  }
58
66
 
59
67
  function toContact(row: ContactDbRow): ContactRow {
@@ -67,15 +75,19 @@ function toContact(row: ContactDbRow): ContactRow {
67
75
  cachedCertifier: row.cachedCertifier ?? undefined,
68
76
  source: row.source as ContactSource,
69
77
  createdAt: row.created_at,
70
- updatedAt: row.updated_at
78
+ updatedAt: row.updated_at,
79
+ favourite: !!row.favourite,
80
+ removedAt: row.removedAt ?? undefined
71
81
  }
72
82
  }
73
83
 
74
84
  export interface ContactsStore {
85
+ /** The address book: everyone not removed. */
75
86
  listContacts(userId: number): Promise<ContactRow[]>
76
87
  /** Case-insensitive substring match on `name` and `cachedHandle`. Forgiving,
77
88
  * not scored — "fuzzy" in the design sense, not a ranked fuzzy algorithm. */
78
89
  searchContacts(userId: number, query: string): Promise<ContactRow[]>
90
+ /** Including a removed one (check `removedAt`): adding them again restores them. */
79
91
  getContact(userId: number, identityKey: string): Promise<ContactRow | undefined>
80
92
  /** Throws on a duplicate (userId, identityKey) — callers check `getContact` first when they need "already a contact" as a non-throwing fact. */
81
93
  createContact(args: {
@@ -96,12 +108,17 @@ export interface ContactsStore {
96
108
  cache: { cachedHandle?: string; cachedAvatarUrl?: string; cachedCertifier?: string }
97
109
  ): Promise<void>
98
110
  deleteContact(userId: number, identityKey: string): Promise<void>
111
+ /** Star or unstar. */
112
+ setFavourite(userId: number, identityKey: string, favourite: boolean): Promise<void>
113
+ /** Take out of the address book, keeping the row so `restoreContact` can undo it. */
114
+ removeContact(userId: number, identityKey: string): Promise<void>
115
+ restoreContact(userId: number, identityKey: string): Promise<void>
99
116
  }
100
117
 
101
118
  export function createContactsStore(db: ContactsDb): ContactsStore {
102
119
  return {
103
120
  async listContacts(userId) {
104
- const rows = (await db.getAllAsync('SELECT * FROM contacts WHERE userId = ? ORDER BY name COLLATE NOCASE ASC', [
121
+ const rows = (await db.getAllAsync('SELECT * FROM contacts WHERE userId = ? AND removedAt IS NULL ORDER BY name COLLATE NOCASE ASC', [
105
122
  userId
106
123
  ])) as ContactDbRow[]
107
124
  return rows.map(toContact)
@@ -112,7 +129,7 @@ export function createContactsStore(db: ContactsDb): ContactsStore {
112
129
  if (query.trim() === '') return createContactsStore(db).listContacts(userId)
113
130
  const rows = (await db.getAllAsync(
114
131
  `SELECT * FROM contacts
115
- WHERE userId = ?
132
+ WHERE userId = ? AND removedAt IS NULL
116
133
  AND (lower(name) LIKE ? OR lower(coalesce(cachedHandle, '')) LIKE ?)
117
134
  ORDER BY name COLLATE NOCASE ASC`,
118
135
  [userId, needle, needle]
@@ -178,6 +195,33 @@ export function createContactsStore(db: ContactsDb): ContactsStore {
178
195
 
179
196
  async deleteContact(userId, identityKey) {
180
197
  await db.runAsync('DELETE FROM contacts WHERE userId = ? AND identityKey = ?', [userId, identityKey])
198
+ },
199
+
200
+ async setFavourite(userId, identityKey, favourite) {
201
+ await db.runAsync('UPDATE contacts SET favourite = ?, updated_at = ? WHERE userId = ? AND identityKey = ?', [
202
+ favourite ? 1 : 0,
203
+ new Date().toISOString(),
204
+ userId,
205
+ identityKey
206
+ ])
207
+ },
208
+
209
+ async removeContact(userId, identityKey) {
210
+ const now = new Date().toISOString()
211
+ await db.runAsync('UPDATE contacts SET removedAt = ?, updated_at = ? WHERE userId = ? AND identityKey = ?', [
212
+ now,
213
+ now,
214
+ userId,
215
+ identityKey
216
+ ])
217
+ },
218
+
219
+ async restoreContact(userId, identityKey) {
220
+ await db.runAsync('UPDATE contacts SET removedAt = NULL, updated_at = ? WHERE userId = ? AND identityKey = ?', [
221
+ new Date().toISOString(),
222
+ userId,
223
+ identityKey
224
+ ])
181
225
  }
182
226
  }
183
227
  }
@@ -18,6 +18,7 @@ import {
18
18
  type MigrationResult,
19
19
  type UnlockState
20
20
  } from '../services/secrets'
21
+ import { takeStartupSecrets } from './startupPrewarm'
21
22
 
22
23
  // The identity is shared storage, so overlapping provider mounts must share the
23
24
  // guard too. Hold it through both the existence check and the completed write.
@@ -112,7 +113,8 @@ export default function LocalStorageProvider({ children }: { children: React.Rea
112
113
  ;(async () => {
113
114
  let result: MigrationResult
114
115
  try {
115
- result = await migrateLegacySecrets()
116
+ // begun at startup if the app prewarmed (core/context/startupPrewarm)
117
+ result = await (takeStartupSecrets() ?? migrateLegacySecrets())
116
118
  } catch (err) {
117
119
  console.warn('[LocalStorageProvider] migration threw', (err as Error)?.message)
118
120
  result = { outcome: 'failed', stage: 'unknown', retryable: true }