Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BEDS-486) API: rename notification response structs #1231

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions backend/pkg/api/handlers/public.go

Large diffs are not rendered by default.

44 changes: 16 additions & 28 deletions backend/pkg/api/types/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ type NotificationOverviewData struct {
ClientsSubscriptionCount uint64 `db:"clients_subscription_count" json:"clients_subscription_count"`
NetworksSubscriptionCount uint64 `db:"networks_subscription_count" json:"networks_subscription_count"`
}

type InternalGetUserNotificationsResponse ApiDataResponse[NotificationOverviewData]
type GetUserNotificationsResponse ApiDataResponse[NotificationOverviewData]

// ------------------------------------------------------------
// Dashboards Table
Expand All @@ -43,8 +42,7 @@ type NotificationDashboardsTableRow struct {
EntityCount uint64 `db:"entity_count" json:"entity_count"`
EventTypes pq.StringArray `db:"event_types" json:"event_types" tstype:"('validator_online' | 'validator_offline' | 'group_efficiency_below' | 'attestation_missed' | 'proposal_success' | 'proposal_missed' | 'proposal_upcoming' | 'max_collateral' | 'min_collateral' | 'sync' | 'withdrawal' | 'validator_got_slashed' | 'validator_has_slashed' | 'incoming_tx' | 'outgoing_tx' | 'transfer_erc20' | 'transfer_erc721' | 'transfer_erc1155')[]" faker:"slice_len=2, oneof: validator_online, validator_offline, group_efficiency_below, attestation_missed, proposal_success, proposal_missed, proposal_upcoming, max_collateral, min_collateral, sync, withdrawal, validator_got_slashed, validator_has_slashed, incoming_tx, outgoing_tx, transfer_erc20, transfer_erc721, transfer_erc1155"`
}

type InternalGetUserNotificationDashboardsResponse ApiPagingResponse[NotificationDashboardsTableRow]
type GetUserNotificationDashboardsResponse ApiPagingResponse[NotificationDashboardsTableRow]

// ------------------------------------------------------------
// Validator Dashboard Notification Detail
Expand All @@ -53,13 +51,11 @@ type NotificationEventValidatorBackOnline struct {
Index uint64 `json:"index"`
EpochCount uint64 `json:"epoch_count"`
}

type NotificationEventWithdrawal struct {
Index uint64 `json:"index"`
Amount decimal.Decimal `json:"amount"`
Address Address `json:"address"`
}

