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
|
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 getConversations = async (did: string = null) => {
|
||||||
const { data } = await orbis.getConversations({
|
const { data } = await orbis.getConversations({
|
||||||
did,
|
did,
|
||||||
@ -205,41 +233,35 @@ function OrbisProvider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getMessageNotifs = async () => {
|
const getMessageNotifs = async () => {
|
||||||
|
let did = account?.did
|
||||||
|
|
||||||
|
if (!did && accountId) {
|
||||||
|
did = await getDid(accountId)
|
||||||
|
}
|
||||||
|
|
||||||
const { data, error } = await orbis.api.rpc('orbis_f_notifications', {
|
const { data, error } = await orbis.api.rpc('orbis_f_notifications', {
|
||||||
user_did: account?.did || 'none',
|
user_did: did || 'none',
|
||||||
notif_type: 'messages'
|
notif_type: 'messages'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log({ did, data, error })
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
setUnreadMessages([])
|
setUnreadMessages([])
|
||||||
} else if (data.length > 0) {
|
} else if (data.length > 0) {
|
||||||
const _unreads = data.filter((o: IOrbisNotification) => {
|
// Check if did is mainnet
|
||||||
return o.status === 'new'
|
const chainId = parseInt(did.split(':')[3])
|
||||||
})
|
if (chainId === 0) {
|
||||||
setUnreadMessages(_unreads)
|
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 () => {
|
useInterval(async () => {
|
||||||
await getMessageNotifs()
|
await getMessageNotifs()
|
||||||
}, NOTIFICATION_REFRESH_INTERVAL)
|
}, 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
|
error: any
|
||||||
status: number
|
status: number
|
||||||
}>
|
}>
|
||||||
getNotifications: (options: { type: string; context?: string }) => Promise<{
|
getNotifications: (
|
||||||
data: any
|
options: {
|
||||||
error: any
|
context: string
|
||||||
status: number
|
did: string
|
||||||
}>
|
master?: string
|
||||||
|
only_master?: boolean
|
||||||
|
tag?: string
|
||||||
|
algorithm?: string
|
||||||
|
},
|
||||||
|
page: number
|
||||||
|
) => Promise<any>
|
||||||
getPost: (post_id: string) => Promise<{
|
getPost: (post_id: string) => Promise<{
|
||||||
data: IOrbisPost
|
data: IOrbisPost
|
||||||
error: any
|
error: any
|
||||||
|
@ -7,7 +7,6 @@ import ChevronUp from '@images/chevronup.svg'
|
|||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
const {
|
const {
|
||||||
// unreadMessages,
|
|
||||||
conversationId,
|
conversationId,
|
||||||
openConversations,
|
openConversations,
|
||||||
conversationTitle,
|
conversationTitle,
|
||||||
|
Loading…
Reference in New Issue
Block a user