diff --git a/package.json b/package.json index 1c1ba62d..01634aa3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/models/RootStore.ts b/src/models/RootStore.ts index 1b6faa95..30a4fbd5 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 = 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. diff --git a/src/models/WalletProfileStore.ts b/src/models/WalletProfileStore.ts index dda0427d..8bd1c57d 100644 --- a/src/models/WalletProfileStore.ts +++ b/src/models/WalletProfileStore.ts @@ -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) { diff --git a/src/models/helpers/setupRootStore.ts b/src/models/helpers/setupRootStore.ts index 0620a4e4..2170b0d8 100644 --- a/src/models/helpers/setupRootStore.ts +++ b/src/models/helpers/setupRootStore.ts @@ -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(