diff --git a/src/constants/projects.ts b/src/constants/projects.ts index 3e2f72c2..2af1f89d 100644 --- a/src/constants/projects.ts +++ b/src/constants/projects.ts @@ -47,7 +47,7 @@ export const COMING_SOON_PROJECTS: Array = [ id: 'avive', name: 'Avive', description: - 'One of the world\'s largest UBI & DePin Projects, with over 9 million worldwide users.', + "One of the world's largest UBI & DePin Projects, with over 9 million worldwide users.", url: 'https://www.avive.world', isComingSoon: true, isVerified: false, @@ -57,8 +57,7 @@ export const COMING_SOON_PROJECTS: Array = [ { id: 'maverick', name: 'Maverick Protocol', - description: - 'Maverick Protocol is a leading provider of smart contract solutions in DeFi.', + description: 'Maverick Protocol is a leading provider of smart contract solutions in DeFi.', url: 'https://app.mav.xyz', isComingSoon: true, isVerified: false, @@ -68,8 +67,7 @@ export const COMING_SOON_PROJECTS: Array = [ { id: 'loopring-pro', name: 'Loopring Pro', - description: - 'Explore the Loopring DEX, Earn, and NFT Management.', + description: 'Explore the Loopring DEX, Earn, and NFT Management.', url: 'https://loopring.io/#/pro', isComingSoon: true, isVerified: false, @@ -79,8 +77,7 @@ export const COMING_SOON_PROJECTS: Array = [ { id: 'loopring-earn', name: 'Loopring Earn', - description: - 'Access the most innovative structural products brought to the DeFi world.', + description: 'Access the most innovative structural products brought to the DeFi world.', url: 'https://earn.loopring.io/', isComingSoon: true, isVerified: false, diff --git a/src/contexts/W3iContext/hooks/notifyHooks.ts b/src/contexts/W3iContext/hooks/notifyHooks.ts index f7ae65e4..7a1adf35 100644 --- a/src/contexts/W3iContext/hooks/notifyHooks.ts +++ b/src/contexts/W3iContext/hooks/notifyHooks.ts @@ -153,6 +153,24 @@ export const useNotifyState = (w3iProxy: Web3InboxProxy, proxyReady: boolean) => } }) + const notifyReregisterSub = notifyClient.observe('notify_reregister', { + next: params => { + handleRegistration(params.userPubkey).then(() => { + switch (params.nextAction.type) { + case 'subscribe': + notifyClient.subscribe(params.nextAction.params) + break + case 'deleteSubscription': + notifyClient.deleteSubscription(params.nextAction.params) + break + case 'update': + notifyClient.update(params.nextAction.params) + break + } + }) + } + }) + const syncUpdateSub = notifyClient.observe('sync_update', { next: refreshNotifyState }) @@ -165,6 +183,7 @@ export const useNotifyState = (w3iProxy: Web3InboxProxy, proxyReady: boolean) => notifySubsChanged.unsubscribe() notifySignatureRequestedSub.unsubscribe() notifySignatureRequestCancelledSub.unsubscribe() + notifyReregisterSub.unsubscribe() } }, [notifyClient, refreshNotifyState, setWatchSubscriptionsComplete]) diff --git a/src/w3iProxy/listenerTypes.ts b/src/w3iProxy/listenerTypes.ts index b136064b..886b2198 100644 --- a/src/w3iProxy/listenerTypes.ts +++ b/src/w3iProxy/listenerTypes.ts @@ -1,4 +1,4 @@ -import type { NotifyClientTypes } from '@walletconnect/notify-client' +import type { NotifyClient, NotifyClientTypes } from '@walletconnect/notify-client' import type { ChatClientTypes } from './chatProviders/types' @@ -21,6 +21,13 @@ export interface ChatFacadeEvents { sync_update: never } +type NextAction = { + type: T + params: Parameters[0] +} + +type NextActions = NextAction<'subscribe'> | NextAction<'update'> | NextAction<'deleteSubscription'> + export interface NotifyFacadeEvents { notify_message: NotifyClientTypes.EventArguments['notify_message'] notify_subscription: NotifyClientTypes.EventArguments['notify_subscription'] @@ -29,5 +36,6 @@ export interface NotifyFacadeEvents { notify_subscriptions_changed: NotifyClientTypes.EventArguments['notify_subscriptions_changed'] notify_signature_requested: { message: string } notify_signature_request_cancelled: never + notify_reregister: { userPubkey: string; nextAction: NextActions } sync_update: never } diff --git a/src/w3iProxy/notifyProviders/internalNotifyProvider.ts b/src/w3iProxy/notifyProviders/internalNotifyProvider.ts index 685b9d88..d8fb5121 100644 --- a/src/w3iProxy/notifyProviders/internalNotifyProvider.ts +++ b/src/w3iProxy/notifyProviders/internalNotifyProvider.ts @@ -163,6 +163,23 @@ export default class InternalNotifyProvider implements W3iNotifyProvider { throw new Error(this.formatClientRelatedError('subscribe')) } + if ( + !this.notifyClient.isRegistered({ + account: params.account, + domain: window.location.hostname, + allApps: true + }) + ) { + this.emitter.emit('notify_reregister', { + userPubkey: params.account, + nextAction: { + type: 'subscribe', + params + } + }) + return false + } + let subscribed: boolean = false try { subscribed = await this.notifyClient.subscribe({ @@ -187,6 +204,27 @@ export default class InternalNotifyProvider implements W3iNotifyProvider { throw new Error(this.formatClientRelatedError('update')) } + const account = this.notifyClient.subscriptions.keys.includes(params.topic) + ? this.notifyClient.subscriptions.get(params.topic).account + : '' + + const isRegistered = this.notifyClient.isRegistered({ + account, + domain: window.location.hostname, + allApps: true + }) + + if (!isRegistered) { + this.emitter.emit('notify_reregister', { + userPubkey: account, + nextAction: { + type: 'update', + params + } + }) + return false + } + const updated = await this.notifyClient.update(params) return updated @@ -197,6 +235,23 @@ export default class InternalNotifyProvider implements W3iNotifyProvider { throw new Error(this.formatClientRelatedError('deleteSubscription')) } + const account = this.notifyClient.subscriptions.keys.includes(params.topic) + ? this.notifyClient.subscriptions.get(params.topic).account + : '' + + if ( + !this.notifyClient.isRegistered({ account, domain: window.location.hostname, allApps: true }) + ) { + this.emitter.emit('notify_reregister', { + userPubkey: account, + nextAction: { + type: 'deleteSubscription', + params + } + }) + return + } + return this.notifyClient.deleteSubscription(params) }