Skip to content

Commit

Permalink
Add memo field for Ton sending and receiving
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Jan 18, 2024
1 parent fcdeb9f commit 041b422
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ dependencies {
debugImplementation leakCanary

// Wallet kits
implementation 'com.github.horizontalsystems:ton-kit-kmm:18bc110'
implementation 'com.github.horizontalsystems:ton-kit-kmm:90f9c77'
implementation 'com.github.horizontalsystems:bitcoin-kit-android:4956962'
implementation 'com.github.horizontalsystems:ethereum-kit-android:3a02f3a'
implementation 'com.github.horizontalsystems:blockchain-fee-rate-kit-android:1d3bd49'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ interface ISendSolanaAdapter {

interface ISendTonAdapter {
val availableBalance: BigDecimal
suspend fun send(amount: BigDecimal, address: String)
suspend fun send(amount: BigDecimal, address: String, memo: String?)
suspend fun estimateFee() : BigDecimal
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class TonAdapter(
source = wallet.transactionSource,
mainValue = TransactionValue.CoinValue(wallet.token, value),
fee = fee?.let { TransactionValue.CoinValue(wallet.token, it) },
memo = transaction.memo,
type = type,
transfers = transaction.transfers.map { createTransferRecprd(it) }
)
Expand Down Expand Up @@ -240,8 +241,8 @@ class TonAdapter(
override val availableBalance: BigDecimal
get() = balance

override suspend fun send(amount: BigDecimal, address: String) {
tonKit.send(address, amount.movePointRight(decimals).toBigInteger().toString())
override suspend fun send(amount: BigDecimal, address: String, memo: String?) {
tonKit.send(address, amount.movePointRight(decimals).toBigInteger().toString(), memo)
}

override suspend fun estimateFee(): BigDecimal {
Expand All @@ -261,6 +262,7 @@ class TonTransactionRecord(
source: TransactionSource,
override val mainValue: TransactionValue,
val fee: TransactionValue?,
val memo: String?,
val type: Type,
val transfers: List<TonTransfer>
) : TransactionRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fun HSMemoInput(
hint = stringResource(R.string.Send_DialogMemoHint),
hintColor = ComposeAppTheme.colors.grey50,
hintStyle = ComposeAppTheme.typography.bodyItalic,
textColor = ComposeAppTheme.colors.light,
textColor = ComposeAppTheme.colors.leah,
textStyle = ComposeAppTheme.typography.bodyItalic,
pasteEnabled = false,
singleLine = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.horizontalsystems.bankwallet.modules.send.ton

import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -23,11 +21,13 @@ import io.horizontalsystems.bankwallet.modules.amount.AmountInputModeViewModel
import io.horizontalsystems.bankwallet.modules.amount.HSAmountInput
import io.horizontalsystems.bankwallet.modules.availablebalance.AvailableBalance
import io.horizontalsystems.bankwallet.modules.fee.HSFee
import io.horizontalsystems.bankwallet.modules.memo.HSMemoInput
import io.horizontalsystems.bankwallet.modules.send.SendConfirmationFragment
import io.horizontalsystems.bankwallet.modules.send.SendScreen
import io.horizontalsystems.bankwallet.modules.sendtokenselect.PrefilledData
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryYellow
import io.horizontalsystems.bankwallet.ui.compose.components.VSpacer
import java.math.BigDecimal

@Composable
Expand Down Expand Up @@ -75,7 +75,7 @@ fun SendTonScreen(
rate = viewModel.coinRate
)

Spacer(modifier = Modifier.height(12.dp))
VSpacer(12.dp)
HSAmountInput(
modifier = Modifier.padding(horizontal = 16.dp),
focusRequester = focusRequester,
Expand All @@ -96,7 +96,7 @@ fun SendTonScreen(
)

if (uiState.showAddressInput) {
Spacer(modifier = Modifier.height(12.dp))
VSpacer(12.dp)
HSAddressInput(
modifier = Modifier.padding(horizontal = 16.dp),
initial = prefilledData?.address?.let { Address(it) },
Expand All @@ -110,7 +110,12 @@ fun SendTonScreen(
}
}

Spacer(modifier = Modifier.height(12.dp))
VSpacer(12.dp)
HSMemoInput(maxLength = 120) {
viewModel.onEnterMemo(it)
}

VSpacer(12.dp)
HSFee(
coinCode = viewModel.feeToken.coin.code,
coinDecimal = viewModel.feeTokenMaxAllowedDecimals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SendTonViewModel(
private var amountState = amountService.stateFlow.value
private var addressState = addressService.stateFlow.value
private var feeState = feeService.stateFlow.value
private var memo: String? = null

var uiState by mutableStateOf(
SendTonUiState(
Expand Down Expand Up @@ -110,7 +111,8 @@ class SendTonViewModel(
address = address,
contact = contact,
coin = wallet.coin,
feeCoin = feeToken.coin
feeCoin = feeToken.coin,
memo = memo,
)
}

Expand All @@ -122,12 +124,16 @@ class SendTonViewModel(
}
}

fun onEnterMemo(memo: String) {
this.memo = memo.ifBlank { null }
}

private suspend fun send() = withContext(Dispatchers.IO) {
try {
sendResult = SendResult.Sending
logger.info("sending tx")

adapter.send(amountState.amount!!, addressState.tonAddress!!)
adapter.send(amountState.amount!!, addressState.tonAddress!!, memo)

sendResult = SendResult.Sent
logger.info("success")
Expand Down Expand Up @@ -173,6 +179,7 @@ class SendTonViewModel(
fee = feeState.fee,
)
}

}

data class SendTonUiState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class TransactionInfoViewItemFactory(
TonTransactionRecord.Type.Unknown -> {
}
}
addMemoItem(transaction.memo, miscItemsSection)
}
is EvmIncomingTransactionRecord ->
itemSections.add(
Expand Down

0 comments on commit 041b422

Please sign in to comment.