Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class SignService : SignClient {
finalAmount = finalAmount,
fee = fee,
)
return listOf(getSigner(params).signWithdrawal(data, privateKey).toByteArray())
return getSigner(params).signStake(data, privateKey).map { it.toByteArray() }
}
override fun supported(chain: Chain): Boolean {
return when (chain.toChainType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ class DelegationViewModel @Inject constructor(
.stateIn(viewModelScope, SharingStarted.Eagerly, null)

fun onStake(call: AmountTransactionAction) {
call(buildStake(TransactionType.StakeDelegate))
buildStake(TransactionType.StakeDelegate)?.let { call(it) }
}

fun onUnstake(amountCall: AmountTransactionAction, confirmCall: ConfirmTransactionAction) {
val assetInfo = assetInfo.value ?: return
val delegation = delegation.value ?: return
if (assetInfo.chain.changeAmountOnUnstake) {
amountCall(buildStake(TransactionType.StakeUndelegate))
buildStake(TransactionType.StakeUndelegate)?.let { amountCall(it) }
return
}
val from = assetInfo.owner ?: return
Expand All @@ -189,7 +189,7 @@ class DelegationViewModel @Inject constructor(
}

fun onRedelegate(call: AmountTransactionAction) {
call(buildStake(TransactionType.StakeRedelegate))
buildStake(TransactionType.StakeRedelegate)?.let { call(it) }
}

fun onWithdraw(call: ConfirmTransactionAction) {
Expand All @@ -216,12 +216,14 @@ class DelegationViewModel @Inject constructor(
)
}

private fun buildStake(type: TransactionType): AmountParams {
private fun buildStake(type: TransactionType): AmountParams? {
val assetId = assetInfo.value?.asset?.id ?: return null
val delegation = delegation.value ?: return null
return AmountParams.buildStake(
assetId = assetInfo.value?.asset?.id!!,
assetId = assetId,
txType = type,
validatorId = delegation.value?.validator?.id,
delegationId = delegation.value?.base?.delegationId!!
validatorId = delegation.validator.id,
delegationId = delegation.base.delegationId,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ internal fun LazyListScope.stakeActions(
amountAction: AmountTransactionAction,
onRewards: () -> Unit
) {
if (actions.isEmpty()) {
return
}
item {
SubheaderItem(R.string.common_manage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.wallet.core.primitives.Delegation
import com.wallet.core.primitives.DelegationState
import com.wallet.core.primitives.TransactionType
import com.wallet.core.primitives.WalletType
import com.gemwallet.android.ext.isViewOnly
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -158,7 +159,7 @@ class StakeViewModel @Inject constructor(
onOpenDetail: (String, String) -> Unit,
onConfirm: ConfirmTransactionAction,
) {
if (delegation.base.state != DelegationState.AwaitingWithdrawal) {
if (walletType.value?.isViewOnly == true || delegation.base.state != DelegationState.AwaitingWithdrawal) {
onOpenDetail(delegation.validator.id, delegation.base.delegationId)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import com.wallet.core.primitives.Account
import com.wallet.core.primitives.AssetId
import com.wallet.core.primitives.Chain
import com.wallet.core.primitives.Wallet
import com.wallet.core.primitives.WalletType

fun Wallet.getAccount(chain: Chain): Account? {
return accounts.firstOrNull { it.chain == chain }
}

fun Wallet.getAccount(assetId: AssetId): Account? = getAccount(assetId.chain)
fun Wallet.getAccount(assetId: AssetId): Account? = getAccount(assetId.chain)

val WalletType.isViewOnly: Boolean get() = this == WalletType.View
val WalletType.canSign: Boolean get() = !isViewOnly
Loading