Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dashevo/dash-wallet into …
Browse files Browse the repository at this point in the history
…dashpay-quick-voting
  • Loading branch information
HashEngineering committed Nov 20, 2024
2 parents 15142ab + 92d361c commit 3d351ef
Show file tree
Hide file tree
Showing 39 changed files with 274 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import retrofit2.HttpException
import java.io.IOException
import java.net.UnknownHostException
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import kotlin.math.pow
import kotlin.time.Duration
Expand All @@ -77,6 +78,7 @@ interface CrowdNodeApi {
suspend fun deposit(amount: Coin, emptyWallet: Boolean, checkBalanceConditions: Boolean): Boolean
suspend fun withdraw(amount: Coin): Boolean
suspend fun getWithdrawalLimit(period: WithdrawalLimitPeriod): Coin
suspend fun getFee(): Double
fun hasAnyDeposits(): Boolean
fun refreshBalance(retries: Int = 0, afterWithdrawal: Boolean = false)
fun trackLinkingAccount(address: Address)
Expand Down Expand Up @@ -342,6 +344,11 @@ class CrowdNodeApiAggregator @Inject constructor(
)
}

override suspend fun getFee(): Double {
refreshFees()
return config.get(CrowdNodeConfig.FEE_PERCENTAGE) ?: FeeInfo.DEFAULT_FEE
}

override fun hasAnyDeposits(): Boolean {
val accountAddress = this.accountAddress
requireNotNull(accountAddress) { "Account address is null, make sure to sign up" }
Expand Down Expand Up @@ -854,6 +861,22 @@ class CrowdNodeApiAggregator @Inject constructor(
}
}

/**
* obtains the current CrowdNode fee on masternode rewards once per 24 hours
*/
private suspend fun refreshFees() {
val lastFeeRequest = config.get(CrowdNodeConfig.LAST_FEE_REQUEST)
if (lastFeeRequest == null || (lastFeeRequest + TimeUnit.DAYS.toMillis(1)) < System.currentTimeMillis()) {
val feeInfo = webApi.getFees(accountAddress)
log.info("crowdnode feeInfo: {}", feeInfo)
val fee = feeInfo.getNormal()?.fee
fee?.let {
config.set(CrowdNodeConfig.FEE_PERCENTAGE, fee)
config.set(CrowdNodeConfig.LAST_FEE_REQUEST, System.currentTimeMillis())
}
}
}

