-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/TRA-329-trade-isolated-margin-receip…
…t-lines-liquidation-price
- Loading branch information
Showing
13 changed files
with
361 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 10 additions & 15 deletions
25
src/commonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
package exchange.dydx.abacus.processor.router.skip | ||
|
||
import exchange.dydx.abacus.processor.base.BaseProcessor | ||
import exchange.dydx.abacus.output.input.SelectionOption | ||
import exchange.dydx.abacus.protocols.ParserProtocol | ||
|
||
internal class SkipChainProcessor(parser: ParserProtocol) : BaseProcessor(parser) { | ||
private val keyMap = mapOf( | ||
"string" to mapOf( | ||
"chain_name" to "stringKey", | ||
"networkIdentifier" to "stringKey", | ||
"chain_id" to "type", | ||
"logo_uri" to "iconUrl", | ||
), | ||
) | ||
|
||
override fun received( | ||
existing: Map<String, Any>?, | ||
internal class SkipChainProcessor(private val parser: ParserProtocol) { | ||
fun received( | ||
payload: Map<String, Any> | ||
): Map<String, Any> { | ||
return transform(existing, payload, keyMap) | ||
): SelectionOption { | ||
return SelectionOption( | ||
stringKey = parser.asString(payload["network_identifier"]) ?: parser.asString(payload["chain_name"]), | ||
string = parser.asString(payload["network_identifier"]) ?: parser.asString(payload["chain_name"]), | ||
type = parser.asString(payload["chain_id"]) ?: "", | ||
iconUrl = parser.asString(payload["logo_uri"]), | ||
) | ||
} | ||
} |
26 changes: 11 additions & 15 deletions
26
...ommonMain/kotlin/exchange.dydx.abacus/processor/router/skip/SkipChainResourceProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
package exchange.dydx.abacus.processor.router.skip | ||
|
||
import exchange.dydx.abacus.processor.base.BaseProcessor | ||
import exchange.dydx.abacus.output.input.TransferInputChainResource | ||
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"]), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/commonTest/kotlin/exchange.dydx.abacus/processor/router/skip/SkipProcessorTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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 | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.jsonObject | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
internal fun templateToJson(template: String): Map<String, Any> { | ||
return Json.parseToJsonElement(template.trimIndent()).jsonObject.toMap() | ||
} | ||
|
||
class SkipProcessorTests { | ||
|
||
internal val internalState = InternalTransferInputState() | ||
internal val skipProcessor = SkipProcessor(parser = Parser(), internalState = internalState) | ||
internal val skipChainsMock = SkipChainsMock() | ||
|
||
@Test | ||
fun testReceivedChains() { | ||
val modified = skipProcessor.receivedChains( | ||
existing = mapOf(), | ||
payload = templateToJson( | ||
skipChainsMock.payload, | ||
), | ||
) | ||
|
||
val expectedChains = listOf( | ||
SelectionOption(stringKey = "Ethereum", string = "Ethereum", type = "1", iconUrl = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png"), | ||
SelectionOption(stringKey = "aura", string = "aura", type = "xstaxy-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/xstaxy/chain.png"), | ||
SelectionOption(stringKey = "cheqd", string = "cheqd", type = "cheqd-mainnet-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/cheqd-mainnet/chain.png"), | ||
SelectionOption(stringKey = "kujira", string = "kujira", type = "kaiyo-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/kaiyo/chain.png"), | ||
SelectionOption(stringKey = "osmosis", string = "osmosis", type = "osmosis-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/osmosis/chain.png"), | ||
SelectionOption(stringKey = "stride", string = "stride", type = "stride-1", iconUrl = "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/stride/chain.png"), | ||
) | ||
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", | ||
), | ||
) | ||
assertEquals(expectedModified, modified) | ||
} | ||
} |
Oops, something went wrong.