From 8b37a8887f7322879c90ef0828e0dbb9cc373aa4 Mon Sep 17 00:00:00 2001 From: jeremy lee Date: Wed, 29 May 2024 22:29:09 -0400 Subject: [PATCH] update chain resources processor as well --- .../output/input/TransferInput.kt | 4 +-- .../router/skip/SkipChainResourceProcessor.kt | 25 ++++++++----------- .../processor/router/skip/SkipProcessor.kt | 9 ++++--- .../v2/supervisor/OnboardingSupervisor.kt | 3 ++- .../router/skip/SkipProcessorTests.kt | 19 +++++++------- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt b/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt index e094ef997..bca5f610e 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt @@ -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? ) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainResourceProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainResourceProcessor.kt index d4906869d..97025fdc3 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainResourceProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainResourceProcessor.kt @@ -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?, + fun received( payload: Map - ): Map { - 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"]), + ) } } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt index 8aac5ef8e..37e425405 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessor.kt @@ -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 @@ -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 } @@ -117,15 +118,15 @@ internal class SkipProcessor( throw NotImplementedError("defaultTokenAddress is not implemented in SkipProcessor!") } - override fun chainResources(chainId: String?): Map? { - val chainResources = mutableMapOf() + override fun chainResources(chainId: String?): Map? { + val chainResources = mutableMapOf() 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) } } } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt index a6b197be1..22a1cbcc2 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/OnboardingSupervisor.kt @@ -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 diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt index 087484ef3..84456fdd9 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt @@ -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 @@ -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)