private fun notifyIfNeeded(message: String, tag: String) {
if (showNotificationOnResult) {
notificationService.showNotification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ interface CrowdNodeEndpoint {
@Path("address") address: String
): Response<List<WithdrawalLimit>>

@GET("odata/apifundings/GetFeeJson(address='{address}')")
suspend fun getFees(
@Path("address") address: String
): Response<FeeInfo>

@GET("odata/apiaddresses/IsApiAddressInUse(address='{address}')")
suspend fun isAddressInUse(
@Path("address") address: String
Expand Down Expand Up @@ -269,6 +274,26 @@ open class CrowdNodeWebApi @Inject constructor(
}
}

open suspend fun getFees(address: Address?): FeeInfo {
return try {
val response = endpoint.getFees(address?.toBase58() ?: "")

return if (response.isSuccessful) {
response.body()!!
} else {
FeeInfo.default
}
} catch (ex: Exception) {
log.error("Error in getFees: $ex")

if (ex !is IOException) {
analyticsService.logError(ex)
}

FeeInfo.default
}
}

open suspend fun isApiAddressInUse(address: Address): Pair<Boolean, Address?> {
return try {
val result = endpoint.isAddressInUse(address.toBase58())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.dash.wallet.integrations.crowdnode.model

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.RawValue

data class FeeLadder(
val name: String,
val type: String,
val amount: Double,
val fee: Double
)

/*
[
{
"Key":"FeeLadder",
"Value":"[
{
\"name\":\"Up to 10 Dash and above\",
\"type\":\"Normal\",
\"amount\":10.0,\"fee\":35.0
},
{
\"name\":\"Trustless up to 100 Dash and above\",
\"type\":\"Trustless\",
\"amount\":100.0,
\"fee\":20.0
}
]"
}
]
*/
@Parcelize
data class FeeInfo(
@SerializedName("FeeLadder") val feeLadder: @RawValue List<FeeLadder>
) : Parcelable {
companion object {
const val DEFAULT_FEE = 35.0
const val DEFAULT_AMOUNT = 100.0
const val KEY_FEELADDER = "FeeLadder"
const val TYPE_NORMAL = "Normal"
const val TYPE_TRUSTLESS = "Trustless"
val default = FeeInfo(listOf(FeeLadder("", TYPE_NORMAL, DEFAULT_AMOUNT, DEFAULT_FEE)))
}

fun getNormal() = feeLadder.find { it.type == FeeInfo.TYPE_NORMAL }
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import org.dash.wallet.common.services.analytics.AnalyticsConstants
import org.dash.wallet.common.services.analytics.AnalyticsService
import org.dash.wallet.common.ui.BalanceUIState
import org.dash.wallet.integrations.crowdnode.api.CrowdNodeApi
import org.dash.wallet.integrations.crowdnode.model.FeeInfo
import org.dash.wallet.integrations.crowdnode.model.MessageStatusException
import org.dash.wallet.integrations.crowdnode.model.OnlineAccountStatus
import org.dash.wallet.integrations.crowdnode.model.SignUpStatus
Expand Down Expand Up @@ -118,6 +119,7 @@ class CrowdNodeViewModel @Inject constructor(
val crowdNodeBalance: LiveData<BalanceUIState>
get() = _crowdNodeBalance

private var crowdNodeFee: Double = FeeInfo.DEFAULT_FEE
val dashFormat: MonetaryFormat
get() = globalConfig.format.noCode()

Expand Down Expand Up @@ -164,6 +166,12 @@ class CrowdNodeViewModel @Inject constructor(
}
}
.launchIn(viewModelScope)

config.observe(CrowdNodeConfig.FEE_PERCENTAGE)
.onEach {
crowdNodeFee = it ?: FeeInfo.DEFAULT_FEE
}
.launchIn(viewModelScope)
}

fun backupPassphrase() {
Expand Down Expand Up @@ -413,6 +421,7 @@ class CrowdNodeViewModel @Inject constructor(
}

fun getCrowdNodeAPY(): Double {
return 0.85 * getMasternodeAPY()
val withoutFees = (100.0 - crowdNodeFee) / 100
return withoutFees * getMasternodeAPY()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.dash.wallet.integrations.crowdnode.utils

import android.content.Context
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.doublePreferencesKey
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
Expand Down Expand Up @@ -47,5 +48,7 @@ open class CrowdNodeConfig @Inject constructor(
val WITHDRAWAL_LIMIT_PER_HOUR = longPreferencesKey("withdrawal_limit_per_hour")
val WITHDRAWAL_LIMIT_PER_DAY = longPreferencesKey("withdrawal_limit_per_day")
val LAST_WITHDRAWAL_BLOCK = intPreferencesKey("last_withdrawal_block")
val FEE_PERCENTAGE = doublePreferencesKey("fee_double")
val LAST_FEE_REQUEST = longPreferencesKey("last_fee_request")
}
}
2 changes: 1 addition & 1 deletion wallet/res/layout/fragment_verfiy_identity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
android:ellipsize="middle"
android:gravity="center_vertical"
android:imeOptions="actionNext"
android:maxLength="75"
android:maxLength="128"
tools:visibility="visible" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down
34 changes: 2 additions & 32 deletions wallet/res/navigation/nav_username.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,9 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:startDestination="@id/createUsernameFragment"
app:startDestination="@id/requestUsernameFragment"
android:id="@+id/nav_username">

<fragment
android:id="@+id/createUsernameFragment"
android:name="de.schildbach.wallet.ui.username.CreateUsernameFragment"
tools:layout="@layout/fragment_create_username">

<argument
android:name="createUsernameFragmentArgs"
app:argType="de.schildbach.wallet.ui.username.CreateUsernameArgs" />

<action
android:id="@+id/create_username_to_username_privacy"
app:destination="@id/createUsernamePrivacyFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/activity_stay"
app:popExitAnim="@anim/slide_out_left" />

</fragment>

<fragment
android:id="@+id/createUsernamePrivacyFragment"
android:name="de.schildbach.wallet.ui.coinjoin.CoinJoinLevelFragment"
tools:layout="@layout/fragment_coinjoin_level">
<action
android:id="@+id/username_privacy_to_createUsernameFragment"
app:popUpTo="@+id/createUsernameFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/activity_stay"
app:popExitAnim="@anim/slide_out_left" />
</fragment>

<fragment
android:id="@+id/welcomeToDashPayFragment"
android:name="de.schildbach.wallet.ui.username.voting.WelcomeToDashPayFragment"
Expand Down Expand Up @@ -143,7 +113,7 @@
<fragment
android:id="@+id/usernameRegistrationFragment"
android:name="de.schildbach.wallet.ui.username.UsernameRegistrationFragment"
tools:layout="@layout/fragment_verfiy_identity">
tools:layout="@layout/fragment_username_registration">
</fragment>


Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-de/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ Benutzernamen</b></string>
<string name="coinjoin_mixing">Mixing</string>
<string name="coinjoin_paused">Mixing pausiert</string>
<string name="coinjoin_not_started">Nicht gestartet</string>
<string name="coinjoin_progress">%s (%d%%) %s von %s</string>
<string name="coinjoin_progress_balance">%1$s von %2$s</string>
<string name="coinjoin_progress_finished">Vollständig gemixt</string>
<string name="coinjoin_change_level_confirmation">Möchtest du die Einstellung der Privatsphäre wirklich ändern\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-el/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="coinjoin_mixing">Ανάμιξη</string>
<string name="coinjoin_paused">Ανάμειξη σε παύση</string>
<string name="coinjoin_not_started">Δεν ξεκίνησε</string>
<string name="coinjoin_progress">%s (%d%%) %s από %s</string>
<string name="coinjoin_progress_balance">%1$s από%2$s</string>
<string name="coinjoin_progress_finished">Πλήρως αναμεμειγμένα</string>
<string name="coinjoin_change_level_confirmation">Είστε σίγουροι ότι θέλετε να αλλάξετε το επίπεδο απορρήτου;</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-es/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ de Dash</b></string>
<string name="coinjoin_mixing">Mezclando</string>
<string name="coinjoin_paused">Mezcla en pausa</string>
<string name="coinjoin_not_started">No iniciado</string>
<string name="coinjoin_progress">%s (%d%%) %s of %s</string>
<string name="coinjoin_progress_balance">%1$s de %2$s</string>
<string name="coinjoin_progress_finished">Completamente mezclado</string>
<string name="coinjoin_change_level_confirmation">¿Estás seguro de que deseas cambiar el nivel de privacidad\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-fa/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@
<string name="coinjoin_mixing">در حال ترکیب</string>
<string name="coinjoin_paused">توقف موقت ترکیب</string>
<string name="coinjoin_not_started">شروع نشده</string>
<string name="coinjoin_progress">%s(%d%%) %s از %s</string>
<string name="coinjoin_progress_balance">%1$s از %2$s</string>
<string name="coinjoin_progress_finished">کاملا ترکیب شده</string>
<string name="coinjoin_change_level_confirmation">آیا مطمئن هستید که می‌خواهید سطح محرمانگی را تغییر دهید؟</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-fil/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ Username</b></string>
<string name="coinjoin_mixing">Paghahalo</string>
<string name="coinjoin_paused">Nakahinto ang Paghahalo</string>
<string name="coinjoin_not_started">Hindi Nagsimula</string>
<string name="coinjoin_progress">%s (%d%%) %s ng %s</string>
<string name="coinjoin_progress_balance">%1$s ng %2$s</string>
<string name="coinjoin_progress_finished">Ganap na Nahalo</string>
<string name="coinjoin_change_level_confirmation">Sigurado ka bang gusto mong baguhin ang antas ng privacy\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-fr/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
<string name="coinjoin_mixing">Mélange</string>
<string name="coinjoin_paused">Mélange mis en pause</string>
<string name="coinjoin_not_started">Non démarré</string>
<string name="coinjoin_progress">%s (%d%%) %s de %s</string>
<string name="coinjoin_progress_balance">%1$s de %2$s</string>
<string name="coinjoin_progress_finished">Entièrement mélangé</string>
<string name="coinjoin_change_level_confirmation">Souhaitez-vous vraiment modifier le niveau de confidentialité \?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-id/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ Dash</b> anda</string>
<string name="coinjoin_mixing">Pencampuran</string>
<string name="coinjoin_paused">Pencampuran Dijeda</string>
<string name="coinjoin_not_started">Tidak Dimulai</string>
<string name="coinjoin_progress">%s (%d%%) %s dari %s</string>
<string name="coinjoin_progress_balance">%1$s dari %2$s</string>
<string name="coinjoin_progress_finished">Tercampur Sepenuhnya</string>
<string name="coinjoin_change_level_confirmation">Apakah Anda yakin ingin mengubah tingkat privasi\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-it/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ Username</b></string>
<string name="coinjoin_mixing">Miscelazione</string>
<string name="coinjoin_paused">Miscelazione in pausa</string>
<string name="coinjoin_not_started">Non iniziato</string>
<string name="coinjoin_progress">%s (%d %% ) %s di %s</string>
<string name="coinjoin_progress_balance">%1$s di %2$s</string>
<string name="coinjoin_progress_finished">Completamente Miscelato</string>
<string name="coinjoin_change_level_confirmation">Sei sicuro di voler modificare il livello di privacy\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-ja/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@
<string name="coinjoin_mixing">ミキシング中</string>
<string name="coinjoin_paused">ミキシングを一時停止しました</string>
<string name="coinjoin_not_started">開始していません</string>
<string name="coinjoin_progress">%sの%s (%d%%) と%s</string>
<string name="coinjoin_progress_balance">%2$sの%1$s</string>
<string name="coinjoin_progress_finished">ミキシング完了しました</string>
<string name="coinjoin_change_level_confirmation">プライバシーレベルを変更してよろしいですか。</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-ko/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
<string name="coinjoin_mixing">믹싱</string>
<string name="coinjoin_paused">믹싱이 멈춰짐</string>
<string name="coinjoin_not_started">시작되지 않음</string>
<string name="coinjoin_progress">%s 중 %s (%d%%) %s</string>
<string name="coinjoin_progress_balance">%2$s 중 %1$s</string>
<string name="coinjoin_progress_finished">완전히 믹싱됨</string>
<string name="coinjoin_change_level_confirmation">정말 프라이버시 수준을 변경하시겠습니까\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-nl/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ gebruikersnaam</b></string>
<string name="coinjoin_mixing">Aan het mixen</string>
<string name="coinjoin_paused">mixen gepauzeerd </string>
<string name="coinjoin_not_started">Niet gestart</string>
<string name="coinjoin_progress">%s (%d%%) %s van %s</string>
<string name="coinjoin_progress_balance">%1$s van %2$s</string>
<string name="coinjoin_progress_finished">Volledig gemixt</string>
<string name="coinjoin_change_level_confirmation">Weet je zeker dat je het privacy niveau wilt wijzigen\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-pl/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@
<string name="coinjoin_mixing">Miksowanie</string>
<string name="coinjoin_paused">Miksowanie zostało zatrzywame</string>
<string name="coinjoin_not_started">Nie rozpoczęto</string>
<string name="coinjoin_progress">%s (%d%%) %s lub %s</string>
<string name="coinjoin_progress_balance">%1$s z %2$s</string>
<string name="coinjoin_progress_finished">Całkowicie wymieszane</string>
<string name="coinjoin_change_level_confirmation">Czy na pewno chcesz zmienić poziom prywatności\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-pt/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ Dash</b></string>
<string name="coinjoin_mixing">Misturando</string>
<string name="coinjoin_paused">Mistura Pausada</string>
<string name="coinjoin_not_started">Não iniciado</string>
<string name="coinjoin_progress">%s (%d%%) %s de %s</string>
<string name="coinjoin_progress_balance">%1$s de %2$s</string>
<string name="coinjoin_progress_finished">Totalmente Misturado</string>
<string name="coinjoin_change_level_confirmation">Tem certeza de que deseja mudar o nível de privacidade\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-ru/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ Dash</b></string>
<string name="coinjoin_mixing">Перемешивание</string>
<string name="coinjoin_paused">Перемешивание на паузе</string>
<string name="coinjoin_not_started">Не начато</string>
<string name="coinjoin_progress">%s (%d %%) %s из %s</string>
<string name="coinjoin_progress_balance">%1$s из %2$s</string>
<string name="coinjoin_progress_finished">Полностью перемешано</string>
<string name="coinjoin_change_level_confirmation">Уверены, что хотите изменить уровень приватности\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-sk/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ používateľské meno</b></string>
<string name="coinjoin_mixing">Miešanie</string>
<string name="coinjoin_paused">Miešanie pozastavené</string>
<string name="coinjoin_not_started">Nespustené</string>
<string name="coinjoin_progress">%s (%d%%) %s z %s</string>
<string name="coinjoin_progress_balance">%1$s z %2$s</string>
<string name="coinjoin_progress_finished">Plne zmiešané</string>
<string name="coinjoin_change_level_confirmation">Naozaj chcete zmeniť úroveň ochrany osobných údajov\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-tr/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@
<string name="coinjoin_mixing">Karıştırma</string>
<string name="coinjoin_paused">Karıştırma Duraklatıldı</string>
<string name="coinjoin_not_started">Başlamadı</string>
<string name="coinjoin_progress">%s (%d%%) %s / %s</string>
<string name="coinjoin_progress_balance">%1$s / %2$s</string>
<string name="coinjoin_progress_finished">Tamamen Karıştırılmış</string>
<string name="coinjoin_change_level_confirmation">Gizlilik düzeyini değiştirmek istediğinizden emin misiniz\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-uk/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@
<string name="coinjoin_mixing">Змішування</string>
<string name="coinjoin_paused">Змішування на паузі</string>
<string name="coinjoin_not_started">Не розпачато</string>
<string name="coinjoin_progress">%s(%d%%)%s з %s</string>
<string name="coinjoin_progress_balance">%1$s з %2$s</string>
<string name="coinjoin_progress_finished">Повністю змішано</string>
<string name="coinjoin_change_level_confirmation">Ви впевнені, що бажаєте змінити рівень конфіденційності\?</string>
Expand Down
1 change: 0 additions & 1 deletion wallet/res/values-zh-rTW/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@
<string name="coinjoin_mixing">混合</string>
<string name="coinjoin_paused">混合暫停</string>
<string name="coinjoin_not_started">尚未開始</string>
<string name="coinjoin_progress">%s (%d%%) %s of %s</string>
<string name="coinjoin_progress_balance">%1$s of %2$s</string>
<string name="coinjoin_progress_finished">充分混合</string>
<string name="coinjoin_change_level_confirmation">您確定要變更隱私等級嗎?</string>
Expand Down
Loading

0 comments on commit 3d351ef

Please sign in to comment.