Skip to content

Commit

Permalink
[plat-1111] add usdc purchase seller and buyer notifications (#3770)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrina-kiam authored Jul 24, 2023
1 parent bc04f52 commit ce2548e
Show file tree
Hide file tree
Showing 16 changed files with 551 additions and 67 deletions.
50 changes: 25 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/common/src/models/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export enum Name {
NOTIFICATIONS_CLICK_TRENDING_UNDERGROUND_TWITTER_SHARE = 'Notifications: Clicked Trending Underground Twitter Share',
NOTIFICATIONS_CLICK_TASTEMAKER_TWITTER_SHARE = 'Notifications: Clicked Tastemaker Twitter Share',
NOTIFICATIONS_CLICK_ADD_TRACK_TO_PLAYLIST_TWITTER_SHARE = 'Notifications: Clicked Add Track to Playlist Twitter Share',
NOTIFICATIONS_CLICK_USDC_PURCHASE_TWITTER_SHARE = 'Notifications: Clicked USDC Purchase Twitter Share',
NOTIFICATIONS_TOGGLE_SETTINGS = 'Notifications: Toggle Setting',
BROWSER_NOTIFICATION_SETTINGS = 'Browser Push Notification',

Expand Down Expand Up @@ -922,6 +923,10 @@ type NotificationsClickAddTrackToPlaylist = {
eventName: Name.NOTIFICATIONS_CLICK_ADD_TRACK_TO_PLAYLIST_TWITTER_SHARE
text: string
}
type NotificationsClickUSDCPurchaseBuyer = {
eventName: Name.NOTIFICATIONS_CLICK_USDC_PURCHASE_TWITTER_SHARE
text: string
}
type NotificationsClickTrendingTrack = {
eventName: Name.NOTIFICATIONS_CLICK_TRENDING_TRACK_TWITTER_SHARE
text: string
Expand Down Expand Up @@ -1737,6 +1742,7 @@ export type AllTrackingEvents =
| NotificationsClickTrendingPlaylist
| NotificationsClickTrendingTrack
| NotificationsClickTrendingUnderground
| NotificationsClickUSDCPurchaseBuyer
| NotificationsClickTastemaker
| NotificationsToggleSettings
| ProfilePageTabClick
Expand Down
40 changes: 39 additions & 1 deletion packages/common/src/services/audius-backend/AudiusBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,45 @@ export const audiusBackend = ({
entityType,
...formatBaseNotification(notification)
}
} else if (notification.type === 'usdc_purchase_seller') {
let entityId = 0
let entityType = Entity.Track
let amount = 0
const userIds = notification.actions
.map((action) => {
const data = action.data
entityId = decodeHashId(data.content_id) as number
entityType = Entity.Track
amount = data.amount
return decodeHashId(data.buyer_user_id)
})
.filter(removeNullable)
return {
type: NotificationType.USDCPurchaseSeller,
userIds,
entityId,
entityType,
amount,
...formatBaseNotification(notification)
}
} else if (notification.type === 'usdc_purchase_buyer') {
let entityId = 0
let entityType = Entity.Track
const userIds = notification.actions
.map((action) => {
const data = action.data
entityId = decodeHashId(data.content_id) as number
entityType = Entity.Track
return decodeHashId(data.seller_user_id)
})
.filter(removeNullable)
return {
type: NotificationType.USDCPurchaseBuyer,
userIds,
entityId,
entityType,
...formatBaseNotification(notification)
}
} else {
console.error('Notification does not match an expected type.')
}
Expand Down Expand Up @@ -2216,7 +2255,6 @@ export const audiusBackend = ({
}

const { unread_count, notifications } = response

return {
totalUnviewed: unread_count,
notifications: notifications.map(
Expand Down
39 changes: 38 additions & 1 deletion packages/common/src/store/notifications/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export enum NotificationType {
SupporterRankUp = 'SupporterRankUp',
SupportingRankUp = 'SupportingRankUp',
AddTrackToPlaylist = 'AddTrackToPlaylist',
SupporterDethroned = 'SupporterDethroned'
SupporterDethroned = 'SupporterDethroned',
USDCPurchaseSeller = 'USDCPurchaseSeller',
USDCPurchaseBuyer = 'USDCPurchaseBuyer'
}

export enum PushNotificationType {
Expand Down Expand Up @@ -240,6 +242,13 @@ export type DiscoveryCreatePlaylistNotificationAction = {
is_album: boolean
playlist_id: string[]
}
export type DiscoveryUSDCPurchaseNotificationAction = {
content_type: string
content_id: string
seller_user_id: string
buyer_user_id: string
amount: number
}

export type TrendingRange = 'week' | 'month' | 'year'

Expand Down Expand Up @@ -320,6 +329,14 @@ export type DiscoveryCreateNotification = DiscoveryBaseNotification<
| DiscoveryCreateTrackNotificationAction
| DiscoveryCreatePlaylistNotificationAction
>
export type DiscoveryUSDCPurchaseBuyerNotification = DiscoveryBaseNotification<
'usdc_purchase_buyer',
DiscoveryUSDCPurchaseNotificationAction
>
export type DiscoveryUSDCPurchaseSellerNotification = DiscoveryBaseNotification<
'usdc_purchase_seller',
DiscoveryUSDCPurchaseNotificationAction
>
export type DiscoveryTrendingPlaylistNotification = DiscoveryBaseNotification<
'trending_playlist',
{
Expand Down Expand Up @@ -379,6 +396,8 @@ export type DiscoveryNotification =
| DiscoverySaveOfRepostNotification
| DiscoveryAddTrackToPlaylistNotification
| DiscoveryTastemakerNotification
| DiscoveryUSDCPurchaseBuyerNotification
| DiscoveryUSDCPurchaseSellerNotification

export type AnnouncementNotification = BaseNotification & {
type: NotificationType.Announcement
Expand Down Expand Up @@ -722,6 +741,7 @@ export type TastemakerNotification = BaseNotification & {
export type ChallengeRewardNotification = BaseNotification & {
type: NotificationType.ChallengeReward
challengeId: ChallengeRewardID
entityType: string
}

export type TierChangeNotification = BaseNotification & {
Expand Down Expand Up @@ -866,6 +886,21 @@ export type AddTrackToPlaylistPushNotification = {
}
}

export type USDCPurchaseSellerNotification = BaseNotification & {
type: NotificationType.USDCPurchaseSeller
entityId: ID
userIds: ID[]
entityType: string
amount: number
}

export type USDCPurchaseBuyerNotification = BaseNotification & {
type: NotificationType.USDCPurchaseBuyer
entityId: ID
userIds: ID[]
entityType: string
}

export type Notification =
| AnnouncementNotification
| UserSubscriptionNotification
Expand All @@ -890,6 +925,8 @@ export type Notification =
| SupportingRankUpNotification
| SupporterDethronedNotification
| AddTrackToPlaylistNotification
| USDCPurchaseSellerNotification
| USDCPurchaseBuyerNotification

export type IdentityNotification = Omit<Notification, 'timestamp'> & {
timestamp: string
Expand Down
Loading

0 comments on commit ce2548e

Please sign in to comment.