-
Notifications
You must be signed in to change notification settings - Fork 15
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
|
@@ -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() | ||
|
||
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!!, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I don't know if there is a better kotlin way to do this tho There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, does kotlin remove the field entirely if the value is null? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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", | ||
|
@@ -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) { | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 codeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, feel that