-
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
Implement triggerCompliance, also implement compliance in V2 #333
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package exchange.dydx.abacus.state.v2.manager | ||
|
||
import exchange.dydx.abacus.output.Compliance | ||
import exchange.dydx.abacus.output.ComplianceAction | ||
import exchange.dydx.abacus.output.ComplianceStatus | ||
import exchange.dydx.abacus.output.Notification | ||
import exchange.dydx.abacus.output.PerpetualState | ||
import exchange.dydx.abacus.output.Restriction | ||
|
@@ -70,6 +73,7 @@ import exchange.dydx.abacus.state.v2.supervisor.stopWatchingLastOrder | |
import exchange.dydx.abacus.state.v2.supervisor.subaccountNumber | ||
import exchange.dydx.abacus.state.v2.supervisor.subaccountTransferPayload | ||
import exchange.dydx.abacus.state.v2.supervisor.trade | ||
import exchange.dydx.abacus.state.v2.supervisor.triggerCompliance | ||
import exchange.dydx.abacus.state.v2.supervisor.triggerOrders | ||
import exchange.dydx.abacus.state.v2.supervisor.triggerOrdersPayload | ||
import exchange.dydx.abacus.state.v2.supervisor.withdrawPayload | ||
|
@@ -81,6 +85,7 @@ import exchange.dydx.abacus.utils.Parser | |
import exchange.dydx.abacus.utils.UIImplementations | ||
import kollections.JsExport | ||
import kollections.iListOf | ||
import kollections.toIMap | ||
|
||
@JsExport | ||
internal class StateManagerAdaptorV2( | ||
|
@@ -170,6 +175,14 @@ internal class StateManagerAdaptorV2( | |
} | ||
} | ||
|
||
internal open var geo: String? = null | ||
set(value) { | ||
if (field != value) { | ||
field = value | ||
didSetGeo(value) | ||
} | ||
} | ||
|
||
internal var readyToConnect: Boolean = false | ||
internal set(value) { | ||
if (field != value) { | ||
|
@@ -298,6 +311,9 @@ internal class StateManagerAdaptorV2( | |
onboarding.readyToConnect = readyToConnect | ||
markets.readyToConnect = readyToConnect | ||
accounts.readyToConnect = readyToConnect | ||
if (readyToConnect) { | ||
fetchGeo() | ||
} | ||
} | ||
|
||
private fun didSetIndexerConnected(indexerConnected: Boolean) { | ||
|
@@ -429,6 +445,30 @@ internal class StateManagerAdaptorV2( | |
return null | ||
} | ||
|
||
private fun fetchGeo() { | ||
val url = environment.endpoints.geo | ||
if (url != null) { | ||
networkHelper.get( | ||
url, | ||
null, | ||
null, | ||
callback = { _, response, httpCode, _ -> | ||
geo = if (networkHelper.success(httpCode) && response != null) { | ||
val payload = networkHelper.parser.decodeJsonObject(response)?.toIMap() | ||
if (payload != null) { | ||
val country = networkHelper.parser.asString(networkHelper.parser.value(payload, "geo.country")) | ||
country | ||
} else { | ||
null | ||
} | ||
} else { | ||
null | ||
} | ||
}, | ||
) | ||
} | ||
} | ||
|
||
internal fun trade(data: String?, type: TradeInputField?) { | ||
accounts.trade(data, type) | ||
} | ||
|
@@ -553,6 +593,10 @@ internal class StateManagerAdaptorV2( | |
accounts.screen(address, callback) | ||
} | ||
|
||
internal fun triggerCompliance(address: ComplianceAction, callback: TransactionCallback) { | ||
accounts.triggerCompliance(address, callback) | ||
} | ||
|
||
private fun updateRestriction(indexerRestriction: UsageRestriction?) { | ||
restriction = indexerRestriction ?: accounts.addressRestriction ?: UsageRestriction.noRestriction | ||
} | ||
|
@@ -589,4 +633,37 @@ internal class StateManagerAdaptorV2( | |
) | ||
} | ||
} | ||
|
||
private fun didSetGeo(geo: String?) { | ||
val state = stateMachine.state | ||
stateMachine.state = PerpetualState( | ||
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. kotlin tip: |
||
state?.assets, | ||
state?.marketsSummary, | ||
state?.orderbooks, | ||
state?.candles, | ||
state?.trades, | ||
state?.historicalFundings, | ||
state?.wallet, | ||
state?.account, | ||
state?.historicalPnl, | ||
state?.fills, | ||
state?.transfers, | ||
state?.fundingPayments, | ||
state?.configs, | ||
state?.input, | ||
state?.availableSubaccountNumbers ?: iListOf(), | ||
state?.transferStatuses, | ||
state?.restriction, | ||
state?.launchIncentive, | ||
Compliance(geo, state?.compliance?.status ?: ComplianceStatus.COMPLIANT), | ||
) | ||
ioImplementations.threading?.async(ThreadingType.main) { | ||
stateNotification?.stateChanged( | ||
stateMachine.state, | ||
StateChanges( | ||
iListOf(Changes.restriction), | ||
), | ||
) | ||
} | ||
} | ||
} |
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.
Similar to your other PR, what is the purpose of the
callback
here? We're not doing anything asynchronous here.