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

feat: call compliance endpoint for keplr #588

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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.8.95"
version = "1.8.96"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class V4StateManagerConfigs(
"screen":"/v4/screen",
"complianceScreen":"/v4/compliance/screen",
"complianceGeoblock":"/v4/compliance/geoblock",
"complianceGeoblockKeplr":"/v4/compliance/geoblock-keplr",
"height":"/v4/height"
},
"private":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,15 @@ internal open class AccountSupervisor(
status: ComplianceStatus,
complianceAction: ComplianceAction
) {
val chainId = helper.environment.dydxChainId
val message = "Compliance verification message"
val payload =
helper.jsonEncoder.encode(
mapOf(
"message" to message,
"action" to complianceAction.toString(),
"status" to status.toString(),
"chainId" to chainId.toString(),
),
)
helper.transaction(
Expand All @@ -767,20 +769,29 @@ internal open class AccountSupervisor(
val result = helper.parser.decodeJsonObject(additionalPayload)

if (error == null && result != null) {
val url = complianceGeoblockUrl()
val signedMessage = helper.parser.asString(result["signedMessage"])
val publicKey = helper.parser.asString(result["publicKey"])
val timestamp = helper.parser.asString(result["timestamp"])
val isKeplr = helper.parser.asBool(result["isKeplr"])
val url = if (isKeplr == true) complianceGeoblockKeplrUrl() else complianceGeoblockUrl()
Copy link
Contributor

Choose a reason for hiding this comment

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

[discussion] we're starting to get a lot of branching in this function. you think it's worth splitting this into 2 separate functions? or creating 2 separate helper functions?

if this is urgent i'm down to stamp right away though since the logic makes sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely thought about it, and tried initially. Ended with this approach because the only code path change is just the body and url, but if you feel strongly I can take another stab!

Copy link
Contributor

Choose a reason for hiding this comment

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

nah no worries! i think we can do this as part of a larger cleanup task in the future to reduce code duplication. the OnboardingSupervisor is a really bad offender of this... so easy to make mistakes when updating things since there's so much duplicate code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, feel that


val isUrlAndKeysPresent =
url != null &&
signedMessage != null &&
publicKey != null &&
timestamp != null
publicKey != null && (timestamp != null || isKeplr == true)
rosepuppy marked this conversation as resolved.
Show resolved Hide resolved

val isStatusValid = status != ComplianceStatus.UNKNOWN

if (isUrlAndKeysPresent && isStatusValid) {
val body: IMap<String, String> =
val body: Map<String, String> =
if (isKeplr == true) {
iMapOf(
"address" to address.rawAddress,
"message" to message,
"action" to complianceAction.toString(),
"signedMessage" to signedMessage!!,
Copy link
Contributor

Choose a reason for hiding this comment

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

[q] why do these properties have to be assumed non-null? (i know it's part of previously committed code too, but curious if you have the answer)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just that the request needs all these fields.

I check for it to be not null with isUrlAndKeysPresent before the body gets used, so if anything is null, the request would not send.

I don't know if there is a better kotlin way to do this tho

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, does kotlin remove the field entirely if the value is null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh it will actually throw, thats a good catch actually. I think it should be inside the if statement

"pubkey" to publicKey!!,
)
} else {
iMapOf(
"address" to address.rawAddress,
"message" to message,
Expand All @@ -790,6 +801,9 @@ internal open class AccountSupervisor(
"pubkey" to publicKey!!,
"timestamp" to timestamp!!,
)
}

if (isUrlAndKeysPresent && isStatusValid) {
val header =
iMapOf(
"Content-Type" to "application/json",
Expand Down Expand Up @@ -853,6 +867,10 @@ internal open class AccountSupervisor(
return helper.configs.publicApiUrl("complianceGeoblock")
}

private fun complianceGeoblockKeplrUrl(): String? {
return helper.configs.publicApiUrl("complianceGeoblockKeplr")
}

open fun screenSourceAddress() {
val address = sourceAddress
if (address != null) {
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.8.95'
spec.version = '1.8.96'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down
Loading