Skip to content

Commit

Permalink
update chain resources processor as well
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed May 30, 2024
1 parent bbbc67e commit 8b37a88
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ data class TransferOutInputOptions(
@Serializable
data class TransferInputChainResource(
val chainName: String?,
val rpc: String?,
val networkName: String?,
val rpc: String? = null,
val networkName: String? = null,
val chainId: Int?,
val iconUrl: String?
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package exchange.dydx.abacus.processor.router.skip

import exchange.dydx.abacus.output.input.TransferInputChainResource
import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.protocols.ParserProtocol

internal class SkipChainResourceProcessor(parser: ParserProtocol) : BaseProcessor(parser) {
private val keyMap = mapOf(
"string" to mapOf(
"chain_name" to "chainName",
"rpc" to "rpc",
"networkName" to "networkName",
"chain_id" to "chainId",
"logo_uri" to "iconUrl",
),
)
internal class SkipChainResourceProcessor(private val parser: ParserProtocol) {

override fun received(
existing: Map<String, Any>?,
fun received(
payload: Map<String, Any>
): Map<String, Any> {
return transform(existing, payload, keyMap)
): TransferInputChainResource {
return TransferInputChainResource(
chainName=parser.asString(payload["chain_name"]),
rpc=parser.asString(payload["rpc"]),
networkName=parser.asString(payload["networkName"]),
chainId=parser.asInt(payload["chain_id"]),
iconUrl=parser.asString(payload["logo_uri"]),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package exchange.dydx.abacus.processor.router.skip

import exchange.dydx.abacus.output.input.SelectionOption
import exchange.dydx.abacus.output.input.TransferInputChainResource
import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.processor.router.IRouterProcessor
import exchange.dydx.abacus.processor.router.SharedRouterProcessor
Expand Down Expand Up @@ -47,7 +48,7 @@ internal class SkipProcessor(
val selectedChainId = defaultChainId()
modified.safeSet("transfer.chain", selectedChainId)
selectedChainId?.let {
modified.safeSet("transfer.resources.chainResources", chainResources(selectedChainId))
internalState.chainResources = chainResources(chainId = selectedChainId)
}
return modified
}
Expand Down Expand Up @@ -117,15 +118,15 @@ internal class SkipProcessor(
throw NotImplementedError("defaultTokenAddress is not implemented in SkipProcessor!")
}

override fun chainResources(chainId: String?): Map<String, Any>? {
val chainResources = mutableMapOf<String, Any>()
override fun chainResources(chainId: String?): Map<String, TransferInputChainResource>? {
val chainResources = mutableMapOf<String, TransferInputChainResource>()
chainId?.let {
this.chains?.find {
parser.asString(parser.asNativeMap(it)?.get("chain_id")) == chainId
}?.let {
val processor = SkipChainResourceProcessor(parser)
parser.asNativeMap(it)?.let { payload ->
chainResources[chainId] = processor.received(null, payload)
chainResources[chainId] = processor.received(payload)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import exchange.dydx.abacus.state.manager.HumanReadableSubaccountTransferPayload
import exchange.dydx.abacus.state.manager.HumanReadableTransferPayload
import exchange.dydx.abacus.state.manager.HumanReadableWithdrawPayload
import exchange.dydx.abacus.state.manager.pendingCctpWithdraw
import exchange.dydx.abacus.state.model.TradingStateMachine
import exchange.dydx.abacus.state.model.*
import exchange.dydx.abacus.state.model.routerChains
import exchange.dydx.abacus.state.model.squidRoute
import exchange.dydx.abacus.state.model.squidRouteV2
import exchange.dydx.abacus.state.model.squidStatus
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package exchange.dydx.abacus.processor.router.skip
import exchange.dydx.abacus.output.input.SelectionOption
import exchange.dydx.abacus.output.input.TransferInputChainResource
import exchange.dydx.abacus.state.internalstate.InternalTransferInputState
import exchange.dydx.abacus.tests.payloads.SkipChainsMock
import exchange.dydx.abacus.utils.Parser
Expand Down Expand Up @@ -37,18 +38,18 @@ class SkipProcessorTests {
)
assertEquals(expectedChains, internalState.chains)

val expectedChainResources = mapOf(
"1" to TransferInputChainResource(
chainName = "Ethereum",
chainId = 1,
iconUrl = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
)
)
assertEquals(expectedChainResources, internalState.chainResources)

val expectedModified = mapOf(
"transfer" to mapOf(
"chain" to "1",
"resources" to mapOf(
"chainResources" to mapOf(
"1" to mapOf(
"chainName" to "Ethereum",
"chainId" to "1",
"iconUrl" to "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
),
),
),
),
)
assertEquals(expectedModified, modified)
Expand Down

0 comments on commit 8b37a88

Please sign in to comment.