mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
update get notifications logic
This commit is contained in:
parent
1f6c9a06a6
commit
323f10d2b8
@ -139,6 +139,34 @@ function OrbisProvider({ children }: { children: ReactNode }): ReactElement {
|
||||
return null
|
||||
}
|
||||
|
||||
const getDid = async (address: string) => {
|
||||
if (!address) return null
|
||||
|
||||
const { data, error } = await orbis.getDids(address)
|
||||
|
||||
if (error) {
|
||||
return
|
||||
}
|
||||
|
||||
let _did: string = null
|
||||
|
||||
if (data && data.length > 0) {
|
||||
console.log(data)
|
||||
|
||||
// Try to get mainnet did
|
||||
const mainnetDid = data.find((o: any) => {
|
||||
const did = o.did.split(':')
|
||||
return did[3] === '1'
|
||||
})
|
||||
|
||||
_did = mainnetDid?.did || data[0].did
|
||||
} else {
|
||||
_did = `did:pkh:eip155:0:${address.toLowerCase()}`
|
||||
}
|
||||
|
||||
return _did
|
||||
}
|
||||
|
||||
const getConversations = async (did: string = null) => {
|
||||
const { data } = await orbis.getConversations({
|
||||
did,
|
||||
@ -205,41 +233,35 @@ function OrbisProvider({ children }: { children: ReactNode }): ReactElement {
|
||||
}
|
||||
|
||||
const getMessageNotifs = async () => {
|
||||
let did = account?.did
|
||||
|
||||
if (!did && accountId) {
|
||||
did = await getDid(accountId)
|
||||
}
|
||||
|
||||
const { data, error } = await orbis.api.rpc('orbis_f_notifications', {
|
||||
user_did: account?.did || 'none',
|
||||
user_did: did || 'none',
|
||||
notif_type: 'messages'
|
||||
})
|
||||
|
||||
console.log({ did, data, error })
|
||||
|
||||
if (error) {
|
||||
setUnreadMessages([])
|
||||
} else if (data.length > 0) {
|
||||
const _unreads = data.filter((o: IOrbisNotification) => {
|
||||
return o.status === 'new'
|
||||
})
|
||||
setUnreadMessages(_unreads)
|
||||
// Check if did is mainnet
|
||||
const chainId = parseInt(did.split(':')[3])
|
||||
if (chainId === 0) {
|
||||
setUnreadMessages(data)
|
||||
} else {
|
||||
const _unreads = data.filter((o: IOrbisNotification) => {
|
||||
return o.status === 'new'
|
||||
})
|
||||
setUnreadMessages(_unreads)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getDid = async (address: string) => {
|
||||
if (!address) return null
|
||||
|
||||
const { data, error } = await orbis.getDids(address)
|
||||
|
||||
if (error) {
|
||||
return
|
||||
}
|
||||
|
||||
let _did: string = null
|
||||
|
||||
if (data && data.length > 0) {
|
||||
_did = data[0].did
|
||||
} else {
|
||||
_did = `did:pkh:eip155:0:${address.toLowerCase()}`
|
||||
}
|
||||
|
||||
return _did
|
||||
}
|
||||
|
||||
useInterval(async () => {
|
||||
await getMessageNotifs()
|
||||
}, NOTIFICATION_REFRESH_INTERVAL)
|
||||
|
16
src/@types/Orbis.d.ts
vendored
16
src/@types/Orbis.d.ts
vendored
@ -164,11 +164,17 @@ declare interface IOrbis {
|
||||
error: any
|
||||
status: number
|
||||
}>
|
||||
getNotifications: (options: { type: string; context?: string }) => Promise<{
|
||||
data: any
|
||||
error: any
|
||||
status: number
|
||||
}>
|
||||
getNotifications: (
|
||||
options: {
|
||||
context: string
|
||||
did: string
|
||||
master?: string
|
||||
only_master?: boolean
|
||||
tag?: string
|
||||
algorithm?: string
|
||||
},
|
||||
page: number
|
||||
) => Promise<any>
|
||||
getPost: (post_id: string) => Promise<{
|
||||
data: IOrbisPost
|
||||
error: any
|
||||
|
@ -7,7 +7,6 @@ import ChevronUp from '@images/chevronup.svg'
|
||||
|
||||
export default function Header() {
|
||||
const {
|
||||
// unreadMessages,
|
||||
conversationId,
|
||||
openConversations,
|
||||
conversationTitle,
|
||||
|
Loading…
Reference in New Issue
Block a user