type NotificationValidatorDashboardDetail struct {
DashboardName string `db:"dashboard_name" json:"dashboard_name"`
GroupName string `db:"group_name" json:"group_name"`
Expand All @@ -77,25 +73,22 @@ type NotificationValidatorDashboardDetail struct {
MinCollateral []Address `json:"min_collateral"` // node addresses
MaxCollateral []Address `json:"max_collateral"` // node addresses
}

type InternalGetUserNotificationsValidatorDashboardResponse ApiDataResponse[NotificationValidatorDashboardDetail]
type GetUserNotificationsValidatorDashboardResponse ApiDataResponse[NotificationValidatorDashboardDetail]

type NotificationEventExecution struct {
Address Address `json:"address"`
Amount decimal.Decimal `json:"amount"`
TransactionHash Hash `json:"transaction_hash"`
TokenName string `json:"token_name"` // this field will prob change depending on how execution stuff is implemented
}

type NotificationAccountDashboardDetail struct {
IncomingTransactions []NotificationEventExecution `json:"incoming_transactions"`
OutgoingTransactions []NotificationEventExecution `json:"outgoing_transactions"`
ERC20TokenTransfers []NotificationEventExecution `json:"erc20_token_transfers"`
ERC721TokenTransfers []NotificationEventExecution `json:"erc721_token_transfers"`
ERC1155TokenTransfers []NotificationEventExecution `json:"erc1155_token_transfers"`
}

type InternalGetUserNotificationsAccountDashboardResponse ApiDataResponse[NotificationAccountDashboardDetail]
type GetUserNotificationsAccountDashboardResponse ApiDataResponse[NotificationAccountDashboardDetail]

// ------------------------------------------------------------
// Machines Table
Expand All @@ -105,8 +98,7 @@ type NotificationMachinesTableRow struct {
EventType string `json:"event_type" tstype:"'offline' | 'storage' | 'cpu' | 'memory'" faker:"oneof: offline, storage, cpu, memory"`
Timestamp int64 `json:"timestamp"`
}

type InternalGetUserNotificationMachinesResponse ApiPagingResponse[NotificationMachinesTableRow]
type GetUserNotificationMachinesResponse ApiPagingResponse[NotificationMachinesTableRow]

// ------------------------------------------------------------
// Clients Table
Expand All @@ -116,8 +108,7 @@ type NotificationClientsTableRow struct {
Url string `json:"url"`
Timestamp int64 `json:"timestamp"`
}

type InternalGetUserNotificationClientsResponse ApiPagingResponse[NotificationClientsTableRow]
type GetUserNotificationClientsResponse ApiPagingResponse[NotificationClientsTableRow]

// ------------------------------------------------------------
// Networks Table
Expand All @@ -127,8 +118,7 @@ type NotificationNetworksTableRow struct {
EventType string `json:"event_type" tstype:"'new_reward_round' | 'gas_above' | 'gas_below' | 'participation_rate'" faker:"oneof: new_reward_round, gas_above, gas_below, participation_rate"`
Threshold decimal.Decimal `json:"threshold,omitempty"` // participation rate threshold should also be passed as decimal string
}

type InternalGetUserNotificationNetworksResponse ApiPagingResponse[NotificationNetworksTableRow]
type GetUserNotificationNetworksResponse ApiPagingResponse[NotificationNetworksTableRow]

// ------------------------------------------------------------
// Notification Settings
Expand All @@ -145,24 +135,23 @@ type NotificationNetwork struct {
ChainId uint64 `json:"chain_id"`
Settings NotificationSettingsNetwork `json:"settings"`
}
type InternalPutUserNotificationSettingsNetworksResponse ApiDataResponse[NotificationNetwork]
type PutUserNotificationSettingsNetworksResponse ApiDataResponse[NotificationNetwork]

type NotificationPairedDevice struct {
Id uint64 `json:"id"`
PairedTimestamp int64 `json:"paired_timestamp"`
Name string `json:"name,omitempty"`
IsNotificationsEnabled bool `json:"is_notifications_enabled"`
}
type InternalPutUserNotificationSettingsPairedDevicesResponse ApiDataResponse[NotificationPairedDevice]
type PutUserNotificationSettingsPairedDevicesResponse ApiDataResponse[NotificationPairedDevice]

type NotificationSettingsClient struct {
Id uint64 `json:"id"`
Name string `json:"name"`
Category string `json:"category" tstype:"'execution_layer' | 'consensus_layer' | 'other'" faker:"oneof: execution_layer, consensus_layer, other"`
IsSubscribed bool `json:"is_subscribed"`
}

type InternalPutUserNotificationSettingsClientResponse ApiDataResponse[NotificationSettingsClient]
type PutUserNotificationSettingsClientResponse ApiDataResponse[NotificationSettingsClient]

type NotificationSettingsGeneral struct {
DoNotDisturbTimestamp int64 `json:"do_not_disturb_timestamp"` // notifications are disabled until this timestamp
Expand All @@ -178,15 +167,16 @@ type NotificationSettingsGeneral struct {
IsMachineMemoryUsageSubscribed bool `json:"is_machine_memory_usage_subscribed"`
MachineMemoryUsageThreshold float64 `json:"machine_memory_usage_threshold" faker:"boundary_start=0, boundary_end=1"`
}
type InternalPutUserNotificationSettingsGeneralResponse ApiDataResponse[NotificationSettingsGeneral]
type PutUserNotificationSettingsGeneralResponse ApiDataResponse[NotificationSettingsGeneral]

type NotificationSettings struct {
GeneralSettings NotificationSettingsGeneral `json:"general_settings"`
HasMachines bool `json:"has_machines"`
Networks []NotificationNetwork `json:"networks"`
PairedDevices []NotificationPairedDevice `json:"paired_devices"`
Clients []NotificationSettingsClient `json:"clients" faker:"slice_len=10"`
}
type InternalGetUserNotificationSettingsResponse ApiDataResponse[NotificationSettings]
type GetUserNotificationSettingsResponse ApiDataResponse[NotificationSettings]

type NotificationSettingsValidatorDashboard struct {
WebhookUrl string `json:"webhook_url" faker:"url"`
Expand All @@ -207,8 +197,7 @@ type NotificationSettingsValidatorDashboard struct {
IsMinCollateralSubscribed bool `json:"is_min_collateral_subscribed"`
MinCollateralThreshold float64 `json:"min_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
}

type InternalPutUserNotificationSettingsValidatorDashboardResponse ApiDataResponse[NotificationSettingsValidatorDashboard]
type PutUserNotificationSettingsValidatorDashboardResponse ApiDataResponse[NotificationSettingsValidatorDashboard]

type NotificationSettingsAccountDashboard struct {
WebhookUrl string `json:"webhook_url" faker:"url"`
Expand All @@ -223,7 +212,7 @@ type NotificationSettingsAccountDashboard struct {
IsERC721TokenTransfersSubscribed bool `json:"is_erc721_token_transfers_subscribed"`
IsERC1155TokenTransfersSubscribed bool `json:"is_erc1155_token_transfers_subscribed"`
}
type InternalPutUserNotificationSettingsAccountDashboardResponse ApiDataResponse[NotificationSettingsAccountDashboard]
type PutUserNotificationSettingsAccountDashboardResponse ApiDataResponse[NotificationSettingsAccountDashboard]

type NotificationSettingsDashboardsTableRow struct {
IsAccountDashboard bool `json:"is_account_dashboard"` // if false it's a validator dashboard
Expand All @@ -235,5 +224,4 @@ type NotificationSettingsDashboardsTableRow struct {
Settings interface{} `json:"settings" tstype:"NotificationSettingsAccountDashboard | NotificationSettingsValidatorDashboard" faker:"-"`
ChainIds []uint64 `json:"chain_ids" faker:"chain_ids"`
}

type InternalGetUserNotificationSettingsDashboardsResponse ApiPagingResponse[NotificationSettingsDashboardsTableRow]
type GetUserNotificationSettingsDashboardsResponse ApiPagingResponse[NotificationSettingsDashboardsTableRow]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { TableQueryParams } from '~/types/datatable'

import type {
InternalGetUserNotificationSettingsDashboardsResponse,
InternalPutUserNotificationSettingsAccountDashboardResponse,
InternalPutUserNotificationSettingsValidatorDashboardResponse,
GetUserNotificationSettingsDashboardsResponse,
NotificationSettingsAccountDashboard,
NotificationSettingsDashboardsTableRow,
NotificationSettingsValidatorDashboard,
PutUserNotificationSettingsAccountDashboardResponse,
PutUserNotificationSettingsValidatorDashboardResponse,
} from '~/types/api/notifications'

export function useNotificationsManagementDashboards() {
const { fetch } = useCustomFetch()
const { refreshOverview } = useNotificationsDashboardOverviewStore()
const data = ref<InternalGetUserNotificationSettingsDashboardsResponse>()
const data = ref<GetUserNotificationSettingsDashboardsResponse>()
const {
cursor,
isStoredQuery,
Expand All @@ -36,7 +36,7 @@ export function useNotificationsManagementDashboards() {
isLoading.value = true
setStoredQuery(q)
const res
= await fetch<InternalGetUserNotificationSettingsDashboardsResponse>(
= await fetch<GetUserNotificationSettingsDashboardsResponse>(
'GET_NOTIFICATIONS_SETTINGS_DASHBOARD',
undefined,
undefined,
Expand Down Expand Up @@ -72,30 +72,30 @@ export function useNotificationsManagementDashboards() {
settings.webhook_url = ''
settings.is_webhook_discord_enabled = false
if (is_account_dashboard) {
const accountDashboarSettings = settings as NotificationSettingsAccountDashboard
accountDashboarSettings.erc20_token_transfers_value_threshold = 0
accountDashboarSettings.is_erc1155_token_transfers_subscribed = false
accountDashboarSettings.is_erc20_token_transfers_subscribed = false
accountDashboarSettings.is_erc721_token_transfers_subscribed = false
accountDashboarSettings.is_ignore_spam_transactions_enabled = false
accountDashboarSettings.is_incoming_transactions_subscribed = false
accountDashboarSettings.is_outgoing_transactions_subscribed = false
const accountDashboardSettings = settings as NotificationSettingsAccountDashboard
accountDashboardSettings.erc20_token_transfers_value_threshold = 0
accountDashboardSettings.is_erc1155_token_transfers_subscribed = false
accountDashboardSettings.is_erc20_token_transfers_subscribed = false
accountDashboardSettings.is_erc721_token_transfers_subscribed = false
accountDashboardSettings.is_ignore_spam_transactions_enabled = false
accountDashboardSettings.is_incoming_transactions_subscribed = false
accountDashboardSettings.is_outgoing_transactions_subscribed = false
return
}
const accountDashboarSettings = settings as NotificationSettingsValidatorDashboard
accountDashboarSettings.group_efficiency_below_threshold = 0
accountDashboarSettings.is_attestations_missed_subscribed = false
accountDashboarSettings.is_block_proposal_subscribed = false
accountDashboarSettings.is_group_efficiency_below_subscribed = false
accountDashboarSettings.is_max_collateral_subscribed = false
accountDashboarSettings.is_min_collateral_subscribed = false
accountDashboarSettings.is_slashed_subscribed = false
accountDashboarSettings.is_sync_subscribed = false
accountDashboarSettings.is_upcoming_block_proposal_subscribed = false
accountDashboarSettings.is_validator_offline_subscribed = false
accountDashboarSettings.is_withdrawal_processed_subscribed = false
accountDashboarSettings.max_collateral_threshold = 0
accountDashboarSettings.min_collateral_threshold = 0
const accountDashboardSettings = settings as NotificationSettingsValidatorDashboard
accountDashboardSettings.group_efficiency_below_threshold = 0
accountDashboardSettings.is_attestations_missed_subscribed = false
accountDashboardSettings.is_block_proposal_subscribed = false
accountDashboardSettings.is_group_efficiency_below_subscribed = false
accountDashboardSettings.is_max_collateral_subscribed = false
accountDashboardSettings.is_min_collateral_subscribed = false
accountDashboardSettings.is_slashed_subscribed = false
accountDashboardSettings.is_sync_subscribed = false
accountDashboardSettings.is_upcoming_block_proposal_subscribed = false
accountDashboardSettings.is_validator_offline_subscribed = false
accountDashboardSettings.is_withdrawal_processed_subscribed = false
accountDashboardSettings.max_collateral_threshold = 0
accountDashboardSettings.min_collateral_threshold = 0
}
const deleteDashboardNotifications = async (
{
Expand All @@ -117,7 +117,7 @@ export function useNotificationsManagementDashboards() {
settings,
})
if (is_account_dashboard) {
return await fetch<InternalPutUserNotificationSettingsAccountDashboardResponse>(
return await fetch<PutUserNotificationSettingsAccountDashboardResponse>(
'NOTIFICATIONS_MANAGEMENT_DASHBOARD_ACCOUNT_SET_NOTIFICATION',
{
body: settings,
Expand All @@ -128,7 +128,7 @@ export function useNotificationsManagementDashboards() {
},
)
}
return await fetch<InternalPutUserNotificationSettingsValidatorDashboardResponse>(
return await fetch<PutUserNotificationSettingsValidatorDashboardResponse>(
'NOTIFICATIONS_MANAGEMENT_DASHBOARD_VALIDATOR_SET_NOTIFICATION',
{
body: settings,
Expand Down Expand Up @@ -173,7 +173,7 @@ export function useNotificationsManagementDashboards() {
settings: NotificationSettingsValidatorDashboard,
},
) {
await fetch<InternalPutUserNotificationSettingsValidatorDashboardResponse>(
await fetch<PutUserNotificationSettingsValidatorDashboardResponse>(
'SAVE_VALIDATOR_DASHBOARDS_SETTINGS',
{
body: {
Expand Down
6 changes: 3 additions & 3 deletions frontend/stores/notifications/useNotificationsClientsStore.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defineStore } from 'pinia'
import type { InternalGetUserNotificationClientsResponse } from '~/types/api/notifications'
import type { GetUserNotificationClientsResponse } from '~/types/api/notifications'

import type { TableQueryParams } from '~/types/datatable'

const notificationsClientStore = defineStore('notifications-clients-store', () => {
const data = ref<InternalGetUserNotificationClientsResponse | undefined>()
const data = ref<GetUserNotificationClientsResponse | undefined>()
return { data }
})

Expand All @@ -24,7 +24,7 @@ export function useNotificationsClientStore() {
isLoading.value = true
setStoredQuery(q)
try {
const result = await fetch<InternalGetUserNotificationClientsResponse>(
const result = await fetch<GetUserNotificationClientsResponse>(
'NOTIFICATIONS_CLIENTS',
undefined,
undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {
InternalGetUserNotificationsValidatorDashboardResponse,
GetUserNotificationsValidatorDashboardResponse,
NotificationDashboardsTableRow, NotificationValidatorDashboardDetail,
} from '~/types/api/notifications'

Expand All @@ -18,7 +18,7 @@ export const useNotificationsDashboardDetailsStore = defineStore('notifications-
search?: string,
},
) => {
return fetch<InternalGetUserNotificationsValidatorDashboardResponse>(
return fetch<GetUserNotificationsValidatorDashboardResponse>(
'NOTIFICATIONS_DASHBOARDS_DETAILS_VALIDATOR',
{
query: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { defineStore } from 'pinia'
import type { InternalGetUserNotificationDashboardsResponse } from '~/types/api/notifications'
import type { GetUserNotificationDashboardsResponse } from '~/types/api/notifications'

import type { TableQueryParams } from '~/types/datatable'
import type { ChainIDs } from '~/types/network'

const notificationsDashboardStore = defineStore(
'notifications-dashboard-store',
() => {
const data = ref<InternalGetUserNotificationDashboardsResponse | undefined>()
const data = ref<GetUserNotificationDashboardsResponse | undefined>()
return { data }
},
)
Expand Down Expand Up @@ -38,7 +38,7 @@ export function useNotificationsDashboardStore(networkId: globalThis.Ref<ChainID
isLoading.value = true
setStoredQuery(q)
try {
const result = await fetch<InternalGetUserNotificationDashboardsResponse>(
const result = await fetch<GetUserNotificationDashboardsResponse>(
'NOTIFICATIONS_DASHBOARDS',
{ query: { networks: networkId.value } },
undefined,
Expand Down
6 changes: 3 additions & 3 deletions frontend/stores/notifications/useNotificationsMachineStore.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defineStore } from 'pinia'
import type { InternalGetUserNotificationMachinesResponse } from '~/types/api/notifications'
import type { GetUserNotificationMachinesResponse } from '~/types/api/notifications'

import type { TableQueryParams } from '~/types/datatable'

const notificationsMachineStore = defineStore('notifications-network-store', () => {
const data = ref<InternalGetUserNotificationMachinesResponse | undefined>()
const data = ref<GetUserNotificationMachinesResponse | undefined>()
return { data }
})

Expand All @@ -24,7 +24,7 @@ export function useNotificationsMachineStore() {
isLoading.value = true
setStoredQuery(q)
try {
const result = await fetch<InternalGetUserNotificationMachinesResponse>(
const result = await fetch<GetUserNotificationMachinesResponse>(
'NOTIFICATIONS_MACHINE',
undefined,
undefined,
Expand Down
Loading
Loading