Migrate to the new NOSTR relay server

This commit is contained in:
minibits-cash
2024-05-28 11:57:49 +02:00
parent 195d389046
commit 76402c805a
4 changed files with 49 additions and 3 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "minibits_wallet",
"version": "0.1.7-beta.16",
"version": "0.1.7-beta.17",
"private": true,
"scripts": {
"android:clean": "cd android && ./gradlew clean",
+1 -1
View File
@@ -8,7 +8,7 @@ import {PaymentRequestsStoreModel} from './PaymentRequestsStore'
import {ProofsStoreModel} from './ProofsStore'
import {RelaysStoreModel} from './RelaysStore'
export const rootStoreModelVersion = 13 // Update this if model changes require migrations defined in setupRootStore.ts
export const rootStoreModelVersion = 14 // Update this if model changes require migrations defined in setupRootStore.ts
/**
* A RootStore model.
+35
View File
@@ -85,6 +85,41 @@ export const WalletProfileStoreModel = types
return false // silent
}
}),
migrateToNewRelay: flow(function* migrateToNewRelay() {
try {
const {pubkey, name, picture, nip05, lud16} = self
// announce to new minibits relay
const profileEvent: NostrUnsignedEvent = {
kind: 0,
pubkey,
tags: [],
content: JSON.stringify({
name,
picture,
nip05,
lud16,
}),
created_at: Math.floor(Date.now() / 1000)
}
const rootStore = getRootStore(self)
const relaysToPublish: string[] = NostrClient.getMinibitsRelays()
log.debug('[publishToRelays]', 'Migrate profile to new relay', {profileEvent, relaysToPublish})
const publishedEvent: Event | undefined = yield NostrClient.publish(
profileEvent,
relaysToPublish
)
return publishedEvent
} catch (e: any) {
log.error(e.name, e.message)
return false // silent
}
}),
}))
.actions(self => ({
hydrate: flow(function* hydrate(profileRecord: WalletProfileRecord) {
+12 -1
View File
@@ -284,7 +284,18 @@ async function _runMigrations(rootStore: RootStore) {
rootStore.setVersion(rootStoreModelVersion)
log.info(`Completed rootStore migrations to the version v${rootStoreModelVersion}`)
}
}
if(currentVersion < 14) {
log.trace(`Starting rootStore migrations from version v${currentVersion} -> v14`)
try {
await walletProfileStore.migrateToNewRelay()
} catch (e: any) {
log.warn('[setupRootStore]', e.message)
}
log.info(`Completed rootStore migrations to the version v${rootStoreModelVersion}`)
rootStore.setVersion(rootStoreModelVersion)
}
} catch (e: any) {
throw new AppError(