From 3909660529ee173d516d52ff2ed62ef0c2713372 Mon Sep 17 00:00:00 2001 From: minibits-cash Date: Tue, 10 Mar 2026 12:57:34 +0100 Subject: [PATCH] Upgrade cashu-ts and remove InteractionManager --- package.json | 2 +- src/models/WalletStore.ts | 59 ++++--------------------- src/screens/Contacts/PublicContacts.tsx | 17 +++---- src/screens/Contacts/RandomName.tsx | 25 +++-------- src/screens/DeveloperScreen.tsx | 2 +- src/services/logService.ts | 2 +- yarn.lock | 10 ++--- 7 files changed, 29 insertions(+), 88 deletions(-) diff --git a/package.json b/package.json index 8516ed60..133c3d8b 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "machine-translate": "npx @inlang/cli machine translate --project minibits.inlang" }, "dependencies": { - "@cashu/cashu-ts": "3.3.0", + "@cashu/cashu-ts": "3.5.0", "@fortawesome/fontawesome-svg-core": "^7.1.0", "@fortawesome/free-brands-svg-icons": "^7.1.0", "@fortawesome/free-regular-svg-icons": "^7.1.0", diff --git a/src/models/WalletStore.ts b/src/models/WalletStore.ts index 9e617d59..449ea15c 100644 --- a/src/models/WalletStore.ts +++ b/src/models/WalletStore.ts @@ -28,7 +28,7 @@ import { Proof } from './Proof' import { InFlightRequest, Mint } from './Mint' import { getRootStore } from './helpers/getRootStore' import { Transaction } from './Transaction' -// refresh +// refresh refresh /* Not persisted, in-memory only model of the cashu-ts wallet instances and wallet keys persisted in the device secure store. @@ -1105,58 +1105,17 @@ export const WalletStoreModel = types // PERF: Time wallet creation const perfWalletCreate = performance.now() - // Get mint model instance for keysets metadata - const mintInstance = self.getMintModelInstance(mintUrl) - - if(!mintInstance) { - throw new AppError(Err.VALIDATION_ERROR, 'Missing mint instance', {mintUrl}) - } - - // Check if the requested keyset is inactive - const requestedKeyset = mintInstance.keysets?.find(k => k.id === keysetId) - const isInactiveKeyset = requestedKeyset && !requestedKeyset.active - // Create separate CashuMint and CashuWallet instances for restore operation - // to avoid polluting the main wallet state with inactive keyset data + // to avoid polluting the main wallet state with inactive keyset data. + // cashu-ts 3.4.1+ supports restore from inactive keysets natively. const cashuMint = new CashuMint(mintUrl) - let cashuWallet: CashuWallet + const cashuWallet = new CashuWallet(cashuMint, { + unit, + keysetId, + bip39seed: seed + }) - if (isInactiveKeyset) { - // For inactive keysets, create wallet without binding to the inactive keyset - // (which would fail in finishInit), then manually load keys and rebind - log.trace('[WalletStore.restore]', 'Creating wallet for inactive keyset', {keysetId}) - - // Create wallet WITHOUT keysetId - it will bind to cheapest active keyset - cashuWallet = new CashuWallet(cashuMint, { - unit, - bip39seed: seed - }) - - // Load mint info - succeeds because wallet is bound to active keyset - yield cashuWallet.loadMint() - - // Fetch and set keys for the inactive keyset - log.trace('[WalletStore.restore]', 'Loading keys for inactive keyset', {keysetId}) - const {keysets: fetchedKeys} = yield cashuMint.getKeys(keysetId) as Promise - if (fetchedKeys && fetchedKeys.length > 0) { - const inactiveKeyset = cashuWallet.keyChain.getKeyset(keysetId) - inactiveKeyset.keys = fetchedKeys[0].keys - } - - // Rebind to the inactive keyset now that it has keys - cashuWallet.bindKeyset(keysetId) - } else { - // For active keysets, create wallet with keysetId directly - log.trace('[WalletStore.restore]', 'Creating wallet for active keyset', {keysetId}) - - cashuWallet = new CashuWallet(cashuMint, { - unit, - keysetId, - bip39seed: seed - }) - - yield cashuWallet.loadMint() - } + yield cashuWallet.loadMint() log.info('[PERF][WalletStore.restore] CashuWallet created:', { ms: (performance.now() - perfWalletCreate).toFixed(2) }) diff --git a/src/screens/Contacts/PublicContacts.tsx b/src/screens/Contacts/PublicContacts.tsx index cb178981..585c176e 100644 --- a/src/screens/Contacts/PublicContacts.tsx +++ b/src/screens/Contacts/PublicContacts.tsx @@ -1,6 +1,6 @@ import {observer} from 'mobx-react-lite' import React, {useEffect, useRef, useState} from 'react' -import {FlatList, Image, InteractionManager, LayoutAnimation, Platform, TextInput, TextStyle, UIManager, View, ViewStyle} from 'react-native' +import {FlatList, Image, LayoutAnimation, Platform, TextInput, TextStyle, UIManager, View, ViewStyle} from 'react-native' import {verticalScale} from '@gocodingnow/rn-size-matters' import { Metadata, Contacts } from 'nostr-tools/kinds' import Clipboard from '@react-native-clipboard/clipboard' @@ -93,9 +93,7 @@ export const PublicContacts = observer(function (props: { relaysStore.addDefaultRelays() } - InteractionManager.runAfterInteractions(async () => { - subscribeToOwnProfileAndPubkeys() - }) + subscribeToOwnProfileAndPubkeys() }, []) @@ -104,10 +102,8 @@ export const PublicContacts = observer(function (props: { return } log.trace('Reloading...') - InteractionManager.runAfterInteractions(async () => { - subscribeToOwnProfileAndPubkeys() - setShouldReload(false) - }) + subscribeToOwnProfileAndPubkeys() + setShouldReload(false) }, [shouldReload]) @@ -205,11 +201,8 @@ export const PublicContacts = observer(function (props: { setIsLoading(false) } - InteractionManager.runAfterInteractions(async () => { - loadProfiles() - }) + loadProfiles() - }, [followingPubkeys]) diff --git a/src/screens/Contacts/RandomName.tsx b/src/screens/Contacts/RandomName.tsx index 0eede078..bfcd11fc 100644 --- a/src/screens/Contacts/RandomName.tsx +++ b/src/screens/Contacts/RandomName.tsx @@ -4,7 +4,6 @@ import { TextStyle, View, ViewStyle, - InteractionManager, FlatList, } from 'react-native' import {spacing} from '../../theme' @@ -36,23 +35,13 @@ export const RandomName = observer(function (props: {pubkey: string}) { const [error, setError] = useState() useEffect(() => { - const load = async () => { - setIsLoading(true) - InteractionManager.runAfterInteractions(async () => { - let i = 0 - let names = [] - while (i < 8) { - const name = getRandomUsername() - names.push(name) - i++ - } - - setRandomNames(names) - setIsLoading(false) - }) - } - load() - return () => {} + setIsLoading(true) + const timer = setTimeout(() => { + const names = Array.from({length: 8}, () => getRandomUsername()) + setRandomNames(names) + setIsLoading(false) + }, 0) + return () => clearTimeout(timer) }, []) const confirmSelectedName = async function () { diff --git a/src/screens/DeveloperScreen.tsx b/src/screens/DeveloperScreen.tsx index 91591a03..df6f1cc0 100644 --- a/src/screens/DeveloperScreen.tsx +++ b/src/screens/DeveloperScreen.tsx @@ -34,7 +34,7 @@ import RNExitApp from 'react-native-exit-app' import { TransactionStatus } from '../models/Transaction' import { maxTransactionsInHistory } from '../models/TransactionsStore' import { StaticScreenProps, useNavigation } from '@react-navigation/native' -// refresh +// refresh refresh type Props = StaticScreenProps diff --git a/src/services/logService.ts b/src/services/logService.ts index bb844a6f..68a3dc9f 100644 --- a/src/services/logService.ts +++ b/src/services/logService.ts @@ -18,7 +18,7 @@ import { Platform } from "react-native" import AppError, { Err } from "../utils/AppError" const { userSettingsStore } = rootStoreInstance -// +// refresh refresh if (!__DEV__) { Sentry.init({ diff --git a/yarn.lock b/yarn.lock index f3eb1813..78da8b78 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2869,15 +2869,15 @@ __metadata: languageName: node linkType: hard -"@cashu/cashu-ts@npm:3.3.0": - version: 3.3.0 - resolution: "@cashu/cashu-ts@npm:3.3.0" +"@cashu/cashu-ts@npm:3.5.0": + version: 3.5.0 + resolution: "@cashu/cashu-ts@npm:3.5.0" dependencies: "@noble/curves": ^2.0.1 "@noble/hashes": ^2.0.1 "@scure/base": ^2.0.0 "@scure/bip32": ^2.0.1 - checksum: beba7c33347dbd86385b071ad0624178645e86f2479dff91a655563ae1f6b8a730a7856d1b09e9df368bbfcc1e9ba1001c19512967787e41f417fc183537ce9e + checksum: 75af4dd2aa7100d85675b83b141d8e0f30c5ea71445bedbe5642d3f2c3d3f712565daa5265a19bf52ca6e51130a3f0c3974663503e98e0373eef0ac5be0f45a6 languageName: node linkType: hard @@ -14606,7 +14606,7 @@ __metadata: "@babel/plugin-proposal-export-namespace-from": ^7.18.9 "@babel/preset-env": ^7.25.3 "@babel/runtime": ^7.25.0 - "@cashu/cashu-ts": 3.3.0 + "@cashu/cashu-ts": 3.5.0 "@fortawesome/fontawesome-svg-core": ^7.1.0 "@fortawesome/free-brands-svg-icons": ^7.1.0 "@fortawesome/free-regular-svg-icons": ^7.1.0