From d509bb3a2580e9d16a5b51345c94bf18fe9252ff Mon Sep 17 00:00:00 2001 From: minibits-cash Date: Thu, 27 Jun 2024 12:39:04 +0200 Subject: [PATCH] Support the update of mint URL if it had to be changed by mint operator --- package.json | 2 +- src/models/Mint.ts | 3 +-- src/models/RootStore.ts | 2 +- src/models/helpers/setupRootStore.ts | 7 ++++--- src/models/helpers/useStores.ts | 3 ++- src/models/index.ts | 3 ++- src/services/logService.ts | 2 +- src/utils/utils.ts | 5 ++++- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 45adb703..d889198a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minibits_wallet", - "version": "0.1.8-beta.30", + "version": "0.1.8-beta.31", "private": true, "scripts": { "android:clean": "cd android && ./gradlew clean", diff --git a/src/models/Mint.ts b/src/models/Mint.ts index 81d3eea5..94536ce7 100644 --- a/src/models/Mint.ts +++ b/src/models/Mint.ts @@ -3,7 +3,6 @@ import {withSetPropAction} from './helpers/withSetPropAction' import type {GetInfoResponse, MintKeys, MintKeyset} from '@cashu/cashu-ts' import {colors, getRandomIconColor} from '../theme' import { log, MintClient } from '../services' -import { MINIBITS_MINT_URL } from '@env' import AppError, { Err } from '../utils/AppError' import { MintUnit } from '../services/wallet/currency' @@ -54,7 +53,7 @@ export type MintProofsCounter = { */ export const MintModel = types .model('Mint', { - id: types.optional(types.identifier, generateId(8)), + id: types.optional(types.string, () => generateId(8)), mintUrl: types.string, hostname: types.maybe(types.string), shortname: types.maybe(types.string), diff --git a/src/models/RootStore.ts b/src/models/RootStore.ts index c9b3feb7..18f9226b 100644 --- a/src/models/RootStore.ts +++ b/src/models/RootStore.ts @@ -8,7 +8,7 @@ import {PaymentRequestsStoreModel} from './PaymentRequestsStore' import {ProofsStoreModel} from './ProofsStore' import {RelaysStoreModel} from './RelaysStore' -export const rootStoreModelVersion = 15 // Update this if model changes require migrations defined in setupRootStore.ts +export const rootStoreModelVersion = 16 // Update this if model changes require migrations defined in setupRootStore.ts /** * A RootStore model. diff --git a/src/models/helpers/setupRootStore.ts b/src/models/helpers/setupRootStore.ts index 07bb43ef..35778975 100644 --- a/src/models/helpers/setupRootStore.ts +++ b/src/models/helpers/setupRootStore.ts @@ -265,13 +265,14 @@ async function _runMigrations(rootStore: RootStore) { } } - if(currentVersion < 15) { - log.trace(`Starting rootStore migrations from version v${currentVersion} -> v15`) + if(currentVersion < 16) { + log.trace(`Starting rootStore migrations from version v${currentVersion} -> v16`) try { for (const mint of mintsStore.allMints) { try { - mint.setId() + mint.setId() + log.trace('[_runMigrations]', {id: mint.id, mintUrl: mint.mintUrl}) } catch (e: any) { log.warn('[_runMigrations]', e.message) continue diff --git a/src/models/helpers/useStores.ts b/src/models/helpers/useStores.ts index 6c413a2a..ad7c95a6 100644 --- a/src/models/helpers/useStores.ts +++ b/src/models/helpers/useStores.ts @@ -1,6 +1,7 @@ import { createContext, useContext, useEffect, useState } from "react" // import { setReactotronRootStore } from "../../services/reactotron" -import { RootStore, RootStoreModel } from "../RootStore" +import { RootStoreModel } from "../RootStore" +import type { RootStore } from "../RootStore" import { setupRootStore } from "./setupRootStore" /** diff --git a/src/models/index.ts b/src/models/index.ts index c03cfe96..0b2f157a 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,4 +1,5 @@ export * from "./RootStore" +export * from "./helpers/setupRootStore" export * from "./helpers/getRootStore" export * from "./helpers/useStores" -export * from "./helpers/setupRootStore" + diff --git a/src/services/logService.ts b/src/services/logService.ts index 53784a99..44ed7a00 100644 --- a/src/services/logService.ts +++ b/src/services/logService.ts @@ -23,7 +23,7 @@ const customSentryTransport: transportFunctionType = props => { // Log to Sentry only if user setting is switched on if (!userSettingsStore.isLoggerOn) { return true - } + } if (props.level.text === 'error') { // Capture error log diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 74635a0c..f3c26c06 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -2,6 +2,7 @@ import { showMessage } from "react-native-flash-message" import { colors, spacing, useThemeColor } from "../theme" import QuickCrypto from 'react-native-quick-crypto' import { fromByteArray } from "react-native-quick-base64" +import { log } from "../services/logService" /** * sleep statement. @@ -65,7 +66,9 @@ export const generateId = function (lengthInBytes: number) { const random = QuickCrypto.randomBytes(lengthInBytes) const uint8Array = new Uint8Array(random) - return Buffer.from(uint8Array).toString('hex') + const id: string = Buffer.from(uint8Array).toString('hex') + log.trace('[generateId]', {id}) + return id }