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

TRCL-3695 Add configs for notification provider types #657

Merged
merged 8 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.11.7"
version = "1.11.8"

repositories {
google()
Expand Down
221 changes: 126 additions & 95 deletions integration/iOS/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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

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

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

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

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

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

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

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

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

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,77 @@ import exchange.dydx.abacus.state.manager.V4Environment
import exchange.dydx.abacus.state.manager.notification.providers.BlockRewardNotificationProvider
import exchange.dydx.abacus.state.manager.notification.providers.OrderStatusChangesNotificationProvider
import exchange.dydx.abacus.state.model.TradingStateMachine
import exchange.dydx.abacus.state.v2.supervisor.NotificationProviderType
import exchange.dydx.abacus.utils.IMap
import exchange.dydx.abacus.utils.JsonEncoder
import exchange.dydx.abacus.utils.ParsingHelper
import exchange.dydx.abacus.utils.UIImplementations
import kollections.toIMap

interface NotificationsProviderProtocol {
internal interface NotificationsProviderProtocol {
fun buildNotifications(
subaccountNumber: Int
): IMap<String, Notification>
}

class NotificationsProvider(
internal class NotificationsProvider(
private val stateMachine: TradingStateMachine,
private val uiImplementations: UIImplementations,
private val environment: V4Environment,
private val parser: ParserProtocol,
private val jsonEncoder: JsonEncoder,
private val useParentSubaccount: Boolean = false,
private val providers: List<NotificationsProviderProtocol> = listOf(
BlockRewardNotificationProvider(
stateMachine,
uiImplementations,
environment,
jsonEncoder,
),
FillsNotificationProvider(
stateMachine,
uiImplementations,
parser,
jsonEncoder,
),
PositionsNotificationProvider(
stateMachine,
uiImplementations,
parser,
jsonEncoder,
useParentSubaccount,
),
OrderStatusChangesNotificationProvider(
stateMachine,
uiImplementations,
parser,
jsonEncoder,
),
val notifications: List<NotificationProviderType> = listOf(
NotificationProviderType.BlackReward,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚫ Blockreward ⚫

NotificationProviderType.Fills,
NotificationProviderType.Positions,
NotificationProviderType.OrderStatusChange,
),
private val providers: List<NotificationsProviderProtocol> = listOfNotNull(
if (notifications.contains(NotificationProviderType.BlackReward)) {
BlockRewardNotificationProvider(
stateMachine,
uiImplementations,
environment,
jsonEncoder,
)
} else {
null
},

if (notifications.contains(NotificationProviderType.Fills)) {
FillsNotificationProvider(
stateMachine,
uiImplementations,
parser,
jsonEncoder,
)
} else {
null
},

if (notifications.contains(NotificationProviderType.Positions)) {
PositionsNotificationProvider(
stateMachine,
uiImplementations,
parser,
jsonEncoder,
useParentSubaccount,
)
} else {
null
},

if (notifications.contains(NotificationProviderType.OrderStatusChange)) {
OrderStatusChangesNotificationProvider(
stateMachine,
uiImplementations,
parser,
jsonEncoder,
)
} else {
null
},
),
) : NotificationsProviderProtocol {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ class FillsNotificationProvider(

val notificationId = "order:$orderId"
return Notification(
notificationId,
NotificationType.INFO,
NotificationPriority.NORMAL,
marketImageUrl,
title,
text,
"/orders/$orderId",
paramsAsJson,
fill.createdAtMilliseconds,
id = notificationId,
type = NotificationType.INFO,
priority = NotificationPriority.NORMAL,
image = marketImageUrl,
title = title,
text = text,
link = "/orders/$orderId",
data = paramsAsJson,
updateTimeInMilliseconds = fill.createdAtMilliseconds,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ class PositionsNotificationProvider(

val notificationId = "position:$marketId"
notifications[notificationId] = Notification(
notificationId,
NotificationType.INFO,
NotificationPriority.NORMAL,
marketImageUrl,
title,
text,
null,
paramsAsJson,
closedAt.toEpochMilliseconds().toDouble(),
id = notificationId,
type = NotificationType.INFO,
priority = NotificationPriority.NORMAL,
image = marketImageUrl,
title = title,
text = text,
link = null,
data = paramsAsJson,
updateTimeInMilliseconds = closedAt.toEpochMilliseconds().toDouble(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,20 @@ data class MarketsConfigs(
}
}

enum class SubaccountSubscriptionType {
SUBACCOUNT,
PARENT_SUBACCOUNT,
NONE,
}

@JsExport
data class SubaccountConfigs(
val retrieveFills: Boolean,
val retrieveTransfers: Boolean,
val retrieveHistoricalPnls: Boolean,
val subscribeToSubaccount: Boolean,
val useParentSubaccount: Boolean,
var notifications: List<NotificationProviderType> =
listOf(
NotificationProviderType.BlackReward,
NotificationProviderType.Fills,
NotificationProviderType.OrderStatusChange,
NotificationProviderType.Positions,
),
) {
companion object {
val forApp = SubaccountConfigs(
Expand Down Expand Up @@ -173,7 +174,6 @@ data class OnboardingConfigs(
V2WithdrawalOnly,
}

var squidVersion: SquidVersion = SquidVersion.V2
var alchemyApiKey: String? = null

companion object {
Expand All @@ -186,6 +186,14 @@ data class OnboardingConfigs(
}
}

@JsExport
enum class NotificationProviderType {
BlackReward,
Fills,
OrderStatusChange,
Positions
}

@JsExport
data class AppConfigsV2(
val systemConfigs: SystemConfigs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ internal class SubaccountSupervisor(
}

private val notificationsProvider = NotificationsProvider(
stateMachine,
helper.uiImplementations,
helper.environment,
helper.parser,
helper.jsonEncoder,
configs.useParentSubaccount,
stateMachine = stateMachine,
uiImplementations = helper.uiImplementations,
environment = helper.environment,
parser = helper.parser,
jsonEncoder = helper.jsonEncoder,
useParentSubaccount = configs.useParentSubaccount,
notifications = configs.notifications,
)

internal var notifications: IMap<String, Notification> = iMapOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class PushNotificationRegistrationHandler(
if (helper.success(httpCode) && response != null) {
Logger.d { "Push notification token registered successfully" }
} else {
Logger.e { "Push notification token registration failed" }
Logger.e { "Push notification token registration failed: $response" }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'v4_abacus'
spec.version = '1.11.7'
spec.version = '1.11.8'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down
Loading