Skip to content

Commit

Permalink
create memo field for transferInput (#401)
Browse files Browse the repository at this point in the history
Co-authored-by: mobile-build-bot-git <[email protected]>
  • Loading branch information
2 people authored and yogurtandjam committed May 31, 2024
1 parent 1296b6b commit 303bc08
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 4 deletions.
79 changes: 77 additions & 2 deletions docs/Input/TransferInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ data class TransferInput(
&emsp;val fee: Double?,
&emsp;val chain: String?,
&emsp;val address: String?,
&emsp;val memo: String?,
&emsp;val depositOptions: DepositInputOptions?,
&emsp;val withdrawalOptions: WithdrawalInputOptions?,
&emsp;val transferOutOptions: TransferOutInputOptions?,
&emsp;val summary: TransferInputSummary?,
&emsp;val resources: TransferInputResources?,
&emsp;val requestPayload: TransferInputRequestPayload?
Expand Down Expand Up @@ -39,10 +42,22 @@ Selected chain to perform the transfer

Selected token address of the chain to perform the transfer

## memo

Memo for transfer

## depositOptions

structure of [DepositInputOptions](#DepositInputOptions)

## withdrawalOptions

structure of [WithdrawalInputOptions](#WithdrawalInputOptions)

## transferOutOptions

structure of [TransferOutInputOptions](#TransferOutInputOptions)

## summary

structure of [TransferInputSummary](#TransferInputSummary)
Expand Down Expand Up @@ -80,6 +95,66 @@ UX should let the user choose whether to use fast speed

Option of assets to choose from

# WithdrawalInputOptions

data class DepositInputOptions(
&emsp;val needsSize: Boolean?,
&emsp;val needsAddress: Boolean?,
&emsp;val needsFastSpeed: Boolean?,
&emsp;val exchanges: Array<SelectionOption>?
&emsp;val chains: Array<SelectionOption>?
&emsp;val assets: Array<SelectionOption>?
)

## needsSize

UX should let user enter the size

## needsAddress

UX should let user enter a wallet address

## needsFastSpeed

UX should let the user choose whether to use fast speed

## exchanges

Option of exchanges to choose from

## chains

Option of chains to choose from

## assets

Option of assets to choose from

# TransferOutInputOptions

data class TransferOutInputOptions(
&emsp;val needsSize: Boolean?,
&emsp;val needsAddress: Boolean?,
&emsp;val chains: Array<SelectionOption>?,
&emsp;val assets: Array<SelectionOption>?
)

## needsSize

UX should let user enter the size

## needsAddress

UX should let user enter a wallet address

## chains

Option of chains to choose from

## assets

Option of assets to choose from

# TransferInputSummary

data class TransferInputSummary(
Expand All @@ -102,7 +177,7 @@ Whether the transfer transaction can be filled

# TransferInputResources

The chain and token resources of the selected chain and its associated tokens. Use the chainId
The chain and token resources of the selected chain and its associated tokens. Use the chainId
and token address of the key to the maps, respectively, to get the resource.

data class TransferInputResources(
Expand Down Expand Up @@ -147,4 +222,4 @@ data class TransferInputRequestPayload(
&emsp;val gasPrice: String?,
&emsp;val maxFeePerGas: String?,
&emsp;val maxPriorityFeePerGas: String?
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ data class TransferOutInputOptions(
val needsSize: Boolean?,
val needsAddress: Boolean?,
val chains: IList<SelectionOption>?,
val assets: IList<SelectionOption>?
val assets: IList<SelectionOption>?,
) {
companion object {
internal fun create(
Expand Down Expand Up @@ -474,6 +474,7 @@ data class TransferInput(
val chain: String?,
val token: String?,
val address: String?,
val memo: String?,
val depositOptions: DepositInputOptions?,
val withdrawalOptions: WithdrawalInputOptions?,
val transferOutOptions: TransferOutInputOptions?,
Expand Down Expand Up @@ -509,6 +510,7 @@ data class TransferInput(
val chain = parser.asString(data["chain"])
val token = parser.asString(data["token"])
val address = parser.asString(data["address"])
val memo = parser.asString(data["memo"])

var depositOptions: DepositInputOptions? = null
if (type == TransferType.deposit) {
Expand Down Expand Up @@ -577,6 +579,7 @@ data class TransferInput(
existing.chain != chain ||
existing.token != token ||
existing.address != address ||
existing.memo != memo ||
existing.depositOptions != depositOptions ||
existing.withdrawalOptions != withdrawalOptions ||
existing.transferOutOptions != transferOutOptions ||
Expand All @@ -595,6 +598,7 @@ data class TransferInput(
chain,
token,
address,
memo,
depositOptions,
withdrawalOptions,
transferOutOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum class TransferInputField(val rawValue: String) {
chain("chain"),
token("token"),
address("address"),
MEMO("memo"),
fastSpeed("fastSpeed");

companion object {
Expand Down Expand Up @@ -69,6 +70,7 @@ fun TradingStateMachine.transfer(
transfer.safeSet("size.usdcSize", null)
transfer.safeSet("route", null)
transfer.safeSet("requestPayload", null)
transfer.safeSet("memo", null)
if (parser.asString(data) == "TRANSFER_OUT") {
transfer.safeSet("chain", "chain")
transfer.safeSet("token", "usdc")
Expand Down Expand Up @@ -135,7 +137,6 @@ fun TradingStateMachine.transfer(
iListOf(subaccountNumber),
)
}

TransferInputField.fastSpeed.rawValue -> {
transfer.safeSet(typeText, parser.asBool(data))
changes = StateChanges(
Expand Down Expand Up @@ -166,6 +167,14 @@ fun TradingStateMachine.transfer(
iListOf(subaccountNumber),
)
}
TransferInputField.MEMO.rawValue -> {
transfer.safeSet(typeText, parser.asString(data))
changes = StateChanges(
iListOf(Changes.input),
null,
iListOf(subaccountNumber),
)
}
else -> {}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class TransferInputTests : V3BaseTests() {

testTransferOutTransferInput()
perp.log("Transfer Out", time)

testTransferInputTypeChange()
}

private fun testDepositTransferInput() {
Expand Down Expand Up @@ -414,6 +416,10 @@ class TransferInputTests : V3BaseTests() {
perp.transfer("5000.0", TransferInputField.usdcSize)
}, null)

test({
perp.transfer("test memo", TransferInputField.MEMO)
}, null)

test(
{
perp.transfer("1000.0", TransferInputField.usdcSize)
Expand All @@ -423,6 +429,7 @@ class TransferInputTests : V3BaseTests() {
"input": {
"transfer": {
"type": "TRANSFER_OUT",
"memo": "test memo",
"size": {
"usdcSize": 1000.0
},
Expand Down Expand Up @@ -469,4 +476,70 @@ class TransferInputTests : V3BaseTests() {
},
)
}

private fun testTransferInputTypeChange() {
test(
{
perp.transfer("DEPOSIT", TransferInputField.type)
},
"""
{
"input": {
"transfer": {
"type": "DEPOSIT",
"memo": null
}
}
}
""".trimIndent(),
)

test(
{
perp.transfer("TRANSFER_OUT", TransferInputField.type)
},
"""
{
"input": {
"transfer": {
"type": "TRANSFER_OUT",
"memo": null
}
}
}
""".trimIndent(),
)

test(
{
perp.transfer("test memo", TransferInputField.MEMO)
},
"""
{
"input": {
"transfer": {
"type": "TRANSFER_OUT",
"memo": "test memo"
}
}
}
""".trimIndent(),
)

test(
{
perp.transfer("WITHDRAWAL", TransferInputField.type)
},
"""
{
"input": {
"transfer": {
"type": "WITHDRAWAL",
"memo": null
}
}
}
""".trimIndent(),
)
}
}

0 comments on commit 303bc08

Please sign in to comment.